[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-glpk] How to get a variable's absolute value with GNU mathprog

**From**: |
Andrew Makhorin |

**Subject**: |
Re: [Help-glpk] How to get a variable's absolute value with GNU mathprog |

**Date**: |
Fri, 27 Feb 2009 12:36:22 +0300 |

>* Would anyone tell me how to get a variable's absolute value with GNU*
>* mathprog? *
>* var X;*
>* var Xabs;*
>* s.t. absolte: Xabs = abs(X);*
>* It always says: argument for abs has invalid type.*
You cannot use variables in abs(), because this leads to a non-linear
constraint not allowed in glpk.
>* If I write this:*
>* s.t absolte: Xabs = if X<=0 then (-1)*X else X;*
>* It says: operand proceding <= has invalid type.*
Analogously.
>* Then what should I do?*
It depends on the context where you need to use absolute value.
In general case you can model abs with binary variables. However,
sometimes this is not needed, for example, if abs is part of the
objective function which should be minimized; see:
http://lists.gnu.org/archive/html/help-glpk/2007-08/msg00036.html