gurobi - 错误代码=10004 无法检索属性“X”

8

在我的c++/gurobi文件中出现了一个错误:

错误代码=10004,无法检索属性“X”

我读到这可能与标签有关?但我不明白哪里有问题。对于某些输入文件,它是有效的,但对于其他输入则无效。因此,我创建了一个附带的玩具文件t5.txt。这个文件无法正常工作,但是删除最后一列并将8设置为7可以解决它。我感到困惑...

下面是model.write的输出。每件事似乎都很合理,有什么想法我做错了吗? 每当我执行model.write(test.sol)时,程序就会停止,因此解决方案似乎有问题>

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

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
1个回答

11
问题在于您的lp实例是不可行的,因此调用.optimize()会导致不可行状态。从您的代码来看。
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 文件之前,应确保 gurobi 有解决方案,或者获得许多属性,包括“X”、“Pi”和“ObjVal”。OPTIMAL status codes 确保有可用的解决方案,但像 SUBOPTIMAL 这样的代码也表示有可用的解决方案,而像 TIME_LIMIT、NODE_LIMIT 这样的代码则意味着可能有可用的解决方案。您可以获取属性SolCount 来明确指示是否有可用的解决方案。
你的问题无解,因为(R1, R7, R13)这些约束条件表明学生1和2至少需要3个项目,但(R19, R20)这些约束条件表明他们只能有一个项目。你可以使用IIS求解器来查看。在交互式Gurobi中,你可以获得一个不可约矛盾子系统
m = read("test2.lp")
m.optimize()
m.computeIIS()
m.write("test2.ilp")

我刚想写下来,发现它们是不可行的。加入了一些更正(即虚拟实例)使其变得可行。但错误信息并不是很清晰。 - dorien

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接