2017-05-30 6 views
-2

Ich folgte eine tutorial von Python PLUP, aber ein anderes Ergebnis. StattUnerwartetes Ergebnis mit Python PLUP

Optimal weekly number of soldiers to produce: 20 
Optimal weekly number of trains to produce: 60 

Ich habe:

Optimal weekly number of soldiers to produce: 0 
Optimal weekly number of trains to produce: 0 

aber die Reste gleich sind ... Wenn Sie wissen wollen, dass; s der Code (fast Kopieren und Einfügen):

prob = pulp.LpProblem('Giapetto', pulp.LpMinimize) 
soldiers = pulp.LpVariable('soldiers', lowBound=0, cat='Integer') 
trains = pulp.LpVariable('trains', lowBound=0, cat='Integer') 

raw_material_costs = 10 * soldiers + 9 * trains 
variable_costs = 14 * soldiers + 10 * trains 
revenues = 27 * soldiers + 21 * trains 
profit = revenues - (raw_material_costs + variable_costs) 
prob += profit 

carpentry_hours = soldiers + trains 
prob += (carpentry_hours <= 80) 

finishing_hours = 2*soldiers + trains 
prob += (finishing_hours <= 100) 

prob += (soldiers <= 40) 
print(prob) 
optimization_result = prob.solve() 
assert optimization_result == pulp.LpStatusOptimal 

for var in (soldiers, trains): 
    print('Optimal weekly number of {} to produce: {:1.0f}'.format(var.name, var.value())) 

Irgendwas falsch?

+1

Sieht für mich wie Sie es gesagt, um den Gewinn zu minimieren, und es hat erfolgreich den Gewinn minimiert. – user2357112

Antwort

1

Es ist genau das, was es tun soll.

Sie verändert das Wichtigste, das Ziel:

prob = pulp.LpProblem('Giapetto', pulp.LpMinimize) 

Sie wollen also das Ziel, zu minimieren, was ist:

profit = revenues - (raw_material_costs + variable_costs) 

Da beide nur abhängig sind von zwei Variablen, die sind beide nicht negativ, der Mindestwert ist 0.

Sie können Ihr Ziel reformieren, um zu sehen, dass es nicht niedriger als 0 sein kann, wenn beide Variablen nicht negativ sind:

obj = 27 * soldiers + 21 trains - 24 soldiers - 19 trains 
    = 3 * soldiers + 2 trains 
+0

Gosh ... Ich habe die automatische Vervollständigung aktiviert, habe das nicht bemerkt ... Danke! –