1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | language Essence 1.3 $ Problem Wagner-Whitin Distribution $ $ Problem details available at http://www.csplib.org/Problems/prob040/ $ $ Essence model by Andrew Martin $ $ Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/ $ in this model, rather than define multiple levels, children of each node are defined explicitly given numNodes : int (1..) $ leaves are always first numLeaves nodes $ leaves cannot have any children given numLeaves : int (1..) $ period 0 is empty, all stock is 0 given numPeriods : int (1..) $ used to provide bound to output given maxStock : int (1..) letting dNodes be domain int (1..numNodes) letting dLeaves be domain int (1..numLeaves) letting dAllPeriods be domain int (0..numPeriods) letting dPeriods be domain int (1..numPeriods) given holdingCost : matrix indexed by [dNodes] of int (0..) given procCost : matrix indexed by [dNodes] of int (0..) given demand : matrix indexed by [dLeaves, dPeriods] of int (0..) $ used to determine where supply comes goes to given children : matrix indexed by [dNodes] of set of dNodes find orders : matrix indexed by [dNodes, dPeriods] of int (0..maxStock) $ AUX find statement find stock : matrix indexed by [dNodes, dAllPeriods] of int (0..maxStock) $ minimising the cost $ holding*stock per period per node plus proc if any orders were placed per period per node minimising ( sum t : dPeriods . ( sum i : dNodes . (holdingCost[i] * stock[i][t] + procCost[i] * toInt (orders[i][t] > 0)))) such that $ stock starts at 0 forAll i : dNodes . stock[i][0] = 0 , $ non-leaf constraints - orders coming from children must be fulfilled forAll t : dPeriods . forAll i : int (numLeaves+1..numNodes) . stock[i][t] = stock[i][t-1] + orders[i][t] - ( sum m in children[i] . orders[m][t]) , $ leaf constraints - demands must be fullfilled forAll t : dPeriods . forAll i : dLeaves . stock[i][t] = stock[i][t-1] + orders[i][t] - demand[i][t] |