How to make the script run multiple times using RngSeedMange::SetRun()?

218 views
Skip to first unread message

Yufei Yan

unread,
May 29, 2019, 2:44:18 AM5/29/19
to ns-3-users
Hey, guys, 

I'm new to ns3, and I'm reading the manual. I was trying to run a script multiple times with RngSeedMange::SetRun() according to Chapter 2, but it didn't work. 
I've searched this group like 100 times. And trust me, I have seen some posts asking how to use SetRun() and SetSeed() to run a script multiple times without manually re-run. It seems they all have no immediate answers. 

In the API document, it says: 
if code is this: 

int N = atol(argv[1]); // Read in run number from command line.
UniformVariable x(0,10);
ExponentialVariable y(2902);

then 
N could successively be equal to 1,2,3, etc. and the user would continue to get independent runs out of the single simulation. For this simple example, the following might work:
./simulation 0
...Results for run 0:...

./simulation 1
...Results for run 1:...


OK. In my mind, it tells me that if I write: RngSeedManager::SetRun(3); the script runs 3 times, one by one without doing "./waf --run ..." in command line.
However, when I write the similar code, it does not work that way. It only executes once.

My simple code for example:

int
main (int argc, char *argv[])
{
RngSeedManager::SetSeed(10);
RngSeedManager::SetRun(3);
Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
x->SetAttribute ("Max", DoubleValue (10));
std::cout << "x:" << std::endl;
}

I am expecting 3 lines in output, like:
x: 111
x: 222
x: 333

But, every time, I only get only 1 line in output. 


Well, How should I write the code? Can anyone point to me or kindly give me a simple example that runs multiple times in a single simulation?

This makes me crazy.

Thanks a lot.

Tommaso Zugno

unread,
May 30, 2019, 9:25:11 AM5/30/19
to ns-3-users
Hi!

The methods SetRun and SetSeed are used to configure the run number and the seed number which controls the random variable generation. Basically, if you run the same simulation using the same run number and the same seed number you obtain the same results. Here you can find a detailed description: https://www.nsnam.org/docs/manual/html/random-variables.html.

If you want to run your simulation multiple times using a different run number each time you need to write an external script (I use bash) which runs multiple simulations passing the run number through the command line.

Best,
Tommaso

Yufei Yan

unread,
May 30, 2019, 3:25:05 PM5/30/19
to ns-3-users
Hi, Tommaso, 

Thank you so much for the reply. 
It completely relieves me. 

At the beginning, I also thought it was used to set some kind if parameter for random variable after reading the manual. But the fact is that the API document confuses me. 

Well, I hope this post can address some confusions for beginners like me.

Thank you again. 

Merly Marilyn

unread,
Jun 2, 2019, 3:09:31 AM6/2/19
to ns-3-...@googlegroups.com
Hello Tommaso,

How can i create this script or could you provide us a link with the instructions?
I've been looking for that but  since i'm not very skill in programming i just getting confused..

Thanks in advance for your time.

Merly

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/2266f3c1-ccde-48d4-bae0-44a4cc22b11a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Atte,

Merly Asuncion Rojas
Bachiller - Ingeniería de Telecomunicaciones - UNI
 

Tommaso Zugno

unread,
Jun 2, 2019, 5:00:44 AM6/2/19
to ns-3-users
Hi,
This is a simple example in bash:

#!/bin/bash

for r in `seq 1 25`;
do
  mkdir -p run${r}
./waf --run "scratch/script --RngRun=$r" > "run${r}/log.txt" 2>&1
done

You can find many tutorials on bash by searching on the web.

Best,
Tommaso
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-...@googlegroups.com.


--
Atte,

Merly Asuncion Rojas

Muhammad Absar

unread,
Jan 17, 2023, 5:33:00 AM1/17/23
to ns-3-users
Hi do I run 1000 runs with the help of the confidence interval 95%

Tom Henderson

unread,
Jan 17, 2023, 10:02:38 AM1/17/23
to ns-3-...@googlegroups.com, Muhammad Absar
The number of runs to reach a given confidence interval depends on how
many independent samples (of the metric you are measuring) are generated
in each run, and the width of the confidence interval you are seeking.

These references may be useful to you:

https://dl.acm.org/doi/pdf/10.1145/224401.224412

https://www.researchgate.net/publication/4111831_Simulation_Output_Analysis_A_Tutorial_Based_on_One_Research_Thread
> https://www.nsnam.org/docs/manual/html/random-variables.html <https://www.nsnam.org/docs/manual/html/random-variables.html>.
>
> If you want to run your simulation multiple times using
> a different run number each time you need to write an
> external script (I use bash) which runs multiple
> simulations passing the run number through the command line.
>
> Best,
> Tommaso
>
> Il giorno mercoledì 29 maggio 2019 08:44:18 UTC+2, Yufei
> Yan ha scritto:
>
> Hey, guys,
>
> I'm new to ns3, and I'm reading the manual. I was
> trying to run a script multiple times
> with RngSeedMange::SetRun() according to Chapter 2,
> but it didn't work.
> I've searched this group like 100 times. And trust
> me, I have seen some posts asking how to use
> SetRun() and SetSeed() to run a script multiple
> times without manually re-run. It seems they all
> have no immediate answers.
>
> In the API document, it says:
> if code is this:
>
> RngSeedManager::SetSeed
> <https://www.nsnam.org/docs/release/3.29/doxygen/classns3_1_1_rng_seed_manager.html#ab2a95901871c7b47a3dcf0f70adc58f4>(12);
> int N = atol(argv[1]); // Read in run number from
> command line.
> RngSeedManager::SetRun
> <https://www.nsnam.org/docs/release/3.29/doxygen/classns3_1_1_rng_seed_manager.html#a14c9a839f8141b0e9ec2af0e96d68263>(N);
> UniformVariable x
> <https://www.nsnam.org/docs/release/3.29/doxygen/namespacesample-rng-plot.html#a5b903688ba4a0e9d00ef4d0aa174b44f>(0,10);
> ExponentialVariable y(2902);
>
> then
> N could successively be equal to 1,2,3, /etc./ and
> the user would *continue to get independent runs*
> out of the *single simulation*. For this simple
> example, the following might work:
> ./simulation 0
> ...Results forrun 0:...
>
> ./simulation 1
> ...Results forrun 1:...
>
>
> OK. In my mind, it tells me that if I write:
> RngSeedManager::SetRun
> <https://www.nsnam.org/docs/release/3.29/doxygen/classns3_1_1_rng_seed_manager.html#a14c9a839f8141b0e9ec2af0e96d68263>(3); the script runs 3 times, one by one without doing "./waf --run ..." in command line.
> <https://groups.google.com/group/ns-3-users>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ns-3-users/2266f3c1-ccde-48d4-bae0-44a4cc22b11a%40googlegroups.com <https://groups.google.com/d/msgid/ns-3-users/2266f3c1-ccde-48d4-bae0-44a4cc22b11a%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
>
> --
> Atte,
>
> Merly Asuncion Rojas
> merly....@gmail.com
>
> Bachiller - Ingeniería de Telecomunicaciones - UNI
>
> --
> Posting to this group should follow these guidelines
> https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
> <https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting>
> ---
> You received this message because you are subscribed to the Google
> Groups "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ns-3-users+...@googlegroups.com
> <mailto:ns-3-users+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ns-3-users/7802f02c-9436-46eb-a9be-cb40e1aa9fbcn%40googlegroups.com <https://groups.google.com/d/msgid/ns-3-users/7802f02c-9436-46eb-a9be-cb40e1aa9fbcn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Message has been deleted

Tom Henderson

unread,
Jan 17, 2023, 2:36:11 PM1/17/23
to ns-3-...@googlegroups.com, Muhammad Absar
Please stop asking the same question on different threads.  I provided you with useful references to consult.  If you read them and are still in doubt, please check with your supervisor.

- Tom

On 1/17/23 11:32, Muhammad Absar wrote:
My supervisor told me to generate simulation results with 95% C.I., So How can we run 100 or 1000 runs in ns3 with the help of confidence interval 95%.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/83ca3d8c-ff1d-4024-bd3d-ab6d6a06aa99n%40googlegroups.com.


Muhammad Absar

unread,
Jan 18, 2023, 11:12:59 AM1/18/23
to ns-3-users
Sorry for that, actually I was not able to see your reply, as it went into the Spam folder of my email.

Sorry again.
Reply all
Reply to author
Forward
0 new messages