I'm very new to Gurobi and I'm trying to implement an assignment problem as follows:
# Create decision variables for the allocation
x = {}
for s in arr1:
for t in arr2:
x[s,t] = m.addVar(vtype=GRB.BINARY, name="allocation")
x[s,t] == x[s,t] * mymat[s]
m.modelSense = GRB.MAXIMIZE
m.update()
I want to know that writing a linear expression as above is possible so that I can maximize the allocation of people to the same task who have similar preferences.
However running the model written as above generated an error when retrieving results using x[s,t].x . The error was
GurobiError: Unable to retrieve attribute 'X'
Data coming to the model from a separate file and the code is as follows:
data=c.execute('select id,pref from data')
result = c.fetchall()
pref_data=dict(result)
mymat=defaultdict(int)
a=1
for i in range(1,10):
row = []
for x in range(0,i):
row.append(0)
for j in range(i+1, 10):
if pref_data[i]==pref_data[j]:
row.append(1)
else:
row.append(0)
mymat[a]=row
a+=1