Class: WeightedGraph::PositiveWeightedGraph

Inherits:
Graph
  • Object
show all
Defined in:
lib/weighted_graph/positive_weighted_graph.rb

Overview

API for a graph that requires positive edge weights

Instance Method Summary collapse

Methods inherited from Graph

#contains_edge?, #get_adjacent_vertices, #get_edge_weight, #remove_edge, #remove_undirected_edge

Constructor Details

#initializePositiveWeightedGraph

Initialize an empty adjacency list for edges



8
9
10
# File 'lib/weighted_graph/positive_weighted_graph.rb', line 8

def initialize
  super(Hash.new(0))
end

Instance Method Details

#add_edge(source, destination, weight) ⇒ Object

Add directed edge (source, destination) to the graph with given weight Requires that weight is a positive number



14
15
16
# 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) ⇒ Object

Add undirected edge (vertex_a, vertex_b) to the graph with given weight Requires that weight is a positive number



20
21
22
# 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