简体   繁体   中英

It is possible to create constraints between solutions in Choco?

I have this problem:

find as large a set S of strings (words) of length 8 over the alphabet W = { A,C,G,T } with the following properties:

  1. Each word in S has 4 symbols from { C,G }

  2. Each pair of distinct words in S differ in at least 4 position.

I did first point. I said that 8 variables take values between 1 and 4 and 1 and 2 must appear in 4 places:

V = {x1, x2, x3, x4, x5, x6, x7, x8}
D = {1, 2, 3, 4}
C = {1 and 2 must appear in 4 places; I uses `ICF.among()` function}

Now, for the second point, I have no idea. Maybe it's wrong the way I begin. I don't know if it's possible to create constraints between solutions.

I used choco3, and here is the code:

Solver s = new Solver("My pb");
IntVar[] var = new IntVar[8];

for(int i=0;i<8;i++)


var[i]=VariableFactory.bounded("Letter"+i, 1, 4, s);

IntVar o = VariableFactory.bounded("Occurence", 4, 4, s);
int[] ind = {1,2};
int[] ind1={3,4};

s.post(ICF.among(o, var, ind));
s.findSolution();   
do{
    for(int i=0;i<8;i++){
        System.out.print(s.getVar(i)+" ");
    }
    System.out.println();
}while(s.nextSolution());

Sure you can add constraints during search. It is even possible to specifies whether or not you want them to be removed upon backtracking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM