I’m posting a scalar constraint and I’d like to be able to print its result out when I get a solution. So I’d like to somehow cache it in an IntVar…
I found an old answer with the old Choco syntax and I’m just not able to make it work with the modern Choco:
pb.post(eq(y, pb.scalar(new IntDomainVar(){x1,x2,...,xn}, new int[]{1,1...,1})));
Maybe it’s not exactly what I’m looking for because y might just be an int constant and not an IntVar…
Anyway, do you know a way to do that? For the moment I could recompute the scalar from the values when I get the solution, but I’m planning to add a minimize objective based on the average of those scalars…
I’ve tried to work around this by decomposing the scalar into several variables but now I’m getting zero solutions:
IntVar[][] scalarResults = new IntVar[x][y];
IntVar[] sumsOfScalars = new IntVar[x];
IntVar[] sumsOfScalars = model.intVarArray(x, 0, ub);
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
scalarResults[i][j] = model.intScaleView(mainValues[i][j], coeffs[j]);
// Works great.
model.sum(scalarResults[i], "=", sumsOfScalars[i]).post();
}
}
What am I doing wrong? Thanks for any help!