Gurobi with Java without objective function

妖精的绣舞 提交于 2019-12-12 04:36:37

问题


I'm using the solver Gurobi with Java; I read all the Gurobi's Reference Manual, but I still have a few question

  1. it's possible to optimize a model without a objective function or I have to put one?
  2. 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:


  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.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!