I have a model where I seek a solution that represents a connected graph, so I am checking the cuts after every solution and adding appropriate constraints to avoid these cuts. I am following the example in the documentation:
https://pyomo.readthedocs.io/en/stable/working_models.html
That is I have
self.model.cnstr_cuts = pyo.ConstraintList()
self.instance = self.model.create_instance(data=...)
self.results = self.opt.solve(self.instance)
and then at every iteration
for i in set_x:
for j in base_set - set_x:
expr += self.instance.x[i, j]
self.instance.cnstr_cuts.add(expr >= 1)
However, I keep getting infeasible models after the second try. It seems to me that in my case it does not want to change the values of the variables in the second solve, e.g. I am adding the following cut constraint
x[157,156] + x[158,157] >= 1
but in the next step the model gets infeasible, and displays the new constraint as the variable values are fixed to zeroes, from the previous iteration:
cnstr_cuts : Size=1
Key : Lower : Body : Upper
1 : 1.0 : 0.0 : None
I don't have any upper bounds imposed on the (edge) variables, so there is no reason for this new constraint to be unsatisfyable. I even rewrote the official pyomo example to a class to be perfectly analogous with the implementation with my model, and compared them line by line, yet see no difference that could explain it.
I am also open to alternative ways of re-solving my model using added constraints (I tried adding the constraints with self.model.x[i, j] but it said it is not yet constructed, I also tried making ALL updates to self.model and creating new self.instance objects but couldn't figure out how to do either).