[SCIP] Lazy constraints

Marco Correia marco.v.correia at gmail.com
Sun Apr 25 18:48:31 CEST 2021


Hi,

I'm trying to understand the minimal requirements for adding constraints
during search to SCIP.

My toy problem is to try to enforce that two variables x1, x2, both
integral with domains {1,2}, add up to 3, only by using lazy constraints.

To this I created a constraint handler, and implemented:

* SCIP_DECL_CONSCHECK : Checks if x1 + x2 == 3, returning SCIP_FEASIBLE, or
SCIP_INFEASIBLE accordingly.

* SCIP_DECL_CONSENFOLP : Adds x1 + x2 == 3 to the model
using SCIPcreateConsBasicLinear and SCIPaddCons and returning
SCIP_CONSADDED.

* SCIP_DECL_CONSLOCK : Calls SCIPaddVarLocks() for both x1 and x2.

* SCIP_DECL_CONSENFOPS : Do nothing (only return SCIP_OKAY). I don't know
what to do here and it seems this never gets called in my example anyway.

* SCIP_DECL_CONSTRANS: Just return SCIP_OKAY.

Then I add this constraint handler using needscons=false, since if I
understand correctly, this way it will run even if I don't associate any
constraints with it.

Besides adding the constraint handler, I do not add any constraints, and
simply call minimize x1.

I get this trace:

Called CHECK with values x1=1, x2=1 (which returns false)
(repeats 6 times)
Called ENFOLP with values x1=1, x2=1 (which adds the x1+x2==3 and returns
CONSADDED)

and then SCIP stops with state "infeasible".

I was expecting instead to see SCIP branching and eventually finding x1=1,
x2=2.

I have the feeling I'm missing something obvious. I can't find a simple
enough example in the documentation, all examples there seem to require
that constraints are added to the constraint handler, and are much more
involved. I am essentially looking for something as simple as the gurobi
callback mechanism: just call a function at each node that can add global
constraints to the search tree.

Any hints?

As a second question, why is CHECK called 7 times with the same variable
values? Is SCIP expecting that CHECK is non-deterministic?

Thanks!
Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.zib.de/pipermail/scip/attachments/20210425/06b3a731/attachment.html>


More information about the Scip mailing list