使用PULP的MIP无法达到结果

时间:2018-12-31 12:53:33

标签: python pulp

我正在尝试解决MIP问题。我试图通过尽量减少使用的技术总数来查找每种技术在一周内要进行的考试数量。 我在单独的数据框中有需求,每种技术所花的时间,技术列表等。

最初,我使用成本函数来最大限度地减少用于完成需求的总时间,@ kabdulla帮助我解决了linkhere

现在,使用新的成本函数,脚本会卡住并且似乎无法收敛,我无法确定原因。

到目前为止,我的代码如下:

# Instantiate problem class
model = pulp.LpProblem("Time minimizing problem", pulp.LpMinimize)

capacity = pulp.LpVariable.dicts("capacity",
                                 ((examdate , techname, region) for examdate, techname, region in tech_data_new.index),
                                 lowBound=0,
                                 cat='Integer')

tech_used = pulp.LpVariable.dicts("techs",
                             ((examdate,techname) for examdate,techname,region in tech_data_new.index.unique()),
                             cat='Binary')

model += pulp.lpSum(tech_used[examdate, techname] for examdate,techname in date_techname_index.index.unique())

for date in demand_data.index.get_level_values('Exam Date').unique():
    for i in demand_data.loc[date].index.tolist():
        model += pulp.lpSum([capacity[examdate,techname,region] for examdate, techname, region in tech_data_new.index if (date == examdate and i == region)]) == demand_data.loc[(demand_data.index.get_level_values('Exam Date') == date) & (demand_data.index.get_level_values('Body Region') == i), shiftname].item()

for examdate, techname,region in tech_data_new.index:
    model += (capacity[examdate, techname, region]) <= tech_data_new.loc[(examdate,techname,region), 'Max Capacity']*tech_used[examdate, techname]

# Number of techs used in a day should be less than 8    
for examdate in tech_data_new.index.get_level_values('Exam Date').unique():
    model += pulp.lpSum(tech_used[examdate, techname] for techname in tech_data_new.index.get_level_values('Technologist Name').unique()) <=8


# Max time each tech should work in a day should be less than 8 hours(28800 secs)    
for date in tech_data_new.index.get_level_values('Exam Date').unique():
    for name in tech_data_new.loc[date].index.get_level_values('Technologist Name').unique():
        #print(name)
        model += pulp.lpSum(capacity[examdate,techname,region] * tech_data_new.loc[(examdate,techname,region), 'Time taken'] for examdate, techname, region in tech_data_new.index if (date == examdate and name == techname)) <= 28800

最后一个条件似乎是问题所在,如果我删除它,问题将趋于收敛。但是,我无法理解问题。

请让我知道,我所欠缺的知识。谢谢。

0 个答案:

没有答案