gurobi - Error code = 10004 Unable to retrieve attribute 'X'

不想你离开。 提交于 2019-12-01 06:04:22

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;
}

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.

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")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!