Programming constraints: scheduling schedules as soon as possible

I am trying to adapt the already solved problem of programming restrictions by Hakan Kjellerstrand (@hakankless) and could help with some help.

Original problem solved: There are 6 public speakers and 6 rooms. Each loudspeaker should be assigned to a room, while not a single room will remain empty, and each speaker in one room.

Solutions here: Google OR-Tools and MiniZinc

Help with this adaptation: There are 3 public speakers and 6 time slots (i.e. one room). Each speaker should be assigned to one time interval in order to minimize the duration from the initial slot (it is assumed that it starts from slot 1 or everyone is busy starting from the next available slot).

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

The solution would be (A, 1), (C, 3), (B, 4). If we started with (C, 1), it would end with (A, 5) or (B, 5). Since 4 <5, the first solution is correct. How can i solve this?

Visual solution:

 +---+----------+----------+----------+ | | A | B | C | +---+----------+----------+----------+ | 1 | SELECTED | Busy | | | 2 | Busy | Busy | Busy | | 3 | Busy | Busy | SELECTED | | 4 | | SELECTED | | | 5 | | | Busy | | 6 | Busy | Busy | | +---+----------+----------+----------+ 
+1
algorithm constraint-programming mathematical-optimization solver
source share
2 answers

You have mixed array sizes. This helps if you give your variables more meaningful names to make them more obvious, which goes 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) ---------- 
+1
source share

This turns your satisfaction problem into an optimization problem. That is, this is not enough to find a solution more, you want the best. So, for the MiniZinc model you will 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 most time allotted.

+3
source share

All Articles