(!******************************************************* Mosel Example Problems ====================== file contract.mos ````````````````` Contract Allocation example. (c) 2001 Dash Associates author: S.Heipcke, rev. 2007 *********************************************************!) model Contract ! Start a new model uses "mmxprs" ! Load the optimizer library declarations District = 6 ! Number of districts Contract = 10 ! Number of contracts RD = 1..District RC = 1..Contract OUTPUT: array(RD) of integer ! Max. output per district COST : array(RD) of integer ! Cost per district VOLUME: array(RC) of integer ! Volume of contracts x: array(RD,RC) of mpvar ! =1 if a project is chosen y: array(RD,RC) of mpvar ! Quantities allocated to contractors end-declarations OUTPUT :: [50, 40, 10, 20, 70, 50] COST :: [50, 20, 25, 30, 45, 40] VOLUME :: [20, 10, 30, 15, 20, 30, 10, 50, 10, 20] Cost:= sum(d in RD, c in RC) COST(d)*y(d,c) ! Objective function: total cost forall(c in RC) do ! Cover the required contract volume Size(c) := sum(d in RD) y(d,c) >= VOLUME(c) ! At least 2 districts per contract Min(c) := sum(d in RD) x(d,c) >= 2 end-do ! Do not exceed max. output of any district forall(d in RD) Output(d) := sum(c in RC) y(d,c) <= OUTPUT(d) ! If a contract is allocated to a district, then at least 1 unit is ! allocated to it forall(d in RD, c in RC) XY(d,c) := x(d,c) <= y(d,c) forall(d in RD, c in RC) do x(d,c) is_binary y(d,c) is_semcont 5 y(d,c) <= OUTPUT(d) end-do minimize(Cost) ! Solve the LP-problem writeln("Objective: ", getobjval) forall(d in RD) do forall(c in RC) if(getsol(x(d,c))>0) then write("y(",d,",",c,"):", getsol(y(d,c)), ", ") end-if writeln end-do end-model