Vous êtes sur la page 1sur 9


1. Xpress-MP Software Installation

Download Xpress-MP (Student Version) by going to the following web page.

Press Ctrl key and click on the above link or just copy and paste onto your Internet browser.

Submit all the necessary information, and wait for the password email to arrive almost immediately.

Proceed to download and install Xpress-MP.

2. Getting Started with Xpress-MP

Once installed, a program named Xpress-IVE will be located under Xpress-MP folder from your start
menu. Click on Xpress-IVE and be sure to read the license agreement before clicking on I agree. The
program takes a few seconds to load, so do not panic.

2.1 Creating a mosel file

Click File then New then the following window will appear.

Click here to
change file
Type new location
file name

Type in a file name (sample) for your model, and select Mosel Type. Change the Absolute path to
wherever you want to store your new file. Leaving the suggested path unchanged is preferable. The
following window will then appear:


1. Click here
to close the
MODEL created file

Now you have successfully created a new mosel program file. This file under normal circumstances can
not be edited because it has Read-only property.

Procedure to resolve this Read-only problem:

1. Close the file that you have just created
2. Click File and Open that same file
3. If you still cannot type in the model editor then check your file to make sure it does not have
Read-only property on.

Once you are able to type in the model editor. Type the following model:
model simple
uses "mmxprs"
a: mpvar
b: mpvar

first:= 3*a + 2*b <=400

second:= a + 3*b <=200
profit:= a + 2*b

writeln("Profit is ", getobjval)


Use model to begin

your model, and end-
model to end your

Uses mmxprs is to
load the solver
algorithm to solve LP

declarations and end-

declarations encloses
the variables that the
model uses. mpvar
simply means that
they are continuous

All the constraints and

the objective function
must have a single
word name.
Then you have to
declare whether to
maximize or to
When you click the Run Button, the following window will appear: minimize the objective

writeln(whatever you
want to appear,
getobjval). getobjval
returns the value of the
objective function.

This means that the maximum profit = 171.429.

GETTING STARTED with Xpress-MP You can also see the values of the data
and variables by clicking on the
appropriate identifiers in the "Entities" tab
3. Getting More Detail Solution on the left window pane.
The following expressions will help you model:
getsol(mpvar) returns the value of mpvar solution.
getdual(constraint) returns the value of an additional resource of the constraint.

Incorporate these expressions into our model.

The solution will be as shown.


4. Implementing Formulation with Summation Operation and Binary Variable

Consider the following mathematical formulation: (Knapsack Problem)

Maximize MaxValue = X
i =1
i * Valuei

such that
MaxWeight = X
i =1
i * Weight i < WTMAX

X i : Binary

The data is the following:

WTMAX = 102

Item 1 2 3 4 5 6 7 8
Value 15 100 90 60 40 15 10 1
Weight 2 20 20 30 40 30 60 10

In order to implement this formulation into mosel we will need to learn the following concepts:

Declare an array of real number variables such as Weight (i) and Value(i)
Declare an array of decision variables such as X(i)
Declare range variables such as Items=1..8
Declare constants
Input data for real numbers variables
Correct way to declare summation operation such as sum(i:=1 in Items) Weight(i) * X(i)
Incorporate for loop statement by using keyword: forall
Declaring binary variables by using keyword: is_binary

The mosel model for this burglar problem is given when you install XpressMP, as

The following window will appear when you load burg.mos file.


The solution is as follows:

This means that items 1,2,3,4, and 6 are taken and their total value is 280.


5. Initialize data from external data file

From the previous burglar problem we will now read data from an external data file. The advantage of
this practice is that we will make the mosel model code more compact and more professional.

Use notepad to create a data file with the following lines in the same directory as the mosel file and
name it burg.dat

! Data file for burg.mos

WTMAX: 102
VALUE: [ 15 100 90 60 40 15 10 1]
WEIGHT: [ 2 20 20 30 40 30 60 10]

Notice the data file does not contain coma (,) between each data point.

Your new mosel code need the following changes as pointed by Dotted POINTER


6. Initialize data from Excel

For the previous burglar problem we will now read data from an external Excel file.
Suppose we have the following Excel file (burg.xls) which has the data:

Note that WTMAX data is in the cell B2, VALUE

data is in cells C5:C12 and WEIGHT data is in cells

The new Mosel code is as follows (the dotted boxes highlight the changes):
Here are the key changes:

Add uses mmodbc to the top of the file to tell XPRESS to communicate with Excel
After the declarations section you need an initializations section:

initializations from mmodbc.odbc:burg.xls

.. see next bullet

Inside the initializations section you need to tell it what cells have the data in the
Excel file. For example, in the file burg.xls WTMAX data is in the cell B2, VALUE
data is in cells C5:C12 and WEIGHT data is in cells D5:D12, so we write:

initializations from "mmodbc.odbc:burg.xls"

WTMAX as "[B1:B2]"
VALUE as "[C4:C12]"
WEIGHT as "[D4:D12]"

Notice that each initialization starts one cell above where the data is. Thats an Xpress
quirk. I dont know why its set up that way, but it is to get the right data, you always
have to start reading from one cell higher than the datas location.