Page **2** of **3**

### Re: Modeling the absolute value

Posted: **Fri Jul 28, 2017 1:32 pm**

by **Manassaldi**

You can find some here (page 14):

http://www.minlp.org/pdf/GBDEWOGrossmann.pdfTh Basic Steps are simple, the difficult is the manipulation of the propositions.

Best regard!

### Re: Modeling the absolute value

Posted: **Wed Aug 30, 2017 3:58 pm**

by **PeterBe**

Hi guys, I have a further question:

I still have not fully understood how to modell the absolute value of a difference in GAMS. I have used the following equations for binary variables for modelling: abs(x(t) - y(t)):

eq_z_firstCondition(t).. z(t) =l= 2 - x(t) - y(t);

eq_z_secondCondition(t).. z(t) =l= x (t) + y(t);

but what if you don't have binary variables but for example a sum:

abs( (sum(t, x(t))) - (sum(t, y(t))).

How could I model something like that?

### Re: Modeling the absolute value

Posted: **Wed Sep 06, 2017 2:02 pm**

by **PeterBe**

Hi guys,

does nobody have a clue? I just want incoorporate the absolute value of:

abs( (sum(t, x(t))) - (sum(t, y(t))) (with x(t) and y(t) being binary variables)

**Manassaldi** suggest the following for binary variables:

Code: Select all

`eq1(t).. 1 - x(t) + c(t) + absvalue(t) =g= 1;`

eq2(t).. 1 - x(t) + 1-c(t) + 1-absvalue(t) =g= 1;

eq3(t).. x(t) + 1-c(t) + absvalue(t) =g= 1;

eq4(t).. x(t) + c(t) + 1- absvalue(t) =g= 1;

eq5.. z =e= sum(t,absvalue(t) )

Let's say x(t) and c(t) are not binary variables. How would you model the absolute value of the difference between them: abs (x(t)-c(t))?

### Re: Modeling the absolute value

Posted: **Wed Sep 06, 2017 5:29 pm**

by **Manassaldi**

Hi again PeterBe, I think this can works

x(t) and c(t) are continuous variables

p(t) are binary variables

M is a sufficiently large number (BigM parameter)

if "p=1", by "eq3" (x-c) is greater than 0 so by "eq1" and "eq2" absvalue = x-c (the rest of equation are also satisfied)

if "p=0", by "eq6" (x-c) is lower than 0 so by "eq4" and "eq5" absvalue = c-x (the rest of equation are also satisfied)

eq1(t).. absvalue(t) =l= x(t) - c(t) + (1-p(t))*M;

eq2(t).. absvalue(t) =g= x(t) - c(t) - (1-p(t))*M;

eq3(t).. x(t) - c(t) =g= -(1-p(t))*M

eq4(t).. absvalue(t) =l= c(t) - x(t) + p(t)*M;

eq5(t).. absvalue(t) =g= c(t) - x(t) - p(t)*M;

eq6(t).. x(t) - c(t) =l= p(t)*M

eq7.. z =e= sum(t,absvalue(t))

All this restrictions are for "z = sum(t,abs(x(t)-c(t)))" with x and c continuous variables

Bye!

### Re: Modeling the absolute value

Posted: **Tue Sep 12, 2017 6:56 am**

by **gnaeidj**

Dear Friend

I've Written a MIQCP code which has an absolute value in its constraints and I don't know how exactly I must write it so that the code works.

here is the constraint:

sum((n,m,t),abs(z(n,m,t) - z(n,m,t+1)) =l= 2*j

the summation basically is based on t (time) and I want this absolute value constraint to work within my code

I'll be so thankful if you guide me

Best Reards

Ghassem

### Re: Modeling the absolute value

Posted: **Tue Sep 12, 2017 12:38 pm**

by **Manassaldi**

Hi,

What kind of variables are z and j?

### Re: Modeling the absolute value

Posted: **Tue Sep 12, 2017 4:27 pm**

by **gnaeidj**

Hi,

Z is a binary variable and J is a scalar

actually the Z variable represents a line status (being in circuit or out of it) and J represents the maximum number of lines which can get out of service

I want to use the mentioned constraint to express the maximum number of switching in a system, but I don't know how to insert it into my codes, so that it works properly.

### Re: Modeling the absolute value

Posted: **Wed Sep 13, 2017 12:46 pm**

by **Manassaldi**

Hi, this constraints are equivalent to "sum((n,m,t),abs(z(n,m,t) - z(n,m,t+1)) =l= 2*j"

With the command "$" you must decide what happens with the last t

eq1(n,m,t).. 1 - z(n,m,t) + z(n,m,t+1) + absvalue(n,m,t) =g= 1;

eq2(n,m,t).. 1 - z(n,m,t) + 1-z(n,m,t+1) + 1-absvalue(n,m,t) =g= 1;

eq3(n,m,t).. z(n,m,t) + 1-z(n,m,t+1) + absvalue(n,m,t) =g= 1;

eq4(n,m,t).. z(n,m,t) + z(n,m,t+1) + 1-absvalue(n,m,t) =g= 1;

eq5.. sum((n,m,t),absvalue(n,m,t)) =l= 2*j;

Bye

### Re: Modeling the absolute value

Posted: **Wed Sep 13, 2017 7:07 pm**

by **gnaeidj**

Thank you so much

### Re: Modeling the absolute value

Posted: **Wed Sep 13, 2017 7:15 pm**

by **gnaeidj**

Just something I didn't catch

what did you mean by "$" command?