how to model abs(variable) linearly Topic is solved

Problems with syntax of GAMS
yanzhiping
User
User
Posts: 85
Joined: 7 months ago

how to model abs(variable) linearly

Postby yanzhiping » 4 months ago

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 non-linear.
How can I keep the problem linear while getting the absolute value of the variable Q?

User avatar
Gideon Kruseman
User
User
Posts: 15
Joined: 4 months ago

Re: how to model abs(variable) linearly  Topic is solved

Postby Gideon Kruseman » 4 months ago

positive variables Qpos, Qneg;

Q =e= Qpos - Qneg;

* objextive now becomes 2*(Qpos+Qneg)
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-ecnomic data @CGIAR_BigData

User avatar
dirkse
Moderator
Moderator
Posts: 6
Joined: 1 year ago
Location: Washington, DC

Re: how to model abs(variable) linearly

Postby dirkse » 3 months ago

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 avatar
Gideon Kruseman
User
User
Posts: 15
Joined: 4 months ago

Re: how to model abs(variable) linearly

Postby Gideon Kruseman » 3 months ago

Of course Steve, I forgot to mention that in my reply to the question. My bad.
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-ecnomic data @CGIAR_BigData

yanzhiping
User
User
Posts: 85
Joined: 7 months ago

Re: how to model abs(variable) linearly

Postby yanzhiping » 3 months ago

I should mention that my problem is minimization.

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.

yanzhiping
User
User
Posts: 85
Joined: 7 months ago

Re: how to model abs(variable) linearly

Postby yanzhiping » 3 months ago

should they be defined as below?
positive variables Qpos;
negative variables Qneg;
Gideon Kruseman wrote:positive variables Qpos, Qneg;

Q =e= Qpos - Qneg;

* objextive now becomes 2*(Qpos+Qneg)

User avatar
Gideon Kruseman
User
User
Posts: 15
Joined: 4 months ago

Re: how to model abs(variable) linearly

Postby Gideon Kruseman » 3 months ago

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 = Qpos-Qneg;

equation Objective;

Objective.. Z =g= 2*(Qpos+Qneg);
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-ecnomic data @CGIAR_BigData

User avatar
Gideon Kruseman
User
User
Posts: 15
Joined: 4 months ago

Re: how to model abs(variable) linearly

Postby Gideon Kruseman » 3 months ago

Absolute_definition_of_Q.. Q =e= Qpos-Qneg;
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-ecnomic data @CGIAR_BigData

User avatar
Gideon Kruseman
User
User
Posts: 15
Joined: 4 months ago

Re: how to model abs(variable) linearly

Postby Gideon Kruseman » 3 months ago

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
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-ecnomic data @CGIAR_BigData

yanzhiping
User
User
Posts: 85
Joined: 7 months ago

Re: how to model abs(variable) linearly

Postby yanzhiping » 3 months ago

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


Return to “Syntax”

Who is online

Users browsing this forum: No registered users and 1 guest