Conditional Statement with Strings Topic is solved

Problems with syntax of GAMS
Post Reply
moatta
User
User
Posts: 16
Joined: 4 years ago

Conditional Statement with Strings

Post by moatta »

Hello Everyone,

Is it possible to type a conditional statement with a string?

For example, to sum the output of all generators of the same fuel type at each hour after the solve statement:

Code: Select all

units(t,"Oil") = sum(g, P.l(g,t)$(gendata(g,"Type")="Oil"));
But I am getting the following error at the end of the line "Oil":

Code: Select all

119  Number (primary) expected
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Conditional Statement with Strings

Post by bussieck »

The trouble is that GAMS has no string valued symbols, everything is double valued or sets (with yes/no membership). So gendata(g,"Type")="Oil" does not work in GAMS. There a a couple of ways around this. You could make a set genType(g,f) (f for fuel) and then the algebra would read: units(t,"Oil") = sum(g, P.l(g,t)$genType(g,"Oil"));

-Michael
moatta
User
User
Posts: 16
Joined: 4 years ago

Re: Conditional Statement with Strings

Post by moatta »

bussieck wrote: 1 year ago The trouble is that GAMS has no string valued symbols, everything is double valued or sets (with yes/no membership). So gendata(g,"Type")="Oil" does not work in GAMS. There a a couple of ways around this. You could make a set genType(g,f) (f for fuel) and then the algebra would read: units(t,"Oil") = sum(g, P.l(g,t)$genType(g,"Oil"));

-Michael
Thanks Michael for your help

I defined a new set f and a new parameter genType(g,f) as you suggested, but I got the following error:

Code: Select all

 Parameter genType(g,f)
  45  /
  46  g1.Oil-CT
  47  g2.Oil-CT
****       $1,334
  48  g3.Coal-Steam
  49  g4.Coal-Steam
  /;

Code: Select all

 
1  Real number expected
334  Illegal data following a data element - rest ignored
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Conditional Statement with Strings

Post by bussieck »

Use Set not Parameter since this expects a number to be stored with a record.

Code: Select all

 Set genType(g,f)
    /
    g1.Oil-CT
    g2.Oil-CT
    g3.Coal-Steam
    g4.Coal-Steam
  /;
-Michael
moatta
User
User
Posts: 16
Joined: 4 years ago

Re: Conditional Statement with Strings

Post by moatta »

bussieck wrote: 1 year ago Use Set not Parameter since this expects a number to be stored with a record.

Code: Select all

 Set genType(g,f)
    /
    g1.Oil-CT
    g2.Oil-CT
    g3.Coal-Steam
    g4.Coal-Steam
  /;
-Michael
Thank you very much. That resolved the issue.
I appreciate your help and support.
Post Reply