(!******************************************************* Mosel Example Problems ====================== file coco.mos ````````````` Complete Coco Problem. Specify phase by PHASE parameter. Data input in the model, not via data files. (c) 2001 Dash Associates author: S.Heipcke, rev. 2007 *********************************************************!) model Coco ! Start a new model uses "mmxprs" ! Load the optimizer library parameters PHASE=5 (!* Phase = 3: Multi-period parameterised model; mines always open * Phase = 4: Mines may open/closed freely; when closed save 20000 per month * Phase = 5: Once closed always closed; larger saving !) end-parameters declarations NT=4 ! Number of time periods RP=1..2 ! Range of products (p) RF=1..2 ! factories (f) RR=1..2 ! raw materials (r) RT=1..NT ! time periods (t) REV: array(RP,RT) of real ! Unit selling price of product p CMAKE: array(RP,RF) of real ! Unit cost to make product p ! at factory f CBUY: array(RR,RT) of real ! Unit cost to buy raw material r COPEN: array(RF) of real ! Fixed cost of factory f being ! open for one period REQ: array(RP,RR) of real ! Requirement by unit of product p ! for raw material r MXSELL: array(RP,RT) of real ! Max. amount of p that can be sold MXMAKE: array(RF) of real ! Max. amount factory f can make ! over all products PSTOCK0: array(RP,RF) of real ! Initial product p stock level ! at factory f RSTOCK0: array(RR,RF) of real ! Initial raw material r stock ! level at factory f CPSTOCK = 2.0 ! Unit cost to store any product p CRSTOCK = 1.0 ! Unit cost to store any raw mat. r MXRSTOCK = 300 ! Max. amount of r that can be ! stored each f and t make: array(RP,RF,RT) of mpvar ! Amount of product p made at ! factory f sell: array(RP,RF,RT) of mpvar ! Amount of product p sold from ! factory f in period t buy: array(RR,RF,RT) of mpvar ! Amount of raw material r bought ! for factory f in period t pstock: array(RP,RF,1..NT+1) of mpvar ! Stock level of product p at ! factory f at start of period t rstock: array(RR,RF,1..NT+1) of mpvar ! Stock level of raw material r at ! factory f at start of period t openm: array(RF,RT) of mpvar ! 1 if factory f is open in ! period t, else 0 end-declarations REV := [400, 380, 405, 350, 410, 397, 412, 397] CMAKE := [150, 153, 75, 68] CBUY := [100, 98, 97, 100, 200, 195, 198, 200] COPEN := [50000, 63000] REQ := [1.0, 0.5, 1.3, 0.4] MXSELL := [650, 600, 500, 400, 600, 500, 300, 250] MXMAKE := [400, 500] PSTOCK0 := [50, 100, 50, 50] RSTOCK0 := [100, 150, 50, 100] ! Objective: maximize total profit MaxProfit:= sum(p in RP,f in RF,t in RT) REV(p,t) * sell(p,f,t) - ! revenue sum(p in RP,f in RF,t in RT) CMAKE(p,f) * make(p,f,t) - ! prod. cost sum(r in RR,f in RF,t in RT) CBUY(r,t) * buy(r,f,t) - ! raw mat. cost sum(p in RP,f in RF,t in 2..NT+1) CPSTOCK * pstock(p,f,t) - ! p stor. cost sum(r in RR,f in RF,t in 2..NT+1) CRSTOCK * rstock(r,f,t) ! r stor. cost if PHASE=4 then ! Factory fixed cost MaxProfit -= sum(f in RF,t in RT) (COPEN(f)-20000)*openm(f,t) elif PHASE=5 then MaxProfit -= sum(f in RF,t in RT) COPEN(f)* openm(f,t) end-if ! Product stock balance forall(p in RP,f in RF,t in RT) PBal(p,f,t):= (pstock(p,f,t+1) = pstock(p,f,t) + make(p,f,t) - sell(p,f,t)) ! Raw material stock balance forall(r in RR,f in RF,t in RT) RBal(r,f,t):= rstock(r,f,t+1) = rstock(r,f,t) + buy(r,f,t) - sum(p in RP) REQ(p,r)*make(p,f,t) ! Capacity limit at factory f forall(f in RF,t in RT) MxMake(f,t):= sum(p in RP) make(p,f,t) <= MXMAKE(f)*openm(f,t) ! Limit on the amount of prod. p to be sold forall(p in RP,t in RT) MxSell(p,t):= sum(f in RF) sell(p,f,t) <= MXSELL(p,t) ! Raw material stock limit forall(f in RF,t in 2..NT+1) MxRStock(f,t):= sum(r in RR) rstock(r,f,t) <= MXRSTOCK if PHASE=5 then ! Once closed, always closed forall(f in RF,t in 1..NT-1) Closed(f,t):= openm(f,t+1) <= openm(f,t) end-if ! Initial product levels forall(p in RP,f in RF) pstock(p,f,1) = PSTOCK0(p,f) ! Initial raw material levels forall(r in RR,f in RF) rstock(r,f,1) = RSTOCK0(r,f) if PHASE>=4 then forall(f in RF,t in RT) openm(f,t) is_binary else forall(f in RF,t in RT) openm(f,t) = 1 end-if maximize(MaxProfit) ! Solve the LP or MIP-problem ! Print out the solution writeln("Solution:\n Objective: ", getobjval) ! Uncomment to print out the solution values: (! forall(p in RP, f in RF) do forall(t in RT) write(" make(",p,",",f,",",t,"):", getsol(make(p,f,t)), " sell(",p,",",f,",",t,"):", getsol(sell(p,f,t)), " ") writeln end-do forall(p in RP, f in RF) do forall(t in 1..NT+1) write(" pstock(",p,",",f,",",t,"):", getsol(pstock(p,f,t))) writeln end-do forall(r in RR, f in RF) do forall(t in RT) write(" buy(",r,",",f,",",t,"):", getsol(buy(r,f,t))) writeln end-do forall(r in RR, f in RF) do forall(t in 1..NT+1) write(" rstock(",r,",",f,",",t,"):", getsol(rstock(r,f,t))) writeln end-do forall(f in RF, t in RT) write(" openm(",f,",",t,"):", getsol(openm(f,t))) writeln !) end-model