用机器约束的车间安排

发布于 2025-02-02 17:18:26 字数 2329 浏览 3 评论 0原文

我正在研究JOP商店的调度问题,并试图集成仅允许某些作业分配给某些机器的约束。 我以为我可以通过创建一组其他类型的机器(a,b),然后创建一个约束,该约束只允许使用此特定类型的作业来处理。

数据:

dict_jobs = {
10 : {'dur' : 45, 'type' : 'A', 'JobDeadline' : '31/05/2022'},
20 : {'dur' : 45, 'type' : 'A', 'JobDeadline' : '31/05/2022'},    
30 : {'dur' : 70, 'type' : 'A', 'JobDeadline' : '27/05/2022'},
100 : {'dur' : 55, 'type' : 'B', 'JobDeadline' : '25/05/2022'},
110 : {'dur' : 75, 'type' : 'B', 'JobDeadline' : '30/05/2022'},
120 : {'dur' : 45, 'type' : 'B', 'JobDeadline' : '30/05/2022'}}


dict_machine = {
111 : {'duration' : 500, 'end' : '16:00:00', 'start' : '08:30:00', 'type' : 'A', 'date' : '30/05/2022'},
222 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'A', 'date' : '25/05/2022'},
333 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'B', 'date' : '30/05/2022'},
444 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'B', 'date' : '25/05/2022'}}

模型

model = ConcreteModel()

model.JOBS= Set(initialize = dict_jobs.keys(), dimen=1)

model.MACHINES = Set(initialize = dict_machines.keys(), dimen=1)

model.TYPES = Set(initialize = ['A', 'B'])

model.TASKS = Set(initialize = model.JOBS * model.MACHINES, dimen=2)


model.MACHINE_ASSIGNED = Var(model.TASKS, domain = Binary)


model.TYPE_JOBS = Set(initialize = [(10 , 'A'), (20 , 'A'), (30, 'A'), (100, 'B'), (110, 'B'), (120, 'B')], dimen = 2)

model.JOB_TYPE = Var(model.TPYE_JOBS, domain = Binary)

model.TYPE_MACHINE= Set(initialize = [(111, 'A'), (222, 'A'), (333, 'B'), (444, 'B')], dimen = 2)

 model.MACHINE_TYPE= Var(model.TYPE_MACHINE, domain = Binary)

约束

def type_condition(model, type, machine):
      return (model.MACHINE_ASSIGNED[job, machine] * model.JOB_TYPE[job, type] <=(model.MACHINE_TYPE[machine, type]) for type in model.TYPES)

 model.APPLY_SPEC = Constraint(model.TASKS, rule=type_condition)

客观

def objective_function(model):
    return summation(model.UTILIZATION)
model.OBJECTIVE = Objective(rule = objective_function, sense = maximize)

问题 当我试图解决这个问题时,我会遇到此错误:“ keyError:“ index'(10,'b')'对于索引组件'job_type'“”“”。

有什么想法我如何修改约束?

I am working on a jop shop scheduling problem and trying to integrate a constraint that only allows certain jobs to be assigned to certain machines.
I thought I could do this by creating an additional Set of different types of machines (A,B) and then creating a constraint that only allows jobs with this specific type to be handled on the machine.

Data:

dict_jobs = {
10 : {'dur' : 45, 'type' : 'A', 'JobDeadline' : '31/05/2022'},
20 : {'dur' : 45, 'type' : 'A', 'JobDeadline' : '31/05/2022'},    
30 : {'dur' : 70, 'type' : 'A', 'JobDeadline' : '27/05/2022'},
100 : {'dur' : 55, 'type' : 'B', 'JobDeadline' : '25/05/2022'},
110 : {'dur' : 75, 'type' : 'B', 'JobDeadline' : '30/05/2022'},
120 : {'dur' : 45, 'type' : 'B', 'JobDeadline' : '30/05/2022'}}


dict_machine = {
111 : {'duration' : 500, 'end' : '16:00:00', 'start' : '08:30:00', 'type' : 'A', 'date' : '30/05/2022'},
222 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'A', 'date' : '25/05/2022'},
333 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'B', 'date' : '30/05/2022'},
444 : {'duration' : 800, 'end' : '17:00:00', 'start' : '08:00:00', 'type' : 'B', 'date' : '25/05/2022'}}

Model

model = ConcreteModel()

model.JOBS= Set(initialize = dict_jobs.keys(), dimen=1)

model.MACHINES = Set(initialize = dict_machines.keys(), dimen=1)

model.TYPES = Set(initialize = ['A', 'B'])

model.TASKS = Set(initialize = model.JOBS * model.MACHINES, dimen=2)


model.MACHINE_ASSIGNED = Var(model.TASKS, domain = Binary)


model.TYPE_JOBS = Set(initialize = [(10 , 'A'), (20 , 'A'), (30, 'A'), (100, 'B'), (110, 'B'), (120, 'B')], dimen = 2)

model.JOB_TYPE = Var(model.TPYE_JOBS, domain = Binary)

