[Scip] Constraints which involve two variables

Tobias Achterberg achterberg at zib.de
Fri Apr 23 19:44:52 MEST 2010


Hi Marty,

yes, adding the constraint with SCIPaddCons() is the way to go. You should see your 'and' 
constraints in the log output of SCIP somewhere.

Note that if you do not need the SCIP_CONS* pointers anymore, you should call 
SCIPreleasCons() after having added the constraint to SCIP. Otherwise, you have a memory leak.

If you need further help with your model, I suggest that you send your log output to the 
SCIP mailing list. Maybe, someone can help you there. Additionally, you may want to send 
your code to a member of the SCIP team (which I am no longer part of).


Regards,

Tobias


Martina Astegno wrote:
> Hi,
>
> as you suggested me I use the SCIPcreateConsAnd() function to create and
> capture the AND constraint. After that, I simply insert the constraint
> to SCIP problem with SCIPaddCons(). Is it ok?
> I don't find any solution, and I think I have inserted in a wrong way
> the constraints.
>
> I'm going crazy!!!
>
> Thanks!!
>
> Marty
>
> --- *Gio 22/4/10, Tobias Achterberg /<achterberg at zib.de>/* ha scritto:
>
>
>     Da: Tobias Achterberg <achterberg at zib.de>
>     Oggetto: Re: [Scip] Constraints which involve two variables
>     A: "Ambros Gleixner" <gleixner at zib.de>
>     Cc: scip at zib.de, "Martina Astegno" <talpatina at yahoo.it>
>     Data: Giovedì 22 Aprile 2010, 15:52
>
>     You can also directly use the AND constraint, which is supported by
>     SCIP, see cons_and.h:
>
>     SCIP_VAR***** z; /* 4-dim SCIP_VAR* array */
>     SCIP_VAR*** w; /* 2-dim SCIP_VAR* array */
>     SCIP_VAR* vars[2];
>
>     vars[0] = w[i][j];
>     vars[1] = w[l][h];
>     retcode = SCIPcreateConsAnd(scip, &cons, "myname", z[i][l][j][h], 2,
>     vars, ...);
>
>     This constraint would automatically add the three linear rows to the
>     LP relaxation, and it
>     could be slightly faster for domain propagation and the like.
>
>
>     Tobias
>
>
>     Ambros Gleixner wrote:
>      > Hi Marty,
>      >
>      > to have
>      >
>      >> z[i][l][j][h]<= w[i][j]
>      >> z[i][l][j][h]<= w[l][h]
>      >> z[i][l][j][h]>= w[i][j] + w[l][h] -1
>      >
>      > in form of a linear constraint, you need to rewrite it as
>      >
>      >> -SCIPinfinity(scip)<= z[i][l][j][h] - w[i][j]<= 0
>      >> -SCIPinfinity(scip)<= z[i][l][j][h] - w[l][h]<= 0
>      >> -1<= z[i][l][j][h] - w[i][j] - w[l][h]<= SCIPinfinity(scip)
>      >
>      > Then you can use SCIPcreateConsLinear.
>      >
>      > For the first two constraints you could alternatively create a so
>     called
>      > "variable bound constraint" with SCIPcreateConsVarbound. See the
>      > documentation for more details. (Since SCIP will detect this
>     structure
>      > automatically, it is perfectly ok to use SCIPcreateConsLinear,
>     though.)
>      >
>      > ambros
>      >
>      >
>      >
>      > Am 22.04.2010 15:21, schrieb Martina Astegno:
>      >> Hi all!
>      >>
>      >> I'm modelling a clustering problem and it requires to use a binary
>      >> variable for each element and for each cluster. w[i][j] = 1 if
>      >> element i is in cluster j; 0 otherwise.
>      >>
>      >> I have to define another binary variable, z[i][l][j][h], that is
>      >> equal to 1 if (w[i][j] and w[l][h]) = 1; 0 otherwise.
>      >>
>      >> AND logic operator is implemented introducing 3 new constraints in
>      >> the problem: z[i][l][j][h]<= w[i][j] z[i][l][j][h]<= w[l][h]
>      >> z[i][l][j][h]>= w[i][j] + w[l][h] -1
>      >>
>      >> So, when I have to create the solver, to define the constraint on z
>      >> variable, in function SCIPcreateConsLinear(), I don't know how
>     to fix
>      >> the lb/ub equal to the value of the w variable, because it's
>      >> SCIP_VAR* type. It's possible to know the value associated to a
>      >> variable with the function SCIPgetSolVal() only after solve method
>      >> and not during the solver construction.
>      >>
>      >> Any idea what's going on?
>      >>
>      >>
>      >> Thanks!
>      >>
>      >> Marty
>      >>
>      >>
>      >>
>      >>
>      >>
>      >>
>      >>
>      >> _______________________________________________
>      >> Scip mailing list
>      >> Scip at zib.de </mc/compose?to=Scip at zib.de>
>      >> http://listserv.zib.de/mailman/listinfo/scip
>      >
>
>


More information about the Scip mailing list