Reputation: 7607
How to check in Choco if a complex variable satisfies the constraints? For example, if I have the following list of configurations:
int[][] configurations = new int[][] {
{20, 24, 10, 3, 4},
{20, 13, 1, 3, 4}};
where config1 = {20, 24, 10, 3, 4} and config2 = {20, 13, 1, 3, 4}
int[] constraints = new int[]{21, 15, 2, 10, 10};
is a list of constraints such that, for a given configuration each element in the configuration needs to be higher (or lower) than the coresponding constraint. For example: config1 = {20, 24, 10, 3, 4} constraints = {21, 15, 2, 10, 10}
check if config1[0] < constraints[0] AND config1[1] < constraints[1] AND ...
If all the constraints are satisfied then just mark it as a solution. This is what I have
// c = number of configurations
// q = number of elements in each configuration
// p = configurations matrix
for (int i = 0; i < c; i++) {
for (int j = 0; j < q; j++) {
model.arithm(model.intVar(p[i][j]), "<", model.intVar(k[j])).post();
}
}
Upvotes: 0
Views: 106
Reputation: 23
There is probably a better way to do this, but you could create an initial IntVar called config (bound between 0 and the number of configurations). Then separate IntVar's for each element (elementA, elementB, elementC etc).
You can then add logic that says that:
if config = 0 then elementA = 20
if config = 0 then elementB = 24
...
On top of this you can add further constraints based on the elements to return your solution.
Upvotes: 0
Reputation: 249
CP relies on variables and constraints. You should create variables first and then post constraints on them. Please do not call "constraints" an array of ints that is just some input of your problems.
You can find a simple choco example here: - https://www.cosling.com/choco-solver/hello-world I think this hello word is sufficient for what you need. If you want to go deeper, read this: http://choco-tuto.readthedocs.io/en/latest/
Upvotes: 1