Reputation: 173
I've found a Choco solver as constraint programming software working with Java. I would like to learn it more. I have done some basic example. But now I would like to try something more complex (Pritsker project scheduling alg) and I need your help. In order to progress I have to understand how to put constraints on rows of matrix variable. Exactly I need to keep a sum of rows equal 1 (task starts only once). I have tried it but unsuccessfuly. Could you help? I do use Choco 2.1.5 My matrix is as follows:
int n = 10; // projects
int m = 12; // time horizon in months
IntegerVariable[][] x = new IntegerVariable[n][m];
int i, j;
for (i = 0; i < n; i++){
for (j = 0; j < m; j++){
x[i][j] = Choco.makeIntVar("x_" + i +"_" + j, 0, 1, Options.V_ENUM);
model.addVariable(x[i][j]);
}
}
Upvotes: 0
Views: 1675
Reputation: 33
To add constraint over the rows, you should transpose the matrix and apply the constraint over the lines :
transposed = ArrayUtils.transpose(x);
for(int i=0; i<n; ++i){
model.sum(transposed[i], "=", 1);
}
Upvotes: 0