From aaf89afa16f0f055ab273e5bfe948ac1568e7963 Mon Sep 17 00:00:00 2001 From: pszufe Date: Sun, 9 Jan 2022 02:54:52 +0100 Subject: [PATCH] upgrade LightGraphs.jl to Graphs.jl --- Project.toml | 8 ++++---- README.md | 6 +++--- samples/plotting_with_folium.jl | 2 +- src/OpenStreetMapX.jl | 2 +- src/a_star.jl | 10 +++++----- src/parseMap.jl | 4 ++-- src/routing.jl | 14 +++++++------- src/types.jl | 6 +++--- test/runtests.jl | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Project.toml b/Project.toml index 69965c4..bdfa9f9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,15 +1,15 @@ name = "OpenStreetMapX" uuid = "86cd37e6-c0ff-550b-95fe-21d72c8d4fc9" authors = ["Przemyslaw Szufel ", "Bartosz Pankratz ", "Anna Szczurek ", "Bogumil Kaminski ", "Pawel Pralat "] -version = "0.2.7" +version = "0.3.0" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" LibExpat = "522f3ed2-3f36-55e3-b6df-e94fee9b0c07" -LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" ProtoBuf = "3349acd9-ac6a-5e09-bcdb-63829b23a429" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -18,12 +18,12 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] +CodecZlib = "^0.7.0" DataStructures = "^0.17.0, ^0.18.0" HTTP = "^0.7.0, ^0.8.0, ^0.9.0" JSON = "^0.20.0, ^0.21.0" LibExpat = "^0.6.0" -LightGraphs = "^1.3.3" -CodecZlib = "^0.7.0" +Graphs = "^1.4.1" ProtoBuf = "=0.11.3" StableRNGs = "^1.0.0" julia = "^1.3.0" diff --git a/README.md b/README.md index 31582c7..eb1f5b7 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ * Package for spatial analysis, simulation and visualization of Open Street Map data * The plotting functionality is provided via a separate package [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl) -The goal of this package is to provide a backbone for multi-agent simulation of cities. +The goal of this package is to provide a backbone for multi-agent modelling and simulation of cities. -The package can parse `*.osm` and `*.pbf` (contributed by [@blegat](https://github.com/blegat/)) files and generate a LightGraphs representation along the metadata. +The package can parse `*.osm` and `*.pbf` (contributed by [@blegat](https://github.com/blegat/)) files and generate a Graphs.jl representation along the metadata. | **Documentation** | **Build Status** | @@ -94,7 +94,7 @@ In order to obtain the `*.osm` file follow the steps below: Compared to the original package major changes include among many others: -- `LightGraphs.jl` is used for map data storage +- Nwe `Graphs.jl` is used for map data storage - Several changes with routing algorithm (currently finding a route in a 1 million people city takes around 150ms) - Added support for using Google Maps API for routing - Data structure adjustment to make the library more suitable to run simulations of cities. diff --git a/samples/plotting_with_folium.jl b/samples/plotting_with_folium.jl index 89fb606..175419e 100644 --- a/samples/plotting_with_folium.jl +++ b/samples/plotting_with_folium.jl @@ -1,4 +1,4 @@ -using OpenStreetMapX, LightGraphs, PyCall +using OpenStreetMapX, Graphs, PyCall # This code assumes that folium has benn installed diff --git a/src/OpenStreetMapX.jl b/src/OpenStreetMapX.jl index 6b3dd99..325f899 100644 --- a/src/OpenStreetMapX.jl +++ b/src/OpenStreetMapX.jl @@ -1,7 +1,7 @@ module OpenStreetMapX using LibExpat -using LightGraphs +using Graphs using SparseArrays using DataStructures using Serialization diff --git a/src/a_star.jl b/src/a_star.jl index 0efd4f2..505cbd9 100644 --- a/src/a_star.jl +++ b/src/a_star.jl @@ -36,12 +36,12 @@ end a_star_algorithm(g::AbstractGraph{U}, s::Integer, t::Integer, - distmx::AbstractMatrix{T}=LightGraphs.weights(g), + distmx::AbstractMatrix{T}=Graphs.weights(g), heuristic::Function = (u,v) -> zero(T)) where {T, U} High level function - implementation of A star search algorithm: (https://en.wikipedia.org/wiki/A*_search_algorithm). -Based on the implementation in LightGraphs library, +Based on the implementation in Graphs library, however significantly improved in terms of performance. **Arguments** @@ -52,10 +52,10 @@ however significantly improved in terms of performance. * `distmx` : distance matrix * `heuristic` : search heuristic function; by default returns zero """ -function a_star_algorithm(g::LightGraphs.AbstractGraph{U}, # the g +function a_star_algorithm(g::Graphs.AbstractGraph{U}, # the g s::Integer, # the start vertex t::Integer, # the end vertex - distmx::AbstractMatrix{T}=LightGraphs.weights(g), + distmx::AbstractMatrix{T}=Graphs.weights(g), heuristic::Function = (u,v) -> zero(T)) where {T, U} nvg = nv(g) checkbounds(distmx, Base.OneTo(nvg), Base.OneTo(nvg)) @@ -72,7 +72,7 @@ function a_star_algorithm(g::LightGraphs.AbstractGraph{U}, # the g u = dequeue!(frontier) cost_so_far = dists[u] u == t && (return OpenStreetMapX.extract_a_star_route(parents,s,u), cost_so_far) - for v in LightGraphs.outneighbors(g, u) + for v in Graphs.outneighbors(g, u) col = colormap[v] if col < UInt8(2) dist = distmx[u, v] diff --git a/src/parseMap.jl b/src/parseMap.jl index e77ea08..8a69e3f 100644 --- a/src/parseMap.jl +++ b/src/parseMap.jl @@ -160,13 +160,13 @@ function MapData(mapdata::OSMData, road_levels::Set{Int}, only_intersections::Bo 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(length(v)) + g = Graphs.DiGraph(length(v)) for edge in e add_edge!(g,v[edge[1]], v[edge[2]]) end if trim_to_connected_graph - conn_components = sort!(LightGraphs.strongly_connected_components(g), + conn_components = sort!(Graphs.strongly_connected_components(g), lt=(x,y)->length(x) graph vertex) * `n` : vector of OpenStreetMap node ids for each corresponding graph vertex * `e` : vector of edges in the graph represented as a tuple (source,destination) @@ -291,11 +291,11 @@ mutable struct MapData roadways::Array{Way,1} intersections::Dict{Int,Set{Int}} # Transporation network graph data and helpers to increase routing speed - g::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64} # Graph object + g::Graphs.SimpleGraphs.SimpleDiGraph{Int64} # Graph object v::Dict{Int,Int} # (node id) => (graph vertex) 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}(),Int[], Tuple{Int64,Int64}[], SparseMatrixCSC(Matrix{Float64}(undef,0,0)),Int[]) + #MapData(bounds, nodes, roadways, intersections) = new(bounds, nodes, roadways, intersections, Graphs.SimpleGraphs.SimpleDiGraph{Int64}(), Dict{Int,Int}(),Int[], Tuple{Int64,Int64}[], SparseMatrixCSC(Matrix{Float64}(undef,0,0)),Int[]) end diff --git a/test/runtests.jl b/test/runtests.jl index 77a944f..11bb008 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using Test, OpenStreetMapX using Random, StableRNGs -import LightGraphs +import Graphs @testset "$ext" for ext in ["osm", "pbf"] pth = joinpath(dirname(pathof(OpenStreetMapX)),"..","test","data","reno_east3.$ext") @@ -68,13 +68,13 @@ import LightGraphs #Returns seem to be equal yet returning false (?) @test sort(distance(m.nodes,OpenStreetMapX.get_edges(m.nodes,m.roadways[1:2])[1])) ≈ sort([30.2013937293296, 7.243941886194111, 35.492758006997796, 12.29992029473937, 11.290063259013777]) - conn_components = sort!(LightGraphs.strongly_connected_components(m.g), + conn_components = sort!(Graphs.strongly_connected_components(m.g), lt=(x,y)->length(x)1 @test length(conn_components[1])==1799 m2 = OpenStreetMapX.get_map_data(pth,use_cache = false, trim_to_connected_graph=true); - conn_components2 = sort!(LightGraphs.strongly_connected_components(m2.g), + conn_components2 = sort!(Graphs.strongly_connected_components(m2.g), lt=(x,y)->length(x)