Random numbers

196 views
Skip to first unread message

Phil.Kleff

unread,
Apr 19, 2007, 6:20:50 PM4/19/07
to am...@googlegroups.com

Hello everyone,
I hope you can help me out:

1) I want AMPL to choose a number out of a predefined set. For example I
want AMPL to choose randomly between numbers 5, 9, 19. This should be quite
simple but what I found in A-3 didn't help me.

2) I want to create a random sequence for a production model. This means I
want AMPL to choose parameters (products) and give them a random number in
the production sequence. Additionally this should be controlled by
probabilities:
For example AMPL should randomly choose to pick product 2 for position 5 in
the sequence with a probability of 13%, product 3 for position 5 with a
probability of 21 % and so on...

Phil Kleffner
--
View this message in context: http://www.nabble.com/Random-numbers-tf3610091.html#a10088112
Sent from the AMPL mailing list archive at Nabble.com.

Steven Harrod

unread,
Apr 20, 2007, 12:00:46 AM4/20/07
to am...@googlegroups.com
set source ordered;

let source:= {5, 9, 19};

for {1..10} display member(floor(1+(Uniform(0,1)*3)),source);

--
Steven Harrod
Lexington, KY
859 225 1572

Phil.Kleff

unread,
Apr 20, 2007, 6:04:20 AM4/20/07
to am...@googlegroups.com

Thank you for your fast reply. The problem with your solution is, that AMPL
will always choose the same numbers. In most cases I only want to get one
number instead of your suggested 10 values.
When I delete the for {1..10} in your statement, AMPL always picks the
middle member in the set. So it isn't really random.

--
View this message in context: http://www.nabble.com/Random-numbers-tf3610091.html#a10094075

Phil.Kleff

unread,
Apr 20, 2007, 6:04:20 AM4/20/07
to am...@googlegroups.com

Thank you for your fast reply. The problem with your solution is, that AMPL
will always choose the same numbers. In most cases I only want to get one
number instead of your suggested 10 values.
When I delete the "for {1..10} in your statement, AMPL always picks the
middle member in the set. So it isn't really random.

--
View this message in context: http://www.nabble.com/Random-numbers-tf3610091.html#a10094075

Ronald Menich

unread,
Apr 20, 2007, 11:35:11 AM4/20/07
to am...@googlegroups.com
http://www.ampl.com/FAQ/#HowdoIsolveaseriesofdifferentrandomproblemswith
datadrawnfromthesamedistribution
"Then AMPL will take new samples from the Normal distribution after each
reset data:"


set source ordered;
for { 1..10 } {


let source := { 5, 9, 19 };

display member(floor(1+(Uniform(0,1)*3)),source);
reset data;
}


member(floor(1 + Uniform(0, 1)*3), source) = 9

member(floor(1 + Uniform(0, 1)*3), source) = 5

member(floor(1 + Uniform(0, 1)*3), source) = 19

member(floor(1 + Uniform(0, 1)*3), source) = 19

member(floor(1 + Uniform(0, 1)*3), source) = 5

member(floor(1 + Uniform(0, 1)*3), source) = 19

member(floor(1 + Uniform(0, 1)*3), source) = 9

member(floor(1 + Uniform(0, 1)*3), source) = 5

member(floor(1 + Uniform(0, 1)*3), source) = 9

member(floor(1 + Uniform(0, 1)*3), source) = 9

Steven Harrod

unread,
Apr 20, 2007, 12:14:34 PM4/20/07
to am...@googlegroups.com
I think the definition of "random" bears some examination. "Random" in
an experimental sense does not mean "something different happening every
time". Random means a series of values that can be argued represent a
plausible sample from a defined probability distribution. In an
experimental design or simulation, you do indeed want the sample stream
to be identical with each run, because that is the only way you can
compare alternate models or decisions.

Robert Fourer

unread,
Apr 21, 2007, 1:02:38 PM4/21/07
to am...@googlegroups.com, Ronald Menich

There are two mechanisms for getting new samples of random numbers from
AMPL. The use of "reset data" as posted by Ronald Menich is described on
page 209 of the AMPL book. You can also use "option randseed 0" as
explained on page 122.

Bob Fourer
4...@ampl.com


> -----Original Message-----
> From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of
> Phil.Kleff
> Sent: Friday, April 20, 2007 5:04 AM
> To: am...@googlegroups.com
> Subject: [AMPL 1025] Re: Random numbers
>
>
>

Reply all
Reply to author
Forward
0 new messages