Initializing help system before first use

Solving the chess set problem

The Chess Set problem can be solved easily using Mosel. The first stage is to get the model we have just developed into the syntax of the Mosel language. Remember that we use the notation that items in italics (for example, small) are the mathematical variables. The corresponding Mosel variables will be the same name in non-italic courier (for example, small).

We illustrate this simple example by using the command line version of Mosel. The model can be entered into a file named, perhaps, chess.mos as follows:

model "Chess"
 declarations
  small: mpvar                       ! Number of small chess sets to make
  large: mpvar                       ! Number of large chess sets to make
 end-declarations

 Profit:=  5*small + 20*large        ! Objective function
 Lathe:=   3*small + 2*large <= 160  ! Lathe-hours
 Boxwood:=   small + 3*large <= 200  ! kg of boxwood
end-model

Indentations are purely for clarity. The symbol ! signifies the start of a comment, which continues to the end of the line. Comments over multiple lines start with (! and terminate with !).

Notice that the character `*' is used to denote multiplication of the decision variables by the units of machine time and wood that one unit of each uses in the Lathe and Boxwood constraints.

The modeling language distinguishes between upper and lower case, so Small would be recognized as different from small.

Let's see what this all means.

A model is enclosed in a model / end-model block.

The decision variables are declared as such in the declarations / end-declarations block. Every decision variable must be declared. LP, MIP and QP variables are of type mpvar. Several decision variables can be declared on the same line, so

 declarations
  small, large: mpvar
 end-declarations

is exactly equivalent to what we first did. By default, Mosel assumes that all mpvar variables are constrained to be non-negative unless it is informed otherwise, so there is no need to specify non-negativity constraints on variables.

Here is an example of a constraint:

Lathe:=   3*small + 2*large <= 160

The name of the constraint is Lathe. The actual constraint then follows. If the `constraint' is unconstrained (for example, it might be an objective function), then there is no <=, >= or = part.

In Mosel you enter the entire model before starting to compile and run it. Any errors will be signaled when you try to compile the model, or later when you run it (see Chapter Correcting errors in Mosel models on correcting syntax errors).

Obtaining a solution using Mosel

So far, we have just specified a model to Mosel. Next we shall try to solve it. The first thing to do is to specify to Mosel that it is to use Xpress Optimizer to solve the problem. Then, assuming we can solve the problem, we want to print out the optimum values of the decision variables, small and large, and the value of the objective function. The model becomes

model "Chess (completed)"
 uses "mmxprs"                       ! We shall use Xpress Optimizer</p>

 declarations
  small,large: mpvar                 ! Decision variables: produced quantities
 end-declarations

 Profit:=  5*small + 20*large        ! Objective function
 Lathe:=   3*small + 2*large <= 160  ! Lathe-hours
 Boxwood:=   small + 3*large <= 200  ! kg of boxwood

 maximize(Profit)                    ! Solve the problem

 writeln("Make ", getsol(small), " small sets")
 writeln("Make ", getsol(large), " large sets")
 writeln("Best profit is ", getobjval)
end-model

The line

 uses "mmxprs"

tells Mosel that Xpress Optimizer will be used to solve the LP. The Mosel modules mmxprs module provides us with such things as maximization, handling bases etc.

The line

 maximize(Profit)

tells Mosel to maximize the objective function called Profit.

More complicated are the writeln statements, though it is actually quite easy to see what they do. If some text is in quotation marks, then it is written literally. getsol and getobjval are special Mosel functions that return respectively the optimal value of the argument, and the optimal objective function value. writeln writes a line terminator after writing all its arguments (to continue writing on the same line, use write instead). writeln can take many arguments. The statement

 writeln("small: ", getsol(small), " large: ", getsol(large) )

will result in the values being printed all on one line.

Running Mosel from a command line

When you have entered the complete model into a file (let us call it chess.mos), we can proceed to get the solution to our problem. We start Mosel at the command prompt by typing the following command

mosel execute chess.mos

and we will see output something like that below.

Make 0 small sets
Make 66.6667 large sets
Best profit is 1333.33

The Mosel command for executing the model can be abbreviated to

mosel exec chess

or simply

mosel chess

The model execution performed by the command execute comprises three stages:

  1. Compiling chess.mos
  2. Loading the compiled model
  3. Running the model we have just loaded.

Instead of using execute, we can choose to explicitly generate the compiled model file chess.bim

mosel compile chess.mos

followed by

mosel run chess.bim

to load and run the compiled model.

Using Xpress Workbench

Under Microsoft Windows you may also use Xpress Workbench, a development studio type environment for working with your Mosel models. Xpress Workbench is a complete modeling and optimization development environment that presents Mosel in an easy-to-use Graphical User Interface (GUI), with a built-in text editor.

To execute the model file chess.mos you need to carry out the following steps.

  • Start up Workbench.
  • Open the model file by choosing File » Open. The model source is then displayed in the central window (the Workbench Editor).
  • Click the Run button MoselUG/butrun.png at the top of the window, making sure that the desired filename is selected in the input field to its left, or alternatively, choose Run » Run chess.mos.

The resulting screen display is shown in Figure Xpress Workbench screen after running chess.mos.

MoselUG/chesswb.png

Figure 2.1: Xpress Workbench screen after running chess.mos

The logging pane at the bottom of the workspace is automatically displayed when compilation starts. If syntax errors are found in the model, they are displayed here, with details of the line and character position where the error was detected and a description of the problem, if available. If the model has been compiled successfully, this pane displays the output produced by running the model.

If the model is run in debug mode by selecting the Debug button MoselUG/butdebug.png Workbench makes all information about the solution available through the Debugger pane on the right border of the workspace window. By expanding the Variables entry in this pane, the solution and reduced cost values for decision variables are displayed. Dual and slack values for constraints may also be obtained.

MoselUG/chesswbdbg.png

Figure 2.2: Running chess.mos with Xpress Workbench in debug mode


© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.