<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hallo,</p>
<p><br>
</p>
<p>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:</p>
<p><br>
</p>
<p>Option 1 (Available if you can claim that x should always be
larger than y (or vice versa)):</p>
<p>x >= y + 1</p>
<p><br>
</p>
<p>Option 2 (Indicator approach):</p>
<p>s1, s2 >= 0</p>
<p>z1, z2 binaries<br>
</p>
<p>indicator: z1=1 => s1 == 0<br>
</p>
<p>indicator z2=1 => s2 == 0<br>
</p>
<p>z1 + z2 = 1</p>
<p>s1 + s2 >= 1<br>
</p>
<p>x = y +s1 - s2</p>
<p><br>
</p>
<p>Option 3 (SOS):</p>
<p>s1, s2 >= 0</p>
<p>x = y + s1 - s2</p>
<p>s1 + s2 >= 1</p>
<p>SOS1(s1, s2)<br>
</p>
<p><br>
</p>
<p>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<br>
</p>
<p><br>
</p>
<p>@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. <br>
</p>
<p><br>
</p>
<p>Cheers and hope this helped,</p>
<p>Mark<br>
</p>
<div class="moz-cite-prefix">On 1/31/24 09:50, Peter Notebaert
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CABLPfu9O4UmZVCRj0wEtexMUntp5viqW3yvq6DSRm6-h0LhgNg@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>What would be the purpose of such a constraint? Only when x
and y would be integer this would make sense according to me.</div>
<div>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 ?</div>
<div><br>
</div>
<div>You see my point?</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 31 Jan 2024 at
08:45, Jing GONG <<a href="mailto:jing.gong@gmail.com"
moz-do-not-send="true" class="moz-txt-link-freetext">jing.gong@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I am a new user of pyscipopt and try to add a
constraint for two integers with <b> x!=y </b>for
decision optimization.</div>
<div><br>
</div>
<div>As scip seems to only "support constraints with
'<=', '>=', or '=='", I could not use
model.addCons(x!=y).</div>
<div><br>
</div>
<div>If use addConsOr likes</div>
<div><br>
</div>
<div> x = model.addVar("x", "I")<br>
y = model.addVar("y", "I")<br>
r = model.addVar("r", "B")<br>
model.addConsOr([x>=y+1, x<=y-1],r)<br>
</div>
<div><br>
</div>
<div>there is "segmentation fault" error. </div>
<div><br>
</div>
<div>How can I add constraint for x!=y ? Thanks. </div>
<div><br>
</div>
<div><br>
</div>
</div>
_______________________________________________<br>
Scip mailing list<br>
<a href="mailto:Scip@zib.de" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">Scip@zib.de</a><br>
<a href="https://listserv.zib.de/mailman/listinfo/scip"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://listserv.zib.de/mailman/listinfo/scip</a><br>
</blockquote>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Scip mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Scip@zib.de">Scip@zib.de</a>
<a class="moz-txt-link-freetext" href="https://listserv.zib.de/mailman/listinfo/scip">https://listserv.zib.de/mailman/listinfo/scip</a>
</pre>
</blockquote>
</body>
</html>