moatta
November 7, 2022, 12:41pm
1
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:

```
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”:

```
119 Number (primary) expected
```

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
November 7, 2022, 2:16pm
3
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:

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

```
1 Real number expected
334 Illegal data following a data element - rest ignored
```

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

```
Set genType(g,f)
/
g1.Oil-CT
g2.Oil-CT
g3.Coal-Steam
g4.Coal-Steam
/;
```

-Michael

moatta
November 7, 2022, 3:41pm
5
Use Set not Parameter since this expects a number to be stored with a record.

```
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.