Consider the following problem:
300 boxes need to be loaded and shipped to a warehouse from a factory.
The logistics planner may rent trucks that can accommodate 40 boxes and 30 boxes, for USD 500 and USD 400 respectively.
How many trucks of each type to minimise the cost?
Our goal is to minimise the cost of shipping these boxes by selecting the right amount of the different trucks.
This is a simple optimisation problem.
However, we don’t usually think in mathematical term while solving it.
For many people, the answer is simple, even trivial.
A box costs USD 12.50 for 40-boxes-truck and USD 13.33 for 30-boxes-truck.
So we should prefer 40-boxes-truck to 30-boxes-truck.
We first spend USD 3500 (7 x USD 500) for 280 boxes in 7 40-boxes-trucks.
Then we add an eighth 30-boxes-truck for USD 400 for the remaining 20 boxes.
Total cost is USD 3900.
This looks fine.
But this is not the best solution.
With 6 trucks of 40 boxes (240 boxes and USD 3000) and 2 trucks with 30 seats (60 boxes and USD 800), we can ship the boxes and pay only USD 3800).
We can save USD 100!
The best decision is not that obvious.
Read more about the full background story at Integer Linear Programming with Graphical Method article.
This problem is a very simple example with only 2 variables, which are 2 kinds of trucks.
In reality, real business problems in real companies can contain up to thousands or more variables.
Solving it using your brain purely or graphically is totally impossible.
With modern tools, like Xpress and CPLEX, companies can tackle more complex real-world problems and the return of investment would not be just USD 100 as in our toy truck problem but millions of dollars.
In this article, we will solve this truckload problem with FICO Xpress.
Or you can use IBM ILOG CPLEX Optimization instead.
Downloading FICO Xpress Optimisation Software (Community Edition)
FICO Xpress Optimisation Software (Community Edition) is a free optimisation tool to develop, model and deploy mathematical models.
- Go to FICO Xpress Community License page.
- Fill up the form and submit.
You can download the FICO Xpress Optimisation Software (Community Edition) immediately.
Installing FICO Xpress Optimisation Software (Community Edition)
There are 3 components included in this Community edition:
- Workbench: the Integrated Development Environment (IDE) for developing optimisation models, services and complete solutions.
- Mosel: A high-level algebraic modelling language combined with a programming language which is tightly integrated with Xpress Solver.
- Solver: The optimisation algorithms and technologies to solve linear, mixed integer and non-linear problems behind the scene.
Before installing the new version, please make sure you uninstall any old version of FICO Xpress Optimization (e.g. a previous student version) and delete the old installation folder (e.g. C:\xpressmp). Otherwise, there may be a conflict.
Mac OS
- Run the .dmg setup file.
Hint: If you are a Symantec user, click “Allow this file to proceed”. - Read the License agreement and accept it by clicking “Yes”.
- Move the FICO Xpress icon into the Applications folder.
- Optionally, copy the FICO Xpress Examples folder to your preferred location and unzip it.
- When the installation is complete, unmount the DMG file.
- Ctrl-click in the Finder window and select Eject “FICO Xpress Installer”. You can then delete the DMG file.
- Launch Xpress Workbench from the Launchpad.
- Confirm that you want to open Xpress Workbench.
Getting Started with Xpress Workbench
Workbench is the Integrated Development Environment (IDE) for developing optimisation models, services and complete solutions.
- starting up Xpress Workbench
- click
CREATE MOSEL PROJECT
. - close the
Welcome
tab. - double click the
model.mos
near the left panel.
Then, we can write our first model in Mosel.
Create a new Mosel Project
The first step to solve optimisation problems with Xpress is to create a project.
Starting up Xpress Workbench.
Click Create project
near the left panel.
Choose the folder where you want to create the project.
I created a new test1
folder for it.
Click Upload
.
The project is created and your project folder with various files appears in the left panel.
Close the Welcome
tab.
Double click the model.mos
near the left panel.
Writing Mosel Model
Intro
Writing a model in Mosel is similar to building models in other programming languages.
You first declare the variables and then define functions for those variables.
Mosel is a language for building optimisation models, so it is not surprising that it is structured to set up mathematical optimisation problems.
Default Project Folder
By default, we have only 2 files under our project test1
folder, which are model.mos
and readme.html
.
We can delete or ignore the readme.html
and focus on the model.mos
file.
/model.mos
model ModelName
options noimplicit
uses "mmxprs"
declarations
! ...
Objective:linctr
end-declarations
writeln("Begin running model")
!...
writeln("End running model")
end-model
Setup a Blank Model File
L1 model ModelName
: Every Mosel program starts with the keyword model
, followed by a model name chosen by the user, in our case, Test 1
.
L2 options noimplicit
: It forces all objects to be declared. We will remove this in the earlier stage.
L3 uses "mmxprs"
: As Mosel is itself not a solver, we specify that Xpress-Optimizer
is to be used as our optimisation library.
L5-8 Declaration: All objects must be declared in a declarations
section, unless they are defined unambiguously through an assignment.
The section will be ended with end-declarations
.
We will discuss more later with real example, as a start, we removed everything inside.
L10-12 Output printing: We can output text or solution values with this. We can remove all first.
The Mosel program is terminated with the keyword end-model.
By following the instructions above, we will have the edited model.mos
as below:
model "Test 1"
uses "mmxprs"
declarations
end-declarations
end-model
Our Truckload Problem
Going back to our truckload toy problem.
Here is the mathematical formulation:
Minimise: Cost = 500 x truck40 + 400 x truck30
Subject to:
- Boxes: 40 x truck40 + 30 x truck30 = 300
- truck30 >= 0
- truck40 >= 0
This can be translated to the following Mosel model file (.mos):
/model.mos
model "Test 1"
uses "mmxprs"
declarations
truck40, truck30: mpvar
end-declarations
Cost:= 500 * truck40 + 400 * truck30
Capacity:= 40 * truck40 + 30 * truck30 >= 300
minimise(Cost)
writeln("LP Solution ")
writeln(" Objective: ", getobjval)
writeln(" Use ", getsol(truck40), " truck40")
writeln(" Use ", getsol(truck30), " truck30")
end-model
L1 defining the Model Name
L2 Using Xpress-Optimizer library
L4-6 Declaring the decision variables.
mpvar
means mathematical programming variable.
We declared two decision variables, which are truck40
and truck30
.
Since the decision variables are the best values to solve a problem, still unknown, we do not specify the values for these variables.
There is no = (equal to) sign after the names.
The optimisation engine will determine the values for these variables and return them as outputs.
Variables can take values between 0 and infinity by default.
We can specify the bounds.
That’s a story for another day.
We give these variables readable names to help making our code more understandable.
L8 Defining the Objective function.
The formulas can be complicated, sometimes we will write the objective function over several lines, to make it readable.
L10 Defining the Constraints.
L12 Solve the problem, with the keyword of either minimise
or maximise
.
L14 Output text.
L16 Output text and optimal objective value
L18-20 Output text and best solution values for our decision variables.
L22 Model end.
Result
FICO Xpress Mosel 64-bit v5.0.2
(c) Copyright Fair Isaac Corporation 2001-2019. All rights reserved
Compiling model.mos to out/model.bim with -g
Running model
LP Solution
Objective: 3800
Use 6 truck40
Use 2 truck30
We have a solution with objective value of 3800.
So, we actually need 6 40-boxes-trucks and 2 30-boxes-trucks to get the lowest $3800 cost.
Limitation
In this Community edition,
- The sum of the number of rows (constraints) and columns (variables) is restricted to 5000.
- The number of nonlinear tokens (measure of the complexity for nonlinear expressions) is restricted to 1000.
- The number of user functions (black box optimization) is restricted to 1.
- The nonlinear solver is restricted to the use of successive linear programming and the add-on for constraint programming is not licensed at this point.
- The download includes a community license which is valid for 12 months. New versions, including renewed licenses, will be available from this download page.
- While this license provides a fully functioning version of Xpress Insight, including rapid application creation and deployment using VDL, it is limited to one individual.
- It does not provide Tableau integration and all execution work must occur on the same machine.
- It does not include Kalis, the Constraint programming solver.