gurobi-错误代码= 10004无法检索属性"X" [英] gurobi - Error code = 10004 Unable to retrieve attribute 'X'

查看:1806
本文介绍了gurobi-错误代码= 10004无法检索属性"X"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的c ++/gurobi文件出现错误:

I am getting an error in my c++/gurobi file:

错误代码= 10004无法检索属性'X'

Error code = 10004 Unable to retrieve attribute 'X'

我读到这可能与标签有关?但我看不出有什么问题. 它适用于某些输入文件,但不适用于其他输入文件.因此,我在附件中创建了一个玩具文件t5.txt.该文件不起作用,但是删除最后一列并将其设置为8到7可以解决此问题.我很困惑...

I read that this might have something to do with labels? But I don't see how there is a problem. It works for some input files, but not for others. So I have created a toy file, t5.txt in attachment. This file does not work, but removing the last column and setting 8 to 7 fixes it. I am puzzled...

下面是model.write的输出.一切似乎都说得通,有什么主意我做错了吗? 每当我执行model.write(test.sol)时,程序都会停止,因此解决方案似乎有问题>

Below is the output of model.write. Everything seems to make sense, any Ideas what I am doing wrong? Whenever I do a model.write(test.sol), the program stops, so there seems to be something wrong with the solution>

附件: main.cpp-> https://dl.dropboxusercontent.com/u/13564139/main. cpp

Attachments: main.cpp -> https://dl.dropboxusercontent.com/u/13564139/main.cpp

input.txt-> https://dl.dropboxusercontent.com/u/13564139 /t5.txt

input.txt -> https://dl.dropboxusercontent.com/u/13564139/t5.txt

Maximize
  15 student_has_projects4.1
Subject To
 R0: student_has_projects0.0 + student_has_projects1.0
   + student_has_projects2.0 + student_has_projects3.0
   + student_has_projects4.0 + student_has_projects5.0
   + student_has_projects6.0 + student_has_projects7.0 <= 4
 R1: student_has_projects1.0 + student_has_projects2.0 >= 1
 R2: student_has_projects2.0 + 2 student_has_projects5.0 <= 2
 R3: student_has_projects2.0 + 2 student_has_projects5.0 >= 1
 R4: student_has_projects0.0 + student_has_projects3.0
   + student_has_projects4.0 + student_has_projects6.0
   + student_has_projects7.0 >= 1
 R5: student_has_projects2.0 + student_has_projects5.0 <= 1
 R6: student_has_projects0.1 + student_has_projects1.1
   + student_has_projects2.1 + student_has_projects3.1
   + student_has_projects4.1 + student_has_projects5.1
   + student_has_projects6.1 + student_has_projects7.1 <= 4
 R7: student_has_projects1.1 + student_has_projects2.1 >= 1
 R8: student_has_projects2.1 + 2 student_has_projects5.1 <= 2
 R9: student_has_projects2.1 + 2 student_has_projects5.1 >= 1
 R10: student_has_projects0.1 + student_has_projects3.1
   + student_has_projects4.1 + student_has_projects6.1
   + student_has_projects7.1 >= 1
 R11: student_has_projects2.1 + student_has_projects5.1 <= 1
 R12: student_has_projects0.2 + student_has_projects1.2
   + student_has_projects2.2 + student_has_projects3.2
   + student_has_projects4.2 + student_has_projects5.2
   + student_has_projects6.2 + student_has_projects7.2 <= 4
 R13: student_has_projects1.2 + student_has_projects2.2 >= 1
 R14: student_has_projects2.2 + 2 student_has_projects5.2 <= 2
 R15: student_has_projects2.2 + 2 student_has_projects5.2 >= 1
 R16: student_has_projects0.2 + student_has_projects3.2
   + student_has_projects4.2 + student_has_projects6.2
   + student_has_projects7.2 >= 1
 R17: student_has_projects2.2 + student_has_projects5.2 <= 1
 R18: student_has_projects0.0 + student_has_projects0.1
   + student_has_projects0.2 = 1
 R19: student_has_projects1.0 + student_has_projects1.1
   + student_has_projects1.2 = 1
 R20: student_has_projects2.0 + student_has_projects2.1
   + student_has_projects2.2 = 1
 R21: student_has_projects3.0 + student_has_projects3.1
   + student_has_projects3.2 = 1
 R22: student_has_projects4.0 + student_has_projects4.1
   + student_has_projects4.2 = 1
 R23: student_has_projects5.0 + student_has_projects5.1
   + student_has_projects5.2 = 1
 R24: student_has_projects6.0 + student_has_projects6.1
   + student_has_projects6.2 = 1
 R25: student_has_projects7.0 + student_has_projects7.1
   + student_has_projects7.2 = 1
