WeightedGraph
public protocol WeightedGraph: Graph
Description of a weighted graph.
Weighted graphs have a weight associated with each edge.
-
Computes the weight associated with the given edge.
Throws
GraphError.VertexNotPresent
if either vertex is not in the graph.Declaration
Swift
func weight(from: Vertex, to: Vertex) throws -> Double?
Parameters
to
The ‘source’ of the edge to use.
from
The ‘destination’ of the edge to use.
Return Value
The weight associated with the given edge, or
nil
if the edge is not in the graph. -
Adds a new weighted edge to the graph from one vertex to another.
Changes the graph in-place to add the edge.
Throws
GraphError.VertexNotPresent
if either vertex in the edge does not exist in the graph.Declaration
Swift
mutating func addEdge(from: Vertex, to: Vertex, weight: Double) throws
Parameters
from
The ‘source’ of the edge to use.
to
The ‘destination’ of the edge to use.
weight
The ‘weight’ of the new edge to add.
-
totalWeight
Extension methodUndocumented
Declaration
Swift
public protocol WeightedGraph: Graph