model "UFL" uses "mmxprs"; !gain access to the Xpress-Optimizer solver parameters INFILE= "lotsizing.txt" Version=1 BigMVer=1 end-parameters !sample declarations section declarations TIMES: set of integer Demand: array(TIMES) of real ProductionCost: array(TIMES) of real HoldingCost: array(TIMES) of real SetupCost: array(TIMES) of real BigM: real end-declarations initialisations from INFILE Demand ProductionCost HoldingCost SetupCost end-initialisations finalize(TIMES) declarations y: array(TIMES) of mpvar !production s: array(TIMES) of mpvar !inventory x: array(TIMES) of mpvar q: dynamic array(TIMES,TIMES) of mpvar !production in period i for demand in period t end-declarations if Version = 1 then y(1) = Demand(1) + s(1) forall(t in TIMES | t >= 2 and t <= getsize(TIMES) - 1) do s(t-1) + y(t) = Demand(t) + s(t) end-do s(getsize(TIMES) - 1) + y(getsize(TIMES)) = Demand(getsize(TIMES)) forall(t in TIMES) do if BigMVer = 1 then BigM:= sum(k in TIMES) Demand(k) elif BigMVer = 2 then BigM:= sum(k in TIMES | k >= t) Demand(k) end-if y(t) <= BigM * x(t) end-do forall(t in TIMES) do x(t) is_binary end-do Obj:= sum(t in TIMES) (ProductionCost(t)*y(t) + HoldingCost(t)*s(t) + SetupCost(t)*x(t)) else forall(t1 in TIMES, t2 in TIMES | t1 <= t2) do create(q(t1,t2)) end-do forall(t in TIMES) do sum(i in TIMES | i <= t) q(i,t) = Demand(t) forall(i in TIMES) do q(i,t) <= Demand(t)*x(i) end-do x(t) is_binary end-do Obj:= sum(t in TIMES) (sum(i in TIMES | i <= t) ((ProductionCost(i) + sum(k in TIMES | k >= i and k <= t - 1) HoldingCost(k))*q(i,t)) + SetupCost(t)*x(t)) end-if minimise(Obj) end-model