/usr/share/sumo/tools/generate-ns2.py is in sumo-tools 0.15.0~dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | #!/usr/bin/env python
#
# automating generation of ns2-tracefiles
# author: thimor bohn <bohn@itm.uni-luebeck.de>
# date: 2006/08/07
#
#
# BEGIN: change to your needs
#
exporter = "H:\\itm\\sumo\\tools\\traceExporter\\traceExporter.jar"
sumo = "H:\\itm\\sumo\\bin\\sumo.exe"
netconvert = "H:\\itm\\sumo\\bin\\netconvert.exe"
#
#END: change to your needs
#
import os
import sys
from optparse import OptionParser
#
# parse parameters
#
usage = "usage: %prog [options]"
parser = OptionParser()
parser.add_option("--node", "-N", action="store", type="string", dest="nodefile", help="name of nodesfile to be read")
parser.add_option("--edge", "-E", action="store", type="string", dest="edgefile", help="name of edgesfile to be read")
parser.add_option("--route", "-r", action="store", type="string", dest="routefile", help="name of routesfile to be read")
parser.add_option("--net", "-n", action="store", type="string", dest="netfile", help="name of netfile to be read, you need either to specify this or node and edge")
parser.add_option("--begin", "-b", action="store", type="int", dest="begintime", help="time at which simulation starts")
parser.add_option("--end", "-e", action="store", type="int", dest="endtime", help="time at which simulation ends")
parser.add_option("--penetration", "-p", action="append", type="float", dest="penetration", help="penetration factor of vehicles in [0,1]")
parser.add_option("--seed", "-s", action="store", type="int", dest="seed", help="seed value for random generator")
(options, args) = parser.parse_args()
#
# check: correct parameter combination?
#
ok = True
print "checking parameters..."
if (options.routefile==None):
print "you have to specify route"
ok = False
if (options.netfile==None and (options.nodefile==None or options.edgefile==None)):
print "you have to specify either net or node and edge"
ok = False
if (options.begintime==None):
print "you have to specify begin"
ok = False
if (options.endtime==None):
print "you have to specify end"
ok = False
if (options.penetration==None):
print "you have to specify penetration"
ok = False
if (options.seed==None):
print "no seed specified - defaulting to 0"
options.seed = 0
if (ok == False):
sys.exit(1)
print "done"
#
# check: all files exist / parameters correct?
#
print "files exist?"
if (options.nodefile!=None):
if (os.path.isfile(options.nodefile)==False):
print "file does not exist:", options.nodefile
ok = False
if (options.edgefile!=None):
if (os.path.isfile(options.edgefile)==False):
print "file does not exist:", options.edgefile
ok = False
if (options.routefile!=None):
if (os.path.isfile(options.routefile)==False):
print "file does not exist:", options.routefile
ok = False
if (options.netfile!=None):
if (os.path.isfile(options.netfile)==False):
print "file does not exist:", options.netfile
ok = False
if (os.path.isfile(netconvert)==False):
print "file does not exist:", netconvert
ok = False
if (os.path.isfile(sumo)==False):
print "file does not exist:", sumo
ok = False
if (os.path.isfile(exporter)==False):
print "file does not exist:", exporter
ok = False
for val in options.penetration:
if (val < 0 or val > 1):
print "penetration must be in [0,1]"
ok = False
if (ok == False):
sys.exit(1)
print "done"
#
# do the work
#
#
# create netfile if does not exist
#
if (options.netfile==None):
os.system(netconvert + " -n=" + options.nodefile + " -e=" + options.edgefile + " --output-file=net.xml --disable-normalize-node-positions")
if (os.path.isfile("net.xml")==False):
print "error creating net.xml"
sys.exit(1)
os.system(netconvert + " -n=" + options.nodefile + " -e=" + options.edgefile + " --output-file=net-normalized.xml")
if (os.path.isfile("net-normalized.xml")==False):
print "error creating net-normalized.xml"
sys.exit(1)
#
# create netstate
#
if (options.netfile==None):
netfile="net.xml"
else:
netfile=options.netfile
os.system(sumo + " -n " + netfile + " -r " + options.routefile + " --netstate-dump netstate.xml -b " + str(options.begintime) + " -e " + str(options.endtime))
if (os.path.isfile("netstate.xml")==False):
print "error creating netstate.xml"
sys.exit(1)
#
# create mobility, activity
#
for penetration in options.penetration:
print "start: generation tracefile with penetration level of " + str(penetration)
os.system("java -jar " + exporter + " ns2 -n " + netfile + " -t netstate.xml -m mobility_" + str(penetration) + ".tcl -a activity_" + str(penetration) + ".tcl -c config_" + str(penetration) + ".tcl -p " + str(penetration) + " -s " + str(options.seed) + " -b " + str(options.begintime) + " -e " + str(options.endtime))
if (os.path.isfile("mobility_" + str(penetration) + ".tcl")==False or os.path.isfile("activity_" + str(penetration) + ".tcl")==False or os.path.isfile("config_" + str(penetration)+".tcl")==False):
print "error creating mobility, activity, config"
sys.exit(1)
else:
print "finished: generation tracefile with penetration level of " + str(penetration)
#
# remove netstate
#
os.remove("netstate.xml")
sys.exit(0)
|