Mosel User Guide examples
This page lists all examples that are described in the 'Xpress Mosel User Guide'.
|
| A. Using the Mosel language |
|
| Introductory example |
|
|
| Chess - introductory LP model: LP model with solution output
|
| |
|
| Type: |
Production planning |
| Rating: |
1 (simple) |
| Description: |
Modeling a small LP problem (chess0.mos), completing the model with solving and solution output (chess.mos) |
| File(s): |
chess0.mos, chess.mos |
|
|
|
| Basic data handling tasks |
|
|
| Burglar - introductory MIP model: MIP model, string index set
|
| |
|
| Type: |
Knapsack problem |
| Rating: |
1 (simple) |
| Description: |
Modeling and solving a small MIP problem (burglar.mos), alternative version demonstrating the use of index sets of type string
(burglari.mos)
|
| File(s): |
burglar.mos, burglari.mos |
|
|
| Blend - data input from external sources: Accessing data sources (text, spreadsheets, databases)
|
| |
|
| Type: |
Blending problem |
| Rating: |
2 (easy-medium) |
| Description: |
This example is taken from the 'Mosel User Guide', Section 2.2. A blending example.
In many applications data are provided in the form of spreadsheets
or need to be extracted from databases. Mosel has facilities whereby the contents
of ranges within spreadsheets may be read into data tables and databases may
be accessed.
Mosel's ODBC interface (module mmodbc) may be used to read the data from databases. The ODBC technology is a generic means for accessing databases and some spreadsheets
such as certain versions of Microsoft Excel also support (a reduced set of) ODBC functionality. The ODBC interface can be
used in initializations blocks that automatically generate the required SQL statments and it is also possible to employ SQL statements directly in
Mosel models (see blend4.mos).
Mosel also provides specific
interfaces to Excel spreadsheets through the module mmsheet. These interfaces that support all basic tasks
of data exchange (model files blend3*.mos) should be used for working with Excel data.
- blend.mos: Reading data from text files (requires blend.dat or blendb.dat)
- blend2.mos: Using runtime parameters (requires blend.dat)
- blend3.mos: Reading data from an Excel spreadsheet, using the generic spreadsheet driver (requires blend.xls)
- blend3c.mos: Reading data in CSV format (requires blend.csv)
- blend3e.mos: Reading data from an Excel spreadsheet, using the excel I/O driver (requires blend.xls)
- blend4.mos: Reading data from a database (requires blend.mdb or blend.sqlite)
|
| File(s): |
blend.mos, blend2.mos, blend3.mos, blend3c.mos, blend3e.mos, blend4.mos, blend4a.mos |
| Data file(s): |
blend.dat, blendb.dat, blend.csv, blend.sqlite, blend.xls, blend.mdb |
|
|
| Initialization of multi-dimensional arrays: Initializing and accessing multi-dimensional array entries, array enumeration
|
| |
|
| Type: |
Data handling |
| Rating: |
1 (simple) |
| File(s): |
sp.mos |
|
|
|
See examples directory 'mosel/WhitePapers/MoselData' for a comprehensive set of data handling examples. |
|
| More advanced modeling features |
|
|
| Conditional creation of decision variables: use of 'exists', finalization of index sets
|
| |
|
| Type: |
Modelling: variable creation |
| Rating: |
2 (easy-medium) |
| Description: |
If an array of decision variables of type mpvar is created as a dynamic array then its entries must be created explicitly using the subroutine create (doesx.mos). It is recommended to add an explicit 'exists' condition in loops over sparse arrays to improve the performance
of the enumeration (doesx1.mos).
Through the automatic finalization mechanism or via an explicit call to finalize a dynamic set is turned into
a constant set, all subsequently declared arrays that are indexed by this set will be created as static arrays (doesx2.mos).
|
| File(s): |
doesx.mos, doesx1.mos, doesx2.mos |
| Data file(s): |
doesx.dat |
|
|
| Error handling: handling I/O errors during data input
|
| |
|
| Type: |
Error handling |
| Rating: |
2 (easy-medium) |
| Description: |
- errio.mos: Handling I/O errors during 'initializations' (requires errio.dat).
- readdataerr.mos: Reading data with custom I/O error handling (requires transprt.dat)
|
| File(s): |
errio.mos, readdataerr.mos |
| Data file(s): |
errio.dat, transprt.dat |
|
|
| Transport - Using dynamic arrays: dynamic arrays for data and decision variables
|
| |
|
| Type: |
Transportation problem |
| Rating: |
2 (easy-medium) |
| Description: |
Initializing dynamic data arrays from file; creation of the corresponding decision variable array entries. |
| File(s): |
transport.mos |
| Data file(s): |
transprt.dat |
|
|
| Reading sparse data from text files: initializations from, readln, diskdata
|
| |
|
|
| Integer Programming |
|
|
| Manpower planning - Defining SOS: SOS-1
|
| |
|
| Type: |
Resource-constrained project scheduling |
| Rating: |
3 (intermediate) |
| Description: |
Alternative formulations using either binary variables (pplan1.mos) or SOS-1 (pplan2.mos) |
| File(s): |
pplan1.mos, pplan2.mos |
|
|
| Purchase - Formulating piecewise linear functions: pwlin, pws, continuous piecewise linear function, piecewise linear segment, slope
|
| |
|
| Type: |
Purchasing with price breaks |
| Rating: |
3 (intermediate) |
| Description: |
Using the 'pwlin' construct for formulating continuous piecewise linear cost functions, showing 3 variants
- list of breakpoint coordinates
- list of slopes with list X-values of slope changes
- list of linear segments (using 'pws')
|
| File(s): |
purchase_pwl.mos, purchase_pwl_graph.mos |
| Data file(s): |
purchase.dat |
|
|
|
See examples directory 'mosel/Modeling' for further introductory MIP modeling examples. |
|
| Correcting errors in Mosel models |
|
|
| Correcting syntax errors: Syntax error correction, debugging
|
| |
|
| Type: |
LP problem |
| Rating: |
1 (simple) |
| Description: |
The first model (poerror1.mos) contains purposely introduced syntax errors that are corrected in the second (poerror2.mos). |
| File(s): |
poerror1.mos, poerror2.mos |
|
|
|
| B. Advanced language features |
|
| Flow control constructs |
|
|
| Using counters: Using and combining 'count' and 'as counter'
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Using 'count' and 'as counter' separately (count1.mos) or in combination (count2.mos). |
| File(s): |
count1.mos, count2.mos |
| Data file(s): |
count2.dat |
|
|
| Local declarations in with statements: Local declaration of entities, array aliasing
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Definition of 'with' statements for local declaration
of scalar and structured types, including for the enumeration of arrays with unnamed index sets.
|
| File(s): |
usingwith.mos |
|
|
| Largest common divisor: Using the 'while' loop
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Find the largest common divisor of two integer numbers
- recursive function calls
- if-then-elif-then-else statement
- alternative formulation using a 'while' loop
|
| File(s): |
lcdiv1.mos |
|
|
| Smallest and largest value: The 'if-then-elif-then' selection statement
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Find the smallest and the largest value in a set of integers
- use of round, random, min, max
- if-then-elif-then statement
|
| File(s): |
minmax.mos |
|
|
| Perfect numbers: Using the 'forall' loop
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
A perfect number is defined as a number for which the
sum of all the divisors adds up to the number itself.
This examples calculates all perfect numbers up to a given upper bound.
- nested 'forall' loops
- use of 'mod'
|
| File(s): |
perfect.mos |
|
|
| Sort an array of numbers: Nested loops: repeat-until, forall-do, while-do
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
The idea of the Shell sort algorithm is to first sort, by straight insertion, small groups of numbers. Then several small
groups are combined and sorted. This step is repeated until the whole list of numbers is sorted.
|
| File(s): |
shsort.mos |
|
|
|
| Arrays, sets, lists, records, and user types |
|
|
| Working with arrays: array initialization, indexation, sparse array, array dimensions, array size
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
- arraydef.mos: Defining arrays: sparse and dense arrays; deleting array entries; multiple indices; array access functions
- arrayinit.mos: Array initialization from a text file (requires arrayinit.dat)
- autoarray.mos: Working with automatic arrays
- chess2.mos: Indexing arrays by variables
|
| File(s): |
arraydef.mos, arrayinit.mos, autoarray.mos, chess2.mos |
| Data file(s): |
arrayinit.dat |
|
|
| Working with sets: set initialization, set operations, set comparison
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
- prime.mos: Working with sets
- setcomp.mos: Comparison operators for sets
- setops.mos: Performing set operations
|
| File(s): |
prime.mos, setcomp.mos, setops.mos |
|
|
| Working with lists: Lists: initialization, enumeration, operators, access functions
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
A series of examples showing some of Mosel's list handling functionality:
- definining lists and initializing lists with values (listinit.mos)
- enumeration and reversal of lists (listenum.mos)
- operators on lists (listops.mos)
- enumeration and reversal of lists (listenum.mos)
- list access functions (merging two ordered lists, listmerge.mos)
|
| File(s): |
listenum.mos, listinit.mos, listmerge.mos, listops.mos |
| Data file(s): |
listinit.dat |
|
|
| Eulerian circuit - working with lists: list operators, list handling routines
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
A Eulerian circuit is a closed circuit that uses every
given arc exactly once. The algorithm is implemented using
the data structure 'list', making use of list operators and list handling routines (splitting off list head or tail,
first occurrence of an element).
|
| File(s): |
euler.mos, eulerfct.mos |
| Data file(s): |
euler.dat |
|
|
| Working with records: Defining and initializing records
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
- defining records and arrays of records
- accessing record fields
- assigning values to record fields
- initialization with data from file
- defining records of records (recorddef2.mos)
- selecting record fields in initializations (recorddef2.mos)
|
| File(s): |
recorddef.mos, recorddef2.mos |
| Data file(s): |
recorddef.dat, recorddef2.dat |
|
|
| Definition of a network: Working with record data structures
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
- definition of a data structure to represent arcs in a network with source, sink, and other properties
- accessing the different record fields
- initialization of records with data from a text file
- selection of record fields in initializations (arcs2.mos)
- separate initialization of record fields (arcs3.mos)
- sets and lists of records, using type constructors (arcs4.mos)
- constant record definition, sets of constant records (arcs5.mos)
|
| File(s): |
arcs.mos, arcs2.mos, arcs3.mos, arcs4.mos, arcs5.mos |
| Data file(s): |
arcs.dat |
|
|
| User type definition: Defining a user type with a record
|
| |
|
| Type: |
Blending problem |
| Rating: |
3 (intermediate) |
| Description: |
Definition of a user type within a model to simplify the declaration of identical data structures |
| File(s): |
blend5.mos |
| Data file(s): |
blend.dat |
|
|
| Working with unions: defining unions, type any, specifying union type, initialization of unions from/to text format files, reference to operator
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
- uniondef.mos: Defining unions, assignment of values, retrieving type information, compatible union types in subroutine arguments
- unioninit.mos: Initializing unions from a text file (requires uniondata.dat), displaying type names
- unionops.mos: 'reference to' operator, accessing unions of array type (exists, create, delcell, reset)
|
| File(s): |
uniondef.mos, unioninit.mos, unionops.mos |
| Data file(s): |
uniondata.dat |
|
|
|
| Functions and procedures |
|
|
| Subroutines: Subroutine definition, overloading, recursive function calls, function return values, variable number of arguments, subroutine
references, mmreflect
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
- lcdiv2.mos: Recursive function calls
- primefct.mos: function returning a set
- qsort1.mos: 'forward' definition of subroutines
- qsort2.mos: Overloading of subroutines
- shsortfct.mos: Function returning an array
- subrout.mos: Local and global declarations, fixed and variable number of arguments
- reftosubr.mos: Working with subroutine references, using mmreflect functionality for retrieving and calling subroutines
|
| File(s): |
lcdiv2.mos, primefct.mos, qsort1.mos, qsort2.mos, shsortfct.mos, subrout.mos, reftosubr.mos |
|
|
|
| Output |
|
|
| Output formatting: real number format, text formatting
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
The printing format for real numbers may be changed individually with the functions strfmt, textfmt, formattext or by resetting the parameter REALFMT. The function strfmt may also be applied to strings, for instance to change the alignment of the text. |
| File(s): |
fo.mos, numformat.mos, transport2.mos, transport2t.mos |
| Data file(s): |
transprt.dat |
|
|
| Output of expressions: Using 'initializations to' with 'evaluation of'
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Initializations with evaluation of expressions (solution values, function calls). Version 2: 'array' operator, 2s: string
indices.
|
| File(s): |
initeval.mos, initeval2.mos, initeval2s.mos |
|
|
| Trio output: Text output formats: initializations to, free-format writeln, diskdata
|
| |
|
| Type: |
Programming |
| Rating: |
1 (simple) |
| Description: |
Three ways of writing data to a text file using different formats (initializations to, free-format writeln, diskdata) |
| File(s): |
trio_out.mos |
|
|
|
| Advanced Integer Programming tasks |
|
|
| Column generation for a cutting stock problem: Using 'sethidden', working with multiple problems
|
| |
|
| Type: |
Cutting stock problem |
| Rating: |
5 (difficult) |
| Description: |
- paper.mos: Column generation algorithm, using 'sethidden'
- papers.mos: Working with multiple problems within a single model
- papers_log.mos: papers.mos with detailed logging
|
| File(s): |
paper.mos, papers.mos, papers_log.mos |
|
|
| Cut-and-branch and branch-and-cut: Using the optnode callback, addcuts, storecuts and loadcuts, subroutine reference
|
| |
|
| Type: |
Office cleaning problem |
| Rating: |
5 (difficult) |
| Description: |
Solving a MIP by cut-and-branch or branch-and-cut: using the default functionality 'addcuts' for local cuts (clean.mos/cleanm.mos),
or alternatively using 'storecuts' and 'loadcuts' to obtain global cuts (cleansl.mos)
|
| File(s): |
clean.mos, cleanm.mos, cleansl.mos |
| Data file(s): |
clparam.dat, cldata.dat |
|
|
|
See examples directory 'mosel/Solving' for further examples of advanced MIP algorithms. |
|
| Extensions to Linear Programming |
|
|
| Pre-emptive Goal Programming: Changing constraint type, redefining the objective, configuring multiple objective solves
|
| |
|
| Type: |
Goal Programming, Multi-objective optimization |
| Rating: |
3 (intermediate) |
| Description: |
goalctrp.mos: pre-emptive Goal Programming with constraints
- (un)hiding constraints
- adding and deleting constraint terms
- getting solution information
- case statement
- use of procedures
goalobjp.mos: pre-emptive multi-objective optimization
- using the multi-objective solving functionality of Xpress Solver
- configuring multiple objectives via 'objconfig'
- specific solution reporting functionality per objective
|
| File(s): |
goalctrp.mos, goalobjp.mos |
|
|
| Solving a non-linear problem by recursion: Redefinition of constraints
|
| |
|
| Type: |
Nonlinear problem |
| Rating: |
4 (medium-difficult) |
| Description: |
- modifying constraint coefficients
- while statement
- basis in- and output and problem reloading
- setting/accessing optimiser parameters
- procedure
|
| File(s): |
recurse.mos |
|
|
|
| C. Working with the Mosel libraries |
|
| C |
|
|
| Basic embedding tasks: Compile/load/run models, retrieve information about model objects, redirect model output
|
| |
|
| Type: |
Embedding |
| Rating: |
2 (easy-medium) |
| Description: |
- ugcomp.c: Compiling a model into a BIM file (requires burglar2.mos, burglar.dat)
- ugcomptmp.c: Compiling a model into a BIM file saved in Mosel's temporary directory (requires burglar2.mos, burglar.dat)
- ugexec.c: Execute (compile/load/run) a model (requires burglar2.mos, burglar.dat)
- ugrun.c: Executing a BIM file (requires burglar2.bim, burglar.dat)
- ugdefstream.c: Redirecting the model output (requires burglar2.mos, burglar.dat)
- ugarray1.c, ugarray2.c: Accessing modeling objects: sparse arrays (requires transport.mos, transprt.dat)
- ugcb.c: Retrieve model output via a callback (requires burglar2.mos, burglar.dat)
- ugparam1.c, ugparam2.c: Passing parameters to a Mosel model (requires prime2.mos)
- ugsol1.c, ugsol2.c: Accessing modeling objects and solution information (requires burglar3.mos, burglar.dat)
|
| File(s): |
ugcomp.c, ugcomptmp.c, ugexec.c, ugrun.c, ugdefstream.c, ugarray1.c, ugarray2.c, ugcb.c, ugsol1.c, ugsol2.c, ugparam1.c, ugparam2.c, burglar2.mos, transport.mos, prime2.mos, burglar3.mos |
| Data file(s): |
burglar.dat, transprt.dat |
|
|
| In-memory data exchange: Data exchange during model execution
|
| |
|
| Type: |
Embedding |
| Rating: |
3 (intermediate) |
| Description: |
- ugiocb.c: Exchanging data between model and host application. Callbacks for exchanging data: sparse data, string indices (requires
burglar13.mos)
- ugiodense.c: Exchanging data between model and host application. Dense data (requires burglar6.mos)
- ugioscalar.c: Exchanging data between model and host application. Scalars (requires burglar12.mos)
- ugiosparse.c: Exchanging data between model and host application. Sparse data, string indices (requires burglar7.mos)
|
| File(s): |
ugiocb.c, ugiodense.c, ugioscalar.c, ugiosparse.c, burglar13.mos (submodel), burglar6.mos (submodel), burglar12.mos (submodel), burglar7.mos (submodel) |
|
|
| Switching to solving with Xpress Optimizer: Using the Xpress Optimizer library with Mosel
|
| |
|
| Type: |
Embedding |
| Rating: |
4 (medium-difficult) |
| Description: |
Passing from Mosel to solving with Xpress Solver (requires burglar4.mos, burglar.dat) |
| File(s): |
ugxprs1.c, ugxprs2.c, burglar4.mos |
| Data file(s): |
burglar.dat |
|
|
|
See examples directory 'mosel/Library' for further examples of working with the Mosel libraries. |
|
| Java |
|
|
| Basic embedding tasks: Compile/load/run models, retrieve information about model objects, redirect model output
|
| |
|
| Type: |
Embedding |
| Rating: |
2 (easy-medium) |
| Description: |
- ugcomp.java: Compiling a model into a BIM file (requires burglar2.mos, burglar.dat)
- ugcomptmp.java: Compiling a model into a BIM file saved in Mosel's temporary directory (requires burglar2.mos, burglar.dat)
- ugrun.java: Compiling a model into a BIM file, then load and run it (requires burglar2.bim, burglar.dat)
- ugdefstream.java: Redirecting the model output (requires burglar2.mos, burglar.dat)
- ugarray.java: Accessing modeling objects: sparse arrays (requires transport.mos, transprt.dat)
- ugcb.java: Retrieve model output via a callback (requires burglar2.mos, burglar.dat)
- ugparam.java: Passing parameters to a Mosel model (requires prime.mos)
- ugsol.java: Accessing modeling objects and solution information (requires burglar3.mos, burglar.dat)
|
| File(s): |
ugcomp.java, ugcomptmp.java, ugrun.java, ugdefstream.java, ugarray.java, ugcb.java, ugsol.java, ugparam.java, burglar2.mos, transport.mos, prime.mos, burglar3.mos |
| Data file(s): |
burglar.dat, transprt.dat |
|
|
| In-memory data exchange: Data exchange during model execution
|
| |
|
| Type: |
Embedding |
| Rating: |
3 (intermediate) |
| Description: |
- ugiocb.java: Exchanging data between model and host application. Callbacks for exchanging data: sparse data, string indices
(requires burglar13.mos)
- ugiodense.java: Exchanging data between model and host application. Dense data (requires burglar8.mos)
- ugioscalar.java: Exchanging data between model and host application. Scalars (requires burglar11.mos)
- ugiosparse.java: Exchanging data between model and host application. Sparse data, string indices (requires burglar9.mos)
- ugstreamdense.java: Exchanging data between model and host application
using Java streams. Dense data (requires burglar8s.mos)
- ugstreamsparse.java: Exchanging data between model and host application
using Java streams. Sparse data, string indices (requires burglar9s.mos)
- ugstreamdensescrmt.java: Exchanging data between a remote model (started from another model that acts as intermediate) and
a Java host application
using Java streams. Dense data (requires runburglar8sdc.mos and burglar8sdc.mos)
|
| File(s): |
ugiocb.java, ugiodense.java, ugioscalar.java, ugiosparse.java, ugstreamdense.java, ugstreamsparse.java, ugstreamdensescrmt.java, burglar13.mos (submodel), burglar11.mos (submodel), burglar8.mos (submodel), burglar8s.mos (submodel), runburglar8sdc.mos (submodel), burglar8sdc.mos (submodel), burglar9.mos (submodel), burglar9s.mos (submodel) |
|
|
|
| VBA |
|
|
| Basic embedding tasks: Compile/load/run models, redirect model output
|
| |
|
| Type: |
Embedding |
| Rating: |
2 (easy-medium) |
| Description: |
- ugvb.xls: Compiling a model into a BIM file, then load and run it. Passing parameters to a Mosel program (requires burglar5.mos,
burglar.dat, prime4.mos, ugvb.bas)
- ugcb.xls: Redirecting Mosel output and error streams to a callback (requires burglar10.mos, burglar.dat, ugcb.bas)
|
| File(s): |
burglar5.mos, burglar10.mos, prime4.mos |
| Data file(s): |
ugvb.xls, ugcb.xls, burglar.dat, ugvb.bas, burglar.dat, ugcb.bas |
|
|
|
| C# |
|
|
| Basic embedding tasks: Compile/load/run models, retrieve information about model objects, redirect model output
|
| |
|
| Type: |
Embedding |
| Rating: |
2 (easy-medium) |
| Description: |
- ugcomptmp.cs: Compiling a model into a BIM file saved in Mosel's temporary directory (requires burglar2.mos, burglar.dat)
- ugrun.cs: Compiling a model into a BIM file, then load and run it (requires burglar2.bim, burglar.dat)
- ugdefstream.cs: Redirecting the model output (requires burglar2.mos, burglar.dat)
- ugarray.cs: Accessing modeling objects: sparse arrays (requires transport.mos, transprt.dat)
- ugcb.cs: Retrieve model output via a callback into a custom TextWriter (requires burglar2.mos, burglar.dat)
- ugcb2.cs: Retrieve model output via a callback into a string (requires burglar2.mos, burglar.dat)
- ugparam.cs: Passing parameters to a Mosel model (requires prime.mos)
- ugsol.java: Accessing modeling objects and solution information (requires burglar3.mos, burglar.dat)
|
| File(s): |
ugcomptmp.cs, ugcomptmp.csproj, ugrun.cs, ugrun.csproj, ugdefstream.cs, ugdefstream.csproj, ugarray.cs, ugarray.csproj, ugcb.cs, ugcb.csproj, ugcb2.cs, ugcb2.csproj, ugsol.cs, ugsol.csproj, ugparam.cs, ugparam.csproj, burglar2.mos, transport.mos, prime.mos, burglar3.mos |
| Data file(s): |
burglar.dat, transprt.dat |
|
|
| In-memory data exchange: Data exchange during model execution
|
| |
|
| Type: |
Embedding |
| Rating: |
3 (intermediate) |
| Description: |
- ugiocb.cs: Exchanging data between model and host application. Callbacks for exchanging data: sparse data, string indices
(requires burglar13.mos)
- ugiodense.cs: Exchanging data between model and host application. Dense data (requires burglar8d.mos)
- ugioscalar.cs: Exchanging data between model and host application. Scalars (requires burglar11.mos)
- ugiosparse.cs: Exchanging data between model and host application. Sparse data, string indices (requires burglar9d.mos)
- ugdatastream.cs: Exchanging data between model and host application
using a DataStream. Sparse data, string indices (requires burglar13.mos)
|
| File(s): |
ugiocb.cs, ugiocb.csproj, ugiodense.cs, ugiodense.csproj, ugioscalar.cs, ugioscalar.csproj, ugiosparse.cs, ugiosparse.csproj, ugdatastream.cs, ugdatastream.csproj, burglar13.mos (submodel), burglar8d.mos (submodel), burglar11.mos (submodel), burglar9d.mos (submodel) |
|
|
|
|
| Debugger and profiler |
|
|
| Using the debugger and profiler: Debugging and profiling commands, parallel debugging
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
The Mosel debugger and profiler may be used either through Xpress Workbench or from the Mosel command line. The model prime2.mos shows typical debugging and profiling command sequences. The model prime3.mos is a more efficient re-formulation of the same algorithm. The model runprime2d.mos shows a debugging command sequence for a submodel started from this model.
- prime2.mos: Debugging and profiling commands
- runprime2d.mos: Parallel debugging (requires prime2d.mos)
- prime3.mos: Prime number algorithm for large limit values
|
| File(s): |
prime2.mos, prime3.mos, runprime2d.mos, prime2d.mos |
|
|
| Checking memory usage: Using sparse arrays, dynamic array, ahsmap array
|
| |
|
| Type: |
Transportation |
| Rating: |
2 (easy-medium) |
| Description: |
Model efficiency may be measured in terms of model
execution time and memory usage. The latter can be obtained with the help of the lsmods and info commands of the Mosel command line editor as shown by the example flow.mos that demonstrates the use of sparse arrays (flow.mos: dynamic arrays, flowh.mos: hashmap array) to reduce the size of tables.
|
| File(s): |
flow.mos, flowh.mos |
| Data file(s): |
flow.dat |
|
|
|
| Packages |
|
|
| Writing packages: definition of constant symbols, subroutines, types, and parameters: Implementing subroutines, overloading, using packages
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
Packages are libraries written in the Mosel language
that extend the language with
- constant symbols (myconstants.mos)
- subroutines (definition of several overloaded versions of a procedure in solarraypkg.mos, generic implementation using union
types and iterator in solarrayanypkg.mos)
- types (definition of a structure 'arc' to represent arcs in a network with a function to access information: arcpkg.mos)
- parameters (definition of real/integer/string/boolean valued package parameters: parpkg.mos)
|
| File(s): |
myconstants.mos (library, compile separately), myconst_test.mos, solarraypkg.mos (library, compile separately), solarrpkg_test.mos, solarrayanypkg.mos (library, compile separately), solarranypkg_test.mos, arcpkg.mos (library, compile separately), arc_test.mos, parpkg.mos (library, compile separately), params_test.mos |
| Data file(s): |
arcs.dat |
|
|
| Namespace definition: Implementing packages, defining namespaces, namespace search, namespace groups
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
A namespace denotes a group of identifiers in a program that is distinguished by a common name (prefix). A fully qualified entity name in Mosel is of the form nspc~ident where nspc is a namespace name and ident an identifier in the namespace. The use of namespaces can help structure data when working with multiple packages.
|
| File(s): |
mynspkg1.mos (library, compile separately), mynspkg2.mos (library, compile separately), myns_test.mos |
|
|
| Package version management: Implementing packages, version management, deprecation, annotations
|
| |
|
| Type: |
Programming |
| Rating: |
3 (intermediate) |
| Description: |
A package can define annotations to overwrite Mosel's default version compatibility rules, specifying minimum required versions,
initial versions, or deprecation versions.
|
| File(s): |
versionedpkg_v1.mos (library, compile separately), versionedpkg_v2.mos (library, compile separately), versionedpkg.mos (library, compile separately), versionedpkg_test.mos |
|
|
|
See examples directory 'mosel/Module' for further examples of working with packages. |
|
| Language extensions - I/O drivers |
|
|
| Language extensions - Distributed and concurrent models |
|
|
| Runprime - Running a submodel: Local and remote submodel execution, in-memory data exchange
|
| |
|
| Type: |
Distributed computing |
| Rating: |
3 (intermediate) |
| Description: |
- runprime.mos: Running a submodel (requires prime.mos)
- runprime2.mos: Submodel handling, compiling to memory (requires prime.mos)
- runprimedistr.mos: Distributed computing: Running a model on a remote Mosel instance (requires prime.mos or prime3.mos)
- runprimeio.mos: Data exchange via shared memory, using 'bin' and 'shmem' drivers (requires primeio.mos or prime3io.mos)
- runprimeior.mos: Data exchange via shared memory, using 'raw' and 'shmem' drivers (requires primeior.mos or prime3ior.mos)
|
| File(s): |
runprime.mos, prime.mos, runprime2.mos, runprimedistr.mos, prime3.mos, runprimeio.mos, primeio.mos (submodel), prime3io.mos (submodel), runprimeior.mos, primeior.mos (submodel), prime3ior.mos (submodel) |
|
|
|
See examples directories 'mosel/WhitePapers/MoselPar' and 'mosel/Distrib' for further examples of parallel and distributed
solving with Mosel.
|
|
| Language extensions - Graphics and GUIs |
|
|
| Transport - data formats for online use: XML and JSON data formats, generation of HTML
|
| |
|
| Transport - Insight GUI, user graph:
|
| |
|
| Type: |
Transportation problem |
| Rating: |
3 (intermediate) |
| Description: |
- transport_insight.zip: Xpress Insight application (includes transport_insight.mos, transportdata.vdl, transportcustsel.vdl,
transportres.vdl, transportressum.vdl, transprt.dat, transport_insight.xml)
- transport_graph.mos: Graphical solution output with mmsvg (requires transprt.dat)
|
| File(s): |
transport_insight.mos, transportdata.vdl, transportcustsel.vdl, transportres.vdl, transportressum.vdl, transport_insight.xml, transport_graph.mos |
| Data file(s): |
transport_insight.zip, transprt.dat |
|
|
|
See examples directory 'insight' for further examples of working with Xpress Insight, directories 'mosel/Graphing' for graphing
examples, and 'mosel/Programming' for XML.
|
|
| Language extensions - Solvers |
|
|
| Nonlinear Programming: Formulating nonlinear constraints, graphical representation
|
| |
|
| Type: |
Nonlinear |
| Rating: |
2 (easy-medium) |
| Description: |
- airport.mos, airport_graph.mos: QCQP problem (requires airport.dat); user graph drawing
- fin_nl.mos: Nonlinear problem (determine interest rates over multiple time periods)
|
| File(s): |
airport.mos, airport_graph.mos, fin_nl.mos |
| Data file(s): |
airport.dat |
|
|
| Constraint Programming: Stating a CP problem, using 'equiv' and 'maximum'
|
| |
|
| Type: |
Bin packing |
| Rating: |
1 (simple) |
| Description: |
Stating and solving a discrete problem as finite domain CP problem using Xpress Kalis. |
| File(s): |
d4backup_ka.mos |
| Data file(s): |
d4backup.dat |
|
|
|
See examples directories 'mosel/NonLinear' and 'solver/kalis' for further NLP and CP model examples respectively. |
|
| Language extensions - Types |
|
|
| Date and time types: Types 'date', 'datetime', 'time'; initialization and conversion routines; constant declaration
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
Working with dates and times: initialization from text data files, conversion routines and access functions, sorting lists
of dates or times, using sets of constant dates or times as array index.
|
| File(s): |
dates.mos, dates2.mos |
| Data file(s): |
datetime.dat, datetime2.dat |
|
|
| Text handling and regular expressions: Types 'text', 'textarea', 'parsectx'; text parsing
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
- parsectx.mos: Parsing with parser contexts
- regex.mos: Regular expression matching and replacement
|
| File(s): |
parsectx.mos, regex.mos |
|
|
|
| Annotations |
|
|
| Defining and retrieving annotations: Accessing annotations from a model or host application
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
- annottest.mos: Defining and accessing annotations
- annotdisplay.c: Retrieving annotations into a C program (requires annottest.mos)
- annotdisplay.java: Retrieving annotations into a Java program (requires annottest.mos)
|
| File(s): |
annottest.mos, annotdisplay.c, annotdisplay.java |
|
|
| Using documentation annotations: Using documentation annotations, moseldoc tool
|
| |
|
| Type: |
Programming |
| Rating: |
2 (easy-medium) |
| Description: |
The file annotdoc.mos contains some examples of how to define documentation annotations. The model needs to be compiled with
the option '-D' to make sure that the resulting BIM file contains the documentation annotations. As a second step, apply the
tool 'moseldoc' to this BIM file to obtain a subdirectory with the model documentation in HTML format, for example using the
command moseldoc annotdoc.bim
|
| File(s): |
annotdoc.mos |
|
|
|
| E. Remote invocation of Mosel |
|
| XPRD C and XPRD Java |
|
|
| Runprime - Remote model execution: Remote model execution, data exchange between remote nodes
|
| |
|
| Type: |
Distributed Computing |
| Rating: |
3 (intermediate) |
| Description: |
- runprimedistr.c, runprimedistr.java, runprimedistr.mos: Running a model on a remote Mosel instance (requires prime.mos)
- runprimeiodistr.c, runprimeiodistr.java: Running a model on a remote Mosel instance and retrieving output data: data saved
to file or in memory on the remote machine (requires primeio.mos)
- runprimeiodistr2.c, runprimeiodistr2.java: Running a model on a remote Mosel instance and retrieving output data: data saved
in memory on the local machine. Implementation of a file manager for data exchange in memory (requires primeio.mos)
- runprimeiodistr3.c, runprimeiodistr3.java: Running a model on a remote Mosel instance and retrieving output data: data saved
to a file on the local machine (requires primeio.mos)
- runprimeiodistr.mos: mmjobs implementation. Running a model on a remote Mosel instance and retrieving output data (requires primeio.mos)
|
| File(s): |
runprimedistr.c, runprimedistr.java, runprimedistr.mos, prime.mos (submodel), runprimeiodistr.c, runprimeiodistr.java, runprimeiodistr.mos, primeio.mos (submodel), runprimeiodistr2.c, runprimeiodistr2.java, runprimeiodistr3.c, runprimeiodistr3.java |
|
|
|
See examples directories 'mosel/Extra' and 'mosel/WhitePapers/MoselPar/XPRD' for further examples of XPRD programs. |
|
|
|