5

我得到一個錯誤在我的C++/gurobi文件:gurobi - 錯誤代碼= 10004無法檢索屬性 'X'

錯誤代碼= 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 

回答

6

的問題是,你的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意味着你至少需要3個項目給學生1和2,但約束(R19,R20)意味着他們每個項目只能有1個項目,你可以看到這個通過使用IIS求解。在交互gurobi你可以得到一個Irreducible Inconsistent Subsystem

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

我只是,我發現他們在那裏不可行。增加了一些修正(即虛擬實例),使之可行寫。不是雖然真的很清楚錯誤信息。 – dorien