[SCIP] Lazy constraints

Marc Pfetsch pfetsch at mathematik.tu-darmstadt.de
Mon Apr 26 19:09:52 CEST 2021



Hi Marco,

I am not sure I can fix your problem without looking into the code, but
I added some comments inline ...

> 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.

SCIP will try to shift these variables to have lower bounds of and be
binary.

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

This should be o.k.

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

Why do you add a constraint and now a row? The constraint only has an
indirect effect, because the mechanism relies on the linear constraint
handler to produce a row.

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

Correct.

> * 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.

This callback is needed if no LPs are (can be) solved. You could in
principle use a similar code as for CONSCHECK.

> * SCIP_DECL_CONSTRANS: Just return SCIP_OKAY.

Here, I would expect that you transform your variables and use these for
the callback above.

> 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.

Your constraint handler does not produce a constraint by itself, so this
should be o.k.

> I get this trace:
> 
> Called CHECK with values x1=1, x2=1 (which returns false)
> (repeats 6 times)

This probably is called by heuristics. Using a debugger you can probably
confirm this.

> 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.

Yes.

> Any hints?

Can you please try the following two things and send me the outcome
personally?

1. Change the bounds of your variables to [0,1] and the constraint to x1
+ x2 = 1.

2. Can you use the transformed variables as indicated above?


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

No, I assume that this happens because by chance the solutions of some
heuristics turn out to be the same.

Best

Marc


More information about the Scip mailing list