简体   繁体   English

如何防止Gurobi将Max转换为Min概率?

[英]How to prevent Gurobi from converting a Max into a Min prob?

I am using Gurobi (via C++) as part of my MSc thesis to solve Quadratic Knapsack Problem instances . 我正在使用Gurobi(通过C ++)作为我的硕士学位论文的一部分来解决二次背包问题实例 So far, I was able to generate a model with binary decision variables, quadratic objective function and the capacity constraint and Gurobi solved it just fine. 到目前为止,我已经能够生成具有二进制决策变量,二次目标函数和容量约束的模型,Gurobi很好地解决了这个问题。 Then I wanted to solve the continuous relaxation of the QKP. 然后,我想解决QKP的持续放宽。 I built the model as before but with continuous variables instead of binary ones and Gurobi threw me an exception when I tried to optimize it: 我像以前一样构建了模型,但是使用了连续变量而不是二进制变量,当我尝试优化模型时,Gurobi抛出了一个异常:

10020 - Objective Q not PSD (negative diagonal entry)

Which confounded me for a bit since all values form the problem instance are ≥0. 由于问题实例的所有值都≥0,这使我有些困惑。 In preparing to post this question, I wrote both models out to file and discovered the reason: 在准备发布此问题时,我将两个模型都写了出来,并找到了原因:

NAME (null)
* Max problem is converted into Min one

Which of course means that all previously positive values are now negative. 当然,这意味着所有以前为正的值现在都为负。 Now I know why Q is not PSD but how do I fix this? 现在我知道为什么Q不是PSD了,但是我该如何解决呢? Can I prevent the conversion from a Max problem into a Min one? 我可以防止从最大问题转换为最小问题吗? Do I need to configure the model for the continuous relaxation differently? 我是否需要为连续松弛配置不同的模型?

From my (unexperienced) point of view it just looks like Gurobi shot itself in the foot. 从我的经验(无经验)的角度来看,它看起来就像古罗比(Gurobi)自己踩在脚上。

When you are maximizing a quadratic objective with Gurobi or any other convex optimizer, your 'Q' matrix has to be negative semi-definite, and when you are minimizing, your 'Q' matrix needs to be positive definite. 当您使用Gurobi或任何其他凸优化器最大化二次目标时,“ Q”矩阵必须为负半定数,而当您最小化时,“ Q”矩阵必须为正定数。 Changing the sign and the sense of the objective changes nothing. 改变符号和目标感不会改变任何东西。

Gurobi doesn't verify that your problem is convex, but it will report any non-convexity it finds. Gurobi不会验证您的问题是否凸出,但会报告发现的任何非凸性。 The fact that your original problem seemed to solve as a MIP is an accident and you shouldn't rely on it. 您原来的问题似乎可以作为MIP解决,这一事实是偶然的,您不应该依赖它。

You should model a quadratic objective with binary variables as a linear problem with some simple transformations . 您应该使用一些简单的转换将具有二进制变量的二次目标建模为线性问题。 If x and y are binary, the expression x*y can be changed to z if you add the constraints 如果x和y是二进制,则如果添加约束,则表达式x*y可以更改为z

z <= x
z <= y
z >= x + y - 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM