distinguishing positive and negative value of the decision variable

Hi, I am quite newbie in GAMS.

How we can distinguish whether the result of decision variable is positive or negative?
Because this will influence the objective value too. Thanks.

sample condition:

SETS
T time /t1t3/
V /v1
v5/

PARAMETERS
C(T) cost1
/t1 0.2
t2 0.3
t3 0.2 /

I(T) cost2
/t1 0.15
t2 0.35
t3 0.15 /

VARIABLES
P(V,T)

P(V,T) can be positive or negative.
Than, in the objective function we want to minimize the value of Z which is

if P(V,T) positive than Z =E= SUM((V,T),(P(V,T))*C(T)) ;
if P(V,T) negative than Z =E= SUM((V,T),(P(V,T))*I(T)) ;

How to declare this? I am trying just using simple if-else, but it still did not work.
Thanks


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Hello Diaz,

Well, as the values for c(t) and i(t) are of the same order, I think the following will work:
Define P1 and P2 as positive variables and let the difference be equal to your variable P. Add both variables to the objective function (so you’re minimizing the sum of the two).
Redefine your 2 equations, using P1 and P2.

So add/change:
positive variable
p1,p2;

equation
objectivefunction, Pdefinition;

objectivefunction … Z=e=sum((v,t),p1(v,t)*c(t))-sum((v,t),p2(v,t)*i(t))+sum((v,t),p1(v,t)+p2(v,t));
Pdefinition(v,t) … p(v,t)=e=p1(v,t)-p2(v,t);

Please check for each v and t if p1 or p2 is 0.
I hope it’ll work, if it doesn’t (because the parameters are larger/have a larger order as the variables), you could introduce weights.

When you want to be strict, know the maximum absolute value of variable P before starting the optimization (say: it’s M) and do not like to calculate weights, you could introduce binaries instead:

binary variable
y;
positive variable
p1,p2;

equation
objectivefunction,Pdefinition,P1max,P2max;

objectivefunction … Z=e=sum((v,t),p1(v,t)c(t))-sum((v,t),p2(v,t)i(t));
Pdefinition(v,t) … p(v,t)=e=p1(v,t)-p2(v,t);
P1max(v,t) … p1(v,t)=l=M
y;
P2max(v,t) … p2(v,t)=l=M
(1-y);

Kind regards,
Henry Vermue

On Friday, February 15, 2013 2:10:06 AM UTC+1, diaz zadiz wrote:

Hi, I am quite newbie in GAMS.

How we can distinguish whether the result of decision variable is positive or negative?
Because this will influence the objective value too. Thanks.

sample condition:

SETS
T time /t1t3/
V /v1
v5/

PARAMETERS
C(T) cost1
/t1 0.2
t2 0.3
t3 0.2 /

I(T) cost2
/t1 0.15
t2 0.35
t3 0.15 /

VARIABLES
P(V,T)

P(V,T) can be positive or negative.
Than, in the objective function we want to minimize the value of Z which is

if P(V,T) positive than Z =E= SUM((V,T),(P(V,T))*C(T)) ;
if P(V,T) negative than Z =E= SUM((V,T),(P(V,T))*I(T)) ;

How to declare this? I am trying just using simple if-else, but it still did not work.
Thanks


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Dear Henry,

Thank you for your reply.
But, I was curious about your below statement on objective function

objectivefunction … Z=e=sum((v,t),p1(v,t)*c(t))-sum((v,t),p2(v,t)*i(t))+sum((v,t),p1(v,t)+p2(v,t));

Do we need this statement “sum((v,t),p1(v,t)+p2(v,t))” ?
Since I think it will have different units with the aforementioned statement.

Thank you

On Friday, February 15, 2013 10:10:06 AM UTC+9, diaz zadiz wrote:

Hi, I am quite newbie in GAMS.

How we can distinguish whether the result of decision variable is positive or negative?
Because this will influence the objective value too. Thanks.

sample condition:

SETS
T time /t1t3/
V /v1
v5/

PARAMETERS
C(T) cost1
/t1 0.2
t2 0.3
t3 0.2 /

I(T) cost2
/t1 0.15
t2 0.35
t3 0.15 /

VARIABLES
P(V,T)

P(V,T) can be positive or negative.
Than, in the objective function we want to minimize the value of Z which is

if P(V,T) positive than Z =E= SUM((V,T),(P(V,T))*C(T)) ;
if P(V,T) negative than Z =E= SUM((V,T),(P(V,T))*I(T)) ;

How to declare this? I am trying just using simple if-else, but it still did not work.
Thanks


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Dear Diaz,

Well, yes, although you are often not interested in that value.
And I am quite sure the dimension is the same according to GAMS, I guess you are referring to the physical property?
That is not checked by GAMS.

The workaround of P, using P1 and P2 is in that case faulty, as an infinite number of possible combinations of P1 and P2 can form the same value of P. The inclusion of the summation in the objective function forces either P1 or P2 to be equal to 0 (for each element). Removing the summation will only force the difference between P1 and P2 equal to a value (P), which is not what you would like to have.

To point out this flaw a zero-dimensional example:
Say, your value for P is 5. So, P1 should be 5 and P2 should be 0. Removing the term allows P1 to be 7.5, and P2 to be 2.5, if that results in a better solution. You will not have this with the summation term in the objective function (because the solver can find a better solution than 10+‘x’, namely 5+‘x’).

So, the summation forces for each v and t either P2 or P1 equal to zero. This is also the reason why the value of the weight for that term must be well chosen.
It often important that it works (i.e., that either P2 or P1 is zero, while achieving the optimal result). Most people start with a weight of 1, but you can also use something exotic: e.g. half of the summation over t of the absolute values of i and c times the number of elements in v: 0.5*sum(t,abs(i(t)+c(t)))*card(v). This would also problems with physical properties/dimensions.

So, yes, you do need it.

regards,
Henry

PS To my regret I see that I forgot to add dimensions to the binary variable. Without them, either P1 or P2 contains non-zero values. In the new form, this non-zero perperty is checked for each element.
So:
P1max(v,t) … p1(v,t)=l=My(v,t);
P2max(v,t) … p2(v,t)=l=M
(1-y(v,t));


On Friday, February 15, 2013 12:33:17 PM UTC+1, diaz zadiz wrote:

Dear Henry,

Thank you for your reply.
But, I was curious about your below statement on objective function

objectivefunction … Z=e=sum((v,t),p1(v,t)*c(t))-sum((v,t),p2(v,t)*i(t))+sum((v,t),p1(v,t)+p2(v,t));

Do we need this statement “sum((v,t),p1(v,t)+p2(v,t))” ?
Since I think it will have different units with the aforementioned statement.

Thank you

On Friday, February 15, 2013 10:10:06 AM UTC+9, diaz zadiz wrote:

Hi, I am quite newbie in GAMS.

How we can distinguish whether the result of decision variable is positive or negative?
Because this will influence the objective value too. Thanks.

sample condition:

SETS
T time /t1t3/
V /v1
v5/

PARAMETERS
C(T) cost1
/t1 0.2
t2 0.3
t3 0.2 /

I(T) cost2
/t1 0.15
t2 0.35
t3 0.15 /

VARIABLES
P(V,T)

P(V,T) can be positive or negative.
Than, in the objective function we want to minimize the value of Z which is

if P(V,T) positive than Z =E= SUM((V,T),(P(V,T))*C(T)) ;
if P(V,T) negative than Z =E= SUM((V,T),(P(V,T))*I(T)) ;

How to declare this? I am trying just using simple if-else, but it still did not work.
Thanks


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Dear Henry,

Thank you for your kind explanation.
I got your point.
Actually I used your second solution to be more strict. And it works well.
Thank you so much.

On Saturday, February 16, 2013 12:13:12 AM UTC+9, Henry JW Vermue wrote:

Dear Diaz,

Well, yes, although you are often not interested in that value.
And I am quite sure the dimension is the same according to GAMS, I guess you are referring to the physical property?
That is not checked by GAMS.

The workaround of P, using P1 and P2 is in that case faulty, as an infinite number of possible combinations of P1 and P2 can form the same value of P. The inclusion of the summation in the objective function forces either P1 or P2 to be equal to 0 (for each element). Removing the summation will only force the difference between P1 and P2 equal to a value (P), which is not what you would like to have.

To point out this flaw a zero-dimensional example:
Say, your value for P is 5. So, P1 should be 5 and P2 should be 0. Removing the term allows P1 to be 7.5, and P2 to be 2.5, if that results in a better solution. You will not have this with the summation term in the objective function (because the solver can find a better solution than 10+‘x’, namely 5+‘x’).

So, the summation forces for each v and t either P2 or P1 equal to zero. This is also the reason why the value of the weight for that term must be well chosen.
It often important that it works (i.e., that either P2 or P1 is zero, while achieving the optimal result). Most people start with a weight of 1, but you can also use something exotic: e.g. half of the summation over t of the absolute values of i and c times the number of elements in v: 0.5*sum(t,abs(i(t)+c(t)))*card(v). This would also problems with physical properties/dimensions.

So, yes, you do need it.

regards,
Henry

PS To my regret I see that I forgot to add dimensions to the binary variable. Without them, either P1 or P2 contains non-zero values. In the new form, this non-zero perperty is checked for each element.
So:
P1max(v,t) … p1(v,t)=l=My(v,t);
P2max(v,t) … p2(v,t)=l=M
(1-y(v,t));


On Friday, February 15, 2013 12:33:17 PM UTC+1, diaz zadiz wrote:

Dear Henry,

Thank you for your reply.
But, I was curious about your below statement on objective function

objectivefunction … Z=e=sum((v,t),p1(v,t)*c(t))-sum((v,t),p2(v,t)*i(t))+sum((v,t),p1(v,t)+p2(v,t));

Do we need this statement “sum((v,t),p1(v,t)+p2(v,t))” ?
Since I think it will have different units with the aforementioned statement.

Thank you

On Friday, February 15, 2013 10:10:06 AM UTC+9, diaz zadiz wrote:

Hi, I am quite newbie in GAMS.

How we can distinguish whether the result of decision variable is positive or negative?
Because this will influence the objective value too. Thanks.

sample condition:

SETS
T time /t1t3/
V /v1
v5/

PARAMETERS
C(T) cost1
/t1 0.2
t2 0.3
t3 0.2 /

I(T) cost2
/t1 0.15
t2 0.35
t3 0.15 /

VARIABLES
P(V,T)

P(V,T) can be positive or negative.
Than, in the objective function we want to minimize the value of Z which is

if P(V,T) positive than Z =E= SUM((V,T),(P(V,T))*C(T)) ;
if P(V,T) negative than Z =E= SUM((V,T),(P(V,T))*I(T)) ;

How to declare this? I am trying just using simple if-else, but it still did not work.
Thanks


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\