this repo has no description
at develop 1.3 kB view raw
1% Products to be produced 2enum Products; 3% profit per unit for each product 4array[Products] of int: profit; 5% Resources to be used 6enum Resources; 7% amount of each resource available 8array[Resources] of int: capacity; 9 10% units of each resource required to produce 1 unit of product 11array[Products, Resources] of int: consumption; 12constraint assert(forall (r in Resources, p in Products) 13 (consumption[p,r] >= 0), "Error: negative consumption"); 14 15% bound on number of Products 16int: mproducts = max (p in Products) 17 (min (r in Resources where consumption[p,r] > 0) 18 (capacity[r] div consumption[p,r])); 19 20% Variables: how much should we make of each product 21array[Products] of var 0..mproducts: produce; 22array[Resources] of var 0..max(capacity): used; 23 24% Production cannot use more than the available Resources: 25constraint forall (r in Resources) ( 26 used[r] = sum (p in Products)(consumption[p, r] * produce[p]) 27); 28constraint forall (r in Resources) ( 29 used[r] <= capacity[r] 30); 31 32% Maximize profit 33solve maximize sum (p in Products) (profit[p]*produce[p]); 34 35output [ "\(p) = \(produce[p]);\n" | p in Products ] ++ 36 [ "\(r) = \(used[r]);\n" | r in Resources ];