Pyomo日程安排

时间:2018-03-27 05:57:53

标签: optimization job-scheduling pyomo

我正试图在Pyomo中制定一个flowshop调度问题。这是一个抽象模型

问题描述
有3个工作(胸部,门和椅子)和3个机器(切割,焊接,按顺序包装)。目标是尽量减少完工时间。 python代码和数据如下。

## flowshop.py ##
from pyomo.environ import *
flowshop = AbstractModel()
flowshop.jobs = Set()
flowshop.machines = Set()
flowshop.machinesN = Param()
flowshop.jobsN = Param()
flowshop.proc_T = Param(flowshop.jobs, 
                        flowshop.machines, 
                        within=NonNegativeReals)
flowshop.start_T = Var(flowshop.jobs, 
                       flowshop.machines, 
                       within=NonNegativeReals)
flowshop.makespan = Var(within=NonNegativeReals)      

def makespan_rule(flowshop,i,j):
    return flowshop.makespan >= flowshop.start_T[i,j]+flowshop.proc_T[i,j]
flowshop.makespan_cons = Constraint(flowshop.jobs,
                                    flowshop.machines,
                                    rule=makespan_rule)

def objective_rule(flowshop):
    return flowshop.makespan
flowshop.objc = Objective(rule=objective_rule,sense=minimize)  

## data.dat ##
set jobs := chest door chair ;
set machines := cutting welding packing ;
param: machinesN := 3 ;
param: jobsN := 3 ;
param proc_T:   
             cutting      welding     packing  :=
    chest    10           40          45
    door     30           20          25  
    chair    05           30          15  
;

我尚未添加所有约束,我计划在此问题得到修复后添加它们。在上面的代码(flowhop.py)中,对于makespan_rule,我希望完工时间超过最后一台机器的完成时间。  目前,它被设置为超过所有机器的完成时间 为此,我相信,我必须得到machines集的最后一个索引 为此,我尝试了flowshop.machines[-1],但它提出错误说:
 Cannot index unordered set machines

如何解决此问题?
谢谢你的帮助。
PS - 我也在努力模拟用于定义作业优先级的二进制变量。如果您对此有任何想法,那也会有所帮助。

1 个答案:

答案 0 :(得分:0)

由于错误显示为Cannot index unordered sets,因此未订购集flowshop.machines。人们需要在声明集合时提供ordered=True参数 -
 flowshop.machines = Set(ordered=True)
在此之后,可以通过正常索引访问任何元素 - flowshop.machines[i]

对于二进制变量,可以将它们声明为 -

c = flowshop.jobsN*(flowshop.jobsN-1)/2
flowshop.prec = Var(RangeSet(1,c),within=Binary)

然后,此变量可用于确定两个作业之间的优先级并制定赋值约束。可以使用作业的索引找到与一对作业对应的优先级变量(flowshop.jobs必须是有序集 - flowshop.jobs = Set(ordered=True)