Multigraph

class Multigraph<V, E : Multigraph.Edge<V>>(original: Multigraph<V, E>)

This is an implementation of a directed multigraph. A graph consists of a collection of vertices connected by (directed) edges. A vertex v1 may be connected to another vertex v2 by more than one edge, which makes this a multigraph implementation. However, note that v1 and v2 can not be multiply connected by the same edge (i.e., two edges connecting v1 and v2 must not be equal to each other).

Multigraphs are not thread-safe, so they should be protected by some form of explicit synchronization if they are to be accessed by multiple threads.

Author

Mark van Gulik

Parameters

V

The type of vertices of the graph.

E

The type of Edges in the graph.

original

The multigraph to copy.

Constructors

Link copied to clipboard
constructor(original: Multigraph<V, E>)

Construct a new Multigraph based on an existing one. The two multigraphs will have the same vertices and edges.

Types

Link copied to clipboard
class Edge<V>(val source: V, val destination: V)

An edge of a Multigraph. The source and destination are final, to avoid corruption of the multigraph.

Properties

Link copied to clipboard
val edges: List<E>

An immutable List of all edges of this graph.

Functions

Link copied to clipboard
fun addEdge(edge: E)

Add an edge to the graph. The edge (or an equal one) must not already be present in the graph. The edge's source and destination vertices must already be present in the graph.

Link copied to clipboard
fun addVertex(vertex: V)

Add a vertex to the graph. It must not already be present.

Link copied to clipboard
fun containsEdge(edge: E): Boolean

Answer whether the specified edge is present in the graph. The source and destination vertices of the edge do not have to be present in the graph; if not, the answer is simply false.

Link copied to clipboard
fun containsVertex(vertex: V): Boolean

Answer whether the specified vertex is in the graph.

Link copied to clipboard
fun edgesFrom(source: V): Set<E>

Answer an unmodifiable set of edges (if any) leading from the specified source vertex. Note that subsequent changes to the graph may affect this set.

Link copied to clipboard
fun edgesFromTo(source: V, destination: V): Set<E>

Answer an unmodifiable set of edges (if any) between the specified vertices. Note that subsequent changes to the graph may affect this set.

Link copied to clipboard
fun edgesTo(destination: V): Set<E>

Answer an unmodifiable set of edges (if any) leading to the specified destination vertex. Note that subsequent changes to the graph may affect this set.

Link copied to clipboard
fun excludeEdge(edge: E): Boolean

Remove an edge from the graph, doing nothing if it's not present. Answer whether the graph was changed (i.e., if the edge was present).

Link copied to clipboard
fun excludeVertex(vertex: V): Boolean

Remove a vertex from the graph if it was present. If it was not present then do nothing. Answer whether the graph was changed (i.e., whether the vertex was present).

Link copied to clipboard
fun includeEdge(edge: E): Boolean

Include an edge in the graph. If the edge (or an equal one) is already present, do nothing. The edge's source and destination vertices must already be present in the graph. Answer whether the graph changed (i.e., if this edge was not already present in the graph).

Link copied to clipboard
fun includeVertex(vertex: V): Boolean

Add a vertex to the graph. Do nothing if the vertex is already present. Answer whether the graph was changed (i.e., whether the vertex was not already present).

Link copied to clipboard
fun removeEdge(edge: E)

Remove an edge from the graph. The edge must be present in the graph.

Link copied to clipboard
fun removeVertex(vertex: V)

Remove a vertex from the graph. The vertex must be present. Remove all edges connected to or from this vertex.

Link copied to clipboard
fun vertices(): Set<V>

Answer the multigraph's Set of vertices. The set may not be modified. Modifications to the graph may make this set invalid.