How to use SumInt using JaCop in Java?

220 Views Asked by At

I have been trying to learn Jacop to solve my constraint satisfaction problems. I could not find any tutorials online other than the Api.

So I am trying to test out how its methods work.

For example on using SumInt. I am trying to count how many times a number comes on a list. How can i do that using JaCop?

Like if I have a list having these data : 10,20,10,30,10,50,40

How can I count how many times 10, 20 , 30 ,40 , 50 appeared using JaCop? This is an example i got from the Api page online. But that does not look like what I want to do.

    Store store = new Store();
    IntVar a = new IntVar(store, "a", 1, 3); 
    IntVar b = new IntVar(store, "b", 1, 3); 
    IntVar c = new IntVar(store, "c", 1, 3); 
    IntVar sum = new IntVar(store, "sum", 1, 10); 
    IntVar[] v = {a, b, c}; 
    Constraint ctr = new SumInt(store,v, "==", sum); 
    store.impose(ctr);
1

There are 1 best solutions below

0
On

You can use Count or Among constraint.