约束编程:在最短的时间内调度扬声器

时间:2013-12-17 10:28:29

标签: algorithm mathematical-optimization solver constraint-programming

我正在尝试通过Hakan Kjellerstrand(@hakankless)调整已经解决的约束编程问题,并且可以提供一些帮助。

原始解决问题: 共有6位公共演讲者和6位客房。每个扬声器都应分配到一个房间,没有空间,每个扬声器只在一个房间内。

此处的解决方案:Google OR-Tools& MiniZinc

帮助改编: 有3个公共发言人和6个时段(即一个房间)。每个扬声器应分配到一个时隙,目的是最小化起始时隙的持续时间(假设从时隙1开始,或者如果所有忙,则从下一个可用时隙开始)。

+---+------+------+------+
|   |  A   |  B   |  C   |
+---+------+------+------+
| 1 |      | Busy |      |
| 2 | Busy | Busy | Busy |
| 3 | Busy | Busy |      |
| 4 |      |      |      |
| 5 |      |      | Busy |
| 6 | Busy | Busy |      |
+---+------+------+------+

解决方案是(A,1),(C,3),(B,4)。如果我们从(C,1)开始,那么它将以(A,5)或(B,5)结束。从4< 5,第一种解决方案是正确的。 我该如何解决这个问题?

视觉解决方案:

+---+----------+----------+----------+
|   |    A     |    B     |    C     |
+---+----------+----------+----------+
| 1 | SELECTED | Busy     |          |
| 2 | Busy     | Busy     | Busy     |
| 3 | Busy     | Busy     | SELECTED |
| 4 |          | SELECTED |          |
| 5 |          |          | Busy     |
| 6 | Busy     | Busy     |          |
+---+----------+----------+----------+

2 个答案:

答案 0 :(得分:3)

这会将您的满意度问题转变为优化问题。也就是说,仅仅找到 解决方案是不够的,你需要最佳。因此,对于MiniZinc模型,您需要更改

solve :: int_search(x, first_fail, indomain_min, complete) satisfy;

类似

solve :: int_search(x, first_fail, indomain_min, complete) minimize max(x);

最小化最大分配时间。

答案 1 :(得分:1)

您的阵列尺寸混乱了。如果您为变量赋予更有意义的名称,使其更明显的范围超出什么范围,这会有所帮助。

include "globals.mzn";

int: n = 3; % number of speakers
int: s = 6; % number of slots
array[1..n] of set of 1..s: available; % the available slots
array[1..n] of var 1..s: speaks_at; % the allotted speaker slot

solve :: int_search(speaks_at, first_fail, indomain_min, complete)
         minimize max(speaks_at);

constraint
   all_different(speaks_at)
   /\
   forall(i in 1..n) (
      speaks_at[i] in available[i]
   )
;

% at which slot is each speaker available to speak
available = [
    {1,4,5},  
    {4,5},  
    {1,3,4,6}  
];

output
[
    show(speaks_at)
];

这给出了预期的答案:

% Starting search
Found a solution with cost 4
speaks_at = array1d(1..3, [1,4,3]);
% Minimum objective value = 4
% Total time 0.016s cpu (0.000 setup + 0.000 search)
----------