ex_simple_graph v0.1.1 GeoPartition.Graph View Source
Some functions for working with undirected graphs
Link to this section Summary
Functions
Returns the complete graph induced by a set of vertices
If a graph is composed of disjoint cycles, returns the graph with the edges in cycle order
Produce the induced subgraph of a graph resulting from removing a vertex
Produce the induced subgraph of a graph resulting from removing vertices that satisfy condition
Return a set of edges representing a path from inital
to target
wherein every vertex in
between satisfies choose_by
. If sort_by
is specified, it will be used to prioritize
candidate vertices
Given two graphs, return their intersection (vertices and edges included in both)
Produce a subdivision of the given edges using the given point
Link to this section Types
Link to this section Functions
Returns the complete graph induced by a set of vertices
Examples
iex> GeoPartition.Graph.clique([1, 2, 3])
{[1, 2, 3], [MapSet.new([1, 2]), MapSet.new([1, 3]), MapSet.new([2, 3])]}
If a graph is composed of disjoint cycles, returns the graph with the edges in cycle order
Examples
iex> v = [1, 2, 3, 4]
iex> e = [MapSet.new([1, 2]), MapSet.new([2, 3]), MapSet.new([4, 1]), MapSet.new([3, 4])]
iex> GeoPartition.Graph.cycle_sort({v, e})
{:ok, {[1,2,3,4], [MapSet.new([1, 4]), MapSet.new([4, 3]), MapSet.new([3, 2]), MapSet.new([2, 1])]}}
iex> v = [1, 2, 3, 4]
iex> e = [MapSet.new([1, 2]), MapSet.new([2, 3]), MapSet.new([4, 1]), MapSet.new([3, 4]), MapSet.new([2, 4])]
iex> GeoPartition.Graph.cycle_sort({v, e})
{:error, "not cycles"}
iex> v = [1, 2, 3, 4]
iex> e = [MapSet.new([1, 2]), MapSet.new([2, 3]), MapSet.new([2, 4]), MapSet.new([3, 4])]
iex> GeoPartition.Graph.cycle_sort({v, e})
{:error, "not cycles"}
Produce the induced subgraph of a graph resulting from removing a vertex
Examples
iex> v = [1, 2, 3, 4]
iex> edge_pairs = [[1, 2], [1, 3], [2, 3], [3, 4], [4, 1]]
iex> e = Enum.map(edge_pairs, &MapSet.new(&1))
iex> GeoPartition.Graph.delete_vertex({v, e}, 3)
{[1, 2, 4], [MapSet.new([1, 2]), MapSet.new([1, 4])]}
Produce the induced subgraph of a graph resulting from removing vertices that satisfy condition
Examples
iex> v = [1, 2, 3, 4]
iex> edge_pairs = [[1, 2], [1, 3], [2, 3], [3, 4], [4, 1]]
iex> e = Enum.map(edge_pairs, &MapSet.new(&1))
iex> GeoPartition.Graph.delete_vertices_by({v, e}, &(rem(&1, 2) == 0))
{[1, 3], [MapSet.new([1, 3])]}
Return a set of edges representing a path from inital
to target
wherein every vertex in
between satisfies choose_by
. If sort_by
is specified, it will be used to prioritize
candidate vertices.
Examples
iex> v = [1, 2, 3, 4, 5, 6, 7, 8, 9]
iex> {v, e} = GeoPartition.Graph.clique(v)
iex> GeoPartition.Graph.find_path_by({v, e}, 1, 9, &(rem(&1, 2) == 0))
[MapSet.new([1, 2]), MapSet.new([2, 4]), MapSet.new([4, 6]), MapSet.new([6, 8]), MapSet.new([8, 9])]
iex> v = [1, 2, 3, 4, 5, 6, 7, 8, 9]
iex> {v, e} = GeoPartition.Graph.clique(v)
iex> GeoPartition.Graph.find_path_by({v, e}, 1, 9, &(rem(&1, 2) == 0), &Kernel.>=(&1, &2))
[MapSet.new([1, 9])]
Given two graphs, return their intersection (vertices and edges included in both)
Examples
iex> g1 = {[1, 2, 3], [MapSet.new([1, 2]), MapSet.new([2, 3])]}
iex> g2 = {[1, 2], [MapSet.new([1,2])]}
iex> GeoPartition.Graph.intersection(g1, g2)
{[1, 2], [MapSet.new([1, 2])]}
Produce a subdivision of the given edges using the given point.
Merges duplicate edges.
Examples
iex> g = {[1, 2, 3, 4], [MapSet.new([1, 2]), MapSet.new([2, 3]), MapSet.new([3, 4]), MapSet.new([4, 1])]}
iex> GeoPartition.Graph.subdivide(g, [MapSet.new([1, 2]), MapSet.new([3, 4])], "x")
{[1, 2, 3, 4, "x"], [MapSet.new([1, "x"]), MapSet.new([2, "x"]), MapSet.new([3, "x"]), MapSet.new([4, "x"]), MapSet.new([2, 3]), MapSet.new([4, 1])]}
iex> g = {[1, 2, 3], [MapSet.new([1, 2]), MapSet.new([2, 3]), MapSet.new([3, 1])]}
iex> GeoPartition.Graph.subdivide(g, [MapSet.new([1, 2]), MapSet.new([2, 3])], "x")
{[1, 2, 3, "x"], [MapSet.new([1, "x"]), MapSet.new([2, "x"]), MapSet.new([3, "x"]), MapSet.new([1, 3])]}