variable syntax problem

Problems with syntax of GAMS
Post Reply
s0r0n
User
User
Posts: 7
Joined: 5 years ago

variable syntax problem

Post 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.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: variable syntax problem

Post 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
s0r0n
User
User
Posts: 7
Joined: 5 years ago

Re: variable syntax problem

Post 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.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: variable syntax problem

Post 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
s0r0n
User
User
Posts: 7
Joined: 5 years ago

Re: variable syntax problem

Post by s0r0n »

I need to solve the problem as mip
Last edited by s0r0n 5 years ago, edited 3 times in total.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: variable syntax problem

Post 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
s0r0n
User
User
Posts: 7
Joined: 5 years ago

Re: variable syntax problem

Post by s0r0n »

I get that, this picture might help you get my point,it wasn't uploaded at my previous post
Attachments
Screenshot_1.png
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: variable syntax problem

Post 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
Post Reply