首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >纸浆中约束与目标的关联

纸浆中约束与目标的关联
EN

Stack Overflow用户
提问于 2018-12-03 14:50:55
回答 1查看 408关注 0票数 0

我想解决一个MIP问题。我试图通过最小化完成需求所需的总时间,找出每个技术人员在一周内完成考试的次数。

我有需求,每项技术所占用的时间,技术人员的名单等在不同的数据中。

我可以找到的考试次数,以尽量减少目标,但我希望增加一个限制的最大数量的技术将使用8。

我增加了一些二元变量来增加条件,但是我不能把它和目标函数联系起来。

下面是到目前为止我的代码:

代码语言:javascript
复制
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')

for examdate, techname,region in tech_data_new.index:
var = capacity[(examdate,techname,region)]
var.upBound = tech_data_new.loc[(examdate,techname,region), 'Max Capacity']


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)

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()

这些是二元变量,我试着添加,但是不能与目标联系起来,因为乘法会使它变成非线性的。

代码语言:javascript
复制
techs = pulp.LpVariable.dicts("techs",
                                 (techname for techname in tech_data_new.index.get_level_values('Technologist Name').unique()),

                                 cat='Binary')

days = pulp.LpVariable.dicts("day",
                             (examdate for examdate in tech_data_new.index.get_level_values('Exam Date').unique()),

                             cat='Binary')

任何线索都将不胜感激。提前谢谢。如果需要任何其他支持,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-16 14:07:54

如果您想为每个examdate设置一个约束,并且包含索引(examdate, techname, region)的整数变量capacity表示每个技术在每个区域的每个日期所做的考试次数,那么我将创建一组二进制变量tech_used,它被索引为(examdate, techname),它代表是否每天使用reach技术。

在定义这些var之后,您需要设置约束,以便它们按照需要运行.假设列表examdates, technames, regions已被适当声明:

代码语言:javascript
复制
for examdate in examdates:
    for techname in technames:
        model += Lp.sum([capacity[examdate, techname, region] for region in regions]) < max_capacity*tech_used(examdate, techname)

请注意,在上面,max_capacity应该是每个技术的容量,这些约束可以代替您在其他地方放置的最大容量约束。

那你只需要设定你的限制。最多有8名技术人员:

代码语言:javascript
复制
for examdate in examdates:
    model += Lp.sum([tech_used[examdate, techname] for techname in technames])  <= 8
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53596196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档