Debian Codegraph @

tests/spec/unit/regression/abs_bug.mzn

raw
1 /***
2 !Test
3 expected:
4 - !Result
5 solution: !Solution
6 _output_item: |
7 [4, 10]
8 {4,10,13}
9 {1,3,4}
10 depot(a,4).
11 depot(c,10).
12 - !Result
13 solution: !Solution
14 _output_item: |
15 [4, 13]
16 {4,10,13}
17 {1,3,4}
18 depot(a,4).
19 depot(d,13).
20
21 ***/
22
23 % Regression test.
24 % The bounds inferred for absolute values expressions where incorrect in r13710
25 % and before.
26
27 int: nr; % number of restaurants
28 set of int: Restaurant = 1..nr;
29 array[Restaurant] of string: name :: add_to_output;
30
31 array[Restaurant] of 0..910: k; % kilometre position
32 set of int: ks :: add_to_output = { k[r] | r in Restaurant };
33
34 set of Restaurant: first :: add_to_output = { min(r in Restaurant where k[r] == pos)(r) | pos in ks };
35
36 int: number_of_depots;
37 set of int: Depot = 1..number_of_depots;
38 array[Depot] of var 0..910: p :: add_to_output; % position of depot
39
40 constraint forall(d in Depot)(p[d] in ks);
41 constraint forall(d in 1..number_of_depots-1)(p[d] < p[d+1]);
42
43 solve minimize sum(r in Restaurant)(min(d in Depot)(abs(p[d] - k[r])));
44 %satisfy;
45
46 output [ show(p), "\n", show(ks), "\n", show(first), "\n"]++
47 [ if (fix(p[d]) == k[r]) then
48 "depot(" ++ name[r] ++ "," ++ show(p[d]) ++ ").\n"
49 else "" endif | d in Depot, r in first ];
50
51 nr = 4;
52 name = ["a", "b", "c", "d"];
53 k = [4,4,10,13];
54
55 number_of_depots = 2;