如何解决PuLP 优化故障排除
我目前正在开展一个项目,以根据员工的零件生产效率来优化他们的零件生产。我目前已经编译了来自 sql 的所有信息,并将它们放入一个数据框中以供探索。我还从生产经理那里获取用户输入,以获得所需的零件编号和数量。目标是使用 Pulp 包将 QtyProduced 列更改为优化数量(整数将是理想的)。 TimeUsed 列将随着 QtyProduced 的更新而自动更新。我使用平均 TimeUsed 作为目标来最小化,并确保每个员工都保持在可用时间限制之下,并且满足每个零件数量。
我相信这是设置错误,但不确定它在哪里挂断。当我输入一个部分和一个小整数(如 5)的数量时,求解器仍然给出“线性松弛不可行”。
Welcome to the CBC MILP Solver
Version: 2.9.0
Build Date: Feb 12 2015
At line 2 NAME MODEL
At line 3 ROWS
At line 27 COLUMNS
At line 29 RHS
At line 52 BOUNDS
At line 54 ENDATA
Problem MODEL has 22 rows,1 columns and 0 elements
Coin0008I MODEL read with 0 errors
Empty problem - 22 rows,1 columns and 0 elements
Empty problem - 22 rows,1 columns and 0 elements
Primal infeasible - objective value 0
PrimalInfeasible objective 0 - 0 iterations time 0.002
Result - Linear relaxation infeasible
Enumerated nodes: 0
Total iterations: 0
Time (cpu seconds): 0.00
Time (Wallclock Seconds): 0.00
Option for printingOptions changed from normal to all
Total time (cpu seconds): 0.00 (Wallclock seconds): 0.00
Process finished with exit code 0
Enter number of different parts: 3
Enter Part Number : 23496434-LH
Enter Qty of Part Number : 5
Enter Part Number : 84312875-LH-D
Enter Qty of Part Number : 50
Enter Part Number : 84729097-LH-D
Enter Qty of Part Number : 60
PartNo QtyProduced QtyNeeded
0 23496434-LH 0 5
1 84312875-LH-D 0 50
2 84729097-LH-D 0 60
EmplName TimeUsed AvailableTime
0 Employee A 0.0 530.0
1 Employee B 0.0 530.0
2 Employee C 0.0 530.0
3 Employee D 0.0 530.0
4 Employee E 0.0 530.0
5 Employee F 0.0 530.0
6 Employee G 0.0 530.0
7 Employee H 0.0 530.0
8 Employee I 0.0 530.0
9 Employee J 0.0 530.0
Total number of decision variables: 30
PartNo QtyNeeded CycleTime EmplName UpdatedJobEff QtyProduced TimeUsed
0 23496434-LH 5 25.0 Employee A 1.083794 0 0.0
1 23496434-LH 5 25.0 Employee B 1.310655 0 0.0
2 23496434-LH 5 25.0 Employee C 0.400000 0 0.0
3 23496434-LH 5 25.0 Employee D 0.400000 0 0.0
4 23496434-LH 5 25.0 Employee E 1.244152 0 0.0
5 23496434-LH 5 25.0 Employee F 0.400000 0 0.0
6 23496434-LH 5 25.0 Employee G 0.400000 0 0.0
7 23496434-LH 5 25.0 Employee H 0.400000 0 0.0
8 23496434-LH 5 25.0 Employee I 0.400000 0 0.0
9 23496434-LH 5 25.0 Employee J 0.400000 0 0.0
10 84312875-LH-D 50 30.0 Employee A 0.400000 0 0.0
11 84312875-LH-D 50 30.0 Employee B 1.171081 0 0.0
12 84312875-LH-D 50 30.0 Employee C 0.400000 0 0.0
13 84312875-LH-D 50 30.0 Employee D 0.400000 0 0.0
14 84312875-LH-D 50 30.0 Employee E 1.018995 0 0.0
15 84312875-LH-D 50 30.0 Employee F 0.400000 0 0.0
16 84312875-LH-D 50 30.0 Employee G 0.400000 0 0.0
17 84312875-LH-D 50 30.0 Employee H 0.720496 0 0.0
18 84312875-LH-D 50 30.0 Employee I 0.617332 0 0.0
19 84312875-LH-D 50 30.0 Employee J 0.400000 0 0.0
20 84729097-LH-D 60 15.0 Employee A 0.400000 0 0.0
21 84729097-LH-D 60 15.0 Employee B 0.400000 0 0.0
22 84729097-LH-D 60 15.0 Employee C 1.098460 0 0.0
23 84729097-LH-D 60 15.0 Employee D 0.400000 0 0.0
24 84729097-LH-D 60 15.0 Employee E 0.553506 0 0.0
25 84729097-LH-D 60 15.0 Employee F 0.400000 0 0.0
26 84729097-LH-D 60 15.0 Employee G 0.400000 0 0.0
27 84729097-LH-D 60 15.0 Employee H 0.400000 0 0.0
28 84729097-LH-D 60 15.0 Employee I 0.400000 0 0.0
29 84729097-LH-D 60 15.0 Employee J 0.400000 0 0.0
# User Input Part Number,Qty,and pull description and CycleTime for Each #
total_parts = int(input("Enter number of different parts: "))
partno = []
quantity = []
for i in range(total_parts):
pn = input("Enter Part Number : ").strip()
qty = input("Enter Qty of Part Number : ")
partno.append(pn)
quantity.append(qty)
b = {'PartNo': partno,'QtyNeeded': quantity}
DailyDemand = pd.DataFrame(b)
c = pd.merge(DailyDemand,part_number_breakdown)
pd.set_option('colheader_justify','center')
#print(DailyDemand)
# Merging Efficiencies with Parts Entered #
combined_df = pd.merge(c,production_df,on='PartNo',how='left')
combined_df['QtyProduced'] = 0
combined_df['TimeUsed'] = (combined_df.CycleTime * combined_df.QtyProduced)/combined_df.UpdatedJobEff
#print(combined_df)
# Counting Employees #
n = len(pd.unique(combined_df['EmplName']))
#print("")
#print("Number of Employees : ",n)
UniqueEmpl = pd.DataFrame(pd.unique(combined_df['EmplName']))
# Constraint Dataframes #
total_produced = combined_df.groupby('PartNo')['QtyProduced'].sum().reset_index()
total_produced = pd.merge(total_produced,DailyDemand)
total_empl_time = combined_df.groupby('EmplName')['TimeUsed'].sum().reset_index()
total_empl_time['AvailableTime'] = 530.0
print("")
print(total_produced)
print("")
print(total_empl_time)
# Importing PulP and Checking Decision Variables #
import pulp
decision_variables = []
for rownum,row in combined_df.iterrows():
variablestr = str('x' + str(rownum))
variable = pulp.LpVariable(str(variablestr),lowBound=0,upBound=1,cat='Integer')
decision_variables.append(variable)
print("")
print("Total number of decision variables: " + str(len(decision_variables)))
# Define Optimize Function and Constraints#
prob = pulp.LpProblem('AveragetotalTime',pulp.LpMinimize)
prob += sum(combined_df['TimeUsed'])/n,"obj"
for index,row in total_empl_time.iterrows():
prob += pulp.LpConstraint(row['TimeUsed'] <= row['AvailableTime'])
prob += pulp.LpConstraint(row['TimeUsed'] >= 0)
for index,row in total_produced.iterrows():
prob += pulp.LpConstraint(row['QtyProduced'] == row['QtyNeeded'])
prob += pulp.LpConstraint(row['QtyProduced'] >= 0)
########################################################################################################################
prob.solve()
pulp.LpStatus[prob.status]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。