[英]docplex - set an interval_var's size as a function of another variable
In IBM's docplex optimization library, can you set an interval_var
's size parameter as a function of another variable?在 IBM 的 docplex 优化库中,您可以将
interval_var
的大小参数设置为另一个变量的 function 吗? Meaning, say for this example I wanted to make the task size dependent on the skill level of the worker.意思是说,对于这个例子,我想让任务大小取决于工人的技能水平。 If the worker has a skill level of 2 and another worker has a skill level of 1, the task is completed twice as fast with the first worker.
如果工人的技能等级为 2,而另一个工人的技能等级为 1,则第一个工人完成任务的速度是前者的两倍。 So the size parameter of the
interval_var
for that task should be the task.duration / skill_level
.因此,该任务的
interval_var
的大小参数应该是task.duration / skill_level
。
It is typically set as an integer value based on the documentation, so I am wondering if there is a workaround to make this possible.它通常根据文档设置为 integer 值,所以我想知道是否有解决方法可以实现这一点。
From the example:从例子:
Task = (namedtuple("Task", ["name", "duration"]))
TASKS = {Task("masonry", 35),
Task("carpentry", 15),
Task("plumbing", 40),
Task("ceiling", 15),
Task("roofing", 5),
Task("painting", 10),
Task("windows", 5),
Task("facade", 10),
Task("garden", 5),
Task("moving", 5),
}
tasks = {} # dict of interval variable for each house and task
for house in HOUSES:
for task in TASKS:
tasks[(house, task)] = mdl.interval_var(start=period_domain,
end=period_domain,
size=task.duration,
name="house {} task {}".format(house, task))
There are two possibilities:有两种可能:
1- In general, if you have to handle workers with different skills, you will have also to handle the allocation of tasks to workers in the scheduling problem. 1- 通常,如果您必须处理具有不同技能的工人,您还必须在调度问题中处理分配给工人的任务。 In this case, for a given tasks (for instance 'masonry') you will create one optional interval variable per possible worker (or per skill) and you will specify the skill-related duration on this interval variable.
在这种情况下,对于给定的任务(例如“砌体”),您将为每个可能的工人(或每个技能)创建一个可选的间隔变量,并且您将在此间隔变量上指定与技能相关的持续时间。 See for example the delivered Python example "house_building_optional.py" (though in this example, we assume the duration is worker independent).
例如,请参阅交付的 Python 示例“house_building_optional.py”(尽管在此示例中,我们假设持续时间与工人无关)。 So you will end up with a pattern like:
所以你最终会得到一个像这样的模式:
tasks = [ interval_var(name='Task{}'.format(i)) for i in ... ]
tasksOnWorkers = [ [ interval_var(optional=True, size=DURATION[i,j], name='Task{}_Worker{}'.format(i,j)) for j in ...] for i in ... ]
model.add(alternative(tasks[i], [tasksOnWorkers[i][j] for j in ...]) for i in ...)
Stated otherwise, in the example you mention you would not specify the size here:另有说明,在您提到的示例中,您不会在此处指定大小:
tasks[(house, task)] = mdl.interval_var(start=period_domain,
end=period_domain,
size=task.duration,
name="house {} task {}".format(house, task))
But instead, here:但是,在这里:
for house in HOUSES:
for skill in SKILLS:
iv = mdl.interval_var(name='H' + str(house) + '-' + skill.task + '(' + skill.worker + ')')
iv.set_optional()
wtasks[(house, skill)] = iv
2- The above method is the preferred one in case of resource allocation. 2- 在资源分配的情况下,上述方法是首选方法。 But you can also use an integer expression
length_of(intervalVar)
to constrain the length of the interval:但您也可以使用 integer 表达式 length_of
length_of(intervalVar)
来约束间隔的长度:
x = interval_var() # By default length is unconstrained in [0,INTERVAL_MAX)
model.add(length_of(x) == 'Whatever integer expression or variable in the model')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.