Random paramaters and the randseed option

553 views
Skip to first unread message

b.g.van...@gmail.com

unread,
Jul 8, 2017, 10:45:00 AM7/8/17
to AMPL Modeling Language
Hi, 

I have several random parameters based on a uniform distribution in my model. 
I know that setting randseed to 0 changes all the parameters to different values and setting randseed to 1 keeps them the same.
I would like to know if there is a function that keeps the same values for all parameters (i.e. randseed 1) except for one of the instances (i.e. randseed 0).
I tried to do it using the reset data command but it doesn't seem to work.
Thanks in advance

Robert Fourer

unread,
Jul 9, 2017, 11:14:54 AM7/9/17
to am...@googlegroups.com
The "option randseed 0;" command changes the random seed to a number based on the system clock, which will be a different every time the command is given. It also displays the seed that was chosen:

ampl: option randseed 0;
option randseed 18446744073154155119;
ampl:

When you write a parameter definition like

param f {(i,j) in A} := round(Uniform(1000,3000));

the value of the expression on the right is not assigned to f[i,j] immediately. It is only assigned at the first command where f[i,j] is actually used, which may be the "solve" command. To force the assignment to be made before solving, with the random seed that you want, you can declare only "param f {(i,j) in A} >= 0;" in your model and then after the model and data files are read, give the command "let {(i,j) in A} f[i,j] := round(Uniform(1000,3000));". Using this approach, you can organize your script like this:

model CMNDexponentialdecay.mod;
data CMNDexponentialdecay20nodes.dat;

option randseed 1;
<put "let" statements here for params that should have the same random values every time>
option randseed 0;
<put "let" statements here for params that should have different random values every time>

solve;

This arrangement is appropriate for the situation shown in your example, where you do a full "reset;" at the beginning of each run.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages