From 2bb5d4aea6e64dac09f8a0d7186215c268be1f4a Mon Sep 17 00:00:00 2001 From: Ted Steiner <tsteiner2@gmail.com> Date: Fri, 6 Feb 2015 00:34:36 -0500 Subject: [PATCH] Function addNewNode() renamed to addNewNode!(). 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> --- src/nodes.jl | 6 ++++-- test/intersections.jl | 1 - test/routes.jl | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/nodes.jl b/src/nodes.jl index cf43f84..91a68df 100644 --- a/src/nodes.jl +++ b/src/nodes.jl @@ -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 diff --git a/test/intersections.jl b/test/intersections.jl index d5e6fe5..d5b62ff 100644 --- a/test/intersections.jl +++ b/test/intersections.jl @@ -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 diff --git a/test/routes.jl b/test/routes.jl index ecad4b3..a399967 100644 --- a/test/routes.jl +++ b/test/routes.jl @@ -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) @@ -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 @@ -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 @@ -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 @@ -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