Vous êtes sur la page 1sur 9

GETTING STARTED with Xpress-MP

1. Xpress-MP Software Installation

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


http://optimization.fico.com/student-version-of-fico-xpress.html
http://www.dashoptimization.com/cgi-bin/download/evaluation.pl?action=student_request
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.
Select
Mosel
Type

Click here to
change file
Type new location
file name
here

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-
GETTING STARTED with Xpress-MP

1. Click here
to close the
newly
MODEL created file
EDITOR

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"
declarations
a: mpvar
b: mpvar
end-declarations

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


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

maximize(profit)
writeln("Profit is ", getobjval)
end-model

-2-
GETTING STARTED with Xpress-MP

Use model to begin


your model, and end-
model to end your
model

Uses mmxprs is to
load the solver
algorithm to solve LP
models.

declarations and end-


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

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
function.

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

This means that the maximum profit = 171.429.

-3-
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-
GETTING STARTED with Xpress-MP

4. Implementing Formulation with Summation Operation and Binary Variable

Consider the following mathematical formulation: (Knapsack Problem)

8
Maximize MaxValue = X
i =1
i * Valuei

such that
8
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
XPressMP/examples/mosel/extra/modeling/burg.mos

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

-5-
GETTING STARTED with Xpress-MP

The solution is as follows:

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

-6-
GETTING STARTED with Xpress-MP

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

-7-
GETTING STARTED with Xpress-MP

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
D5:D12.

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
end-initializations

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]"
end-initializations

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.