ブレーキ遅延をつけると角で遅くなる。道路の。
40m/s くらいが最高速度か?
netgenerate --grid --grid.x-number=3 --grid.y-number=3 --grid.y-length=500 --grid.x-length=500 --output-file=jam6.net.xml --default.speed=100
丸い道路を作る
sudo find / -name hokkaido
のサンプルファイルを参考にする。
/opt/local/src/sumo-0.16.0/docs/examples/sumo/hokkaido
/opt/local/src/sumo-0.16.0/docs/examples/netconvert/hokkaido
円形を作るスクリプト
round1=500; div=1000 r_div=1.0/(div+0.0) str1="" str2="" pi=PI ((div+1).times).each{|i| str1=str1+(round1*cos(r_div*i*pi-pi/2.0)).to_s str1=str1+","+(round1*sin(r_div*i*pi-pi/2.0)).to_s+" " } str1.gsub!(/ $/,'') (div+1).times.each{|i| str2=str2+(round1*cos(r_div*i*pi+pi/2.0)).to_s str2=str2+","+(round1*sin(r_div*i*pi+pi/2.0)).to_s+" " } str2.gsub!(/ $/,'') f1.puts "<edges xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.sf.net/xsd/edges_file.xsd\">" f1.puts "<edge id=\"1\" from=\"b\" to=\"t\" spreadType=\"center\" shape=\"#{str1}\"/>" f1.puts "<edge id=\"2\" from=\"t\" to=\"b\" spreadType=\"center\" shape=\"#{str2}\"/>" f1.puts "</edges>" f2.puts "<nodes>" f2.puts "<node id=\"b\" y=\"-#{round1}\" x=\"0\"/>" f2.puts "<node id=\"t\" y=\"#{round1}\" x=\"0\"/>" f2.puts "</nodes>" f1.close f2.close #system("netconvert --node-files=test.nod.xml --edge-files=test.edg.xml --output-file=test2.net.xml")
道路にする
wa8
ruby test.edge.rb
netconvert --node-files=test.nod.xml --edge-files=test.edg.xml --output-file=test2.net.xml
netconvert --node-files=test.nod.xml --edge-files=test.edg.xml --output-file=test2.net.xml --default.speed=27
時速約110km
netconvert --node-files=test.nod.xml --edge-files=test.edg.xml --output-file=test2.net.xml --default.speed=30.5556
交通を作るスクリプト
car_number=ARGV[0].to_i; car_number_lane=car_number/2 #number_of_round=2000; # number_of_round=1000; str="1 2" str2="1 2" number_of_round.times{|i| str=str+" "+"1 2" } number_of_round.times{|i| #str2=str2+" "+"1/0to2/0 2/0to1/0" str2=str2+" "+"1 2" } puts "<routes>" puts "<vType id=\"type1\" minGap=\"0\" maxSpeed=\"100\" tau=\"10\" sigma=\"0\"/>" #puts "<vType id=\"type1\" minGap=\"0\" tau=\"1\" sigma=\"0\"/>" # #puts "<vType id=\"type1\" minGap=\"2.4\" tau=\"3\" sigma=\"0\"/>" car_number.times{|i| dx=(250.0)/(car_number_lane+0.0) j=i*dx+rand(); # puts "\t<vehicle id=\"#{i}\" depart=\"1\" departSpeed=\"max\" arrivalSpeed=\"0.00\" color=\"1,1,0\" departPos=\"#{j}\" type=\"type1\">" # #i # # col=i%3 #puts "\t<vehicle id=\"#{i}\" depart=\"#{30*i}\" departSpeed=\"max\" arrivalSpeed=\"0.00\" color=\"#{col},1,0\" departPos=\"0\" type=\"type1\">" # puts "\t<vehicle id=\"#{i}\" depart=\"#{1*i}\" departSpeed=\"max\" arrivalSpeed=\"current\" color=\"#{col},1,0\" departPos=\"0\" type=\"type1\">" if i%2==0 puts "\t\t<route edges=\"#{str}\"/>" else puts "\t\t<route edges=\"#{str2}\"/>" end puts "\t</vehicle>" } puts "</routes>"
実行
ruby jam6_test.rb 10000 > test2.rou.xml
設定ファイル
<configuration> <input> <net-file value="test2.net.xml"/> <route-files value="test2.rou.xml"/> </input> <time> <begin value="0"/> <end value="4000"/> </time> </configuration>
実行
sumo-gui -c test.sumocfg
入り口つき+unreulatedで交差点で止まらないようにする道路。
include Math f1=open("test.edg.xml","w") f2=open("test.nod.xml","w") round1=100; div=1000 r_div=1.0/(div+0.0) str1="" str2="" pi=PI ((div+1).times).each{|i| str1=str1+(round1*cos(r_div*i*pi-pi/2.0)).to_s str1=str1+","+(round1*sin(r_div*i*pi-pi/2.0)).to_s+" " } str1.gsub!(/ $/,'') (div+1).times.each{|i| str2=str2+(round1*cos(r_div*i*pi+pi/2.0)).to_s str2=str2+","+(round1*sin(r_div*i*pi+pi/2.0)).to_s+" " } str2.gsub!(/ $/,'') f1.puts "<edges xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.sf.net/xsd/edges_file.xsd\">" f1.puts "<edge id=\"1\" from=\"b\" to=\"t\" spreadType=\"center\" shape=\"#{str1}\"/>" f1.puts "<edge id=\"2\" from=\"t\" to=\"b\" spreadType=\"center\" shape=\"#{str2}\"/>" f1.puts "<edge id=\"0\" from=\"s\" to=\"b\" spreadType=\"center\"/>" f1.puts "</edges>" f2.puts "<nodes>" f2.puts "<node id=\"b\" y=\"-#{round1}\" x=\"0\" type=\"unregulated\"/>" f2.puts "<node id=\"t\" y=\"#{round1}\" x=\"0\" type=\"unregulated\"/>" f2.puts "<node id=\"s\" y=\"-#{round1}\" x=\"#{-round1}\" type=\"unregulated\"/>" f2.puts "</nodes>" f1.close f2.close system("netconvert --node-files=test.nod.xml --edge-files=test.edg.xml --output-file=test2.net.xml")
乱数+テレポートを防ぐ。
sumo-gui -c test.sumocfg --netstate-dump tmpf.dump --time-to-teleport -1 --random true
解析スクリプト
require 'rubygems' require 'nokogiri' require 'set' #puts "kokomade1" text=Nokogiri::XML(open("tmp2b")); car_number=0; car_number_sum=0; flow=0; f1=open("test2.dat","w") #puts "kokomade2" #a=(text/"edge[id=\"0/0to1/0\"]") # # # # # # counts=[]; counts2=[]; past_car=[]; tmp_car=[] #i2=100000/60 # 2.times.each{|i2| # i=60*i2+99900+0 # i=60*i2+39900+0 #i=99962 # puts "t="+" "+i2.to_s+" "+i.to_s # time=i*100 # puts time; # #i=1002 # # a=(text/"timestep[time=\"#{i.to_s}.00\"]") a=(text/"timestep[time=\"#{i.to_i.to_s}.00\"]") #puts a #puts "kokodayo" a.each{|j| #puts j j2=(j/"edge") # puts j2 j2.each{|j3| # puts j3["id"] # if j3["id"]=="1" then j5=(j3/"vehicle") if not j5.nil? then #puts j4.nil? #puts j4.length car_number=car_number+(j5.length) end a123=Set.new(past_car.map{|i| i["id"]}) a123b=Set.new(j5.map{|i| i["id"]}) #puts "test1" #a123.each{|i| puts i} #puts "test2" #a123b.each{|i| puts i} #puts "test3" #Set.new(j5).each{|i| puts i} flow=(a123 & a123b).length end if j3["id"]=="2" then j4=(j3/"vehicle") if not j4.nil? then #puts j4.nil? car_number=j4.length end tmp_car=j4; end } past_car=tmp_car if i2!=0 then puts i.to_s+","+car_number.to_s+","+flow.to_s f1.puts( i.to_s+","+car_number.to_s+","+flow.to_s) f1.flush end # # # puts j; # end } } # f1.fush if 2!=2 then car_number=(a/"vehicle").length (a/"vehicle").each{|i| id1=i["id"] pos=i["pos"] if pos.to_f>=400 then counts.push(id1) # print id1," ",pos,"\n"; end } car_number_sum=car_number_sum+car_number end #puts car_number; #} #puts a
シミレーションファイル
rm jam_wa.txt #for i in `seq 1 200`;do for i in 100;do #for i in `seq 1 200`;do #for i in 2;do ruby jam6_test.rb $i > test2.rou.xml #str=`grep 99900 tmp.dump | awk -F":" '{print $1}'` #tail -n +$str > tmp2 for i in `seq 1 1`;do sumo -c test.sumocfg --netstate-dump tmpf.dump --time-to-teleport -1 --random true str=`grep -n time=\"39900.00 tmpf.dump | awk -F":" '{print $1}'` echo "$str $i" echo "test1 $i" echo "<sumo-netstate>" > tmp2b tail -n +$str tmpf.dump >> tmp2b echo "test2 $i" # ruby test6_wa_f.rb >> jam_wa.txt ruby test5_poisson.rb >> jam_wa.txt done #tmp1=`ruby test2.rb` # echo $i","$tmp1 # echo $i","$tmp1 >> jam_remove.txt done
計測器(分速:流量のはかり方2通り), 分単位でないと何周もしてしまうので注意
require 'rubygems' require 'nokogiri' require 'set' #puts "kokomade1" text=Nokogiri::XML(open("tmp2b")); car_number=0; car_number_sum=0; flow=0; f1=open("test2.dat","w") #puts "kokomade2" #a=(text/"edge[id=\"0/0to1/0\"]") # # # # # # counts=[]; counts2=[]; past_car=[]; tmp_car=[] speed=0 #i2=100000/60 # 2.times.each{|i2| # i=600*i2+99000+0 # i=60*i2+99000+0 # # i=60*i2+39900+0 #i=99962 # puts "t="+" "+i2.to_s+" "+i.to_s # time=i*100 # puts time; # #i=1002 # # a=(text/"timestep[time=\"#{i.to_s}.00\"]") a=(text/"timestep[time=\"#{i.to_i.to_s}.00\"]") sum_v=0; #puts a #puts "kokodayo" a.each{|j| #puts j j2=(j/"edge") # puts j2 j2.each{|j3| # puts j3["id"] # if j3["id"]=="1" then j5=(j3/"vehicle") if not j5.nil? then #puts j4.nil? #puts j4.length car_number=car_number+(j5.length) end a123=Set.new(past_car.map{|i| i["id"]}) a123b=Set.new(j5.map{|i| i["id"]}) speed=(j5.map{|i| i["speed"].to_f}) speed=speed.inject(:+)/speed.length #puts speed #puts "test1" #a123.each{|i| puts i} #puts "test2" #a123b.each{|i| puts i} #puts "test3" #Set.new(j5).each{|i| puts i} flow=(a123 & a123b).length end if j3["id"]=="2" then j4=(j3/"vehicle") if not j4.nil? then #puts j4.nil? car_number=j4.length end tmp_car=j4; end } past_car=tmp_car if i2!=0 then flow2=(speed*60*car_number/(3.141592*1000/2.0)).to_s puts i.to_s+","+car_number.to_s+","+flow.to_s+","+speed.to_s+","+flow2 f1.puts(i.to_s+","+car_number.to_s+","+flow.to_s+","+speed.to_s+","+flow2) f1.flush end # # # puts j; # end } } # f1.fush
ブレーキ遅延をうまく使うと過飽和の渋滞がでる。
計測方法は、speed×密度
puts "<vType id=\"type1\" minGap=\"0\" maxSpeed=\"100\" tau=\"10\" sigma=\"0\"/>