Constraint Programming: Scheduling speakers in shortest time

后端 未结 2 1099
情深已故
情深已故 2021-01-16 07:34

I\'m trying to adapt an already solved constraint programming problem by Hakan Kjellerstrand (@hakankless) and could do with some help please.

Original s

相关标签:
2条回答
  • 2021-01-16 07:52

    This is turning your satisfaction problem into an optimisation problem. That is, it is not enough to find a solution anymore, you want the optimal one. So for the MiniZinc model, you would need to change

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

    to something like

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

    to minimize the largest allocated time.

    0 讨论(0)
  • 2021-01-16 08:01

    You got your array dimensions mixed up. It helps if you give your variables more meaningful names to make it more obvious what ranges over what.

    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)
    ];
    

    This gives the expected answer:

    % 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)
    ----------
    
    0 讨论(0)
提交回复
热议问题