PySCIPOpt icon indicating copy to clipboard operation
PySCIPOpt copied to clipboard

Question: Implement Constraint Handler properly

Open SanielDous opened this issue 3 years ago • 0 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