[SCIP] add constraint x!=y for decision optimization using pyscipopt

Mark Turner turner at zib.de
Wed Jan 31 12:22:56 CET 2024


Hallo,


I'll throw in some quick options, although there are probably better 
ways to model this. I will avoid using any big-M constraints because 
there's no provided bounds:


Option 1 (Available if you can claim that x should always be larger than 
y (or vice versa)):

x >= y + 1


Option 2 (Indicator approach):

s1, s2 >= 0

z1, z2 binaries

indicator: z1=1 => s1 == 0

indicator z2=1 => s2 == 0

z1 + z2 = 1

s1 + s2 >= 1

x = y +s1 - s2


Option 3 (SOS):

s1, s2 >= 0

x = y + s1 - s2

s1 + s2 >= 1

SOS1(s1, s2)


P.S. This is called an all-different constraint in the constraint 
programming world (I think), so from googling that you can probably find 
alternate MIP formulations


@Peter: Jing has explicitly defined x and y as integers, so this does 
make sense. You are correct that accomplishing this for continuous 
variables is nasty due to numerics.


Cheers and hope this helped,

Mark

On 1/31/24 09:50, Peter Notebaert wrote:
> What would be the purpose of such a constraint? Only when x and y 
> would be integer this would make sense according to me.
> Suppose x is 1.0 in the end result. What is then an acceptable value 
> for y? Not 1.0 but what about 1.000000000000000000001 or 
> 0.9999999999999999999999 ?
>
> You see my point?
>
> On Wed, 31 Jan 2024 at 08:45, Jing GONG <jing.gong at gmail.com> wrote:
>
>     Hi,
>
>     I am a new user of pyscipopt and try to add a constraint for two
>     integers with * x!=y *for decision optimization.
>
>     As scip  seems to only  "support constraints with '<=', '>=', or
>     '=='", I could not use model.addCons(x!=y).
>
>     If use addConsOr likes
>
>      x = model.addVar("x", "I")
>      y = model.addVar("y", "I")
>      r = model.addVar("r", "B")
>      model.addConsOr([x>=y+1, x<=y-1],r)
>
>     there is  "segmentation fault" error.
>
>     How can I add constraint for x!=y ?  Thanks.
>
>
>     _______________________________________________
>     Scip mailing list
>     Scip at zib.de
>     https://listserv.zib.de/mailman/listinfo/scip
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.zib.de/pipermail/scip/attachments/20240131/e903d452/attachment.html>


More information about the Scip mailing list