Gurobi error : unable to retrieve attribute 'Xn'

1,843 views
Skip to first unread message

Hamdy

unread,
May 20, 2016, 3:18:35 PM5/20/16
to Gurobi Optimization
I have a facility location problem and I need to ge the best two solutions so in my  code I am utilizing the .xn attribute to make my model faster. it worked originally but for particular instance I get the following error. GurobiError: Unable to retrieve attribute 'Xn' 
even though clearly I have a second to optimal sol
I am using python to code the problem and (pandas to store my variables) 
is there a try catch function that can handle this issue or should i just stop using attribute xn ?
here is part of my code that includes the problem  



m.setParam('SolutionNumber',1)

#%%

Totalsol=[] 
listofsol =[ i for i in range(NumberOfSol)]
for l in listofsol:
#    m.setParam('TimeLimit', 5*60)    
#    m.setParam('MIPGap',0.02)
    
    m.update()
    m.optimize()

    if m.status == GRB.Status.OPTIMAL:
        print('Optimal objective: %g' % m.objVal)
    elif m.status == GRB.Status.INF_OR_UNBD:
        print('Model is infeasible or unbounded')
        exit(0)
    elif m.status == GRB.Status.INFEASIBLE:
        print('Model is infeasible')
        exit(0)
        break
    elif m.status == GRB.Status.UNBOUNDED:
        print('Model is unbounded')
        exit(0)
    else:
        print('Optimization ended with status %d' % m.status)
        exit(0)

 #%%       
    
    FinalStationslist =[]
    VolumPerStationlist = []
    
    useprevsol=False
    listofnewsolutions=[]
    for j in y.axes[0]:
        if y.loc[j,'YVariables'].x>0 :
            FinalStationslist.append(j)
            VolumPerStationlist.append(D.loc[j].x)
            print (j)
            if j not in oldStationsdf.axes[0] and (l< len(listofsol)-1):
                m.addConstr(y.loc[j,'YVariables'] == 0)
                Totalsol.append([j,m.objVal])
                if y.loc[j,'YVariables'].xn==0:
                    useprevsol=True
                else:
                    useprevsol= False

Renan Garcia

unread,
May 20, 2016, 3:22:07 PM5/20/16
to gur...@googlegroups.com
You should verify that the SolCount model attribute (see https://www.gurobi.com/documentation/6.5/refman/solcount.html#attr:SolCount) has value of at least 2 before querying for the second best solution.

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hamdy

unread,
May 23, 2016, 11:42:12 AM5/23/16
to Gurobi Optimization
Thank you Very much. 
Reply all
Reply to author
Forward
0 new messages