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'
is there a try catch function that can handle this issue or should i just stop using attribute xn ?
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