Я построил пример в Excel Solver просто для демонстрации того, с чего я хочу начать в Python. Я пытался с PuLP в Python, но получаю ошибку. Я пытаюсь минимизировать разницу df ['AP'] и входной переменной или просто максимизировать прибыль.
idx = df.index
#Define Inclusion Variable as Boolean
x1 = LpVariable.dicts("idx", idx, lowBound=-1, upBound = 1)
#Objective
prob += sum([x1[l] for l in idx]), 'Max of Profit'
#prob += lpSum([costs[i]*ingredient_vars[i] for i in Ingredients]), "Total Cost of Ingredients per can"
#Constraints
prob += lpSum([df['CalcVar'][l] for l in idx]) <= curDy + 0.01, "CalcVar"
prob += lpSum([df['CalcVar'][l] for l in idx]) >= curDy - 0.01, "CalcVar"
#Wrap up & Solve
LpSolverDefault.msg = 1
prob.writeLP('LaneOpt.lp')
prob.solve()
Error
Traceback (most recent call last):
File "solver.py", line 84, in <module>
prob.solve()
File "PATH", line 1671, in solve
status = solver.actualSolve(self, **kwargs)
File "PATH", line 1362, in actualSolve
return self.solve_CBC(lp, **kwargs)
File "PATH", line 1427, in solve_CBC
raise PulpSolverError("Pulp: Error while executing "+self.path)
pulp.solvers.PulpSolverError: Pulp: Error while executing ...\cbc.exe