'Choco-solver IntVar declaration : How to declare an IntVar with two(or more) boundedDomain?
IntVar v = model.intVar("v", 1, 12, true);
// or
v= model.intVar("v", 20, 30, true);
I want the value of IntVar v not only in [1,12] but also in [20,30] and in other segment of values [...,....] I don't understand how to do this with the specific declaration of an IntVar
Solution 1:[1]
In choco-solver, you can either define bounded domain variables (with model.intVar(name, lowerBound, upperBound)
)
// domain is [1,7]
IntVar v = model.intVar("v", 1,7);
or enumerated domain variables (with model.intVar(name, values...)
:
// domain is {1,3,5}
IntVar v = model.intVar("v", new int[]{1,3,5});
So, if the domain you want to declare is made of ranges, there is no other option than to list all possible values.
// domain is [1,3]U[5,7]
IntVar v = model.intVar("v", new int[]{1,2,3,5,6,7});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | cprudhom |