## Modeling the absolute value

Problems with modeling
Manassaldi
User Posts: 83
Joined: 2 years ago
Location: Rosario - Argentina

### Re: Modeling the absolute value

Hi, the dollar command is used to manipulate the sets.
For example, if the restrictions eq1, eq2, eq3 and eq4 does not apply to the last "t":

eq1(n,m,t)\$(ord(t) ne card(t)).. 1 - z(n,m,t) + z(n,m,t+1) + absvalue(n,m,t) =g= 1;
eq2(n,m,t)\$(ord(t) ne card(t)).. 1 - z(n,m,t) + 1-z(n,m,t+1) + 1-absvalue(n,m,t) =g= 1;
eq3(n,m,t)\$(ord(t) ne card(t)).. z(n,m,t) + 1-z(n,m,t+1) + absvalue(n,m,t) =g= 1;
eq4(n,m,t)\$(ord(t) ne card(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;

"\$(ord(t) ne card(t))" is mean that the position of the set "t" (card(t)) is not equal (ne) to the last position (card(t)).

Bye!

gnaeidj
User Posts: 8
Joined: 2 years ago

### Re: Modeling the absolute value

Manassaldi wrote:Hi, the dollar command is used to manipulate the sets.
For example, if the restrictions eq1, eq2, eq3 and eq4 does not apply to the last "t":

eq1(n,m,t)\$(ord(t) ne card(t)).. 1 - z(n,m,t) + z(n,m,t+1) + absvalue(n,m,t) =g= 1;
eq2(n,m,t)\$(ord(t) ne card(t)).. 1 - z(n,m,t) + 1-z(n,m,t+1) + 1-absvalue(n,m,t) =g= 1;
eq3(n,m,t)\$(ord(t) ne card(t)).. z(n,m,t) + 1-z(n,m,t+1) + absvalue(n,m,t) =g= 1;
eq4(n,m,t)\$(ord(t) ne card(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;

"\$(ord(t) ne card(t))" is mean that the position of the set "t" (card(t)) is not equal (ne) to the last position (card(t)).

Bye!

Hi
Thank you so much
it was such a great help

Monsef
User Posts: 3
Joined: 2 years ago

### Re: Modeling the absolute value

Does someone know how to linearize and optimize this absolute term |A - B|, where both A and B are free integers. And what if the term changed to |A-1|, what will the minimization look like?.

Here is my Linearization for |A-1|
X>=A-1
X>=1-A
X>=0.

Min X

Is this correct?
Last edited by Monsef 2 months ago, edited 1 time in total.
Monsef Tahir

bussieck
Moderator Posts: 340
Joined: 3 years ago

### Re: Modeling the absolute value

Look at GAMS Model Library model absmip (https://www.gams.com/latest/gamslib_ml/ ... bsmip.html) This shows how to linearly (with discrete variables) model abs, min, max, and sign.

-Michael