Since your variables are integer then not equal means that the difference is at least 1.

You can use the following code:

Scalar M upper bound on an integer default in GAMS is 100 / 100 /;

Binary variable y(i,k) is 1 if x(i,i) is greater than x(k,k);

Equation side1(i,k), Side2(i,k);

Side1(i,k)(ord(i) gt ord(k)).. 1-M*(y(i,k)-1) =L= x(i,i) - x(k,k);
Side2(i,k)(ord(i) gt ord(k))… x(i,i) -x(k,k) =L= -1-M*y(i,k);

Note the $-control on the equations – you only test each pair once and not twice as in some of the previous suggestions.

To ensure that the constraints are OK, try to see what the equations look like with y=0 and y=1 respectively:

Y(i,k)=0: 1-M =L= x(i,i)-x(k,k) =L= -1, i.e. x(i,i) =L= x(k,k)-1

Y(i,k)=1: 1 =L= x(i,i)-x(k,k) =L= -1-M, i.e. x(i,i) =G= x(k,k)+1

Arne Stolbjerg Drud

ARKI Consulting & Development A/S

Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark

Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email: adrud@arki.dk

-----Original Message-----

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of hossein karimi

Sent: Monday, May 21, 2012 8:26 PM

To: gamsworld@googlegroups.com

Subject: Re: Not in-equal operator in constraint

Thx

X is integer in my model.

I also, instead of eps, use a very small number such as 0.001. But it doesn’t work too

On 5/21/12, Arne Stolbjerg Drud wrote:

Destin:

Eps represent a very small number. For most numerical purposes it is

equal to zero so your proposal essentially says that the two variables

are the same. Try to look at the equation listing to see how GAMS

interprets your equation.

You comment “I don’t want to employ an extra binary variable” is not

constructive. If it is necessary, you must use it. But to know, please

indicate which type of variable x is.

Arne

Arne Stolbjerg Drud

ARKI Consulting & Development A/S

Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark

Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email: adrud@arki.dk

-----Original Message-----

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com]

On Behalf Of hossein karimi

Sent: Monday, May 21, 2012 5:39 PM

To: gamsworld@googlegroups.com

Subject: Re: Not in-equal operator in constraint

Why Equation(i,k) $ (ORD(i) ORD(k)) … x(i,i)+eps =e= x(k,k); can

not be used in GAMS for my problem.

I don’t want to employ an extra binary variable.

On 5/21/12, Arne Stolbjerg Drud wrote:

The =N= relationship means â€™non-bindingâ€™ which means that the

constraint can be ignored so this proposal will not work.

The original question did not specify whether x is continuous,

integer, or

binary:

If x is binary then x(i,i) not equal to x(k,k) is equivalent to

x(i,i)

+

x(k,k) =E= 1. If x(i,i) is 1 then x(k,k) must be zero and if x(i,i)

is

0 then x(k,k) must be 1.

If x is integer then you need an extra binary variable to indicate

which of the two variables is larger.

And if x is supposed to be continuous then you are in trouble. Not

equal is not well defined in continuous numerical optimization.

Good luck

Arne

Arne Stolbjerg Drud

ARKI Consulting & Development A/S

Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark

Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email:

adrud@arki.dk

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com]

On Behalf Of Destin Zed

Sent: Monday, May 21, 2012 12:35 PM

To: gamsworld@googlegroups.com

Subject: Re: Not in-equal operator in constraint

Hi,

The piece of code by Yan may work but it is non-linear because it

incorporates the SQR function.

You may try the following (linear formulation):

YourEquation(i,k) $ (ORD(i) NE ORD(k)) …

x(i,i)

=N= x(k,k);

I hope that helps.

Destin

On Sun, May 20, 2012 at 6:36 PM, ä»»å½¦ wrote:

Dear all user,

How can i code (x(i,i)â‰ x(k,k), iâ‰ k) in MIP model?

Thanks in advance,

perhaps you can try if this way would work:

YourExpr(i,k) $ ( ord(i) ord(k) ) Sqr( x(i,i) - x(k,k) ) =g= 0;

HTH,

Yan

–

You received this message because you are subscribed to the Google

Groups “gamsworld” group.

To post to this group, send email to gamsworld@googlegroups.com.

To unsubscribe from this group, send email to

gamsworld+unsubscribe@googlegroups.com

.

For more options, visit this group at

http://groups.google.com/group/gamsworld?hl=en.

–

You received this message because you are subscribed to the Google

Groups “gamsworld” group.

To post to this group, send email to

gamsworld@googlegroups.com.

To unsubscribe from this group, send email to

gamsworld+unsubscribe@googlegroups.com.

For more options, visit this group at

http://groups.google.com/group/gamsworld?hl=en.

–

You received this message because you are subscribed to the Google

Groups “gamsworld” group.

To post to this group, send email to gamsworld@googlegroups.com.

To unsubscribe from this group, send email to

gamsworld+unsubscribe@googlegroups.com.

For more options, visit this group at

http://groups.google.com/group/gamsworld?hl=en.

–

You received this message because you are subscribed to the Google

Groups “gamsworld” group.

To post to this group, send email to gamsworld@googlegroups.com.

To unsubscribe from this group, send email to

gamsworld+unsubscribe@googlegroups.com.

For more options, visit this group at

http://groups.google.com/group/gamsworld?hl=en.

–

You received this message because you are subscribed to the Google

Groups “gamsworld” group.

To post to this group, send email to gamsworld@googlegroups.com.

To unsubscribe from this group, send email to

gamsworld+unsubscribe@googlegroups.com.

For more options, visit this group at

http://groups.google.com/group/gamsworld?hl=en.

–

To post to this group, send email to gamsworld@googlegroups.com.

To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

\