FICO
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

Description

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.)
FilenameDescriptionSection
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 14.1.2.1
*dynbigm2.mos Production planning problem formulation using indicator constraints 14.1.2.1
*ea_smpld.mos Evolutionary algorithm for supply management 14.1.3.3
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 14.1.3.3
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 11.3.2.1
npv.mos Net present value problem (solution for Exercise 6.8) 6.11
*optgrid.mos Optimal breakpoints for piecewise linear approximation 14.2.3
*portfolio.mos Multi-stage stochastic portfolio investment model 11.3.2.5
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

bsnsoptbook_ovw.zip[download all files]

Source Files

Data Files





lim2.mos

(!*********************************************************************
   Mosel Example Problems
   ======================

   file lim2.mos
   `````````````
   Production planning problem 
   Model with possible buy-in of intermediate I1
   
     Example solution for exercise 6.7 in section 6.11 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 

   See See https://examples.xpress.fico.com/example.pl?id=fixbv
   for additional versions.

   author: S. Heipcke, June 2018

   (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
 
       http://www.apache.org/licenses/LICENSE-2.0
 
    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 'lim2'
uses "mmxprs", "mmsystem"

  declarations
    NP=2                    
    NR=2                    
    NI=2                    
    NT=4                    
    RP=1..NP                    ! Products
    RR=1..NR                    ! Raw materials
    RI=1..NI                    ! Intermediate products
    RT=1..NT                    ! Time periods

    RPR: array(RP,RR) of real   ! Requirement by p for r
    RPI: array(RP,RI) of real   ! Requirement by p for i
    RIR: array(RI,RR) of real   ! Requirement by i for r
    PRC: array(RP,RT) of real   ! Selling price of p in t
    CP: array(RP,RT) of real    ! Manufacturing cost of p in t
    CI: array(RP,RT) of real    ! Manufacturing cost of i in t
    A: array(RR,RT) of real     ! Availablities of r in t
    SP0: array(RP) of real      ! Initial stock levels of p
    SI0: array(RI) of real      ! Initial stock levels of i
  end-declarations

  RPR::[8, 10,
        6, 12]
  RPI::[4, 2,
        3, 3]
  RIR::[1.0, 0.7,
        0.6, 1.2]
  PRC::[100, 105, 107, 90,
        90, 100, 110, 115]
  CP::[40, 42, 55, 35,
       38, 35, 44, 40]
  CI::[6.0, 6.2, 5.3, 4.8,
       5.1, 5.2, 5.0, 5.1]
  A::[200, 300, 100, 200,
      250, 400, 50, 240]
  SP0::[40, 38]
  SI0::[60, 50]

  declarations
    mP: array(RP,RT) of mpvar       ! Number of p made in period t
    mI: array(RI,RT) of mpvar       ! Number of i made in period t
    sell: array(RP,RT) of mpvar     ! Number of p sold in period t
    uI: array(RI,RT) of mpvar       ! i's used in month t
    sP: array(RP,RT) of mpvar       ! Stock of p at end of month t
    sI: array(RI,RT) of mpvar       ! Stock of i at end of month t
    ifbuy: array(RT) of mpvar       ! 1 if we buy-in I1 in period t
    buyin: array(RT) of mpvar       ! Amount of I1 bought in
  end-declarations

  Profit:= sum(p in RP,t in RT) PRC(p,t)*sell(p,t) -  ! revenue
         sum(p in RP,t in RT) CP(p,t)*mP(p,t) -       ! making p
         sum(i in RI,t in RT) CI(i,t)*mI(i,t) -       ! making i
         sum(p in RP,t in RT) 3*sP(p,t) -             ! storing p
         sum(i in RI,t in RT) 0.5*sI(i,t) -           ! storing i
         sum(t in RT) 400*ifbuy(t) -                  ! fixed cost
         sum(t in RT) buyin(t)                        ! cost of I1
             
  ! Stock balance for p in period t
  forall(p in RP,t in 2..NT)
    Sbp(p,t):= sP(p,t) = sP(p,t-1) + mP(p,t) - sell(p,t)
  forall(p in RP)
    Sbp0(p):= sP(p,1) = SP0(p) + mP(p,1) - sell(p,1)

  ! Stock balance for i in period t
  forall(t in 2..NT)
    S1bi(t):= sI(1,t) = sI(1,t-1) + mI(1,t) + buyin(t) - uI(1,t)
  S1bi0:= sI(1,1) = SI0(1) + mI(1,1) + buyin(1) - uI(1,1)
  forall(i in 2..NI,t in 2..NT)
    Sbi(i,t):= sI(i,t) = sI(i,t-1) + mI(i,t) - uI(i,t)
  forall(i in 2..NI)
    Sbi0(i):= sI(i,1) = SI0(i) + mI(i,1) - uI(i,1)

  ! Max amount that can be bought per time period
  forall(t in RT) IFB(t):= buyin(t)<= 400*ifbuy(t)

  ! Usage of i related to p made
  forall(i in RI,t in RT)
    Usei(i,t):= uI(i,t) = sum(p in RP) RPI(p,i)*mP(p,t)

  ! Availability of resources
  forall(r in RR,t in RT)
    Ravail(r,t):= sum(p in RP) RPR(p,r)*mP(p,t) +
    sum(i in RI) RIR(i,r)*mI(i,t)<= A(r,t)

  ! Final stock balances
  forall(p in RP,t=NT) sP(p,t) = SP0(p)
  forall(i in RI,t=NT) sI(i,t) = SI0(i)

  ! Max sales in any period
  forall(p in RP,t in RT) sell(p,t)<= 30

  forall(t in RT) ifbuy(t) is_binary

  maximise(Profit)
  writeln("Solution:")

  hline:=60*"-"
  writeln("Total profit: ", getobjval)
  writeln(hline)
  write(8*" ", "Period")
  forall(t in 0..NT) write(strfmt(t,8)) 
  writeln("\n", hline)
  writeln("Finished products\n", 
          "=================")
  forall(p in RP) do
   write(3*" ", "P", p, ":  Prod", 10*" ")
   forall(t in RT) write(strfmt(mP(p,t).sol,8,1))
   writeln
   write(8*" ", "Sell", 10*" ")
   forall(t in RT) write(strfmt(sell(p,t).sol,8,1))
   writeln
   write(8*" ", "(Stock)    (", SP0(p), ")")
   forall(t in 1..NT) write("  (", strfmt(sP(p,t).sol,4,1), ")")
   writeln
  end-do 

  writeln(hline)
  writeln("Intermediates\n", 
          "=============")
  forall(i in RI) do
   write(3*" ", "I", i, "   Prod", 10*" ")
   forall(t in RT) write(strfmt(getsol(mI(i,t)),8,1))
   writeln
   if(i=1) then
     write(8*" ", "Buy ", 10*" ")
     forall(t in RT) write(strfmt(getsol(buyin(t)),8,1))
     writeln
   end-if
   write(8*" ", "Use ", 10*" ")
   forall(t in RT) write(strfmt(getsol(uI(i,t)),8,1))
   writeln
   write(8*" ", "(Stock)    (", SI0(i), ")")
   forall(t in 1..NT) write(" (", strfmt(sI(i,t).sol,5,1), ")")
   writeln
  end-do 
  writeln(hline)

end-model

Back to examples browserPrevious example