## ams_version=1.0 Model Main_SingleLevelSmallBucket { Comment: { "Lot sizing Problem type: MIP (medium) 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 Constantino 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 { Definition: 5; } Parameter NumberOfMachines { Definition: 2; } Parameter NumberOfPeriods { Definition: 12; } Set Items { SubsetOf: Integers; Index: i; Definition: { {1..NumberOfItems} } } Set Machines { SubsetOf: Integers; Index: m; Definition: { {1..NumberOfMachines} } } Set Periods { SubsetOf: Integers; Index: t; Definition: { {1..NumberOfPeriods} } } Parameter Demand { IndexDomain: (i,t); } Parameter SetUpCost; Parameter StartUpCost; Parameter StockCost { IndexDomain: (i); Definition: data { 1 : 2, 2 : 1, 3 : 1, 4 : 1, 5 : 1 }; } Parameter BackloggingCost { IndexDomain: (i); Definition: data { 1 : 800, 2 : 400, 3 : 400, 4 : 400, 5 : 400 }; } Parameter Capacity { IndexDomain: (m); Definition: data { 1 : 7, 2 : 10 }; } Parameter StartUpTime { IndexDomain: (m); Definition: data { 1 : 2, 2 : 4 }; } Variable S { IndexDomain: (i,t); Range: nonnegative; Comment: "Items stocked"; } Variable R { IndexDomain: (i,t); Range: nonnegative; Comment: "End products backlogged"; } Variable X { IndexDomain: (i,t,m); Range: nonnegative; Comment: "Number of items i produced on machine m in period t"; } Variable Y { IndexDomain: (i,t,m); Range: binary; Comment: "Production variable: 1 if item i is produced on machine m in period t"; } Variable Z { IndexDomain: (i,t,m); Range: binary; Comment: "Startup variable: 1 if production of item i is started in period t on machine m"; } Variable TotalCost { Range: free; Definition: { sum((i,t,m), SetUpCost * Y(i, t, m) + StartUpCost * Z(i, t, m)) + sum((i,t), StockCost(i) * S(i, t) + BackloggingCost(i) * R(i, t)) } } Constraint FlowConstraint { IndexDomain: (i,t); Definition: S(i, t-1) - R(i, t-1) + sum(m, X(i, t, m)) = Demand(i, t) + S(i, t) - R(i, t); } Constraint CapacityConstraint { IndexDomain: (i,t,m); Definition: X(i, t, m) + StartUpTime(m) * Z(i, t, m) <= Capacity(m) * Y(i, t, m); } Constraint MachineConstraint { IndexDomain: (m,t); Definition: sum(i, Y(i, t, m)) <= 1; } Constraint StartupConstraint1 { IndexDomain: (i,t,m); Definition: Z(i, t, m) >= Y(i, t, m) - Y(i, t-1, m); } Constraint StartupConstraint2 { IndexDomain: (i,t,m); Definition: Z(i, t, m) <= Y(i, t, m); } Constraint StartupConstraint3 { IndexDomain: (i,t,m); Definition: Y(i, t-1, m) + Z(i, t, m) <= 1; } MathematicalProgram LeastCost { Objective: TotalCost; Direction: minimize; Constraints: AllConstraints; Variables: AllVariables; Type: Automatic; } Procedure MainInitialization { Body: { Demand(i,t) := DATA TABLE 1 2 3 4 5 6 7 8 9 10 11 12 ! 1 2.15 2.07 4.22 4.49 1.88 5.20 1.35 2.06 1.80 1.70 2.51 0.36 2 1.92 1.88 1.97 1.74 1.41 2.44 1.69 0.75 1.15 2.02 0.51 0.65 3 2.11 2.19 2.11 2.19 2.40 2.47 1.62 2.25 2.25 2.89 1.48 1.48 4 0.75 0.92 0.72 0.75 1.39 0.46 0.89 2.35 2.69 0.42 0.46 3.70 5 0.92 0.92 1.00 1.17 1.17 1.17 1.25 0.92 2.09 1.92 0.50 0.50 ; SetUpCost := 100; StartUpCost := 200; } } Procedure MainExecution { Body: { solve LeastCost; } } Procedure MainTermination { Body: { return 1; } } }