简体   繁体   English

Gurobipy 中的 LP 松弛

[英]LP-Relaxation in Gurobipy

I want to find an LP-relaxation solution to my problem by using Gurobi.py (a Python package for solving LP).我想通过使用 Gurobi.py(用于解决 LP 的 Python package)找到我的问题的 LP 松弛解决方案。 I could do it by rewriting.lp file by changing all Integrality constraints to continuous.我可以通过将所有完整性约束更改为连续来重写.lp 文件来做到这一点。 However, I do not want to write.lp file again.但是,我不想再次写入.lp 文件。

There are several ways to do this, depending on your needs.有几种方法可以做到这一点,具体取决于您的需要。 Here are my recommended methods:以下是我推荐的方法:

  1. Easiest: create the relaxed copy by calling the Model.relax() method, which creates a copy of the model as the relaxed model.最简单:通过调用Model.relax()方法创建宽松副本,该方法创建 model 的副本作为宽松 model。
  2. Modify the model by iterating over all variables and set the VType attribute to 'C' for continuous.通过迭代所有变量来修改 model 并将 VType属性设置为“C”以表示连续。
  3. Most complex: write a callback function that calls Model.cbGetNodeRel() to get the relaxed solution at MIP nodes.最复杂:编写一个回调 function 调用Model.cbGetNodeRel()以在 MIP 节点上获得宽松的解决方案。

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

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