MIP使用纸浆不接近结果

2024-09-24 02:24:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试解决一个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

最后一个条件似乎是问题,如果我去掉它,问题就会收敛。但是,我不能理解这个问题。你知道吗

请让我知道,我在我的理解中遗漏了什么。谢谢。你知道吗


Tags: innewfordatagetdateindexlevel