FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious example

Overview of Mosel examples for 'Business Optimization' book


List of FICO Xpress Mosel implementations of examples discussed in the book 'J. Kallrath: Business Optimization Using Mathematical Programming - An Introduction with Case Studies and Solutions in Various Algebraic Modeling Languages' (2nd edition, Springer, Cham, 2021, DOI 10.1007/978-3-030-73237-0).

List of provided model files

(Examples marked with * are newly introduced in the 2nd edition, all other models have been converted from the mp-model versions that were provided with the 1st edition of the book in 1997.)
absval.mos Modeling absolute value terms (linearization) 6.5
*absval2.mos, absval2a.mos Modeling absolute value as general constraints 6.5
bench101.mos Parkbench production planning problem (solution to Exercise 10.1) 10.9
bench102.mos Parkbench production planning problem, MIP problem (solution to Exercise 10.2) 10.9
blend, blend_graph Ore blending problem 2.7.1
*boat.mos Boat renting problem (solution for Exercise 3.3) 1.4.1, 3.7
*boat2.mos Multi-period Boat renting problem 1.6
boatdual.mos Dual of the Boat renting problem (solution for Exercise 3.3) 3.7
brewery.mos Brewery production planning (data files: brewery.xlsx, brewdata.dat) 8.3
burgap.mos Generalized assignment problem (solution for Exercise 7.3) 7.10
burglar Small knapsack problem 7.1.1
buscrew.mos Bus crew scheduling 7.8.4
calves.mos Calves and pigs problem 3.3.1
carton.mos Carton production scheduling problem (data file: carton.dat) 10.3
*ch-2tri.mos Minimal perimeter convex hull for two triangles 10.3
*contract.mos, contract_graph Contract allocation problem with semi-continuous variables 10.2.1
couples.mos Feasibility puzzle problem (solution for Exercise 6.5) 6.11
dea.mos Data envelopment analysis (solution for Exercise 5.2) 5.3
dual.mos Dual problem for a small LP (solution for Exercise 3.1b) 3.5.1
*dynbigm.mos Dynamic computation of big-M coefficients for production planning
*dynbigm2.mos Production planning problem formulation using indicator constraints
*ea_smpld.mos Evolutionary algorithm for supply management
euro.mos Choosing investment projects (solution for Exercise 7.5) 7.10
flowshop.mos, flowshop_graph Flowshop scheduling problem (solution for Exercise 7.7) 7.10
*fracprog.mos Fractional programming example 11.1
gap.mos Generalized assignment problem (solution for Exercise 7.2) 7.10
*goalprog.mos Lexicographic Goal Programming 5.4.3
*lagrel.mos Lagrange relaxation applied to the GAP
lim1.mos, coco Multi-period, multi-site production planning, LP model (solution for Exercise 5.1) 5.3
lim2.mos, coco_fixbv Multi-period, multi-site production planning, MIP model (solution for Exercise 6.7) 6.11
*manufact.mos Production scheduling problem with SOS formulation (solution for Exercise 6.9) 6.11
multk.mos Multi-knapsack problem (solution for Exercise 7.4) 7.10
network.mos Network flow problem (solution for Exercise 4.3) 4.7
network2.mos Generic formulation of network flow problem (Exercise 4.3) 4.7
*newsvendor.mos Newsvendor problem: 2-stage stochastic programming
npv.mos Net present value problem (solution for Exercise 6.8) 6.11
*optgrid.mos, optgrid2.mos Optimal breakpoints for piecewise linear approximation 14.2.3
*portfolio.mos Multi-stage stochastic portfolio investment model
primal.mos Primal problem for a small LP (solution for Exercise 3.1a) 3.7
prodx.mos Simple production planning example 2.5.2
projschd.mos, projplan_graph Project scheduling case study 10.2.3
quadrat.mos Linearized quadratic programming example 11.4
*quadrat2.mos Quadratic programming example solved as NLP 11.4
set.mos Set covering problem (solution for Exercise 7.6) 7.10
simple1.mos Simple LP problem (solution for Exercise 2.2) 2.13
simple2.mos Simple LP problem (solution for Exercise 2.3) 2.13
slab.mos Lifting slabs (solution for Exercise 6.6) 6.11
sludge.mos Sludge production planning example illustrating recursion 11.2.1
*sludge2.mos Recursion example solved as NLP 11.2.1
*teams.mos (solution for Exercise 6.4) 6.11
trim1.mos Trimloss problem LP formulation (solution for Exercise 4.1) 4.1.1
trim2.mos Trimloss problem MIP formulation (solution for Exercise 4.2) 4.1.2
*trimminlp.mos Trimloss problem formulated as a MINLP problem 13.3
*trimminlp2.mos Alternative NLP solver choice for trimloss problem 13.3
tsp.mos Traveling salesman problem (solution for Exercise 7.1) 7.10
*vrp, vrp_graph Vehicle routing - heating oil delivery problem 7.2.3
*woods.mos (solution for Exercise 2.1) 2.13
yldmgmt.mos Yield management, financial modeling 8.4.2[download all files]

