In order to create new GRBVar, I need to provide Objective coefficient for new variable:
GRBVar var = model.addVar (double lowerBound,
double upperBound,
double obj, // objective coefficient
char type,
String name);
According to this example, the value can be set to 0. So I wonder what objective coefficient is.
Objective coefficient is the coefficient of the variable in your objective function. In the example you have given :
maximize x + y + 2 z
subject to x + 2 y + 3 z <= 4
x + y >= 1
x, y, z binary
your objective function is maximize x + y + 2 z
so Objective coefficients are for x: 1 for y: 1 and for z: 2
While creating variables you can give coefficients arbitrary ( here they are as you said 0.0 )
// Create variables
GRBVar x = model.addVar(0.0, 1.0, 0.0, GRB.BINARY, "x");
GRBVar y = model.addVar(0.0, 1.0, 0.0, GRB.BINARY, "y");
GRBVar z = model.addVar(0.0, 1.0, 0.0, GRB.BINARY, "z");
But later you should set to the actual objective coefficients:
// Set objective: maximize x + y + 2 z
GRBLinExpr expr = new GRBLinExpr();
expr.addTerm(1.0, x);
expr.addTerm(1.0, y);
expr.addTerm(2.0, z);
model.setObjective(expr, GRB.MAXIMIZE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With