Page 1 of 1

variable syntax problem

Posted: Tue Sep 11, 2018 12:38 am
by s0r0n
Hello,

I have 2 issues. Firstly I need to declare the square of a variable with 2 arguments, but sqr(V(i,t)) doesn't work.
As for the other, I have the following parameter: LPline_max(f,t,seg) and declared the variable LP_line(f,t,seg). However the following equation gives the errors 145 and 148 for both of them.

Code: Select all

Net16ap2(f,t) .. LP_line(f,t,1) =l= LPline_max(f,t,1);
.

Thanks in advance.

Re: variable syntax problem

Posted: Tue Sep 11, 2018 6:47 am
by bussieck
1) When you say 'but sqr(V(i,t)) doesn't work' what does this mean. The syntax is correct. But perhaps there is a problem somewhere else.
2) In GAMS labels always need quoting. So if you want to access the element '1' from seg do it as follows:

Code: Select all

Net16ap2(f,t) .. LP_line(f,t,'1') =l= LPline_max(f,t,'1');
-Michael

Re: variable syntax problem

Posted: Tue Sep 11, 2018 11:14 am
by s0r0n
Thank you for your response,second issue is solved. For the first one, I want to do something like this

Code: Select all

Set i /1*24/
               t /1*24/;
Variables
sqr(V(i,t));
but 4 errors appear all the time.

Re: variable syntax problem

Posted: Tue Sep 11, 2018 11:51 am
by bussieck
That makes little sense. What should it mean to declare the sqr of a variable? You can use the sqr of a variable in an expression in an equation or in an assignment statement:

Code: Select all

Set i /1*24/
    t /1*24/;
Variables V(i,t);
equation e;
e.. sum((i,t), sqr(V(i,t)) =l= 1;
-Michael

Re: variable syntax problem

Posted: Tue Sep 11, 2018 12:09 pm
by s0r0n
I need to solve the problem as mip

Re: variable syntax problem

Posted: Tue Sep 11, 2018 12:17 pm
by bussieck
MIP often means MILP which only allows linear expressions, so you can't use sqr of variables. I think you need to go back to the basics. Good luck.

-Michael

Re: variable syntax problem

Posted: Tue Sep 11, 2018 12:35 pm
by s0r0n
I get that, this picture might help you get my point,it wasn't uploaded at my previous post

Re: variable syntax problem

Posted: Thu Sep 13, 2018 8:45 am
by bussieck
So if the variable only shows up squared in the model then it is a "naming" issue. Just call the variable Vsqr and after the solve you get the value of V by taking sqrt of Vsqr and decide about the sign.

-Michael