The following is the objective function:
I have the following Java code:
// 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);
Update the code
Your loops look correct, but you are only creating one GRBVar x, instead of creating one GRBVar for each combination of j, k and z. You should create some data structure to store all these GRBVar objects, and create them as you iterate over the combinations of j, k and z.