abstract class CGL::AdjacencyGraph(V, W, L)
Overview
A base class for adjacency list-based undirected graphs
Included Modules
Direct Known Subclasses
Defined in:
cgl/representations/adjacency.crConstructors
- .new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, &block : -> L?)
- .new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, default_label : L? = nil)
- .new(edges : Enumerable(AnyEdge(V)), *, default_weight : W? = nil, &block : -> L?)
- .new(edges : Enumerable(AnyEdge(V)), *, default_weight : W? = nil, default_label : L? = nil)
Instance Method Summary
-
#add_edge(u : V, v : V, weight : W = self.default_weight, label : L? = self.default_label)
Add an edge between vertices u and v.
-
#degree_of(v : V) : Int32
Returns the degree of the given vertex v.
- #remove_edge(u : V, v : V, &)
-
#remove_vertex(v : V)
Remove given vertex v from this graph.
Instance methods inherited from module CGL::AdjacencyHash(V, W, L)
add_edge(edge : AnyEdge(V))
add_edge,
add_vertex(v : V)
add_vertex,
clear
clear,
each_adjacent(u : V) : Iterator(V)each_adjacent(u : V, & : V -> ) each_adjacent, each_vertex : Iterator(V)
each_vertex(& : V -> ) each_vertex, has_edge?(u : V, v : V, weight : W, label : L?) : Bool
has_edge?(u : V, v : V, weight, label) : Bool
has_edge?(u : V, v : V) : Bool has_edge?, has_vertex?(v : V) : Bool has_vertex?, label_block : -> L? label_block, label_of(u : V, v : V) : L? label_of, label_of?(u : V, v : V) : L? label_of?, labeled? : Bool labeled?, order : Int32 order, size : Int32 size, vertices vertices, weight_of(u : V, v : V) : W weight_of, weight_of?(u : V, v : V) : W? weight_of?, weighted? : Bool weighted?
Constructor methods inherited from module CGL::AdjacencyHash(V, W, L)
new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, &block : -> L?)new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, default_label : L? = nil)
new(edges : Enumerable(AnyEdge(V)), *, default_weight : W? = nil, &block : -> L?)
new(edges : Enumerable(AnyEdge(V)), *, default_weight : W? = nil, default_label : L? = nil) new
Instance methods inherited from class CGL::AbstractGraph(V)
connected? : Bool
connected?,
count_connected_components : Int32
count_connected_components,
density : Float64
density,
directed? : Bool
directed?,
each_connected_component(&)each_connected_component : Iterator(Array(V)) each_connected_component, each_edge(& : AnyEdge(V) -> ) each_edge, each_edge_from(u : V, & : AnyEdge(V) -> ) each_edge_from, in_degree_of(v : V) : Int32 in_degree_of, out_degree_of(v : V) : Int32 out_degree_of
Instance methods inherited from class CGL::AnyGraph(V)
==(other : self)==(other) ==, accept(visitor : Visitor(V)) accept, add_edge(u : V, v : V)
add_edge(edge : AnyEdge(V)) add_edge, add_vertex(v : V) add_vertex, breadth_first_search(from vertex : V) : Iterator(V)
breadth_first_search(from vertex : V, &) breadth_first_search, clear clear, clone clone, count_simple_paths(source : V, target : V) count_simple_paths, degree_of(v : V) : Int32 degree_of, density : Float64 density, depth_first_search(from vertex : V) : Iterator(V)
depth_first_search(from vertex : V, &)
depth_first_search(vertex : V, *, colors : Hash(V, Color), &)
depth_first_search(&)
depth_first_search : Iterator(V) depth_first_search, directed? : Bool directed?, dup dup, each_adjacent(u : V) : Iterator(V)
each_adjacent(u : V, & : V -> ) each_adjacent, each_edge : Iterator(AnyEdge(V))
each_edge(& : AnyEdge(V) -> ) each_edge, each_edge_from(u : V, & : AnyEdge(V) -> ) each_edge_from, each_vertex(& : V -> )
each_vertex : Iterator(V) each_vertex, edge(u : V, v : V)
edge(u : V, v : V, &) edge, edge?(u : V, v : V) edge?, edges : Array(AnyEdge(V)) edges, empty? : Bool empty?, has_edge?(edge : Labelable) : Bool
has_edge?(u : V, v : V, weight, label) : Bool
has_edge?(u : V, v : V) : Bool
has_edge?(edge : Weightable) : Bool
has_edge?(edge : AnyEdge(V)) : Bool has_edge?, has_vertex?(v : V) : Bool has_vertex?, hash(hasher) hash, in_degree_of(v : V) : Int32 in_degree_of, label_of(u : V, v : V) label_of, label_of?(u : V, v : V) label_of?, labeled? : Bool labeled?, order : Int32 order, out_degree_of(v : V) : Int32 out_degree_of, remove_edge(u : V, v : V) remove_edge, remove_vertex(v : V) remove_vertex, shortest_path(source : V, target : V) shortest_path, shortest_path_dijkstra(source : V, target : V) shortest_path_dijkstra, shortest_path_unweighted(source : V, target : V) shortest_path_unweighted, size : Int32 size, subgraph(vertices : Enumerable(V), *, clone : Bool = false) : AnyGraph(V)
subgraph(edges : Enumerable(AnyEdge(V)), *, clone : Bool = false) : AnyGraph(V) subgraph, to_a : Array(AnyEdge(V)) to_a, to_dot(path : String)
to_dot(io : IO) to_dot, weight_of(u : V, v : V) weight_of, weight_of?(u : V, v : V) weight_of?, weighted? : Bool weighted?
Constructor Detail
def self.new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, &block : -> L?)
#
def self.new(vertices : Enumerable(V)? = nil, edges : Enumerable(Tuple(V, V))? = nil, weights : Enumerable(W)? = nil, labels : Enumerable(L?)? = nil, *, default_weight : W? = nil, default_label : L? = nil)
#
def self.new(edges : Enumerable(AnyEdge(V)), *, default_weight : W? = nil, default_label : L? = nil)
#
Instance Method Detail
Description copied from class CGL::AnyGraph(V)
Add an edge between vertices u and v.
The given vertices are automatically added if they are not already part of the graph.
A weight and/or a label can be associated to the edge if the concrete class supports it.
def degree_of(v : V) : Int32
#
Description copied from class CGL::AnyGraph(V)
Returns the degree of the given vertex v.
For directed graphs, the value equals #out_degree_of
.
For undirected graphs, the value is the sum of #in_degree_of
and
#in_degree_of
.
def remove_vertex(v : V)
#
Description copied from class CGL::AnyGraph(V)
Remove given vertex v from this graph. Edges incident to v are also removed.
Raises a GraphError
if vertex is not part of the graph.
g = CGL::Graph(String).new(edges: [{"a", "b"}, {"b", "c"}])
g.size # => 2
g.remove_vertex("b")
g.size # => 0