[AMPL 2843] random numbers

View: New views
5 Messages — Rating Filter:   Alert me  

[AMPL 2843] random numbers

by marinachr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

I need 5 randomly generated sets, which may contain integer numbers
from 1 to 1000. The sets have not to be unique. The amount of numbers
in each set is random!! (it shouldn't be ordered such 1, 2, 3 4,...
elements)
How can I do it in AMPL? Please help!

Thank you and best regards,

Mari

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


[AMPL 2844] Re: random numbers

by pietro belotti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Try the following:

option randseed 0; # different random numbers every time

###########################################################
param nsets default 5;
set I = 1..nsets;
set S {I};

param minCard default 0;    # minimum cardinality
param maxCard default 100;  # maximum cardinality

param minElem default 1;    # minimum element
param maxElem default 1000; # maximum element

param cardSet default 0;    # chosen cardinality

for {i in I} {

  let cardSet := minCard + floor ((maxCard - minCard + 1 - 1e-5) *
Uniform01 ());

  let S [i] := {};

  for {j in 1..cardSet}
    let S [i] := S [i] union {minElem + floor ((maxElem - minElem + 1
- 1e-5) * Uniform01 ())};
}

display S;
##################################################################

Cheers,
Pietro


On Sep 24, 5:15 pm, marina...@... wrote:

> Hello,
>
> I need 5 randomly generated sets, which may contain integer numbers
> from 1 to 1000. The sets have not to be unique. The amount of numbers
> in each set is random!! (it shouldn't be ordered such 1, 2, 3 4,...
> elements)
> How can I do it in AMPL? Please help!
>
> Thank you and best regards,
>
> Mari
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2845] Re: random numbers

by marinachr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thank you very very much!!!

On 25 Sep., 04:48, Pietro Belotti <petr....@...> wrote:

> Try the following:
>
> option randseed 0; # different random numbers every time
>
> ###########################################################
> param nsets default 5;
> set I = 1..nsets;
> set S {I};
>
> param minCard default 0;    # minimum cardinality
> param maxCard default 100;  # maximum cardinality
>
> param minElem default 1;    # minimum element
> param maxElem default 1000; # maximum element
>
> param cardSet default 0;    # chosen cardinality
>
> for {i in I} {
>
>   let cardSet := minCard + floor ((maxCard - minCard + 1 - 1e-5) *
> Uniform01 ());
>
>   let S [i] := {};
>
>   for {j in 1..cardSet}
>     let S [i] := S [i] union {minElem + floor ((maxElem - minElem + 1
> - 1e-5) * Uniform01 ())};
>
> }
>
> display S;
> ##################################################################
>
> Cheers,
> Pietro
>
> On Sep 24, 5:15 pm, marina...@... wrote:
>
> > Hello,
>
> > I need 5 randomly generated sets, which may contain integer numbers
> > from 1 to 1000. The sets have not to be unique. The amount of numbers
> > in each set is random!! (it shouldn't be ordered such 1, 2, 3 4,...
> > elements)
> > How can I do it in AMPL? Please help!
>
> > Thank you and best regards,
>
> > Mari
>
>

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


[AMPL 2846] Re: random numbers

by marinachr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello Pietro,

may be you can help me again...
I have to get all possibe unique subsets of a set. The method
discussed in FAQ is not so precise.
For example, initial set is N = {1,2,3}. I need to generate sets {1},
{2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}. Without empty set.

kind regards


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


[AMPL 2847] Re: random numbers

by pietro belotti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Marina,

the method in the FAQs is actually good. The code below is almost
equal to it, and can be appended to what I wrote previously (but
you'll have to declare S as "set S {I} ordered;").
I wouldn't try it on large sets though...
It assumes you want the power set of the *first* of the five sets
generated. Otherwise, just define N as you wish.

###################
set N ordered;
let N := S[1];

param n := card (N);
set SS := 1 .. 2**n - 1;

set POW {k in SS} := {i in N: (k div 2**(ord(i)-1)) mod 2 = 1};

display POW;
##################

Cheers,
P


On Sep 25, 4:18 pm, marina...@... wrote:
> Hello Pietro,
>
> may be you can help me again...
> I have to get all possibe unique subsets of a set. The method
> discussed in FAQ is not so precise.
> For example, initial set is N = {1,2,3}. I need to generate sets {1},
> {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}. Without empty set.
>
> kind regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---