【问题标题】:gurobi - Error code = 10004 Unable to retrieve attribute 'X'gurobi - 错误代码 = 10004 无法检索属性“X”
【发布时间】:2013-10-09 10:56:19
【问题描述】:

我的 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

【问题讨论】:

    标签: c++ math mathematical-optimization linear-programming gurobi


    【解决方案1】:

    问题是您的 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 文件或获取许多属性(包括“X”、“Pi”和“ObjVal”)之前,您应该确保 gurobi 有解决方案。 OPTIMAL status codes 向您保证有一个可用的解决方案,但是像 SUBOPTIMAL 这样的代码也表明有一个可用的解决方案,而其他像 TIME_LIMIT、NODE_LIMIT 这样的代码意味着可能有一个可用的解决方案。您可以获取属性SolCount 以明确指示是否有可用的解决方案。

    您的问题实例不可行,因为约束(R1、R7、R13 意味着学生 1 和 2 至少需要 3 个项目,但约束(R19、R20)意味着他们每个人只能有 1 个项目。您可以通过以下方式查看使用 IIS 求解器。在交互式 gurobi 中,您可以获得 Irreducible Inconsistent Subsystem

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

    【讨论】:

    • 我只是写我发现他们不可行的地方。添加了一些更正(即虚拟实例)以使其可行。虽然不是一个非常明确的错误消息。
    猜你喜欢
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 2019-10-06
    • 1970-01-01
    相关资源
    最近更新 更多