class WeightedGraph::PositiveWeightedGraph
API for a graph that requires positive edge weights
Public Class Methods
new()
click to toggle source
Initialize an empty adjacency list for edges
Calls superclass method
WeightedGraph::Graph::new
# File lib/weighted_graph/positive_weighted_graph.rb, line 8 def initialize super(Hash.new(0)) end
Public Instance Methods
add_edge(source, destination, weight)
click to toggle source
Add directed edge (source, destination) to the graph with given weight Requires that weight is a positive number
Calls superclass method
WeightedGraph::Graph#add_edge
# File lib/weighted_graph/positive_weighted_graph.rb, line 14 def add_edge(source, destination, weight) super(source, destination, weight) if weight > 0 end
add_undirected_edge(vertex_a, vertex_b, weight)
click to toggle source
Add undirected edge (vertex_a, vertex_b) to the graph with given weight Requires that weight is a positive number
Calls superclass method
WeightedGraph::Graph#add_undirected_edge
# File lib/weighted_graph/positive_weighted_graph.rb, line 20 def add_undirected_edge(vertex_a, vertex_b, weight) super(vertex_a, vertex_b, weight) if weight > 0 end