Can GAMS do random sampling from given dataset?

Problems with modeling
Post Reply
GabrielYin
User
User
Posts: 42
Joined: 5 months ago
Location: Dallas, TX, USA

Can GAMS do random sampling from given dataset?

Post by GabrielYin » 4 months ago

Hi experts,

I am considering if I can define one random parameter, which can randomly pick one value from one dataset (assume stored in a parameter or table) each scenario. This can be also referred as sampling, and I know in stochastic programming GAMS can use EMS to do this. However, my goal here is just to randomly pick one value from a given dataset and store it in the parameter or scalar, like the following pseudocode:

Code: Select all

Scalar
	a(scen) = Dataset(scen);

Variables
	x(scen)
	y(scen)
	
Equation 
	eq;

eq(scen)..	  3 * x(scen) + 6 * y(scen) =l= a(scen); 

Model...
That is to say, I want to the random scalar obeys the scenario index, but randomly pick one value from Dataset in each scenario, where Dataset is a given parameter.

Thank you for any information!
Gabriel

Lutz
User
User
Posts: 22
Joined: 1 year ago

Re: Can GAMS do random sampling from given dataset?

Post by Lutz » 4 months ago

Hi,

You can try something like this:

Code: Select all

Set       scen /s1*s5/;
Parameter Dataset(scen) / s1 1.2
                          s2 3.4
                          s3 5.6
                          s4 7.8
                          s5 9.0 /;
Scalar    a,scenToPick;

scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
Hope that helps,
Lutz

GabrielYin
User
User
Posts: 42
Joined: 5 months ago
Location: Dallas, TX, USA

Re: Can GAMS do random sampling from given dataset?

Post by GabrielYin » 4 months ago

Lutz wrote:
4 months ago
Hi,

You can try something like this:

Code: Select all

Set       scen /s1*s5/;
Parameter Dataset(scen) / s1 1.2
                          s2 3.4
                          s3 5.6
                          s4 7.8
                          s5 9.0 /;
Scalar    a,scenToPick;

scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
scenToPick = uniformInt(1,card(scen));
a = sum(scen$(ord(scen)=scenToPick),Dataset(scen));
Display scenToPick, a;
Hope that helps,
Lutz
Fantastic! You are so brilliant! Why couldn't I think about that! Thanks a lot!

Post Reply