Skip to content

Commit

Permalink
update_iss32_docs_n (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
pszufe authored Aug 21, 2020
1 parent 1a4abf9 commit 10828a7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OpenStreetMapX"
uuid = "86cd37e6-c0ff-550b-95fe-21d72c8d4fc9"
authors = ["Przemyslaw Szufel <[email protected]>", "Bartosz Pankratz <[email protected]>", "Anna Szczurek <[email protected]>", "Bogumil Kaminski <[email protected]>", "Pawel Pralat <[email protected]>"]
version = "0.1.13"
version = "0.2.0"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand All @@ -17,7 +17,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
DataStructures = "^0.17.0"
HTTP = "^0.8.0"
JSON = "^0.21.0"
JSON = "^0.20.0"
LibExpat = "^0.6.0"
LightGraphs = "^1.3.0"
julia = "^1.3.0"
Expand Down
4 changes: 2 additions & 2 deletions src/a_star.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
get_distance(A::Int, B::Int,
nodes::Dict{Int,T} ,
vertices_to_nodes::Dict{Int,Int}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
vertices_to_nodes::Vector{Int}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
Auxiliary function - takes two vertices of graph and return the distance between them.
Used to compute straight line distance heuristic for A* algorithm.
Expand All @@ -15,7 +15,7 @@ Used to compute straight line distance heuristic for A* algorithm.
"""
function get_distance(A::Int, B::Int,
nodes::Dict{Int,T},
vertices_to_nodes::Dict{Int,Int}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
vertices_to_nodes::Vector{Int}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}
A,B = vertices_to_nodes[A], vertices_to_nodes[B]
OpenStreetMapX.distance(nodes[A],nodes[B])
end
Expand Down
19 changes: 16 additions & 3 deletions src/parseMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ function get_map_data(filepath::String,filename::Union{String,Nothing}=nothing;
return res
end

"""
Get Vertices and nodes for a set of `edges`
"""
function get_vertices_and_graph_nodes(edges::Vector{Tuple{Int,Int}})
graph_nodes = unique(reinterpret(Int, edges))
vertices = Dict{Int,Int}(zip(graph_nodes, 1:length(graph_nodes)))
return vertices, graph_nodes
end

"""
Internal constructor of `MapData` object
"""
function MapData(mapdata::OSMData, road_levels::Set{Int}, only_intersections::Bool=true;
trim_to_connected_graph::Bool=false, remove_nodes::AbstractSet{Int}=Set{Int}())
#preparing data
Expand Down Expand Up @@ -152,14 +163,16 @@ function MapData(mapdata::OSMData, road_levels::Set{Int}, only_intersections::Bo
weight_vals = OpenStreetMapX.distance(nodes,e)
end
# (node id) => (graph vertex)
v = OpenStreetMapX.get_vertices(e)
n = Dict(reverse.(collect(v)))
v, n = OpenStreetMapX.get_vertices_and_graph_nodes(e)
edges = [v[id] for id in reinterpret(Int, e)]
I = edges[1:2:end]
J = edges[2:2:end]
# w - Edge weights, indexed by graph id
w = SparseArrays.sparse(I, J, weight_vals, length(v), length(v))
g = LightGraphs.DiGraph(w)
g = LightGraphs.DiGraph(length(v))
for edge in e
add_edge!(g,v[edge[1]], v[edge[2]])
end

if trim_to_connected_graph
rm_list = Set{Int}()
Expand Down
7 changes: 0 additions & 7 deletions src/routing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ function get_edges(nodes::Dict{Int,T},roadways::Vector{OpenStreetMapX.Way}) wher
return collect(keys(edges)), collect(values(edges))
end

"""
Get Vertices for a set of `edges`
"""
function get_vertices(edges::Vector{Tuple{Int,Int}})
graph_nodes = unique(reinterpret(Int, edges))
vertices = Dict{Int,Int}(zip(graph_nodes, 1:length(graph_nodes)))
end
"""
Get Distances Between Edges
"""
Expand Down
7 changes: 4 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ This is the main data structure used fot map data analytics.
* `roadways` : unique roads stored as a OpenStreetMapX.Way objects
* `intersections` : roads intersections
* `g` : `LightGraphs` directed graph representing a road network
* `v` : vertices in the road network
* `v` : vertices in the road network
* `n` : OpenStreetMap node ids for the graphs vertices
* `e` : edges in the graph represented as a tuple (source,destination)
* `w` : edge weights, indexed by graph id
* `class` : road class of each edge
Expand All @@ -271,9 +272,9 @@ struct MapData
# Transporation network graph data and helpers to increase routing speed
g::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64} # Graph object
v::Dict{Int,Int} # (node id) => (graph vertex)
n::Dict{Int,Int} # (graph vertex) => (node id)
n::Vector{Int} # (graph vertex) => (node id)
e::Vector{Tuple{Int,Int}} # Edges in graph, stored as a tuple (source,destination)
w::SparseArrays.SparseMatrixCSC{Float64, Int} # Edge weights, indexed by graph id
class::Vector{Int} # Road class of each edge
#MapData(bounds, nodes, roadways, intersections) = new(bounds, nodes, roadways, intersections, LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}(), Dict{Int,Int}(), Tuple{Int64,Int64}[], SparseMatrixCSC(Matrix{Float64}(undef,0,0)),Int[])
#MapData(bounds, nodes, roadways, intersections) = new(bounds, nodes, roadways, intersections, LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}(), Dict{Int,Int}(),Int[], Tuple{Int64,Int64}[], SparseMatrixCSC(Matrix{Float64}(undef,0,0)),Int[])
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ m = OpenStreetMapX.get_map_data(pth,use_cache = false);
#routing.jl/get_edges
@test OpenStreetMapX.get_edges(m.nodes,m.roadways[1:2]) == (Tuple{Int64,Int64}[(139988738, 385046327), (2441017870, 2975020216), (385046327, 385046328), (2441017888, 2441017878), (2441017878, 2441017870)], [1, 4, 1, 4, 4])

#routing.jl/get_vertices
@test OpenStreetMapX.get_vertices(OpenStreetMapX.get_edges(m.nodes,m.roadways[1:2])[1]) == Dict(2441017878=>7,139988738=>1,2975020216=>4,2441017870=>3,385046328=>5,2441017888=>6,385046327=>2)
#parseMap.jl/get_vertices_and_graph_nodes
@test OpenStreetMapX.get_vertices_and_graph_nodes(OpenStreetMapX.get_edges(m.nodes,m.roadways[1:2])[1])[1] == Dict(2441017878=>7,139988738=>1,2975020216=>4,2441017870=>3,385046328=>5,2441017888=>6,385046327=>2)

#routing.jl/distance
#Returns seem to be equal yet returning false (?)
Expand Down

2 comments on commit 10828a7

@pszufe
Copy link
Owner Author

@pszufe pszufe commented on 10828a7 Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/19957

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 10828a74a14f4a08ca262955481d31998092a2a6
git push origin v0.2.0

Please sign in to comment.