简体   繁体   English

docplex - 将 interval_var 的大小设置为另一个变量的 function

[英]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.

相关问题 如何在 docplex (python) 中启动区间变量边界? - How to initiate the interval variable bounds in docplex (python)? 在Matlab中以固定间隔找到两个变量函数的最小值和最大值,并使用该函数在同一图中绘制这些点 - Find minimum and maximum of a two variable function on fixed interval in Matlab, and plotting those points in the same graph with the function 是否有一个 docplex 函数来获得一个以上变量的解决方案,以便在惰性切割中使用? - Is there a docplex function for getting solution of more than one variables for using in lazy cut? 文档集! 中断执行 - Docplex ! Interrupt the execution 根据输入大小来表达一种算法相对于另一种算法的加速 - Expressing the speed up of one algorithm over another as a function of input size 在间隔集合中查找间隔模式 - Find interval pattern in set of intervals 多少个间隔包含另一个间隔? - How many intervals are containing an another interval? 计算包含另一个间隔的间隔数? - Count number of intervals containing another interval? 当一个极限是另一个积分变量的函数时,在matlab中进行双重积分 - double integration in matlab when one limit is a function of another integration variable 使用R的ompr或其他优化功能进行分配 - Assignment with R's ompr or another optimization function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM