从附加的研讨会(带时间戳)中,如果限制所有 presence_literals * interval_size 的总和小于完成时间,则已证明的问题数量会根据视频增加。
当然,我想将其包含在我的基于样本的问题中。但是,我还没有找到如何做到这一点,特别是因为它考虑了机器,所以我的印象是它应该在样本的这一部分中;
# Transition times and transition costs using a circuit constraint.
switch_literals = []
for machine_id in all_machines:
machine_starts = starts_per_machines[machine_id]
machine_ends = ends_per_machines[machine_id]
machine_presences = presences_per_machines[machine_id]
machine_resources = resources_per_machines[machine_id]
machine_ranks = ranks_per_machines[machine_id]
intervals = intervals_per_machines[machine_id]
arcs = []
num_machine_tasks = len(machine_starts)
all_machine_tasks = range(num_machine_tasks)
for i in all_machine_tasks:
# Initial arc from the dummy node (0) to a task.
start_lit = model.NewBoolVar('')
arcs.append([0, i + 1, start_lit])
# If this task is the first, set both rank and start to 0.
model.Add(machine_ranks[i] == 0).OnlyEnforceIf(start_lit)
model.Add(machine_starts[i] == 0).OnlyEnforceIf(start_lit)
# Final arc from an arc to the dummy node.
arcs.append([i + 1, 0, model.NewBoolVar('')])
# Self arc if the task is not performed.
arcs.append([i + 1, i + 1, machine_presences[i].Not()])
model.Add(machine_ranks[i] == -1).OnlyEnforceIf(
machine_presences[i].Not())
for j in all_machine_tasks:
if i == j:
continue
lit = model.NewBoolVar('%i follows %i' % (j, i))
arcs.append([i + 1, j + 1, lit])
model.AddImplication(lit, machine_presences[i])
model.AddImplication(lit, machine_presences[j])
# Maintain rank incrementally.
model.Add(machine_ranks[j] == machine_ranks[i] + 1).OnlyEnforceIf(lit)
# Compute the transition time if task j is the successor of task i.
if machine_resources[i] != machine_resources[j]:
transition_time = 3
switch_literals.append(lit)
else:
transition_time = 0
# We add the reified transition to link the literals with the times
# of the tasks.
model.Add(machine_starts[j] == machine_ends[i] +
transition_time).OnlyEnforceIf(lit)
我尝试按如下方式实现它;
model.Add(sum(machine_presences[i] * intervals[i] for i in all_machine_tasks) <= horizon)
这会产生错误
arg = cmh.assert_is_a_number(arg)
TypeError: Not a number: interval_j5_t11_a0
根据示例,实现此目的的最佳方法是什么?例如,我是否需要duration
在机器上为每个任务创建一个变量,然后将该数字与 presence_literal 相乘?我使用 OR-tools 9.8 和 Python。