decideOrderOfProduction[itemsToProduce_] :=
Map[#[[1]] &, Sort[itemsToProduce, #1[[2]] > #2[[2]] &]]
minimizeWaste[pipe1_, pipe2_] := {
Maximize[{pipe1*x + pipe2*y, pipe1*x + pipe2*y <= 4900,
y >= x >= 0}, {x, y}, Integers]
}
minimizeWaste[pipe_] := {
Maximize[{pipe*x, pipe*x <= 4900, x >= 0}, x, Integers]
}
planProduction[itemsToProduce_] := {
productionOrder = decideOrderOfProduction[itemsToProduce];
strategy = {};
While[Length[productionOrder] >= 2,
pipe1 = productionOrder[[1]];
pipe2 = productionOrder[[2]];
strategy =
Append[strategy, {pipe1, pipe2, minimizeWaste[pipe1, pipe2]}];
productionOrder = Drop[productionOrder, 2];];
If[Length[productionOrder] == 1,
strategy =
Append[strategy, {productionOrder[[1]], Null,
minimizeWaste[productionOrder[[1]]]}]];
strategy
}
items = {{99, 1}, {200, 12}, {1200, 2}, {90, 5}, {70, 1200}};
decideOrderOfProduction[items]
planProduction[items]
{70, 200, 90, 1200, 99}
{{{70, 200, {{4900, {x -> 10, y -> 21}}}}, {90,
1200, {{4890, {x -> 1, y -> 4}}}}, {99,
Null, {{4851, {x -> 49}}}}}}
那是一個開始,但它是壞的,因爲不知何故,我需要考慮到優先級更好,我需要完成的量每個管道。不知何故,我猜想金額也需要考慮到優先級。
你使用的是什麼版本? – rcollyer 2011-03-26 02:39:03
最大化[{y,{x * 100 + y * 1200 == 9900,x> = 0,y> = 0}},{x,y},Integers] – 2011-03-28 15:15:16