问题
I'm using the solver Gurobi with Java; I read all the Gurobi's Reference Manual, but I still have a few question
- it's possible to optimize a model without a objective function or I have to put one?
- it's possible to add a constraint like "x=0 if c>a" where x is a decision variable and c and a are known?
Someone can help me?
Thanks.
回答1:
You don't need to have an objective function, but if you don't Gurobi will consider any feasible solution as good as the next, even one that is obviously (to you) not what you wanted.
When solving a Gurobi model with Java (or pretty much any interface) you can separate values that are known before you have a Gurobi solution, and ones you don't know until you have a solution. The first case includes plain Java variables and hard-coded constants. The latter includes decision variables. In your example, you can write something like
if (c > a) { grb.addConstr(x, '=', 0); }
because both c and a are Java variables, not decision variables. If c or a are decision variables, you can still model the constraints, but you need to add binary variables.
来源:https://stackoverflow.com/questions/26387677/gurobi-with-java-without-objective-function