我已经在Excel Solver中建立了一个示例,只是为了演示我希望从Python开始的内容。我在Python中尝试了PuLP,但始终出现错误。我正在尝试最小化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()
错误
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