1

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());
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Elena
  • 11
  • 2

1 Answers1

0

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