1

我有

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]);
}

我想获得 IntVar 的面积总和

像这样的东西:

IntVar totalAreas = orArea.sum();

并继续使用它

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

1 回答 1

0

您可以像这样声明一个总和约束:

IntVar totalAreas = model.intVar("totalAreas", 0, Stream.of(orArea).mapToInt(IntVar::getUB).sum());
model.sum(orArea, "=", totalAreas).post();
于 2020-05-13T14:12:29.587 回答