Created
June 24, 2021 01:25
-
-
Save cocomoff/0388e704d6642409e545520ae194e3f4 to your computer and use it in GitHub Desktop.
network.xmlのparse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v1.dtd"> | |
<network name="equil test network"> | |
<nodes> | |
<node id="1" x="-20000" y="0"/> | |
<node id="2" x="-15000" y="0"/> | |
<node id="3" x="-865" y="5925"/> | |
<node id="4" x="-2498" y="4331"/> | |
<node id="5" x="-3829" y="3215"/> | |
<node id="6" x="-4698" y="1711"/> | |
<node id="7" x="-5000" y="0"/> | |
<node id="8" x="-4698" y="-1711"/> | |
<node id="9" x="-3829" y="-3215"/> | |
<node id="10" x="-2498" y="-4331"/> | |
<node id="11" x="-865" y="-5925"/> | |
<node id="12" x="0" y="0"/> | |
<node id="13" x="5000" y="0"/> | |
<node id="14" x="5000" y="-10000"/> | |
<node id="15" x="-20000" y="-10000"/> | |
</nodes> | |
<links capperiod="01:00:00"> | |
<link id="1" from="1" to="2" length="10000.00" capacity="36000" freespeed="27.78" permlanes="1" /> | |
<link id="2" from="2" to="3" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="3" from="2" to="4" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="4" from="2" to="5" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="5" from="2" to="6" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="6" from="2" to="7" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="7" from="2" to="8" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="8" from="2" to="9" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="9" from="2" to="10" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="10" from="2" to="11" length="10000.00" capacity="3600" freespeed="27.78" permlanes="1" /> | |
<link id="11" from="3" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="12" from="4" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="13" from="5" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="14" from="6" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="15" from="7" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="16" from="8" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="17" from="9" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="18" from="10" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="19" from="11" to="12" length="5000.00" capacity="1000" freespeed="27.78" permlanes="1" /> | |
<link id="20" from="12" to="13" length="10000.00" capacity="36000" freespeed="27.78" permlanes="1" /> | |
<link id="21" from="13" to="14" length="10000.00" capacity="36000" freespeed="27.78" permlanes="1" /> | |
<link id="22" from="14" to="15" length="35000.00" capacity="36000" freespeed="27.78" permlanes="1" /> | |
<link id="23" from="15" to="1" length="10000.00" capacity="36000" freespeed="27.78" permlanes="1" /> | |
</links> | |
</network> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Plots | |
using EzXML | |
function parse_plot(; name="network.xml") | |
doc = readxml(name) | |
# data | |
nodes_x = Float64[] | |
nodes_y = Float64[] | |
links = Tuple{Int, Int}[] | |
for c in eachelement(root(doc)) | |
if c.name == "nodes" | |
for cc in eachelement(c) | |
push!(nodes_x, parse(Float64, cc["x"])) | |
push!(nodes_y, parse(Float64, cc["y"])) | |
end | |
elseif c.name == "links" | |
for cc in eachelement(c) | |
u = parse(Int, cc["from"]) | |
v = parse(Int, cc["to"]) | |
push!(links, (u, v)) | |
end | |
end | |
end | |
# Plot | |
p = plot(dpi=150) | |
for i in 1:length(links) | |
u, v = links[i] | |
ux, uy = nodes_x[u], nodes_y[u] | |
vx, vy = nodes_x[v], nodes_y[v] | |
plot!(p, [ux, vx], [uy, vy], lw=3, color=:black, label=nothing) | |
end | |
scatter!(p, nodes_x, nodes_y, markersize=8, color=:tomato, label=nothing) | |
savefig(p, "out.png") | |
end | |
parse_plot() |
Author
cocomoff
commented
Jun 24, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment