reset password
Author Message
TC465
Posts: 4
Posted 15:14 Oct 24, 2019 |

I have:

set of int: Rooms = 100..300;

I understand this will return [100, 101, 102, .. , 300] but I want to skip up to 50 such that it will return [100, 150, 200, .. , 300]. I was thinking something along the line of:

range(100, 300, 50) => range(start, end, skip)
Is there a syntax similar to this in MiniZinc?

Thanks

Last edited by TC465 at 15:16 Oct 24, 2019.
rabbott
Posts: 1649
Posted 15:22 Oct 24, 2019 |

Try this.

set of int: Rooms = {100 + 50*n | n in 0..4};
output [show(Rooms)];
Last edited by rabbott at 15:26 Oct 24, 2019.
TC465
Posts: 4
Posted 15:26 Oct 24, 2019 |
rabbott wrote:

Try this.

set of int: Rooms = {100 + 50*n | n in 0..4};
output [show(Rooms)];

Got it, thank you

evosgan
Posts: 3
Posted 12:05 Oct 25, 2019 |
rabbott wrote:

Try this.

set of int: Rooms = {100 + 50*n | n in 0..4};
output [show(Rooms)];

I copied this syntax on the Beach Day problem like this; 

set of int: Age = {25 + 5*n | n in 0..4};

and then 

% This age_to_pos array tells us the position of each age.
array[Age] of var  Position: age_to_pos;
constraint alldifferent(age_to_pos);

 

However, it gave me this error

in variable declaration for 'age_to_pos'

array index set must be contiguous range

I'm not sure how to solve this issue.

kmarlis
Posts: 35
Posted 14:05 Oct 25, 2019 |

I ran into the same issue on the secret agent problem. One of the features in that problem is a secret agent's age. The ages are 25, 30, 35, 40, 45. I got around the problem by spelling out the ages as strings in an enum rather than a set of ints: 

enum Age = { twentyfive, thirty, thirtyfive, forty, fortyfive };

 

Obviously not an ideal solution, but one that works (or at least does in this problem's case where the ages don't need to be compared). Has anybody else found another way around it?

tkitcha
Posts: 19
Posted 22:49 Oct 25, 2019 |

I use  single quote notation and it works

Example:

enum Age = {'11', '12', '13', '14'};