Skip to content

Commit

Permalink
Function addNewNode() renamed to addNewNode!().
Browse files Browse the repository at this point in the history
addNewNode!() now starts the search for a new node ID at hash(location) by default, rather than always from 1. This should speed it up and make node IDs more unique.
Note that the hashes are not consistent between julia sessions.
I had to modify the tests slightly, now that the node IDs on boundaries are not guaranteed to have the same IDs between sessions.
See discussion at Issue #65.

Signed-off-by: Ted Steiner <tsteiner2@gmail.com>
  • Loading branch information
tedsteiner committed Feb 6, 2015
1 parent e8552af commit 2bb5d4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ function nodesWithinRange{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
end

### Add a new node ###
function addNewNode{T<:Union(LLA,ENU)}(nodes::Dict{Int,T}, loc::T)
id = 1
function addNewNode{T<:Union(LLA,ENU)}(nodes::Dict{Int,T},
loc::T,
start_id::Int=abs(int(hash(loc))) )
id = start_id
while id <= typemax(Int)
if !haskey(nodes, id)
nodes[id] = loc
Expand Down
1 change: 0 additions & 1 deletion test/intersections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ highway_sets = findHighwaySets(hwys)
# Cluster intersections
intersection_cluster_mapping = findIntersectionClusters(nodes,intersections,highway_sets,max_dist=15)
intersection_clusters = unique(collect(values(intersection_cluster_mapping)))
@test sort!(intersection_clusters) == [1,2,3,4,5]
@test length(intersection_clusters) == 5

# Replace Nodes in Highways
Expand Down
10 changes: 6 additions & 4 deletions test/routes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ edges = OpenStreetMap.getEdges(network)
for k = 1:Graphs.num_edges(network.g)
@test edges[k].index == k
end
#=
@test edges[10].source.index == 128
@test edges[10].target.index == 154
@test edges[20].source.index == 111
@test edges[30].source.index == 106
@test edges[40].source.index == 9
@test edges[50].source.index == 22
=#

# Form transportation network from segments
intersections = findIntersections(hwys)
Expand Down Expand Up @@ -112,7 +114,7 @@ loc0 = nodesENU[node0]
filteredENU = filter((k,v)->haskey(network.v,k), nodesENU)
local_indices = nodesWithinRange(filteredENU, loc0, 100.0)
@test length(local_indices) == 3
for index in [61317384, 23, 61317383]
for index in [61317384, 61317383]
@test index in local_indices
end

Expand All @@ -121,7 +123,7 @@ start_index = nearestNode(filteredENU, loc0)
node_indices, distances = nodesWithinDrivingDistance(network, start_index, 300.0)
@test length(node_indices) == length(distances)
@test length(node_indices) == 14
for index in [61318574, 18, 17, 575472710, 61317383, 12, 61318436]
for index in [61318574, 575472710, 61317383, 61318436]
@test index in node_indices
end
for dist in distances
Expand All @@ -143,7 +145,7 @@ end
node_indices, distances = nodesWithinDrivingTime(network, start_index, 50.0)
@test length(node_indices) == length(distances)
@test length(node_indices) == 30
for index in [61318572, 33, 270134895, 575440057, 61323886, 473951349, 986189343]
for index in [61318572, 270134895, 575440057, 61323886, 473951349, 986189343]
@test index in node_indices
end
for dist in distances
Expand All @@ -154,7 +156,7 @@ end
node_indices, distances = nodesWithinDrivingTime(network, local_indices, 50.0)
@test length(node_indices) == length(distances)
@test length(node_indices) == 41
for index in [575444707, 270134899, 30, 270134936, 986189343]
for index in [575444707, 270134899, 270134936, 986189343]
@test index in node_indices
end
for dist in distances
Expand Down

0 comments on commit 2bb5d4a

Please sign in to comment.