## ams_version=1.0 Model Main_SingleLevelBigBucket { Comment: { "Lot sizing Problem type: MIP (small) Description: Lot-sizing problems are production planning problems in which the periods are a priori, and production of an item in a given period implies some discrete event such as payment of a cost or the loss of a amount of production capacity, due to placement of an order, or the set-up, startup, or changeover of a machine. References: Problem pp08a from: Belvaux, G., L.A. Wolsey, Lotsizelib: A library of models and matrices for lot-sizing problems, Core discussion paper, Universite Catholique de Louvain, 1999." } Parameter NumberOfItems { Range: integer; Definition: 8; } Parameter NumberOfPeriods { Range: integer; Definition: 8; } Set Items { SubsetOf: Integers; Index: i; Definition: { {1..NumberOfItems} } } Set Periods { SubsetOf: Integers; Index: t; Definition: { {1..NumberOfPeriods} } } Parameter Demand { IndexDomain: (i,t); } Parameter PeriodDemand { IndexDomain: i; Definition: sum(t, Demand(i, t)); } Parameter TotalCapacity { IndexDomain: t; } Parameter Capacity { IndexDomain: (i,t); Definition: Min(PeriodDemand(i), TotalCapacity(t)); } Parameter CostF { IndexDomain: i; } Parameter CostH { IndexDomain: i; } Parameter CostB { IndexDomain: i; } Variable X { IndexDomain: (i,t); Range: nonnegative; Comment: "Number of items i produced in period t"; } Variable S { IndexDomain: (i,t) | t <> NumberOfPeriods; Range: nonnegative; Comment: "Items stocked"; } Variable R { IndexDomain: (i,t) | t <> NumberOfPeriods; Range: nonnegative; Comment: "End products backlogged"; } Variable Y { IndexDomain: (i,t); Range: binary; Comment: "Production variable: 1 if item i is produced in period t"; } Variable TotalCost { Range: free; Definition: sum((i,t), CostH(i) * S(i, t) + CostB(i) * R(i, t) + CostF(i) * Y(i, t)); } Constraint FlowConstraint { IndexDomain: (i,t); Definition: S(i, t-1) - R(i, t-1) + X(i, t) = Demand(i, t) + S(i, t) - R(i, t); } Constraint CapacityConstraint { IndexDomain: (i,t); Definition: X(i, t) <= Capacity(i,t) * Y(i, t); } Constraint TotalCapacityConstraint { IndexDomain: t; Definition: sum(i, X(i, t)) <= TotalCapacity(t); } MathematicalProgram LeastCost { Objective: TotalCost; Direction: minimize; Constraints: AllConstraints; Variables: AllVariables; Type: Automatic; } Procedure MainInitialization { Body: { COMPOSITE TABLE i t Demand ! - - ------ 1 1 0 1 2 70 1 3 50 1 4 100 1 5 20 1 6 80 1 7 0 1 8 100 2 1 20 2 2 40 2 3 50 2 4 10 2 5 30 2 6 0 2 7 40 2 8 50 3 1 40 3 2 50 3 3 0 3 4 100 3 5 40 3 6 80 3 7 90 3 8 160 4 1 0 4 2 100 4 3 100 4 4 150 4 5 160 4 6 90 4 7 100 4 8 100 5 1 50 5 2 0 5 3 20 5 4 40 5 5 10 5 6 10 5 7 20 5 8 10 6 1 70 6 2 40 6 3 40 6 4 40 6 5 100 6 6 20 6 7 40 6 8 50 7 1 0 7 2 20 7 3 50 7 4 10 7 5 20 7 6 60 7 7 40 7 8 40 8 1 10 8 2 20 8 3 0 8 4 0 8 5 10 8 6 10 8 7 20 8 8 30 ; COMPOSITE TABLE t TotalCapacity !- ------------- 1 350 2 350 3 350 4 400 5 400 6 400 7 400 8 500 ; COMPOSITE TABLE i CostH !- ----- 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 ; COMPOSITE TABLE i CostB !- ----- 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 ; COMPOSITE TABLE i CostF !- ----- 1 100 2 200 3 200 4 300 5 400 6 250 7 500 8 300 ; } } Procedure MainExecution { Body: { solve LeastCost; } } Procedure MainTermination { Body: { return 1; } } }