I built an initial model and then try to use the result of that model in a second model while the second model has many similarities with the initial model, it does have some more constraint. My approach was to copy the initial model to the second model as below(mdl
is the initial model which I didn't bring here and mdll
is the secondary model):
mdll=Model('Boarding_test2')
Best_X_values= mdl.getAttr('x', X)
mdll.update()
mdll=mdl.copy()
mdll.getVars()
mdll.getConstrs()
As you can see I copy the initial model as well as the constraints and the variables. To delete a constraint which was present in the initial model but I didn't want it in the second one, I implemented the following:
Del_cons=mdll.getConstrByName('Stefen')
Del_cons.__dict__
mdll.remove(Del_cons)
mdll.update()
Finally, I tried to add new constraints to the second model as below:
mdll.addConstrs((Y[k,p])==1 for k in K for p in P if k==p and p!=p_sim)
mdll.addConstrs(quicksum(Y[k,p] for k in K if k==k_sim )==1 for p in P if p==p_sim)
mdll.addConstrs(quicksum(Y[k,p] for p in P if p==p_sim)==1 for k in K if k==k_sim)
but I receive the following error. Can anyone please help me with this:
GurobiError Traceback (most recent call last)
1 #mdll.remove(mdll.getConstrByName('Stefen'))
----> 2 mdll.addConstrs((Y[k,p])==1 for k in K for p in P if k==p and p!=p_sim)
3 mdll.update()
4 mdll.addConstrs(quicksum(Y[k,p] for k in K if k==k_sim )==1 for p in P if p==p_sim)
5 mdll.update()
model.pxi in gurobipy.Model.addConstrs()
model.pxi in gurobipy.Model.addConstr()
model.pxi in gurobipy.Model.__addConstr()
GurobiError: Variable not in model