I am facing a similar issue. I am trying to assign a value of the expression to a variable in the constraint. Instead of calculating the expression and assigning the values, the constraint is equating my LHS and RHS. I didn't find any documentation related to how to assign expression values. Gurobi has GRB.equal, but I dnt think it has any assignment type operator. Below is the snippet.
list_of_locations=[list of values] (ex. [1,2,3-----])
for t in l:
for j in list_of_locations:
fjt[(j,t)] = model.addVar(vtype="B", name="fjt[%s,%s]"%(j,t))
for t in l:
for j in list_of_locations:
Xjt[(j,t)] = model.addVar(vtype="C", name="Xjt[%s,%s]"%(j,t))
for t in range(0,len(l)-1): # t is different time period
for j in list_of_locations:
model.addConstr(Xjt[(j,t)],"=",(fjt[(j,t)]-fjt[(j,t+1)])) # here lies the problem I want to calculate the difference of the (fjt[(j,t)]-fjt[(j,t+1)]) and assign it to Xjt[(j,t)] to know the locations when facility locations have changed during various time periods. so I expect if a facility moves out of j or a new facility is opened difference value would be {1,-1}, instead I a getting all values of Xjt to be zero because instead of substracting the values and assigning the values, constraint is just equating the LHS and RHS thus imposing the value of RHS to be zero as initialzed values of Xjt is zero.
What is the correct way to do this?
As I tried this way as well:
fjt = m.addVars(l, T, vtype='B', name='fjt')
Xjt = m.addVars(l, T, vtype='C', name='Xjt')
diff = m.addConstrs(((Xjt[j, T[t]] == fjt[j,T[t]] - fjt[j,T[t+1]]) for j in l for t in range(len(T)-1)), name='diff')
Thanks in advance,
Vaibhav Kumar