Multiple simulation runs with different parameters

1,282 views
Skip to first unread message

Daniel Brettschneider

unread,
Jan 29, 2014, 4:33:34 AM1/29/14
to ns-3-...@googlegroups.com
Hi,

is there a way to automatically spawn a lot of simulation runs with different parameters? Currently I have a config header with some defines to set up my simulation. In OMNeT++ it is possible to create a config file and state something like this.is.some.parameter = {1,2,4..8} and OMNeT++ automatically creates all simulation runs in parallel. Is there a way to achieve this in ns-3 or do I have to do this by hand using command line arguments or the config store?

Regards
Daniel

Konstantinos

unread,
Jan 29, 2014, 4:41:32 AM1/29/14
to ns-3-...@googlegroups.com
Dear Daniel,

In order to run independently random simulations, you have to use different RngRun number as explained here 

This can be easily implemented with an "external" bash script where you call your simulation, i.e. ./waf --run ..., in a loop and pass the RgnRun in command line  

However, this can be also implemented within your scenario somehow. It will be a bit more difficult though.

Daniel Brettschneider

unread,
Jan 29, 2014, 4:51:36 AM1/29/14
to ns-3-...@googlegroups.com
Hi,

I am aware of that but my parameters should not be random. For example I want to define the number of nodes from 1 to 10. Is there a way that ns-3 reads this configuration, starts the 10 simulations with the according parameter, so that I can access it and create the according network topology?

Regards
Daniel

Konstantinos

unread,
Jan 29, 2014, 4:58:47 AM1/29/14
to ns-3-...@googlegroups.com
Do you want to have the number of nodes as random variable or fixed?
You can have your parameters fixed, and the randomness with come in places like mobility, start/stop times, backoffs etc.

Also with the bash script, you can have 2 loops, one for changing the RngRun and one to change the number of nodes.

You can use ConfigStore to pass parameters from a file.

Daniel Brettschneider

unread,
Jan 30, 2014, 4:28:32 AM1/30/14
to ns-3-...@googlegroups.com
Hi,

I did not find a bash script that does this job so I hacked together one myself. Maybe someone can use this.

It is a python script that sets up some parameters and then starts a lot of simulations in parallel. The first two parameters have to be adapted. I used them to define the number of nodes in my simulation. The third parameter defines the number of repetitions for each value (RngRun creates randomness). The last parameter defines the maximum number of processes that should run in parallel.
The parameters are passed as command line parameters to ns-3. A tutorial on how to use them is available here: http://www.nsnam.org/docs/release/3.9/tutorial/tutorial_22.html

#!/usr/bin/python

import sys
import os
from multiprocessing import Pool
def start_simulation(data):
run = data[0]
sub_run = data[1]
homes = data[2]
os.system('./waf --command-template="%%s --run_number=%d --sub_run_number=%d --grid_homes=%d --RngRun=%d" --run citygrid' % (run, sub_run, homes, sub_run))

if len(sys.argv) != 5:
print "usage: ./parallel [max_homes] [step] [sub_runs] [processes]"
sys.exit(0)

max_homes = int(sys.argv[1])
step = int(sys.argv[2])
sub_runs = int(sys.argv[3])
processes = int(sys.argv[4])

# create params
params = []
run = 1
for i in range(0, max_homes+step, step):
homes = i
if homes == 0 and step > 1:
homes = 1
elif homes == 0 and step == 1:
continue
for j in range(sub_runs):
params.append([run, j+1, homes])
run += 1

# run
pool = Pool(processes=processes)
pool.map(start_simulation, params)

Regards
Daniel 

Mahmod Ahmad

unread,
Jan 9, 2019, 4:06:45 PM1/9/19
to ns-3-users
 is it solved to simulate nodes number from 1 to 10? please answer
Reply all
Reply to author
Forward
0 new messages