How do I: test if a set element is a specific string

Hi

We have some code that has worked up until now because the set elements, lets say “abc” and “def”, have always been defined in our dataset.

As a dummy example:

MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


However lately the datasets are changing, and these elements may no longer be present, or perhaps “abc” is present but “def” is not. Or similar. In these cases the above code gives a compilation error: 116 Label is unknown

One option is to declare a dummy set so that the elements are present. For example

set dummyset /abc, def/;
MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


But I wondered if there was a better or cleaner way to do this without needing to declare a dummy set?

All help appreciated

Regards
Andy C


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.
For more options, visit https://groups.google.com/d/optout.

Hi AC



You could define your normal set, say

set myset /abc, def, ghi, jkl/;

Then you define a subset for which the parameter should be assigned:

set mysubset(myset) /abd, def/;



parameter my_parameter(myset);



** Assign the values vor all members of myset:

myparameter(myset) = uniform(0,1);



** Change the values for the subset:

myparameter(mysubset) = 100 * my_parameter(mysubset);



Hope this helps

Cheers

Renger





From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of AC
Sent: Dienstag, 12. Mai 2015 23:45
To: gamsworld@googlegroups.com
Subject: How do I: test if a set element is a specific string



Hi

We have some code that has worked up until now because the set elements, lets say “abc” and “def”, have always been defined in our dataset.

As a dummy example:

MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


However lately the datasets are changing, and these elements may no longer be present, or perhaps “abc” is present but “def” is not. Or similar. In these cases the above code gives a compilation error: 116 Label is unknown

One option is to declare a dummy set so that the elements are present. For example

set dummyset /abc, def/;
MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


But I wondered if there was a better or cleaner way to do this without needing to declare a dummy set?

All help appreciated

Regards
Andy C


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.
For more options, visit https://groups.google.com/d/optout.


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.
For more options, visit https://groups.google.com/d/optout.

Hi Renger

Thanks for your reply, but I dont think its quite what I need.

My problem is that my dataset may or may not contain abc, I simply don’t know before the code is run. If it does then I want the abc/def code to be executed, if not then I want it to be ignored.

Is there execution time code that can determine if an element has been declared (defined?)

Cheers
Andrew



On Wednesday, May 13, 2015 at 7:35:25 PM UTC+12, Renger van Nieuwkoop wrote:

Hi AC



You could define your normal set, say

set myset /abc, def, ghi, jkl/;

Then you define a subset for which the parameter should be assigned:

set mysubset(myset) /abd, def/;



parameter my_parameter(myset);



** Assign the values vor all members of myset:

myparameter(myset) = uniform(0,1);



** Change the values for the subset:

myparameter(mysubset) = 100 * my_parameter(mysubset);



Hope this helps

Cheers

Renger





From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of AC
Sent: Dienstag, 12. Mai 2015 23:45
To: gams...@googlegroups.com
Subject: How do I: test if a set element is a specific string



Hi

We have some code that has worked up until now because the set elements, lets say “abc” and “def”, have always been defined in our dataset.

As a dummy example:

MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


However lately the datasets are changing, and these elements may no longer be present, or perhaps “abc” is present but “def” is not. Or similar. In these cases the above code gives a compilation error: 116 Label is unknown

One option is to declare a dummy set so that the elements are present. For example

set dummyset /abc, def/;
MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


But I wondered if there was a better or cleaner way to do this without needing to declare a dummy set?

All help appreciated

Regards
Andy C


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


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.
For more options, visit https://groups.google.com/d/optout.

Hi Andrew



This is a tough one. I solved it using awk. I only check for “abc” and write the subset accordingly. You should do some digging how to check for more than one element in the set using “or” in the regular expression.


\

  • Here I generate your existing to get starting (or just include a file with the set))

$onecho > set.inc

set myset /abc, def, ghi, jkl/;

$offecho


\

  • Be sure that there are no old files around from a previous run

$if exist awkcommand.gms $call rm -f awkcommand.gms

$if exist subset.gms $call rm -f subset.gms


\

  • Be sure that the set file is around to include

$set filename set.inc

$if not exist %filename% $abort %filename% ist not present

$include set.inc


\

  • Generate the awk command file to be included. If abc is in the set it generates a subset

  • with this element, if not it generates an empty set.

$onecho > awkcommand.gms

{print “set mysubset(myset) /”}

(/abc/) { print “abc”;}

{print “/;”}

$offecho


\

  • Run the awk command file and write the output to subset.gms

$call awk -f “awkcommand.gms” %filename% > “subset.gms”


\

  • If the subset has no elements, on- and offempty allow for this “error”

$onempty

$include subset.gms

$offempty



display myset, mysubset;





Hope this helps

Renger







From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of AC
Sent: Donnerstag, 14. Mai 2015 01:57
To: gamsworld@googlegroups.com
Subject: Re: How do I: test if a set element is a specific string



Hi Renger

Thanks for your reply, but I dont think its quite what I need.

My problem is that my dataset may or may not contain abc, I simply don’t know before the code is run. If it does then I want the abc/def code to be executed, if not then I want it to be ignored.

Is there execution time code that can determine if an element has been declared (defined?)

Cheers
Andrew



On Wednesday, May 13, 2015 at 7:35:25 PM UTC+12, Renger van Nieuwkoop wrote:

Hi AC



You could define your normal set, say

set myset /abc, def, ghi, jkl/;

Then you define a subset for which the parameter should be assigned:

set mysubset(myset) /abd, def/;



parameter my_parameter(myset);



** Assign the values vor all members of myset:

myparameter(myset) = uniform(0,1);



** Change the values for the subset:

myparameter(mysubset) = 100 * my_parameter(mysubset);



Hope this helps

Cheers

Renger





From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of AC
Sent: Dienstag, 12. Mai 2015 23:45
To: gams...@googlegroups.com
Subject: How do I: test if a set element is a specific string



Hi

We have some code that has worked up until now because the set elements, lets say “abc” and “def”, have always been defined in our dataset.

As a dummy example:

MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


However lately the datasets are changing, and these elements may no longer be present, or perhaps “abc” is present but “def” is not. Or similar. In these cases the above code gives a compilation error: 116 Label is unknown

One option is to declare a dummy set so that the elements are present. For example

set dummyset /abc, def/;
MY_PARAMETER(myset)$(SameAs(myset, “abc”) OR SameAs(myset, “def”)) = 100 * MY_PARAMETER(myset);


But I wondered if there was a better or cleaner way to do this without needing to declare a dummy set?

All help appreciated

Regards
Andy C


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


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.
For more options, visit https://groups.google.com/d/optout.


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.
For more options, visit https://groups.google.com/d/optout.