带有Java的Gurobi,没有目标函数 [英] Gurobi with Java without objective function

查看:224
本文介绍了带有Java的Gurobi,没有目标函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中使用求解器Gurobi;我阅读了《古罗比》的所有参考手册,但仍然有一些疑问

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

  1. 是否可以在没有目标函数的情况下优化模型,或者我必须提出一个?
  2. 是否可以添加类似"x = 0,如果c> a"的约束,其中x是决策变量,而c和a是已知的?

有人可以帮助我吗?

谢谢.

推荐答案

  1. 您不需要具有目标功能,但是如果您没有目标功能,Gurobi会认为任何可行的解决方案都与下一个一样好,即使是显然(对您而言)都不是您想要的解决方案.

  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.

使用Java(或几乎任何接口)求解Gurobi模型时,可以分离出具有Gurobi解决方案之前已知的值,以及只有在获得解决方案之前才知道的值.第一种情况包括普通的Java变量和硬编码的常量.后者包括决策变量.在您的示例中,您可以编写类似

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

如果(c> a){ grb.addConstr(x,'=',0); }

if (c > a) { grb.addConstr(x, '=', 0); }

因为c和a都是Java变量,而不是决策变量.如果c或a是决策变量,则仍然可以对约束进行建模,但是需要添加二进制变量.

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.

这篇关于带有Java的Gurobi,没有目标函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