python - 使用 Pandas 将 Excel Solver 转换为 Python
问题描述
我在 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
解决方案
推荐阅读
- python - 如何更正提示 SyntaxError?
- android - 如何将参数传递给 dialogFragment
- architecture - 数据湖:修复 Ingestion vs ETL 上损坏的文件
- ios - 无法访问对象数据,只能在 Swift/Xcode 的调试器中显示
- c++ - 如何使用 operator>> 在自定义字符串中输入多个单词?
- dynamic-programming - 这个问题的 dp 和转换是什么
- c++ - 将 C++ 解决方案导出为 .lib 文件并将其用于另一个项目
- c# - 如何参考 ctor 重载文档
? - c# - 无法从 IConfigurationRoot .NET Core 控制台应用程序获取节数据
- javascript - 如何将组件延迟加载到 React 路由器 dom Route 组件?