Bounds
Binaries
 student_has_projects0.0 student_has_projects0.1 student_has_projects0.2
 student_has_projects1.0 student_has_projects1.1 student_has_projects1.2
 student_has_projects2.0 student_has_projects2.1 student_has_projects2.2
 student_has_projects3.0 student_has_projects3.1 student_has_projects3.2
 student_has_projects4.0 student_has_projects4.1 student_has_projects4.2
 student_has_projects5.0 student_has_projects5.1 student_has_projects5.2
 student_has_projects6.0 student_has_projects6.1 student_has_projects6.2
 student_has_projects7.0 student_has_projects7.1 student_has_projects7.2
End

推荐答案

问题是您的lp实例不可行,因此对.optimize()的调用导致状态不可行.从您的代码中

The issue is that your lp instance is infeasible so the call to .optimize() results in an infeasible status. From your code

model.write("test2.lp");
model.optimize();
model.write("forum2.sol");

if(model.get(GRB_IntAttr_Status) != GRB_OPTIMAL){
    cout << "niet optimaal " << endl;
}

在检查成功之前,您正在编写.sol文件. Gurobi在写入.sol文件时从变量获取'X'属性.如果优化失败,则'X'属性不可用,并引发异常.在编写.sol文件或获取许多属性(包括"X","Pi"和"ObjVal")之前,应确保gurobi有解决方案. OPTIMAL 状态代码可确保您有一个可用的解决方案,但是诸如SUBOPTIMAL之类的代码也表明存在一个可用的解决方案,而诸如TIME_LIMIT,NODE_LIMIT之类的其他代码则意味着可能存在一个可用的解决方案.您可以获取属性 SolCount 来明确表明存在解决方案可用.

You are writing a .sol file before you check for success. Gurobi gets the 'X' attributes from the variables when it writes a .sol file. If the optimization fails, the 'X' attributes aren't available and an exception is thrown. You should make sure that gurobi has a solution before you write a .sol file, or get many attributes, including 'X', 'Pi' and 'ObjVal'. The OPTIMAL status codes assures you that that there is an available solution, but codes like SUBOPTIMAL also indicate that there is a solution available and others like TIME_LIMIT, NODE_LIMIT mean there might be a solution available. You can get the attribute SolCount to get a definitive indication that there is a solution available.

您的问题实例是不可行的,因为约束(R1,R7,R13暗示您至少需要3个学生1和2的项目,但是约束(R19,R20)意味着他们每个人可以恰好有1个项目.使用IIS解算器.在交互式gurobi中,您可以获得不可还原的不一致子系统

Your problem instance is infeasible because constraints (R1, R7, R13 imply you need at least 3 projects for students 1 and 2, but constraints (R19, R20) imply they can have exactly 1 project each. You can see this by using the IIS solver. In interactive gurobi you can get get an Irreducible Inconsistent Subsystem

m = read("test2.lp")
m.optimize()
m.computeIIS()
m.write("test2.ilp")

这篇关于gurobi-错误代码= 10004无法检索属性"X"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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