From dbb6c70581a5a81a52c3f51204abfe579948a996 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 26 Apr 2024 11:16:18 -0400 Subject: [PATCH] Change interface names --- examples/multidimgraph_1d.jl | 4 +- examples/multidimgraph_2d.jl | 10 +- .../NamedGraphsGraphsFlowsExt.jl | 24 +- src/abstractnamedgraph.jl | 209 ++++++++---------- src/dfs.jl | 12 +- src/distances_and_capacities.jl | 20 +- src/lib/GraphsExtensions/src/abstracttrees.jl | 22 +- .../src/abstractpartitionedgraph.jl | 48 ++-- .../PartitionedGraphs/src/partitionedgraph.jl | 4 +- src/namedgraph.jl | 76 +++---- src/shortestpaths.jl | 34 ++- src/steiner_tree.jl | 12 +- test/test_abstractnamedgraph.jl | 6 +- test/test_multidimgraph.jl | 6 +- 14 files changed, 230 insertions(+), 257 deletions(-) diff --git a/examples/multidimgraph_1d.jl b/examples/multidimgraph_1d.jl index 59ea353..6aa6bd3 100644 --- a/examples/multidimgraph_1d.jl +++ b/examples/multidimgraph_1d.jl @@ -2,9 +2,9 @@ using Graphs: grid, has_edge, has_vertex, ne, nv using NamedGraphs: NamedGraph using NamedGraphs.GraphsExtensions: ⊔, subgraph -one_based_graph = grid((4,)) +position_graph = grid((4,)) vs = ["A", "B", "C", "D"] -g = NamedGraph(one_based_graph, vs) +g = NamedGraph(position_graph, vs) @show has_vertex(g, "A") @show !has_vertex(g, "E") diff --git a/examples/multidimgraph_2d.jl b/examples/multidimgraph_2d.jl index 8fdf7cd..c330c02 100644 --- a/examples/multidimgraph_2d.jl +++ b/examples/multidimgraph_2d.jl @@ -2,10 +2,10 @@ using Graphs: grid, has_edge, has_vertex, nv using NamedGraphs: NamedGraph using NamedGraphs.GraphsExtensions: ⊔, subgraph -one_based_graph = grid((2, 2)) +position_graph = grid((2, 2)) vs = [("X", 1), ("X", 2), ("Y", 1), ("Y", 2)] -g = NamedGraph(one_based_graph, vs) +g = NamedGraph(position_graph, vs) @show has_vertex(g, ("X", 1)) @show has_edge(g, ("X", 1) => ("X", 2)) @@ -42,9 +42,9 @@ g_sub = subgraph(v -> v[2] == 2, g) @show !has_vertex(g_sub, ("Y", 1)) @show has_vertex(g_sub, ("Y", 2)) -one_based_graph = grid((2, 2)) -g1 = NamedGraph(one_based_graph, Tuple.(CartesianIndices((2, 2)))) -g2 = NamedGraph(one_based_graph, Tuple.(CartesianIndices((2, 2)))) +position_graph = grid((2, 2)) +g1 = NamedGraph(position_graph, Tuple.(CartesianIndices((2, 2)))) +g2 = NamedGraph(position_graph, Tuple.(CartesianIndices((2, 2)))) g_disjoint_union = g1 ⊔ g2 diff --git a/ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl b/ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl index f7eb9c5..3f2f7a8 100644 --- a/ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl +++ b/ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl @@ -6,14 +6,14 @@ using NamedGraphs: AbstractNamedGraph, DefaultNamedCapacity, _symmetrize, - dist_matrix_to_one_based_dist_matrix, - one_based_graph, - one_based_vertex_to_vertex, - vertex_to_one_based_vertex + dist_matrix_to_position_dist_matrix, + ordered_vertices, + position_graph, + vertex_positions using NamedGraphs.GraphsExtensions: GraphsExtensions, directed_graph using SimpleTraits: SimpleTraits, @traitfn -@traitfn function NamedGraphs.dist_matrix_to_one_based_dist_matrix( +@traitfn function NamedGraphs.dist_matrix_to_position_dist_matrix( graph::AbstractNamedGraph::IsDirected, dist_matrix::DefaultNamedCapacity ) return GraphsFlows.DefaultCapacity(graph) @@ -26,15 +26,15 @@ end capacity_matrix=DefaultNamedCapacity(graph), algorithm::GraphsFlows.AbstractFlowAlgorithm=GraphsFlows.PushRelabelAlgorithm(), ) - one_based_part1, one_based_part2, flow = GraphsFlows.mincut( - directed_graph(one_based_graph(graph)), - vertex_to_one_based_vertex(graph, source), - vertex_to_one_based_vertex(graph, target), - dist_matrix_to_one_based_dist_matrix(graph, capacity_matrix), + position_part1, position_part2, flow = GraphsFlows.mincut( + directed_graph(position_graph(graph)), + vertex_positions(graph)[source], + vertex_positions(graph)[target], + dist_matrix_to_position_dist_matrix(graph, capacity_matrix), algorithm, ) - (part1, part2) = map((one_based_part1, one_based_part2)) do one_based_part - return map(v -> one_based_vertex_to_vertex(graph, v), one_based_part) + (part1, part2) = map((position_part1, position_part2)) do position_part + return map(v -> ordered_vertices(graph)[v], position_part) end return (part1, part2, flow) end diff --git a/src/abstractnamedgraph.jl b/src/abstractnamedgraph.jl index a875d64..d94e410 100644 --- a/src/abstractnamedgraph.jl +++ b/src/abstractnamedgraph.jl @@ -44,27 +44,27 @@ abstract type AbstractNamedGraph{V} <: AbstractGraph{V} end # Graphs.vertices(graph::AbstractNamedGraph) = not_implemented() -one_based_graph(graph::AbstractNamedGraph) = not_implemented() +position_graph(graph::AbstractNamedGraph) = not_implemented() Graphs.rem_vertex!(graph::AbstractNamedGraph, vertex) = not_implemented() Graphs.add_vertex!(graph::AbstractNamedGraph, vertex) = not_implemented() GraphsExtensions.rename_vertices(f::Function, g::AbstractNamedGraph) = not_implemented() +# TODO: Is this a good definition? function GraphsExtensions.permute_vertices(graph::AbstractNamedGraph, permutation) - return subgraph(graph, map(v -> one_based_vertex_to_vertex(graph, v), permutation)) + return subgraph(graph, map(v -> ordered_vertices(graph)[v], permutation)) end -# Convert vertex to ordinal (parent) vertex -# Inverse map of `one_based_vertex_to_vertex`. -vertex_to_one_based_vertex(graph::AbstractNamedGraph, vertex) = not_implemented() +# Outputs an object that when indexed by a vertex +# returns the position of that vertex in the parent +# graph `position_graph(graph::AbstractNamedGraph)`. +# Inverse map of `ordered_vertices`. +vertex_positions(graph::AbstractNamedGraph) = not_implemented() -# Convert ordinal (parent) vertex to vertex. -# Use `vertices`, assumes `vertices` is indexed by a parent vertex -# (a Vector for linear indexed parent vertices, a dictionary in general). -function one_based_vertex_to_vertex(graph::AbstractNamedGraph, one_based_vertex::Integer) - return not_implemented() -end +# Outputs an object that when indexed by a vertex position +# returns the corresponding vertex. +ordered_vertices(graph::AbstractNamedGraph) = not_implemented() Graphs.edgetype(graph::AbstractNamedGraph) = not_implemented() @@ -72,14 +72,14 @@ Graphs.edgetype(graph::AbstractNamedGraph) = not_implemented() GraphsExtensions.directed_graph_type(G::Type{<:AbstractNamedGraph}) = not_implemented() GraphsExtensions.undirected_graph_type(G::Type{<:AbstractNamedGraph}) = not_implemented() -# In terms of `one_based_graph_type` +# In terms of `position_graph_type` # is_directed(::Type{<:AbstractNamedGraph}) = not_implemented() GraphsExtensions.convert_vertextype(::Type, ::AbstractNamedGraph) = not_implemented() # TODO: implement as: # -# graph = set_one_based_graph(graph, copy(one_based_graph(graph))) +# graph = set_position_graph(graph, copy(position_graph(graph))) # graph = set_vertices(graph, copy(vertices(graph))) # # or: @@ -100,16 +100,14 @@ end # Derived interface # -one_based_graph_type(graph::AbstractNamedGraph) = typeof(one_based_graph(graph)) +position_graph_type(graph::AbstractNamedGraph) = typeof(position_graph(graph)) function Graphs.has_vertex(graph::AbstractNamedGraph, vertex) # TODO: `vertices` should have fast lookup! return vertex ∈ vertices(graph) end -one_based_vertextype(graph::AbstractNamedGraph) = vertextype(one_based_graph(graph)) - -Graphs.SimpleDiGraph(graph::AbstractNamedGraph) = SimpleDiGraph(one_based_graph(graph)) +Graphs.SimpleDiGraph(graph::AbstractNamedGraph) = SimpleDiGraph(position_graph(graph)) Base.zero(G::Type{<:AbstractNamedGraph}) = G() @@ -126,32 +124,22 @@ end # Default, can overload Base.eltype(graph::AbstractNamedGraph) = eltype(vertices(graph)) -one_based_vertices(graph::AbstractNamedGraph) = vertices(one_based_graph(graph)) -one_based_edges(graph::AbstractNamedGraph) = edges(one_based_graph(graph)) -one_based_edgetype(graph::AbstractNamedGraph) = edgetype(one_based_graph(graph)) - -function edge_to_one_based_edge(graph::AbstractNamedGraph, edge::AbstractEdge) - one_based_src = vertex_to_one_based_vertex(graph, src(edge)) - one_based_dst = vertex_to_one_based_vertex(graph, dst(edge)) - return one_based_edgetype(graph)(one_based_src, one_based_dst) -end - -function edge_to_one_based_edge(graph::AbstractNamedGraph, edge) - return edge_to_one_based_edge(graph, edgetype(graph)(edge)) -end - -function one_based_edge_to_edge(graph::AbstractNamedGraph, one_based_edge::AbstractEdge) - source = one_based_vertex_to_vertex(graph, src(one_based_edge)) - destination = one_based_vertex_to_vertex(graph, dst(one_based_edge)) - return edgetype(graph)(source, destination) +# TODO: Rename `position_edges(graph::AbstractNamedGraph)`. +function edge_to_position_edge(graph::AbstractNamedGraph, edge::AbstractEdge) + return edgetype(position_graph(graph))( + vertex_positions(graph)[src(edge)], vertex_positions(graph)[dst(edge)] + ) end -function one_based_edge_to_edge(graph::AbstractNamedGraph, one_based_edge) - return one_based_edge_to_edge(graph, one_based_edgetype(one_based_edge)) +# TODO: Rename `named_edges(graph::AbstractNamedGraph)`. +function position_edge_to_edge(graph::AbstractNamedGraph, position_edge::AbstractEdge) + return edgetype(graph)( + ordered_vertices(graph)[src(position_edge)], ordered_vertices(graph)[dst(position_edge)] + ) end function Graphs.edges(graph::AbstractNamedGraph) - return map(e -> one_based_edge_to_edge(graph, e), one_based_edges(graph)) + return map(e -> position_edge_to_edge(graph, e), edges(position_graph(graph))) end # TODO: write in terms of a generic function. @@ -163,18 +151,14 @@ for f in [ ] @eval begin function $f(graph::AbstractNamedGraph, vertex) - one_based_vertices = $f( - one_based_graph(graph), vertex_to_one_based_vertex(graph, vertex) - ) - return map(v -> one_based_vertex_to_vertex(graph, v), one_based_vertices) + position_vertices = $f(position_graph(graph), vertex_positions(graph)[vertex]) + return map(v -> ordered_vertices(graph)[v], position_vertices) end # Ambiguity errors with Graphs.jl function $f(graph::AbstractNamedGraph, vertex::Integer) - one_based_vertices = $f( - one_based_graph(graph), vertex_to_one_based_vertex(graph, vertex) - ) - return map(v -> one_based_vertex_to_vertex(graph, v), one_based_vertices) + position_vertices = $f(position_graph(graph), vertex_positions(graph)[vertex]) + return map(v -> ordered_vertices(graph)[v], position_vertices) end end end @@ -227,18 +211,11 @@ end function namedgraph_neighborhood( graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out ) - one_based_distmx = dist_matrix_to_one_based_dist_matrix(graph, distmx) - one_based_vertices = neighborhood( - one_based_graph(graph), - vertex_to_one_based_vertex(graph, vertex), - d, - one_based_distmx; - dir, + position_distmx = dist_matrix_to_position_dist_matrix(graph, distmx) + position_vertices = neighborhood( + position_graph(graph), vertex_positions(graph)[vertex], d, position_distmx; dir ) - return [ - one_based_vertex_to_vertex(graph, one_based_vertex) for - one_based_vertex in one_based_vertices - ] + return [ordered_vertices(graph)[position_vertex] for position_vertex in position_vertices] end function Graphs.neighborhood( @@ -262,17 +239,13 @@ function Graphs.neighborhood( end function namedgraph_neighborhood_dists(graph::AbstractNamedGraph, vertex, d, distmx; dir) - one_based_distmx = dist_matrix_to_one_based_dist_matrix(graph, distmx) - one_based_vertices_and_dists = neighborhood_dists( - one_based_graph(graph), - vertex_to_one_based_vertex(graph, vertex), - d, - one_based_distmx; - dir, + position_distmx = dist_matrix_to_position_dist_matrix(graph, distmx) + position_vertices_and_dists = neighborhood_dists( + position_graph(graph), vertex_positions(graph)[vertex], d, position_distmx; dir ) return [ - (one_based_vertex_to_vertex(graph, one_based_vertex), dist) for - (one_based_vertex, dist) in one_based_vertices_and_dists + (ordered_vertices(graph)[position_vertex], dist) for + (position_vertex, dist) in position_vertices_and_dists ] end @@ -297,9 +270,9 @@ function Graphs.neighborhood_dists( end function namedgraph_mincut(graph::AbstractNamedGraph, distmx) - one_based_distmx = dist_matrix_to_one_based_dist_matrix(graph, distmx) - one_based_parity, bestcut = Graphs.mincut(one_based_graph(graph), one_based_distmx) - return Dictionary(vertices(graph), one_based_parity), bestcut + position_distmx = dist_matrix_to_position_dist_matrix(graph, distmx) + position_parity, bestcut = Graphs.mincut(position_graph(graph), position_distmx) + return Dictionary(vertices(graph), position_parity), bestcut end function Graphs.mincut(graph::AbstractNamedGraph, distmx=weights(graph)) @@ -315,14 +288,13 @@ function GraphsExtensions.partitioned_vertices( graph::AbstractNamedGraph; npartitions=nothing, nvertices_per_partition=nothing, kwargs... ) vertex_partitions = partitioned_vertices( - one_based_graph(graph); npartitions, nvertices_per_partition, kwargs... + position_graph(graph); npartitions, nvertices_per_partition, kwargs... ) - #[inv(vertex_to_one_based_vertex(g))[v] for v in partitions] # TODO: output the reverse of this dictionary (a Vector of Vector # of the vertices in each partition). # return Dictionary(vertices(g), partitions) return map(vertex_partitions) do vertex_partition - return map(v -> one_based_vertex_to_vertex(graph, v), vertex_partition) + return map(v -> ordered_vertices(graph)[v], vertex_partition) end end @@ -334,16 +306,16 @@ function namedgraph_a_star( heuristic::Function=(v -> zero(eltype(distmx))), edgetype_to_return=edgetype(graph), ) - one_based_distmx = dist_matrix_to_one_based_dist_matrix(graph, distmx) - one_based_shortest_path = a_star( - one_based_graph(graph), - vertex_to_one_based_vertex(graph, source), - vertex_to_one_based_vertex(graph, destination), - dist_matrix_to_one_based_dist_matrix(graph, distmx), + position_distmx = dist_matrix_to_position_dist_matrix(graph, distmx) + position_shortest_path = a_star( + position_graph(graph), + vertex_positions(graph)[source], + vertex_positions(graph)[destination], + dist_matrix_to_position_dist_matrix(graph, distmx), heuristic, SimpleEdge, ) - return map(e -> one_based_edge_to_edge(graph, e), one_based_shortest_path) + return map(e -> position_edge_to_edge(graph, e), position_shortest_path) end function Graphs.a_star(graph::AbstractNamedGraph, source, destination, args...) @@ -367,48 +339,45 @@ end function Graphs.spfa_shortest_paths( graph::AbstractNamedGraph, vertex, distmx=weights(graph) ) - one_based_distmx = dist_matrix_to_one_based_dist_matrix(graph, distmx) - one_based_shortest_paths = spfa_shortest_paths( - one_based_graph(graph), vertex_to_one_based_vertex(graph, vertex), one_based_distmx + position_distmx = dist_matrix_to_position_dist_matrix(graph, distmx) + position_shortest_paths = spfa_shortest_paths( + position_graph(graph), vertex_positions(graph)[vertex], position_distmx ) - return Dictionary(vertices(graph), one_based_shortest_paths) + return Dictionary(vertices(graph), position_shortest_paths) end function Graphs.boruvka_mst( g::AbstractNamedGraph, distmx::AbstractMatrix{<:Real}=weights(g); minimize=true ) - one_based_mst, weights = boruvka_mst(one_based_graph(g), distmx; minimize) - return map(e -> one_based_edge_to_edge(g, e), one_based_mst), weights + position_mst, weights = boruvka_mst(position_graph(g), distmx; minimize) + return map(e -> position_edge_to_edge(g, e), position_mst), weights end function Graphs.kruskal_mst( g::AbstractNamedGraph, distmx::AbstractMatrix{<:Real}=weights(g); minimize=true ) - one_based_mst = kruskal_mst(one_based_graph(g), distmx; minimize) - return map(e -> one_based_edge_to_edge(g, e), one_based_mst) + position_mst = kruskal_mst(position_graph(g), distmx; minimize) + return map(e -> position_edge_to_edge(g, e), position_mst) end function Graphs.prim_mst(g::AbstractNamedGraph, distmx::AbstractMatrix{<:Real}=weights(g)) - one_based_mst = prim_mst(one_based_graph(g), distmx) - return map(e -> one_based_edge_to_edge(g, e), one_based_mst) + position_mst = prim_mst(position_graph(g), distmx) + return map(e -> position_edge_to_edge(g, e), position_mst) end -function Graphs.add_edge!(graph::AbstractNamedGraph, edge::AbstractEdge) - add_edge!(one_based_graph(graph), edge_to_one_based_edge(graph, edge)) +function Graphs.add_edge!(graph::AbstractNamedGraph, edge) + add_edge!(position_graph(graph), edge_to_position_edge(graph, edgetype(graph)(edge))) return graph end - -# handles single-argument edge constructors such as pairs and tuples -Graphs.add_edge!(g::AbstractNamedGraph, edge) = add_edge!(g, edgetype(g)(edge)) Graphs.add_edge!(g::AbstractNamedGraph, src, dst) = add_edge!(g, edgetype(g)(src, dst)) function Graphs.rem_edge!(graph::AbstractNamedGraph, edge) - rem_edge!(one_based_graph(graph), edge_to_one_based_edge(graph, edge)) + rem_edge!(position_graph(graph), edge_to_position_edge(graph, edgetype(graph)(edge))) return graph end function Graphs.has_edge(graph::AbstractNamedGraph, edge::AbstractNamedEdge) - return has_edge(one_based_graph(graph), edge_to_one_based_edge(graph, edge)) + return has_edge(position_graph(graph), edge_to_position_edge(graph, edge)) end # handles two-argument edge constructors like src,dst @@ -419,10 +388,10 @@ function Graphs.has_path( graph::AbstractNamedGraph, source, destination; exclude_vertices=vertextype(graph)[] ) return has_path( - one_based_graph(graph), - vertex_to_one_based_vertex(graph, source), - vertex_to_one_based_vertex(graph, destination); - exclude_vertices=map(v -> vertex_to_one_based_vertex(graph, v), exclude_vertices), + position_graph(graph), + vertex_positions(graph)[source], + vertex_positions(graph)[destination]; + exclude_vertices=map(v -> vertex_positions(graph)[v], exclude_vertices), ) end @@ -450,45 +419,45 @@ function Base.union( return union(union(graph1, graph2), graph3, graph_rest...) end -Graphs.is_directed(G::Type{<:AbstractNamedGraph}) = is_directed(one_based_graph_type(G)) +function Graphs.is_directed(graph_type::Type{<:AbstractNamedGraph}) + return is_directed(position_graph_type(graph_type)) +end -Graphs.is_directed(graph::AbstractNamedGraph) = is_directed(one_based_graph(graph)) +Graphs.is_directed(graph::AbstractNamedGraph) = is_directed(position_graph(graph)) -Graphs.is_connected(graph::AbstractNamedGraph) = is_connected(one_based_graph(graph)) +Graphs.is_connected(graph::AbstractNamedGraph) = is_connected(position_graph(graph)) -Graphs.is_cyclic(graph::AbstractNamedGraph) = is_cyclic(one_based_graph(graph)) +Graphs.is_cyclic(graph::AbstractNamedGraph) = is_cyclic(position_graph(graph)) @traitfn function Base.reverse(graph::AbstractNamedGraph::IsDirected) - reversed_one_based_graph = reverse(one_based_graph(graph)) - return h + return not_implemented() end @traitfn function Base.reverse!(g::AbstractNamedGraph::IsDirected) - g.fadjlist, g.badjlist = g.badjlist, g.fadjlist - return g + return not_implemented() end # TODO: Move to `namedgraph.jl`, or make the output generic? function Graphs.blockdiag(graph1::AbstractNamedGraph, graph2::AbstractNamedGraph) - new_one_based_graph = blockdiag(one_based_graph(graph1), one_based_graph(graph2)) + new_position_graph = blockdiag(position_graph(graph1), position_graph(graph2)) new_vertices = vcat(vertices(graph1), vertices(graph2)) @assert allunique(new_vertices) - return GenericNamedGraph(new_one_based_graph, new_vertices) + return GenericNamedGraph(new_position_graph, new_vertices) end # TODO: What `args` are needed? -Graphs.nv(graph::AbstractNamedGraph, args...) = nv(one_based_graph(graph), args...) +Graphs.nv(graph::AbstractNamedGraph, args...) = nv(position_graph(graph), args...) # TODO: What `args` are needed? -Graphs.ne(graph::AbstractNamedGraph, args...) = ne(one_based_graph(graph), args...) +Graphs.ne(graph::AbstractNamedGraph, args...) = ne(position_graph(graph), args...) # TODO: What `args` are needed? function Graphs.adjacency_matrix(graph::AbstractNamedGraph, args...) - return adjacency_matrix(one_based_graph(graph), args...) + return adjacency_matrix(position_graph(graph), args...) end function Graphs.connected_components(graph::AbstractNamedGraph) - one_based_connected_components = connected_components(one_based_graph(graph)) - return map(one_based_connected_components) do one_based_connected_component - return map(v -> one_based_vertex_to_vertex(graph, v), one_based_connected_component) + position_connected_components = connected_components(position_graph(graph)) + return map(position_connected_components) do position_connected_component + return map(v -> ordered_vertices(graph)[v], position_connected_component) end end @@ -547,8 +516,8 @@ end # Returns a Dictionary mapping a vertex to it's parent # vertex in the traversal/spanning tree. function namedgraph_bfs_parents(graph::AbstractNamedGraph, vertex; kwargs...) - one_based_bfs_parents = bfs_parents( - one_based_graph(graph), vertex_to_one_based_vertex(graph, vertex); kwargs... + position_bfs_parents = bfs_parents( + position_graph(graph), vertex_positions(graph)[vertex]; kwargs... ) # Works around issue in this `Dictionary` constructor: # https://github.com/andyferris/Dictionaries.jl/blob/v0.4.1/src/Dictionary.jl#L139-L145 @@ -556,9 +525,9 @@ function namedgraph_bfs_parents(graph::AbstractNamedGraph, vertex; kwargs...) # TODO: Raise an issue with `Dictionaries.jl`. ## vertices_graph = Indices(collect(vertices(graph))) # This makes the vertices ordered according to the parent vertices. - vertices_graph = map(v -> one_based_vertex_to_vertex(graph, v), one_based_vertices(graph)) + vertices_graph = map(v -> ordered_vertices(graph)[v], vertices(position_graph(graph))) return Dictionary( - vertices_graph, map(v -> one_based_vertex_to_vertex(graph, v), one_based_bfs_parents) + vertices_graph, map(v -> ordered_vertices(graph)[v], position_bfs_parents) ) end # Disambiguation from Graphs.jl diff --git a/src/dfs.jl b/src/dfs.jl index ad7071e..cd9d920 100644 --- a/src/dfs.jl +++ b/src/dfs.jl @@ -2,9 +2,7 @@ using Graphs: Graphs, dfs_parents, dfs_tree, topological_sort_by_dfs using SimpleTraits: SimpleTraits, Not, @traitfn @traitfn function Graphs.topological_sort_by_dfs(g::AbstractNamedGraph::IsDirected) - return map( - v -> one_based_vertex_to_vertex(g, v), topological_sort_by_dfs(one_based_graph(g)) - ) + return map(v -> ordered_vertices(g)[v], topological_sort_by_dfs(position_graph(g))) end function namedgraph_dfs_tree(graph::AbstractNamedGraph, vertex; kwargs...) @@ -20,8 +18,8 @@ end # Returns a Dictionary mapping a vertex to it's parent # vertex in the traversal/spanning tree. function namedgraph_dfs_parents(graph::AbstractNamedGraph, vertex; kwargs...) - one_based_dfs_parents = dfs_parents( - one_based_graph(graph), vertex_to_one_based_vertex(graph, vertex); kwargs... + position_dfs_parents = dfs_parents( + position_graph(graph), vertex_positions(graph)[vertex]; kwargs... ) # Works around issue in this `Dictionary` constructor: # https://github.com/andyferris/Dictionaries.jl/blob/v0.4.1/src/Dictionary.jl#L139-L145 @@ -29,9 +27,9 @@ function namedgraph_dfs_parents(graph::AbstractNamedGraph, vertex; kwargs...) # TODO: Raise an issue with `Dictionaries.jl`. ## vertices_graph = Indices(collect(vertices(graph))) # This makes the vertices ordered according to the parent vertices. - vertices_graph = map(v -> one_based_vertex_to_vertex(graph, v), one_based_vertices(graph)) + vertices_graph = map(v -> ordered_vertices(graph)[v], vertices(position_graph(graph))) return Dictionary( - vertices_graph, map(v -> one_based_vertex_to_vertex(graph, v), one_based_dfs_parents) + vertices_graph, map(v -> ordered_vertices(graph)[v], position_dfs_parents) ) end # Disambiguation from Graphs.dfs_parents diff --git a/src/distances_and_capacities.jl b/src/distances_and_capacities.jl index 4c5277a..4c5f514 100644 --- a/src/distances_and_capacities.jl +++ b/src/distances_and_capacities.jl @@ -31,32 +31,32 @@ end getindex_dist_matrix(dist_matrix, I...) = dist_matrix[I...] getindex_dist_matrix(dist_matrix::AbstractDictionary, I...) = dist_matrix[I] -function namedgraph_dist_matrix_to_one_based_dist_matrix( +function namedgraph_dist_matrix_to_position_dist_matrix( graph::AbstractNamedGraph, dist_matrix ) - one_based_dist_matrix = spzeros(valtype(dist_matrix), nv(graph), nv(graph)) + position_dist_matrix = spzeros(valtype(dist_matrix), nv(graph), nv(graph)) for e in edges(graph) - one_based_e = edge_to_one_based_edge(graph, e) - one_based_dist_matrix[src(one_based_e), dst(one_based_e)] = getindex_dist_matrix( + position_e = edge_to_position_edge(graph, e) + position_dist_matrix[src(position_e), dst(position_e)] = getindex_dist_matrix( dist_matrix, src(e), dst(e) ) end - return one_based_dist_matrix + return position_dist_matrix end -@traitfn function dist_matrix_to_one_based_dist_matrix( +@traitfn function dist_matrix_to_position_dist_matrix( graph::AbstractNamedGraph::IsDirected, dist_matrix ) - return namedgraph_dist_matrix_to_one_based_dist_matrix(graph, dist_matrix) + return namedgraph_dist_matrix_to_position_dist_matrix(graph, dist_matrix) end -@traitfn function dist_matrix_to_one_based_dist_matrix( +@traitfn function dist_matrix_to_position_dist_matrix( graph::AbstractNamedGraph::(!IsDirected), dist_matrix ) - return _symmetrize(namedgraph_dist_matrix_to_one_based_dist_matrix(graph, dist_matrix)) + return _symmetrize(namedgraph_dist_matrix_to_position_dist_matrix(graph, dist_matrix)) end -function dist_matrix_to_one_based_dist_matrix( +function dist_matrix_to_position_dist_matrix( graph::AbstractNamedGraph, distmx::Graphs.DefaultDistance ) return distmx diff --git a/src/lib/GraphsExtensions/src/abstracttrees.jl b/src/lib/GraphsExtensions/src/abstracttrees.jl index d8150ca..159a371 100644 --- a/src/lib/GraphsExtensions/src/abstracttrees.jl +++ b/src/lib/GraphsExtensions/src/abstracttrees.jl @@ -1,22 +1,22 @@ # AbstractTreeGraph # Tree view of a graph. abstract type AbstractTreeGraph{V} <: AbstractGraph{V} end -one_based_graph_type(type::Type{<:AbstractTreeGraph}) = not_implemented() -one_based_graph(graph::AbstractTreeGraph) = not_implemented() +position_graph_type(type::Type{<:AbstractTreeGraph}) = not_implemented() +position_graph(graph::AbstractTreeGraph) = not_implemented() function Graphs.is_directed(type::Type{<:AbstractTreeGraph}) - return is_directed(one_based_graph_type(type)) + return is_directed(position_graph_type(type)) end -Graphs.edgetype(graph::AbstractTreeGraph) = edgetype(one_based_graph(graph)) +Graphs.edgetype(graph::AbstractTreeGraph) = edgetype(position_graph(graph)) function Graphs.outneighbors(graph::AbstractTreeGraph, vertex) - return outneighbors(one_based_graph(graph), vertex) + return outneighbors(position_graph(graph), vertex) end function Graphs.inneighbors(graph::AbstractTreeGraph, vertex) - return inneighbors(one_based_graph(graph), vertex) + return inneighbors(position_graph(graph), vertex) end -Graphs.nv(graph::AbstractTreeGraph) = nv(one_based_graph(graph)) -Graphs.ne(graph::AbstractTreeGraph) = ne(one_based_graph(graph)) -Graphs.vertices(graph::AbstractTreeGraph) = vertices(one_based_graph(graph)) +Graphs.nv(graph::AbstractTreeGraph) = nv(position_graph(graph)) +Graphs.ne(graph::AbstractTreeGraph) = ne(position_graph(graph)) +Graphs.vertices(graph::AbstractTreeGraph) = vertices(position_graph(graph)) # AbstractTrees using AbstractTrees: @@ -62,5 +62,5 @@ end @assert is_tree(g) return _TreeGraph(g) end -one_based_graph(graph::TreeGraph) = getfield(graph, :graph) -one_based_graph_type(type::Type{<:TreeGraph}) = fieldtype(type, :graph) +position_graph(graph::TreeGraph) = getfield(graph, :graph) +position_graph_type(type::Type{<:TreeGraph}) = fieldtype(type, :graph) diff --git a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl index 31ffd8f..246dfe3 100644 --- a/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/abstractpartitionedgraph.jl @@ -1,18 +1,26 @@ using Graphs: - Graphs, AbstractEdge, add_vertex!, dst, edgetype, has_vertex, rem_vertex!, src, vertices -using ..NamedGraphs: - NamedGraphs, - AbstractNamedGraph, - one_based_graph, - one_based_vertex_to_vertex, - vertex_to_one_based_vertex -using ..NamedGraphs.GraphsExtensions: GraphsExtensions, add_vertices!, rem_vertices! + Graphs, + AbstractEdge, + add_vertex!, + dst, + edgetype, + has_vertex, + is_directed, + rem_vertex!, + src, + vertices +using ..NamedGraphs: NamedGraphs, AbstractNamedGraph +using ..NamedGraphs.GraphsExtensions: + GraphsExtensions, add_vertices!, not_implemented, rem_vertices! abstract type AbstractPartitionedGraph{V,PV} <: AbstractNamedGraph{V} end #Needed for interface partitioned_graph(pg::AbstractPartitionedGraph) = not_implemented() unpartitioned_graph(pg::AbstractPartitionedGraph) = not_implemented() +function unpartitioned_graph_type(pg::Type{<:AbstractPartitionedGraph}) + return not_implemented() +end partitionvertex(pg::AbstractPartitionedGraph, vertex) = not_implemented() partitionvertices(pg::AbstractPartitionedGraph, verts) = not_implemented() partitionvertices(pg::AbstractPartitionedGraph) = not_implemented() @@ -22,6 +30,10 @@ insert_to_vertex_map!(pg::AbstractPartitionedGraph, vertex) = not_implemented() partitionedge(pg::AbstractPartitionedGraph, edge) = not_implemented() partitionedges(pg::AbstractPartitionedGraph, edges) = not_implemented() partitionedges(pg::AbstractPartitionedGraph) = not_implemented() +function unpartitioned_graph_type(pg::AbstractPartitionedGraph) + return typeof(unpartitioned_graph(pg)) +end + function Graphs.edges(pg::AbstractPartitionedGraph, partitionedge::AbstractPartitionEdge) return not_implemented() end @@ -33,7 +45,6 @@ function Graphs.vertices( ) where {V<:AbstractPartitionVertex} return not_implemented() end -NamedGraphs.one_based_graph_type(PG::Type{<:AbstractPartitionedGraph}) = not_implemented() function GraphsExtensions.directed_graph_type(PG::Type{<:AbstractPartitionedGraph}) return not_implemented() end @@ -41,18 +52,21 @@ function GraphsExtensions.undirected_graph_type(PG::Type{<:AbstractPartitionedGr return not_implemented() end +# AbstractGraph interface. +function Graphs.is_directed(graph_type::Type{<:AbstractPartitionedGraph}) + return is_directed(unpartitioned_graph_type(graph_type)) +end + #Functions for the abstract type Graphs.vertices(pg::AbstractPartitionedGraph) = vertices(unpartitioned_graph(pg)) -function NamedGraphs.one_based_graph(pg::AbstractPartitionedGraph) - return one_based_graph(unpartitioned_graph(pg)) +function NamedGraphs.position_graph(pg::AbstractPartitionedGraph) + return NamedGraphs.position_graph(unpartitioned_graph(pg)) end -function NamedGraphs.vertex_to_one_based_vertex(pg::AbstractPartitionedGraph, vertex) - return vertex_to_one_based_vertex(unpartitioned_graph(pg), vertex) +function NamedGraphs.vertex_positions(pg::AbstractPartitionedGraph) + return NamedGraphs.vertex_positions(unpartitioned_graph(pg)) end -function NamedGraphs.one_based_vertex_to_vertex( - pg::AbstractPartitionedGraph, one_based_vertex::Integer -) - return one_based_vertex_to_vertex(unpartitioned_graph(pg), one_based_vertex) +function NamedGraphs.ordered_vertices(pg::AbstractPartitionedGraph) + return NamedGraphs.ordered_vertices(unpartitioned_graph(pg)) end Graphs.edgetype(pg::AbstractPartitionedGraph) = edgetype(unpartitioned_graph(pg)) function Graphs.nv(pg::AbstractPartitionedGraph, pv::AbstractPartitionVertex) diff --git a/src/lib/PartitionedGraphs/src/partitionedgraph.jl b/src/lib/PartitionedGraphs/src/partitionedgraph.jl index 4240b23..b0ab386 100644 --- a/src/lib/PartitionedGraphs/src/partitionedgraph.jl +++ b/src/lib/PartitionedGraphs/src/partitionedgraph.jl @@ -48,11 +48,13 @@ end #Needed for interface partitioned_graph(pg::PartitionedGraph) = getfield(pg, :partitioned_graph) unpartitioned_graph(pg::PartitionedGraph) = getfield(pg, :graph) +function unpartitioned_graph_type(graph_type::Type{<:PartitionedGraph}) + return fieldtype(graph_type, :graph) +end function GraphsExtensions.partitioned_vertices(pg::PartitionedGraph) return getfield(pg, :partitioned_vertices) end which_partition(pg::PartitionedGraph) = getfield(pg, :which_partition) -NamedGraphs.one_based_graph_type(PG::Type{<:PartitionedGraph}) = fieldtype(PG, :graph) function Graphs.vertices(pg::PartitionedGraph, partitionvert::PartitionVertex) return partitioned_vertices(pg)[parent(partitionvert)] end diff --git a/src/namedgraph.jl b/src/namedgraph.jl index 85534a2..c4a0a1d 100644 --- a/src/namedgraph.jl +++ b/src/namedgraph.jl @@ -17,28 +17,24 @@ using .OrderedDictionaries: OrderedDictionaries, OrderedIndices using .OrdinalIndexing: th struct GenericNamedGraph{V,G<:AbstractSimpleGraph{Int}} <: AbstractNamedGraph{V} - one_based_graph::G + position_graph::G vertices::OrderedIndices{V} - global function _GenericNamedGraph(one_based_graph, vertices) - @assert length(vertices) == nv(one_based_graph) - return new{eltype(vertices),typeof(one_based_graph)}(one_based_graph, vertices) + global function _GenericNamedGraph(position_graph, vertices) + @assert length(vertices) == nv(position_graph) + return new{eltype(vertices),typeof(position_graph)}(position_graph, vertices) end end # AbstractNamedGraph required interface. -function one_based_graph_type(graph_type::Type{<:GenericNamedGraph}) - return fieldtype(graph_type, :one_based_graph) +function position_graph_type(graph_type::Type{<:GenericNamedGraph}) + return fieldtype(graph_type, :position_graph) end -one_based_graph(graph::GenericNamedGraph) = getfield(graph, :one_based_graph) - -# TODO: Rename `vertex_positions(graph::GenericNamedGraph)`. -function vertex_to_one_based_vertex(graph::GenericNamedGraph, vertex) - return OrderedDictionaries.index_positions(vertices(graph))[vertex] +position_graph(graph::GenericNamedGraph) = getfield(graph, :position_graph) +function vertex_positions(graph::GenericNamedGraph) + return OrderedDictionaries.index_positions(vertices(graph)) end - -# TODO: Rename `ordered_vertices(graph::GenericNamedGraph)`. -function one_based_vertex_to_vertex(graph::GenericNamedGraph, one_based_vertex::Integer) - return vertices(graph)[one_based_vertex * th] +function ordered_vertices(graph::GenericNamedGraph) + return OrderedDictionaries.ordered_indices(vertices(graph)) end # TODO: Decide what this should output. @@ -48,7 +44,7 @@ function Graphs.add_vertex!(graph::GenericNamedGraph, vertex) if vertex ∈ vertices(graph) return false end - add_vertex!(one_based_graph(graph)) + add_vertex!(position_graph(graph)) insert!(vertices(graph), vertex) return true end @@ -57,16 +53,16 @@ function Graphs.rem_vertex!(graph::GenericNamedGraph, vertex) if vertex ∉ vertices(graph) return false end - one_based_vertex = vertex_to_one_based_vertex(graph, vertex) - rem_vertex!(one_based_graph(graph), one_based_vertex) + position_vertex = vertex_positions(graph)[vertex] + rem_vertex!(position_graph(graph), position_vertex) delete!(vertices(graph), vertex) return graph end function GraphsExtensions.rename_vertices(f::Function, graph::GenericNamedGraph) # TODO: Fix broadcasting of `OrderedIndices`. - # return GenericNamedGraph(one_based_graph(graph), f.(vertices(graph))) - return GenericNamedGraph(one_based_graph(graph), map(f, vertices(graph))) + # return GenericNamedGraph(position_graph(graph), f.(vertices(graph))) + return GenericNamedGraph(position_graph(graph), map(f, vertices(graph))) end function GraphsExtensions.rename_vertices(f::Function, g::AbstractSimpleGraph) @@ -77,7 +73,7 @@ end function GraphsExtensions.convert_vertextype(vertextype::Type, graph::GenericNamedGraph) return GenericNamedGraph( - one_based_graph(graph), convert(Vector{vertextype}, graph.ordered_vertices) + position_graph(graph), convert(Vector{vertextype}, graph.ordered_vertices) ) end @@ -92,41 +88,41 @@ to_vertices(vertices::Integer) = Base.OneTo(vertices) # Inner constructor # TODO: Is this needed? function GenericNamedGraph{V,G}( - one_based_graph::G, vertices::OrderedIndices{V} + position_graph::G, vertices::OrderedIndices{V} ) where {V,G<:AbstractSimpleGraph{Int}} - return _GenericNamedGraph(one_based_graph, vertices) + return _GenericNamedGraph(position_graph, vertices) end function GenericNamedGraph{V,G}( - one_based_graph::AbstractSimpleGraph, vertices + position_graph::AbstractSimpleGraph, vertices ) where {V,G<:AbstractSimpleGraph{Int}} return GenericNamedGraph{V,G}( - convert(G, one_based_graph), OrderedIndices{V}(to_vertices(vertices)) + convert(G, position_graph), OrderedIndices{V}(to_vertices(vertices)) ) end -function GenericNamedGraph{V}(one_based_graph::AbstractSimpleGraph, vertices) where {V} - return GenericNamedGraph{V,typeof(one_based_graph)}(one_based_graph, vertices) +function GenericNamedGraph{V}(position_graph::AbstractSimpleGraph, vertices) where {V} + return GenericNamedGraph{V,typeof(position_graph)}(position_graph, vertices) end function GenericNamedGraph{<:Any,G}( - one_based_graph::AbstractSimpleGraph, vertices + position_graph::AbstractSimpleGraph, vertices ) where {G<:AbstractSimpleGraph{Int}} - return GenericNamedGraph{eltype(vertices),G}(one_based_graph, vertices) + return GenericNamedGraph{eltype(vertices),G}(position_graph, vertices) end function GenericNamedGraph{<:Any,G}( - one_based_graph::AbstractSimpleGraph + position_graph::AbstractSimpleGraph ) where {G<:AbstractSimpleGraph{Int}} - return GenericNamedGraph{<:Any,G}(one_based_graph, vertices(one_based_graph)) + return GenericNamedGraph{<:Any,G}(position_graph, vertices(position_graph)) end -function GenericNamedGraph(one_based_graph::AbstractSimpleGraph, vertices) - return GenericNamedGraph{eltype(vertices)}(one_based_graph, vertices) +function GenericNamedGraph(position_graph::AbstractSimpleGraph, vertices) + return GenericNamedGraph{eltype(vertices)}(position_graph, vertices) end -function GenericNamedGraph(one_based_graph::AbstractSimpleGraph) - return GenericNamedGraph(one_based_graph, vertices(one_based_graph)) +function GenericNamedGraph(position_graph::AbstractSimpleGraph) + return GenericNamedGraph(position_graph, vertices(position_graph)) end # @@ -174,10 +170,10 @@ end GenericNamedGraph() = GenericNamedGraph(Any[]) # TODO: implement as: -# graph = set_one_based_graph(graph, copy(one_based_graph(graph))) +# graph = set_position_graph(graph, copy(position_graph(graph))) # graph = set_vertices(graph, copy(vertices(graph))) function Base.copy(graph::GenericNamedGraph) - return GenericNamedGraph(copy(one_based_graph(graph)), copy(vertices(graph))) + return GenericNamedGraph(copy(position_graph(graph)), copy(vertices(graph))) end Graphs.edgetype(graph_type::Type{<:GenericNamedGraph}) = NamedEdge{vertextype(graph_type)} @@ -185,17 +181,17 @@ Graphs.edgetype(graph::GenericNamedGraph) = edgetype(typeof(graph)) function GraphsExtensions.directed_graph_type(graph_type::Type{<:GenericNamedGraph}) return GenericNamedGraph{ - vertextype(graph_type),directed_graph_type(one_based_graph_type(graph_type)) + vertextype(graph_type),directed_graph_type(position_graph_type(graph_type)) } end function GraphsExtensions.undirected_graph_type(graph_type::Type{<:GenericNamedGraph}) return GenericNamedGraph{ - vertextype(graph_type),undirected_graph_type(one_based_graph_type(graph_type)) + vertextype(graph_type),undirected_graph_type(position_graph_type(graph_type)) } end function Graphs.is_directed(graph_type::Type{<:GenericNamedGraph}) - return is_directed(one_based_graph_type(graph_type)) + return is_directed(position_graph_type(graph_type)) end # TODO: Implement an edgelist version diff --git a/src/shortestpaths.jl b/src/shortestpaths.jl index 533b57e..37223f9 100644 --- a/src/shortestpaths.jl +++ b/src/shortestpaths.jl @@ -24,11 +24,11 @@ function NamedDijkstraState(parents, dists, predecessors, pathcounts, closest_ve ) end -function one_based_path_state_to_path_state( - graph::AbstractNamedGraph, one_based_path_state::Graphs.DijkstraState +function position_path_state_to_path_state( + graph::AbstractNamedGraph, position_path_state::Graphs.DijkstraState ) - one_based_path_state_parents = map(eachindex(one_based_path_state.parents)) do i - pᵢ = one_based_path_state.parents[i] + position_path_state_parents = map(eachindex(position_path_state.parents)) do i + pᵢ = position_path_state.parents[i] return iszero(pᵢ) ? i : pᵢ end # Works around issue in this `Dictionary` constructor: @@ -37,19 +37,15 @@ function one_based_path_state_to_path_state( # TODO: Raise an issue with `Dictionaries.jl`. ## graph_vertices = Indices(collect(vertices(graph))) # This makes the vertices ordered according to the parent vertices. - graph_vertices = map(v -> one_based_vertex_to_vertex(graph, v), one_based_vertices(graph)) + graph_vertices = map(v -> ordered_vertices(graph)[v], vertices(position_graph(graph))) return NamedDijkstraState( Dictionary( - graph_vertices, - map(v -> one_based_vertex_to_vertex(graph, v), one_based_path_state_parents), + graph_vertices, map(v -> ordered_vertices(graph)[v], position_path_state_parents) ), - Dictionary(graph_vertices, one_based_path_state.dists), - map( - x -> map(v -> one_based_vertex_to_vertex(graph, v), x), - one_based_path_state.predecessors, - ), - Dictionary(graph_vertices, one_based_path_state.pathcounts), - map(v -> one_based_vertex_to_vertex(graph, v), one_based_path_state.closest_vertices), + Dictionary(graph_vertices, position_path_state.dists), + map(x -> map(v -> ordered_vertices(graph)[v], x), position_path_state.predecessors), + Dictionary(graph_vertices, position_path_state.pathcounts), + map(v -> ordered_vertices(graph)[v], position_path_state.closest_vertices), ) end @@ -60,14 +56,14 @@ function namedgraph_dijkstra_shortest_paths( allpaths=false, trackvertices=false, ) - one_based_path_state = dijkstra_shortest_paths( - one_based_graph(graph), - map(v -> vertex_to_one_based_vertex(graph, v), srcs), - dist_matrix_to_one_based_dist_matrix(graph, distmx); + position_path_state = dijkstra_shortest_paths( + position_graph(graph), + map(v -> vertex_positions(graph)[v], srcs), + dist_matrix_to_position_dist_matrix(graph, distmx); allpaths, trackvertices, ) - return one_based_path_state_to_path_state(graph, one_based_path_state) + return position_path_state_to_path_state(graph, position_path_state) end function Graphs.dijkstra_shortest_paths( diff --git a/src/steiner_tree.jl b/src/steiner_tree.jl index dfd321b..c01207f 100644 --- a/src/steiner_tree.jl +++ b/src/steiner_tree.jl @@ -4,12 +4,10 @@ using SimpleTraits: SimpleTraits, Not, @traitfn @traitfn function Graphs.steiner_tree( g::AbstractNamedGraph::(!IsDirected), term_vert, distmx=weights(g) ) - one_based_tree = steiner_tree( - one_based_graph(g), - map(v -> vertex_to_one_based_vertex(g, v), term_vert), - dist_matrix_to_one_based_dist_matrix(g, distmx), - ) - return typeof(g)( - one_based_tree, map(v -> one_based_vertex_to_vertex(g, v), vertices(one_based_tree)) + position_tree = steiner_tree( + position_graph(g), + map(v -> vertex_positions(g)[v], term_vert), + dist_matrix_to_position_dist_matrix(g, distmx), ) + return typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree))) end diff --git a/test/test_abstractnamedgraph.jl b/test/test_abstractnamedgraph.jl index 32b1234..379656a 100644 --- a/test/test_abstractnamedgraph.jl +++ b/test/test_abstractnamedgraph.jl @@ -18,7 +18,7 @@ using Test: @test, @testset add_edge!(ng2, "A" => "C") add_edge!(ng2, "B" => "D") add_edge!(ng2, "C" => "D") - @test NamedGraphs.one_based_graph(ng1) != NamedGraphs.one_based_graph(ng2) + @test NamedGraphs.position_graph(ng1) != NamedGraphs.position_graph(ng2) @test ng1 == ng2 rem_edge!(ng2, "B" => "A") @test ng1 != ng2 @@ -32,7 +32,7 @@ using Test: @test, @testset add_edge!(ndg2, ("X", 1) => ("Y", 1)) add_edge!(ndg2, ("X", 2) => ("Y", 2)) add_edge!(ndg2, ("Y", 1) => ("Y", 2)) - @test NamedGraphs.one_based_graph(ndg1) != NamedGraphs.one_based_graph(ndg2) + @test NamedGraphs.position_graph(ndg1) != NamedGraphs.position_graph(ndg2) @test ndg1 == ndg2 rem_edge!(ndg2, ("Y", 1) => ("X", 1)) @test ndg1 != ndg2 @@ -45,7 +45,7 @@ using Test: @test, @testset add_edge!(nddg2, ("X", 1) => ("Y", 1)) add_edge!(nddg2, ("X", 2) => ("Y", 2)) add_edge!(nddg2, ("Y", 1) => ("Y", 2)) - @test NamedGraphs.one_based_graph(nddg1) != NamedGraphs.one_based_graph(nddg2) + @test NamedGraphs.position_graph(nddg1) != NamedGraphs.position_graph(nddg2) @test nddg1 == nddg2 rem_edge!(nddg2, ("X", 1) => ("Y", 1)) add_edge!(nddg2, ("Y", 1) => ("X", 1)) diff --git a/test/test_multidimgraph.jl b/test/test_multidimgraph.jl index 9e83b3f..5d4e922 100644 --- a/test/test_multidimgraph.jl +++ b/test/test_multidimgraph.jl @@ -5,10 +5,10 @@ using NamedGraphs.GraphsExtensions: ⊔, disjoint_union, subgraph using Test: @test, @testset @testset "NamedGraph" begin - one_based_graph = grid((2, 2)) + position_graph = grid((2, 2)) vertices = [("X", 1), ("X", 2), ("Y", 1), ("Y", 2)] - g = NamedGraph(one_based_graph, vertices) + g = NamedGraph(position_graph, vertices) @test has_vertex(g, ("X", 1)) @test has_edge(g, ("X", 1) => ("X", 2)) @@ -91,7 +91,7 @@ using Test: @test, @testset end @testset "NamedGraph add vertices" begin - one_based_graph = grid((2, 2)) + position_graph = grid((2, 2)) vertices = [("X", 1), ("X", 2), ("Y", 1), ("Y", 2)] g = NamedGraph() add_vertex!(g, ("X", 1))