model.TYPE_MACHINE= Set(initialize = [(111, 'A'), (222, 'A'), (333, 'B'), (444, 'B')], dimen = 2)

 model.MACHINE_TYPE= Var(model.TYPE_MACHINE, domain = Binary)

Constraint

def type_condition(model, type, machine):
      return (model.MACHINE_ASSIGNED[job, machine] * model.JOB_TYPE[job, type] <=(model.MACHINE_TYPE[machine, type]) for type in model.TYPES)

 model.APPLY_SPEC = Constraint(model.TASKS, rule=type_condition)

Objective

def objective_function(model):
    return summation(model.UTILIZATION)
model.OBJECTIVE = Objective(rule = objective_function, sense = maximize)

Problem
When I am trying to solve this I am getting this error: "KeyError: "Index '(10, 'B')' is not valid for indexed component 'JOB_TYPE'"".

Any ideas how I can modify the constraint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2025-02-09 17:18:26

几件事会有所帮助...

首先,您可以将稀疏集用于仅限于兼容的JM配对。这将防止“非法”任务并减少模型的大小。 (请参阅代码)

第二,您可能需要基于机器类型/任何类型的几种类型的子集。你可以&amp;应该使那些具有固定综合的人,等等。

最后,您可能会发现用于索引集的用途,例如由包含一组兼容作业的机器索引的集合。作业集由机器集索引。 (请参阅代码)

# job-shop setup

import pyomo.environ as pyo

jobs = {
    10: {"dur": 45, "type": ["A",], "JobDeadline": "31/05/2022"},
    20: {"dur": 45, "type": ["B",], "JobDeadline": "31/05/2022"},
    30: {"dur": 70, "type": ["A", "B"], "JobDeadline": "27/05/2022"},
}


machines = {
    111: {
        "duration": 500,
        "end": "16:00:00",
        "start": "08:30:00",
        "type": "A",
        "date": "30/05/2022",
    },
    222: {
        "duration": 800,
        "end": "17:00:00",
        "start": "08:00:00",
        "type": "A",
        "date": "25/05/2022",
    },
    333: {
        "duration": 800,
        "end": "17:00:00",
        "start": "08:00:00",
        "type": "B",
        "date": "30/05/2022",
    }
}

compatible_assignments = {(j, m) for j in jobs.keys() 
                            for m in machines.keys() 
                            if machines[m]['type'] in jobs[j]['type']}
jobs_by_machine = {m: 
    [j for j in jobs.keys() if machines[m]['type'] in jobs[j]['type']]
    for m in machines.keys()}

print(compatible_assignments)
print(jobs_by_machine)

model = pyo.ConcreteModel()

#SETS
model.J = pyo.Set(initialize=jobs.keys())
model.M = pyo.Set(initialize=machines.keys())
model.JM = pyo.Set(within=model.J*model.M, initialize=compatible_assignments)
model.J_by_M = pyo.Set(model.M, within=model.J, initialize=jobs_by_machine)

model.pprint()

A couple things will help...

First, you can use a sparse set for the J-M pairings that is restricted to only compatible ones. This will prevent "illegal" assignments and reduce the size of your model. (see code)

Second, you will likely have need for several types of subsets based on machine type/whatever. You can & should make those with set comprehensions, etc. and just put those into the model as needed.

Lastly, you might find use for indexed sets, such as a set that is indexed by machine that contains a set of compatible jobs. The sets of jobs are indexed by the set of machines. (see code)

# job-shop setup

import pyomo.environ as pyo

jobs = {
    10: {"dur": 45, "type": ["A",], "JobDeadline": "31/05/2022"},
    20: {"dur": 45, "type": ["B",], "JobDeadline": "31/05/2022"},
    30: {"dur": 70, "type": ["A", "B"], "JobDeadline": "27/05/2022"},
}


machines = {
    111: {
        "duration": 500,
        "end": "16:00:00",
        "start": "08:30:00",
        "type": "A",
        "date": "30/05/2022",
    },
    222: {
        "duration": 800,
        "end": "17:00:00",
        "start": "08:00:00",
        "type": "A",
        "date": "25/05/2022",
    },
    333: {
        "duration": 800,
        "end": "17:00:00",
        "start": "08:00:00",
        "type": "B",
        "date": "30/05/2022",
    }
}

compatible_assignments = {(j, m) for j in jobs.keys() 
                            for m in machines.keys() 
                            if machines[m]['type'] in jobs[j]['type']}
jobs_by_machine = {m: 
    [j for j in jobs.keys() if machines[m]['type'] in jobs[j]['type']]
    for m in machines.keys()}

print(compatible_assignments)
print(jobs_by_machine)

model = pyo.ConcreteModel()

#SETS
model.J = pyo.Set(initialize=jobs.keys())
model.M = pyo.Set(initialize=machines.keys())
model.JM = pyo.Set(within=model.J*model.M, initialize=compatible_assignments)
model.J_by_M = pyo.Set(model.M, within=model.J, initialize=jobs_by_machine)

model.pprint()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文