Skip to content

Commit 51c444e

Browse files
dtonhoferDekker1
authored andcommitted
Update patrolV2.mzn
This version included "globals.mzn" which is actually only needed in patrolV3.mzn. Removed for clarity. Also reformatted the constraints so that they look exactly as in patrolV1, no changes. Shortened the long output command. Interesting: If the constraint about "not three night shifts" comes before the constraint "evening then not night" (in this change request), then a solution is found in 13s (on my machine). If the constraint about "evening then not night" comes before the constraint "not three night shifts" (originally), then a solution is found in 33s (on my machine).
1 parent bd6e197 commit 51c444e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

functions/patrol/patrolV2.mzn

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
% Patrol Scheduling
2-
include "globals.mzn";
32

43
enum SOLDIER;
54
enum SHIFT = { OFF, EVE, NIGHT };
@@ -13,13 +12,15 @@ int: u;
1312

1413
array[SOLDIER, DAY] of var SHIFT: roster;
1514

16-
constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s, d] = EVE) -> (roster[s, d+1] != NIGHT));
17-
constraint forall (d in 1..(nDays-2), s in SOLDIER) ((roster[s, d] = NIGHT) /\ (roster[s, d+1] = NIGHT) -> (roster[s, d+2] != NIGHT));
15+
constraint forall (d in 1..(nDays-2), s in SOLDIER) ((roster[s,d] = NIGHT) /\ (roster[s,d+1] = NIGHT) -> (roster[s,d+2] != NIGHT));
16+
constraint forall (d in 1..(nDays-1), s in SOLDIER) ((roster[s,d] = EVE) -> (roster[s,d+1] != NIGHT));
1817

19-
constraint forall (d in DAY) (sum (s in SOLDIER) ((roster[s, d] = NIGHT)) = o);
18+
constraint forall (d in DAY) (sum (s in SOLDIER) ((roster[s,d] = NIGHT)) = o);
2019
array[DAY] of var l..u: onEve;
2120
constraint onEve = [sum (s in SOLDIER) (roster[s,d]=EVE) | d in DAY];
2221

2322
solve maximize sum(onEve);
2423

25-
output ["Soldier "++show(s)++" on Day "++show(d)++" takes the "++show(roster[s,d])++" shift\n" ++ if s == max(SOLDIER) then show(onEve[d])++"\n" else "" endif | d in DAY, s in SOLDIER]++[show(sum(onEve))];
24+
output ["Soldier \(s) on Day \(d) takes the \(roster[s,d]) shift\n"
25+
++ if s == max(SOLDIER) then "\(onEve[d])\n" else "" endif | d in DAY, s in SOLDIER]
26+
++[show(sum(onEve))];

0 commit comments

Comments
 (0)