(!******************************************************* Mosel Example Problems ====================== file coco2.mos `````````````` Coco Problem Phase 2. Use parameters, data tables and subscripted variables to separate the model structure from the data. Read data tables in from text data files. (c) 2001 Dash Associates authors: Y. Colombani & S.Heipcke *********************************************************!) model Coco2 ! Start a new model uses "mmxprs","mmetc" ! Load the optimizer and ETC libraries declarations RP=1..2 ! Range of products (p) RF=1..2 ! factories (f) RR=1..2 ! raw materials (r) REV: array(RP) 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) of real ! Unit cost to buy raw material r REQ: array(RP,RR) of real ! Requirement by unit of product p ! for raw material r MXSELL: array(RP) of real ! Maximum amount of p that can be sold MXMAKE: array(RF) of real ! Maximum amount factory f can make ! over all products PROFIT: array(RP,RF) of real ! Profit contribution of product p ! at factory f make: array(RP,RF) of mpvar ! Amount of product p made at factory f end-declarations ! Read data from files diskdata(ETC_DENSE,"rev.dat",REV) diskdata(ETC_DENSE,"cmake.dat",CMAKE) diskdata(ETC_DENSE,"cbuy.dat",CBUY) diskdata(ETC_DENSE,"req.dat",REQ) diskdata(ETC_DENSE,"maxsell.dat",MXSELL) diskdata(ETC_DENSE,"mxmake.dat",MXMAKE) ! Calculate the profit forall(p in RP, f in RF) PROFIT(p,f):= REV(p) - sum(r in RR) REQ(p,r)*CBUY(r) - CMAKE(p,f) ! Objective: maximize total profit MaxProfit:= sum(p in RP,f in RF) PROFIT(p,f) * make(p,f) ! Limit on the amount of product p to be sold forall(p in RP) MxSell(p):= sum(f in RF) make(p,f) <= MXSELL(p) ! Capacity limit at factory f forall(f in RF) MxMake(f):= sum(p in RP) make(p,f) <= MXMAKE(f) maximise(MaxProfit) ! Solve the LP-problem ! Print out the solution writeln("Solution:\n Objective: ", getobjval) forall(p in RP, f in RF) write(" make(", p, ",", f, "): ", getsol(make(p,f))) writeln end-model