excuse me,
I have a variable Q, it can either be positive or negative.
the objective is 2* abs(Q).
but in this way the abs() will make the problem nonlinear.
How can I keep the problem linear while getting the absolute value of the variable Q?
how to model abs(variable) linearly Topic is solved
 Gideon Kruseman
 User
 Posts: 15
 Joined: 4 months ago
Re: how to model abs(variable) linearly Topic is solved
positive variables Qpos, Qneg;
Q =e= Qpos  Qneg;
* objextive now becomes 2*(Qpos+Qneg)
Q =e= Qpos  Qneg;
* objextive now becomes 2*(Qpos+Qneg)
Gideon Kruseman
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
Re: how to model abs(variable) linearly
I was just editing something in the next generation of GAMS documentation about this very example, so I'll comment here that you need to be minimizing abs(Q). If you're maximizing then you'll have to go to a MIP or perhaps a nonlinear formulation, but the nonlinear problem will be nonconvex so you might as well leave it as a MIP.
 Gideon Kruseman
 User
 Posts: 15
 Joined: 4 months ago
Re: how to model abs(variable) linearly
Of course Steve, I forgot to mention that in my reply to the question. My bad.
Gideon Kruseman
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData

 User
 Posts: 85
 Joined: 7 months ago
Re: how to model abs(variable) linearly
I should mention that my problem is minimization.
I wonder if min(abs(Q)) is available in any version of GAMS now.
I wonder if min(abs(Q)) is available in any version of GAMS now.
dirkse wrote:I was just editing something in the next generation of GAMS documentation about this very example, so I'll comment here that you need to be minimizing abs(Q). If you're maximizing then you'll have to go to a MIP or perhaps a nonlinear formulation, but the nonlinear problem will be nonconvex so you might as well leave it as a MIP.

 User
 Posts: 85
 Joined: 7 months ago
Re: how to model abs(variable) linearly
should they be defined as below?
positive variables Qpos;
negative variables Qneg;
positive variables Qpos;
negative variables Qneg;
Gideon Kruseman wrote:positive variables Qpos, Qneg;
Q =e= Qpos  Qneg;
* objextive now becomes 2*(Qpos+Qneg)
 Gideon Kruseman
 User
 Posts: 15
 Joined: 4 months ago
Re: how to model abs(variable) linearly
both variables should be defined as positive.
positive variables Qpos, Qneg;
free variables Q, Z "objective variable";
equation Absolute_definition_of_Q;
Absolute_definition_of_Q.. Q = QposQneg;
equation Objective;
Objective.. Z =g= 2*(Qpos+Qneg);
positive variables Qpos, Qneg;
free variables Q, Z "objective variable";
equation Absolute_definition_of_Q;
Absolute_definition_of_Q.. Q = QposQneg;
equation Objective;
Objective.. Z =g= 2*(Qpos+Qneg);
Gideon Kruseman
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
 Gideon Kruseman
 User
 Posts: 15
 Joined: 4 months ago
Re: how to model abs(variable) linearly
Absolute_definition_of_Q.. Q =e= QposQneg;
Gideon Kruseman
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
 Gideon Kruseman
 User
 Posts: 15
 Joined: 4 months ago
Re: how to model abs(variable) linearly
If you want to define Qneg as negative variable, you have to rearrange the signs in all the equations so it makes sense. Defining both as positive variables is the common way to do this.
Gideon Kruseman
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData
exante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socioecnomic data @CGIAR_BigData

 User
 Posts: 85
 Joined: 7 months ago
Re: how to model abs(variable) linearly
what is the relationship between Qpos, Qneg ?
Does it mean Qpos, Qneg cannot be positive at the same time?
Should we define two binary variables to constraint that?
Qpos<=max_Qpos * x_Qpos
Qneg<=max_Qneg * x_Qneg
x_Qpos + x_Qneg<=1
Does it mean Qpos, Qneg cannot be positive at the same time?
Should we define two binary variables to constraint that?
Qpos<=max_Qpos * x_Qpos
Qneg<=max_Qneg * x_Qneg
x_Qpos + x_Qneg<=1
Who is online
Users browsing this forum: No registered users and 1 guest