Random generating of parameters

956 views
Skip to first unread message

vanair

unread,
Oct 28, 2010, 12:48:20 PM10/28/10
to am...@googlegroups.com

Dear all,

i am beginner in AMPL and so need your help!!
I need to generate integer parameters with a discrete uniform distribution.
Should i use build in function Uniform(m,n) and then round the values? or
there is also different solution?

I will highly appreciate your advice and help!

Greetings

Anna
--
View this message in context: http://old.nabble.com/Random-generating-of-parameters-tp30074906p30074906.html
Sent from the AMPL mailing list archive at Nabble.com.

Paul

unread,
Oct 29, 2010, 9:24:52 AM10/29/10
to AMPL Modeling Language
On Oct 28, 12:48 pm, vanair <a.varshav...@gmail.com> wrote:

> I need to generate  integer parameters with a discrete uniform distribution.
> Should i use build in function Uniform(m,n) and then round the values? or
> there is also different solution?

Rounding Uniform(1,5) will give you a result that takes values 2, 3, 4
with probability .25 each and 1 and 5 with probability .125 each
(because you cannot hit 5 rounding down or 1 rounding up). If you
want U{1,...,5}, generate a value from Uniform(1,6) and then truncate
it (use the trunc function).

/Paul

vanair

unread,
Oct 29, 2010, 9:38:21 AM10/29/10
to am...@googlegroups.com

Thanks a lot for advise!!!!!!!!!!!!
can i ask you another question.
I am randomly generating integer values for a parameter b[i,t] for each time
period t and everything goes well:

param b{i in I, t in T} = Uniform(1,5);

But how can i generate a value in different range for each parameter b[i,t]
separately. For example:
b[1,t] = Uniform(1,5);
b[2,t] = Uniform(10,20);

Is there any solution?
thanks a lot in advance!!!!!

Anna

> --
> You received this message because you are subscribed to the Google Groups
> "AMPL Modeling Language" group.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to
> ampl+uns...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ampl?hl=en.
>
>
>

--
View this message in context: http://old.nabble.com/Random-generating-of-parameters-tp30074906p30085818.html

Paul

unread,
Oct 29, 2010, 1:53:51 PM10/29/10
to AMPL Modeling Language

On Oct 29, 9:38 am, vanair <a.varshav...@gmail.com> wrote:

> I am randomly generating integer values for a parameter b[i,t] for each time
> period t and everything goes well:
>
> param b{i in I, t in T} = Uniform(1,5);
>
> But how can i generate a value in different range for each parameter b[i,t]
> separately. For example:
> b[1,t] = Uniform(1,5);
> b[2,t] = Uniform(10,20);
>

One approach: Make the arguments of the Uniform function expressions
in i and t. For instance,

param b {i in I, t in T} := Uniform((i-1)*t, i*t);

Another approach: Read the arguments of the Uniform function from a
data file. Something like

param blo {I, T}; # lower limits of distribution, read from data file
param bhi {I, T}; # upper limits of distribution, read from data file
param b {i in I, t in T} default Uniform(blo[i, t], bhi[i,t]);

/Paul

vanair

unread,
Oct 30, 2010, 5:40:21 AM10/30/10
to am...@googlegroups.com

Thank you so much for help, Paul!!!

> --
> You received this message because you are subscribed to the Google Groups
> "AMPL Modeling Language" group.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to
> ampl+uns...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ampl?hl=en.
>
>
>

--
View this message in context: http://old.nabble.com/Random-generating-of-parameters-tp30074906p30092171.html

khan

unread,
Feb 21, 2018, 3:54:33 AM2/21/18
to AMPL Modeling Language
Greetings,

Is there any way to use Uniform function to generate numbers in a single row and multiple columns?

Thanx.

AMPL Google Group

unread,
Feb 21, 2018, 2:46:53 PM2/21/18
to am...@googlegroups.com
You can two params to define the range for Uniform() function and generate the random value for each pair of low and high.
Here is an example:
param n :=2;
param low{1..n};
param high{1..n};
param d{i in 1..n} := Uniform(low[i],high[i]);
data;
param low := 1 0 2 0;
param high := 1 1 2 1;

--
Paras Tiwari
am...@googlegroups.com
{#HS:527789342-847#}
--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.

To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages