Skip to content

Commit

Permalink
Change interface names
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Apr 26, 2024
1 parent 32301d6 commit dbb6c70
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 257 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

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")
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

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))
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))

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

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_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)
Expand All @@ -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
Expand Down
Loading

0 comments on commit dbb6c70

Please sign in to comment.