Packages
A package is a library written in the Mosel language (this feature is introduced by Mosel 2.0). Its structure is similar to models, replacing the keyword model by package. Packages are included into models with the uses statement for dynamic loading (the package BIM needs to be present for model execution), in the same way as this is the case for modules (DSO). Alternatively, packages can be loaded statically via imports in which case they get included in the model BIM file (this option is not available for modules that are always dynamic). Unlike Mosel code that is included into a model with the include statement, packages are compiled separately, that is, their contents are not visible to the user.
Typical uses of packages include
- development of your personal `tool box'
- model parts (e.g., reformulations) or algorithms written in Mosel that you wish to distribute without disclosing their contents
- add-ons to modules that are more easily written in the Mosel language
Packages may define new constants, subroutines, types, and parameters for the Mosel language as shown in the following examples (the first two examples correspond to the first two module examples of the Mosel Native Interface User Guide).
Please note the following:
- Package name: compiling a package will result in a file packagename.bim. This package is invoked in a Mosel model by the statement
uses "packagename"
The name of the Mosel package source file (.mos file) may be different from the name given to the BIM file. - Internal package name: the name given in the Mosel file after the keyword package is the internal name of the package. It must be a valid Mosel identifier (and not a string). This name may be different from the name given to the BIM file, but it seems convenient to use the same name for both.
- Package location: for locating packages Mosel applies similar rules as for locating modules; it first uses the list of prefixes defined by the compiler option -bx or the environment variable MOSEL_BIM, it then searches in the directory dso of the Xpress installation (see Section 2.3.1 Directive uses of the Mosel Language Reference for further detail), and in the directories pointed to by the environment variable MOSEL_DSO. The contents of the enviroment variables MOSEL_BIM and MOSEL_DSO can be set freely by the user.
To try out the package examples in this chapter, you may simply include the current working directory ('.') in the locations pointed to by MOSEL_DSO, so that packages in the current working directory will be found, for example:
Windows: set MOSEL_DSO=.
Unix/Linux, C shell: setenv MOSEL_DSO .
Unix/Linux, Bourne shell: export MOSEL_DSO; MOSEL_DSO=.
Alternatively, you can use the compilation option -bx to indicate the location of package files (this option does not apply to DSOs):
mosel exe -bx ./ mymodel.mos
In general, and in particular for the deployment of an application, it is recommended to work with absolute paths in the definition of environment variables.