问题描述
当我们在Windows和Linux OS中部署代码时,我在生产代码中遇到python纸浆库的问题。
问题在于两个操作系统之间的目标价值不同。
作为示例,我使用纸浆2.2从以下网站教程中运行了测试代码: https://benalexkeen.com/linear-programming-with-python-and-pulp-part-5/
在Windows系统中,目标值输出为 10980000 。 在基于Linux的系统(Mac)中,目标值输出为 12906400 。
我在两个系统上都有相同的python版本,也有相同的纸浆版本(2.2)。
有人可以建议为什么会这样吗?有一个已知的错误吗?
编辑(我运行的代码-在教程网站上提供):
import pandas as pd
import pulp
factories = pd.read_csv('factory_variables.csv',index_col=['Month','Factory'])
demand = pd.read_csv('monthly_demand.csv',index_col=['Month'])
production = pulp.LpVariable.dicts("production",((month,factory) for month,factory in factories.index),lowBound=0,cat='Integer')
factory_status = pulp.LpVariable.dicts("factory_status",cat='Binary')
model = pulp.LpProblem("Cost minimising scheduling problem",pulp.LpMinimize)
model += pulp.lpSum(
[production[month,factory] * factories.loc[(month,factory),'Variable_Costs'] for month,factory in factories.index]
+ [factory_status[month,'Fixed_Costs'] for month,factory in factories.index]
)
# Production in any month must be equal to demand
months = demand.index
for month in months:
model += production[(month,'A')] + production[(month,'B')] == demand.loc[month,'Demand']
# Production in any month must be between minimum and maximum capacity,or zero.
for month,factory in factories.index:
min_production = factories.loc[(month,'Min_Capacity']
max_production = factories.loc[(month,'Max_Capacity']
model += production[(month,factory)] >= min_production * factory_status[month,factory]
model += production[(month,factory)] <= max_production * factory_status[month,factory]
# Factory B is off in May
model += factory_status[5,'B'] == 0
model += production[5,'B'] == 0
solver = pulp.PULP_CBC_CMD(keepFiles=True)
model.solve(solver)
pulp.LpStatus[model.status]
另外,请在此链接上找到csv文件:https://github.com/benalexkeen/Introduction-to-linear-programming/tree/master/csv
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)