this repo has no description
at develop 1.2 kB view raw
1% 要制造的产品 2enum Products; 3% 每种产品的单位利润 4array[Products] of int: profit; 5% 用到的资源 6enum Resources; 7% 每种资源可获得的数量 8array[Resources] of int: capacity; 9 10% 制造一个单位的产品需要的资源单位量 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% 产品数量的界 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% 变量:每种产品我们需要制造多少 21array[Products] of var 0..mproducts: produce; 22array[Resources] of var 0..max(capacity): used; 23 24% 产量不可以使用超过可获得的资源量: 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% 最大化利润 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 ];