Skip to content

Commit

Permalink
Renaming, start OrdinalIndexedDictionaries library
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Apr 25, 2024
1 parent fc0f699 commit a0893ad
Show file tree
Hide file tree
Showing 23 changed files with 564 additions and 210 deletions.
4 changes: 2 additions & 2 deletions examples/multidimgraph_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ using Graphs: grid, has_edge, has_vertex, ne, nv
using NamedGraphs: NamedGraph
using NamedGraphs.GraphsExtensions: , subgraph

ordinal_graph = grid((4,))
one_based_graph = grid((4,))
vs = ["A", "B", "C", "D"]
g = NamedGraph(ordinal_graph, vs)
g = NamedGraph(one_based_graph, vs)

@show has_vertex(g, "A")
@show !has_vertex(g, "E")
Expand Down
10 changes: 5 additions & 5 deletions examples/multidimgraph_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ using Graphs: grid, has_edge, has_vertex, nv
using NamedGraphs: NamedGraph
using NamedGraphs.GraphsExtensions: , subgraph

ordinal_graph = grid((2, 2))
one_based_graph = grid((2, 2))
vs = [("X", 1), ("X", 2), ("Y", 1), ("Y", 2)]

g = NamedGraph(ordinal_graph, vs)
g = NamedGraph(one_based_graph, vs)

@show has_vertex(g, ("X", 1))
@show has_edge(g, ("X", 1) => ("X", 2))
Expand Down Expand Up @@ -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))

ordinal_graph = grid((2, 2))
g1 = NamedGraph(ordinal_graph, Tuple.(CartesianIndices((2, 2))))
g2 = NamedGraph(ordinal_graph, Tuple.(CartesianIndices((2, 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))))

g_disjoint_union = g1 g2

Expand Down
24 changes: 12 additions & 12 deletions ext/NamedGraphsGraphsFlowsExt/NamedGraphsGraphsFlowsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ using NamedGraphs:
AbstractNamedGraph,
DefaultNamedCapacity,
_symmetrize,
dist_matrix_to_ordinal_dist_matrix,
ordinal_graph,
ordinal_vertex_to_vertex,
vertex_to_ordinal_vertex
dist_matrix_to_one_based_dist_matrix,
one_based_graph,
one_based_vertex_to_vertex,
vertex_to_one_based_vertex
using NamedGraphs.GraphsExtensions: GraphsExtensions, directed_graph
using SimpleTraits: SimpleTraits, @traitfn

@traitfn function NamedGraphs.dist_matrix_to_ordinal_dist_matrix(
@traitfn function NamedGraphs.dist_matrix_to_one_based_dist_matrix(
graph::AbstractNamedGraph::IsDirected, dist_matrix::DefaultNamedCapacity
)
return GraphsFlows.DefaultCapacity(graph)
Expand All @@ -26,15 +26,15 @@ end
capacity_matrix=DefaultNamedCapacity(graph),
algorithm::GraphsFlows.AbstractFlowAlgorithm=GraphsFlows.PushRelabelAlgorithm(),
)
ordinal_part1, ordinal_part2, flow = GraphsFlows.mincut(
directed_graph(ordinal_graph(graph)),
vertex_to_ordinal_vertex(graph, source),
vertex_to_ordinal_vertex(graph, target),
dist_matrix_to_ordinal_dist_matrix(graph, capacity_matrix),
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),
algorithm,
)
(part1, part2) = map((ordinal_part1, ordinal_part2)) do ordinal_part
return map(v -> ordinal_vertex_to_vertex(graph, v), ordinal_part)
(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)
end
return (part1, part2, flow)
end
Expand Down
2 changes: 2 additions & 0 deletions src/NamedGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module NamedGraphs
include("lib/SimilarType/src/SimilarType.jl")
include("lib/Keys/src/Keys.jl")
include("lib/OrdinalIndexing/src/OrdinalIndexing.jl")
include("lib/OrdinalIndexedDictionaries/src/OrdinalIndexedDictionaries.jl")
include("lib/GraphGenerators/src/GraphGenerators.jl")
include("lib/GraphsExtensions/src/GraphsExtensions.jl")
include("utils.jl")
Expand Down
Loading

0 comments on commit a0893ad

Please sign in to comment.