PySCIPOpt icon indicating copy to clipboard operation
PySCIPOpt copied to clipboard

Question: Implement Constraint Handler properly

Open SanielDous opened this issue 4 years ago • 3 comments

I am trying to implement a Branch-and-Price algorithm. Pricing new variables already works fine but I have some issues when it comes to branching. I already came up with a branching rule that adds new constraints to the child nodes and thereby ensures integrality without branching on the variables. My problem is now to actually add these constraints in the implementation:

This is probably the 1000th time this question is asked and there are some useful hints here and here but I still don't understand how to properly implement a branching rule that adds constraints to the child nodes like:

quicksum(var[i] for i in X) <= C

for one child node and

quicksum(var[i] for i in X) >= C + 1

for the other child node. (So, really simple constraints) This PR tried to make life easier by allowing to use this for example:

self.model.addConsNode(child1, quicksum(var[i] for i in X) >= C + 1)

I don't know if these changes already found its way into master but I still get the following error:

TypeError: Argument 'cons' has incorrect type (expected pyscipopt.scip.Constraint, got pyscipopt.scip.ExprCons)

So, I understood I have to use a Constraint Handler to add the new constraints. I tried to understand the examples from this issue but I don't get it where the constraints are actually added. In other words where to put the Expression from above. The function self.model.createCons(self, name, ...) does not get such an expression. How does the node's model know the new row?

Probably the solution is completely obvious and I just don't see it. Nevertheless, I would appreciate your tips and hints.

SanielDous avatar Jul 28 '22 10:07 SanielDous

Hello, @SanielDous! Sorry for leaving you hanging for so long, your problem seemed out of my league, but now I think I may help a bit.

Are you still having problems? What's the status of this?

Joao-Dionisio avatar Jul 10 '23 13:07 Joao-Dionisio

Hi, thank you for your response but I'm not working on the corresponding project anymore.

SanielDous avatar Jul 11 '23 12:07 SanielDous

I am very sorry for not helping when it was needed. I'm closing the issue then, but if you or anyone else is having similar problems, feel free to reopen the issue.

Joao-Dionisio avatar Jul 11 '23 16:07 Joao-Dionisio