Source Files

Data Files


   Mosel Example Problems

   file network2.mos
   Network problem 
   -- Generic formulation --
     Example solution to exercise 4.3 in section 4.7 /
     discussed in section 4.4 of
     J. Kallrath: Business Optimization Using Mathematical Programming -
     An Introduction with Case Studies and Solutions in Various Algebraic 
     Modeling Languages. 2nd edition, Springer Nature, Cham, 2021 

   author: S. Heipcke, Mar.2020

   (c) Copyright 2020 Fair Isaac Corporation
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


model 'network2'
  uses "mmxprs", "mmsvg"

    SOURCES, SINKS: set of integer             ! Nodes with outflow
    NODES=1..10                                ! All nodes
    INFLOW: array(SOURCES) of real             ! Inflow at source nodes
    OUTFLOW: array(SINKS) of real              ! Outflow at sink nodes
    C: dynamic array(NODES,NODES) of real      ! Cost of flow on arcs
    x: dynamic array(NODES,NODES) of mpvar     ! Flows on arcs

  C(1,3):=2; C(1,4):=2; C(2,4):=3; C(2,5):=5; C(3,4):=2; C(3,8):=5;
  C(4,5):=4; C(4,7):=2; C(5,10):=3; C(6,3):=3; C(6,8):=5;
  C(6,9):=2; C(7,6):=3; C(7,9):=2; C(7,10):=5


 ! Create decision variables for defined arcs
  forall(i,j in NODES | exists(C(i,j))) create(x(i,j))

 ! Objective: minimise total cost of flows
  Cost:= sum(i,j in NODES | exists(x(i,j))) C(i,j)*x(i,j)

 ! Flow conservation constraints:
 ! Outflow from sources
  forall(i in SOURCES) sum(j in NODES | exists(x(i,j))) x(i,j) = INFLOW(i)
 ! Balance at intermediate nodes
  forall(i in NODES-SOURCES-SINKS) 
    sum(j in NODES | exists(x(i,j))) x(i,j) = sum(j in NODES | exists(x(j,i))) x(j,i)
 ! Flow into sinks
 forall(i in SINKS) sum(j in NODES | exists(x(j,i))) x(j,i) = OUTFLOW(i)
 ! Solve the problem
  writeln("Solution: Total cost=", getobjval)
  forall(i,j in NODES | exists(x(i,j)) and x(i,j).sol>0) 
    writeln(i,"->",j,": ", x(i,j).sol)

 ! Graphical representation of the solution
    XPOS,YPOS: array(NODES) of integer       ! Coordinates of nodes

  svgaddgroup("ArcGraph", "Arcs")
  svgaddgroup("NodeGraph", "Nodes")
  svgaddgroup("SolGraph", "Selected arcs")

  forall(i,j in NODES | exists(C(i,j)))
  forall(i in SOURCES) do
    svgsetstyle(svggetlastobj,SVG_STROKEDASH, "1,1")
    svgaddtext("ArcGraph",XPOS(i)-8,YPOS(i)-1, text(INFLOW(i)))
  forall(i in SINKS) do
    svgsetstyle(svggetlastobj,SVG_STROKEDASH, "1,1")
    svgaddtext("ArcGraph",XPOS(i)+6,YPOS(i)-1, text(OUTFLOW(i)))
  forall(i in NODES) do
    svgsetstyle(svggetlastobj,SVG_FILL, SVG_CURRENT)
    svgaddtext("NodeGraph",XPOS(i)+1,YPOS(i)+1, text(i))
  forall(i,j in NODES | exists(x(i,j)) and x(i,j).sol>0)

  svgwaitclose("Close browser window to terminate model execution.", 1)


Back to examples browserPrevious example