I am trying to create a circle network in SuMO. Since I need to experiment with parameters like radius, lanes, vehicles, etc., I want it to be automatically generated.
So far, I wrote a script which utilizes netgenerate
to generate such a circular network by using the option --spider
(as suggested by the SuMO tutorials for building a circular network and driving in circles suggest):
netgenerate --spider --spider.arm-number=1024 --spider.circle-number=1 --spider.space-radius=100 --spider.omit-center --no-turnarounds --default.lanenumber 2 -o circle.net.xml --edges.join --no-internal-links --no-left-connections --junctions.corner-detail 1000
This already gives me a pretty nice circle, however, I still have to manually merge all those edges (i.e. 1024 in this case, this is done in the script):
netconvert -s circle.net.xml --plain-output-prefix circle
netconvert -n circle.nod.xml -e circle.edg.xml -x circle.con.xml -o circle.net.xml --geometry.remove --no-turnarounds --no-internal-links --geometry.remove.keep-edges.explicit '1/1to2/1,'512'/1to'513'/1'
netconvert -n circle.nod.xml -e circle.edg.xml -x circle.con.xml -o circle.net.xml --geometry.remove --no-turnarounds --no-internal-links --geometry.remove.keep-edges.explicit '1/1to'1024'/1'
After those commands I have the following network:
However, this approach seems to be one big hack, since I am calculating the edge names to keep (used in the above commands) manually in my script and it lacks a few features (e.g. removing the road for opposite direction, having only one edge per road/ring in the circle) which are not realizable with netgenerate
.
Is there any other convenient way for generating a circle network?
To me this circle looks just fine :-). If the only thing you are missing is the possibility to remove the opposite direction the you could just remove that from the edge file before putting it back into netconvert. Of course you could also generate your edge shape with a python script like that (x,y is the center, r is the radius, c is the number of corners)
with open("my.edg.xml", "w") as output:
angle = 2 * math.pi / c
shape = ["%.2f,%.2f" % (math.cos(i * angle) * r + x,
math.sin(i * angle) * r + y) for i in range(c)]
print('''
<edges>
<edge id="e1" from="n1" to="n2" shape="%s"/>
<edge id="e2" from="n2" to="n1"/>
</edges>''' % " ".join(shape), file=output)
The content of the node file is left as an exercise for the reader.
Just two more notes: