下面是目标函数:
我有以下 Java 代码:
// Create list of variables
List<GRBVar> varList = new ArrayList<>();
// Set objective: maximize log(p) * x
GRBLinExpr expr = new GRBLinExpr();
int counter = 0;
for(Map.Entry<String, Double[]> entry: probabilityLevels.entrySet()) {
Double[] probs = entry.getValue();
for (Double prob: probs) {
GRBVar x = model.addVar(0.0, 1.0, 0.0, GRB.BINARY, "x" + counter);
expr.addTerm(Math.log(prob), x);
varList.add(x);
}
}
model.setObjective(expr, GRB.MAXIMIZE);
更新代码