I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Take a look at the first example in the following link (the one with
xn and xp):
http://www.gams.com/modlib/libhtml/absmip.htm
Regards
AndyC
On Mar 16, 6:13 am, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Dear Manh
Your function will be linearized as follows:
Scalar BigM A very big number /10000/;
Binary Variable X4;
Free Variable A, B, C, z, X1, X2, X3;
Equations
cost your very own function
constraint1
constraint2
constraint3
constraint4;
cost… z =e= A + B + X3;
constraint1… - X1 - X2 + X3 =e= 0;
constraint2… X1 - BigM * X4 =l= 0;
constraint3… X2 + BigM * X4 =l= BigM;
constraint4… C - X1 + X2 =e= 0;
X1.up = BigM;
X2.up = BigM;
X3.up = BigM;
Please note that C can be easily replaced by a function.
Bests,
Ehsan
On Mar 15, 8:13 pm, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Hi
I believe it would be more efficient to decompose your variable in two
distinct positive variables, that is,
C =e= C_pos - C_neg ;
(where C_pos and C_neg cannot be negative)
and define your cost function as
cost =e= A + B + C_pos + C_neg ;
On 15 mar, 18:13, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Not sure that works
Assume C = -4
C_pos = 6
C_neg = 10
abs(C) = 4
C_pos + C_neg 4
On Mar 17, 9:10 pm, Dax wrote:
Hi
I believe it would be more efficient to decompose your variable in two
distinct positive variables, that is,
C =e= C_pos - C_neg ;
(where C_pos and C_neg cannot be negative)
and define your cost function as
cost =e= A + B + C_pos + C_neg ;On 15 mar, 18:13, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?- Hide quoted text -
- Show quoted text -
\
Try to look into a method referred to as General Disjunctive Programming
Thank you very much and have a pleasant day.
Sincerely,
Ismail Fahmi
Doctoral Student
Process Systems Engineering Group
Chemical Engineering
University of Tulsa
Keplinger Hall Room U314
800 S Tucker Dr
Tulsa, OK 74104
(918) 812-1280
-----Original Message-----
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On
Behalf Of AC
Sent: Thursday, March 17, 2011 3:37 PM
To: gamsworld
Subject: Re: alternative to abs()
Not sure that works
Assume C = -4
C_pos = 6
C_neg = 10
abs(C) = 4
C_pos + C_neg 4
On Mar 17, 9:10 pm, Dax wrote:
Hi
I believe it would be more efficient to decompose your variable in two
distinct positive variables, that is,
C =e= C_pos - C_neg ;
(where C_pos and C_neg cannot be negative)
and define your cost function as
cost =e= A + B + C_pos + C_neg ;On 15 mar, 18:13, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?- Hide quoted text -
- Show quoted text -
\
Hi Ehsan,
I try to dig into your code but I still don’t get your point. Can you
explain more to me?
On Mar 17, 1:17 pm, Ehsan wrote:
Dear Manh
Your function will be linearized as follows:
Scalar BigM A very big number /10000/;
Binary Variable X4;
Free Variable A, B, C, z, X1, X2, X3;Equations
cost your very own function
constraint1
constraint2
constraint3
constraint4;cost… z =e= A + B + X3;
constraint1… - X1 - X2 + X3 =e= 0;
constraint2… X1 - BigM * X4 =l= 0;
constraint3… X2 + BigM * X4 =l= BigM;
constraint4… C - X1 + X2 =e= 0;X1.up = BigM;
X2.up = BigM;
X3.up = BigM;Please note that C can be easily replaced by a function.
Bests,
EhsanOn Mar 15, 8:13 pm, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Thanks Dax,
I think you are missing somthing here. It’s impossible to devide C
into Pos and Neg parts.
On Mar 17, 3:10 pm, Dax wrote:
Hi
I believe it would be more efficient to decompose your variable in two
distinct positive variables, that is,
C =e= C_pos - C_neg ;
(where C_pos and C_neg cannot be negative)
and define your cost function as
cost =e= A + B + C_pos + C_neg ;On 15 mar, 18:13, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
\
Hi Manh Pham,
if you want to minimize your objective function the following should work:
Variables
A
B
C
;
Positive Variables
C_ABS
;
EQ1… C_ABS =g= C;
EQ2… C_ABS =g= -1*C;
COST =e= A + B + C_ABS
Greetings
Robert
Am 15.03.2011 18:13, schrieb Manh Pham:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?
–
Dipl
Dipl.-Wirtsch.-Ing., Dipl.-Ing.
Robert Kunze
Wissenschaftlicher Mitarbeiter
Karlsruher Institut für Technologie (KIT)
Institut für Industriebetriebslehre und Industrielle Produktion (IIP)
Lehrstuhl für Energiewirtschaft
Hertzstr. 16 - Geb. 06.33
D-76187 Karlsruhe
Bitte beachten Sie die neue Telefonnummer!
phone: +49 721 608 44692
fax: +49 721 608 44682
e-mail: robert.kunze@kit.edu
www: http://www.iip.kit.edu/
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der angesprochene Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
–
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.
Dear Manh
Sorry for much delay in answering your question because I’ve not seen
your question up to now.
First of all, I’d like to point out that Olivier’s suggestion is way
better than mine and should work perfectly fine. Since the
coefficients of C_pos and C_neg differs in one minus, they are in fact
linearly dependent. In Simplex method and of course linear
programming, two linearly dependent variables cannot simultaneously
appear in a basis (you can write one of these variables based on a
linear combination of other ones). Therefore one of these two
variables is always zero and both of them cannot be simultaneously
positive.
Regarding my formulation, you might try working a numerical example to
understand it better, but here it goes:
X1and X2 are the same as C_pos and C_neg. If C is positive, X1 is
positive;if C is negative, then X2 is positive. Now you need a
constraint to prevent X1 and X2 from being positive simultaneously.
Constraint2 and Constraint3 do that using binary variable X4. If X1 is
positive, then X4 is one. However, if X2 is positive, then X4 is zero.
I hope this helps.
Good Luck,
Ehsan
On Mar 18, 10:37 am, Manh Pham wrote:
Hi Ehsan,
I try to dig into your code but I still don’t get your point. Can you
explain more to me?On Mar 17, 1:17 pm, Ehsan wrote:
Dear Manh
Your function will be linearized as follows:
Scalar BigM A very big number /10000/;
Binary Variable X4;
Free Variable A, B, C, z, X1, X2, X3;Equations
cost your very own function
constraint1
constraint2
constraint3
constraint4;cost… z =e= A + B + X3;
constraint1… - X1 - X2 + X3 =e= 0;
constraint2… X1 - BigM * X4 =l= 0;
constraint3… X2 + BigM * X4 =l= BigM;
constraint4… C - X1 + X2 =e= 0;X1.up = BigM;
X2.up = BigM;
X3.up = BigM;Please note that C can be easily replaced by a function.
Bests,
EhsanOn Mar 15, 8:13 pm, Manh Pham wrote:
I have a function like this:
cost =e= A + B + abs(C)
The abs() function make my model become nonlinear. I know I can use
binary variables to avoid this but I don’t know how to use binary
variables. Can anybody help me?- Hide quoted text -
- Show quoted text -
\