-1

I'm trying to implement the 'Sport Scheduling Problem' (with a Round-Robin approach to break symmetries). The actual problem is of no importance. I simply want to declare the value at x[1,1] to be the set {1,2} and base the sets in the same column upon the first set. This is modelled as in the code below. The output is included in a screenshot below it. The problem is that the first set is not printed as a set but rather some sort of range while the values at x[2,1] and x[3,1] are indeed printed as sets and x[4,1] again as a range. Why is this? I assume that in the declaration of x that set of 1..n is treated as an integer but if it is not, how to declare it as integers?

EDIT: ONLY the first column of the output is of importance.

int: n  = 8;
int: nw = n-1;
int: np = n div 2;

array[1..np, 1..nw] of var set of 1..n: x;

% BEGIN FIX FIRST WEEK $
constraint(
  x[1,1] = {1, 2}
);

constraint(
  forall(t in 2..np) (x[t,1] = {t+1, n+2-t} )
);

solve satisfy;


output[
  "\(x[p,w])" ++ if w == nw then "\n" else "\t" endif | p in 1..np, w in 1..nw
]

enter image description here

Backend solver: Gecode

Community
  • 1
  • 1
Wouter Vandenputte
  • 1,948
  • 4
  • 26
  • 50
  • 1
    I'm not sure that I understand your question, but `1..8` is a shorthand of the set `{1,2,3,4,5,6,7,8}`, and `5..6` is a shorthand for the set `{5,6}`. – hakank Jun 12 '20 at 15:34
  • Yes, but I explicity declare the set at `x[1,1]` to be `{1,2}` yet it is printed as `1..2`. Btw, only the first column of the output is of importance. I then declare the value for `x[2,1]` to be the set `{3,8}` and this is executed correctly. But the last is then printed as `5..6` for some reason – Wouter Vandenputte Jun 13 '20 at 20:31
  • Well, as mentioned earlier: `5..6` _is_ the set `{5,6}`. The last `5..6` is calculated by `(t+1,n+2-t}` (with n=8 and t=4), i.e. `{4+1,8+2-4`. What did you expect it should be? – hakank Jun 13 '20 at 21:30
  • So it is just a weird decision from the minizinc system to print out a set `{x,y}` if `y - x > 1` and `x..y` else-wise – Wouter Vandenputte Jun 14 '20 at 11:45
  • Well, I'm not sure it's such a a weird decision. It saves space and it's probably easier to read `1..9` instead of `{1,2,3,4,5,6,7,8,9}`. – hakank Jun 14 '20 at 12:22
  • But it is also easier to read `{1,2}` instead of `1..2`. The latter says: everything between1 and 2 (bounds inclusive). But there are no such numbers for integers – Wouter Vandenputte Jun 14 '20 at 13:24
  • I added a summary of this below. Feel free to accept the answer if you think it answer your question (even though you might not agree with my opinions about the advantages of the shorthand version used). – hakank Jun 15 '20 at 07:24

1 Answers1

2

(Here's a summarize of my comments above.)

The range syntax is simply a shorthand for contiguous values in a set: 1..8 is a shorthand of the set {1,2,3,4,5,6,7,8}, and 5..6 is a shorthand for the set {5,6}.

The reason for this shorthand is probably since it's often - and arguably - easier to read the shorthand version than the full list, especially if it's a long list of integers, e.g. 1..1024. It also save space in the output of solutions.

For the two set versions, e.g. {1,2}, this explicit enumeration might be clearer to read than 1..2, though I tend to prefer the shorthand version in all cases.

hakank
  • 6,629
  • 1
  • 17
  • 27