1

I have

IntVar[] orArea = new IntVar[N]; 
IntVar[] orCount = new IntVar[N]; 
IntVar[] orRows = new IntVar[N]; 
IntVar total_trim = model.intVar("trim", 0, 1000);
for (int i = 0; i < N; i++) {
    orRows[i] = model.intVar("or_" + i + "_rows",0, 5);
    orCount[i] = model.intVar("or_" + i + "_count", 0, O[i][2]);
    orArea[i] = model.intScaleView(orCount[i],O[i][0] * O[i][1]);
}

I want get sum of area to IntVar

Something like that:

IntVar totalAreas = orArea.sum();

and continue to use it

IntVar trimToOrder = total_trim.mul(1000000).div(totalAreas).intVar();
model.setObjective(Model.MINIMIZE, trimToOrder);

1 Answers1

0

You can declare a sum constraint like this:

IntVar totalAreas = model.intVar("totalAreas", 0, Stream.of(orArea).mapToInt(IntVar::getUB).sum());
model.sum(orArea, "=", totalAreas).post();
cprudhom
  • 111
  • 4