Package org.graph4j
Interface Multigraph<V,E>
- Type Parameters:
V- the type of vertex labels in this graph.E- the type of edge labels in this graph.
- All Superinterfaces:
Graph<V,E>
- All Known Subinterfaces:
DirectedMultigraph<V,,E> DirectedPseudograph<V,,E> Pseudograph<V,E>
Multiple (parallel) edges are allowed.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from interface org.graph4j.Graph
DEFAULT_EDGE_WEIGHT, DEFAULT_VERTEX_WEIGHT, WEIGHT -
Method Summary
Modifier and TypeMethodDescriptionintaddEdge(int v, int u, double weight) Adds a new weighted edge to the graph.intaddLabeledEdge(int v, int u, E label) Adds a new labeled edge to the graph.intaddLabeledEdge(int v, int u, E label, double weight) Adds a new weighted and labeled edge to the graph.default intaddLabeledEdge(V vLabel, V uLabel, E edgeLabel) Adds a new labeled edge to the graph.intaddLabeledVertex(int v, V label) Adds a new vertex to the graph having the specified number and label.intaddLabeledVertex(V label) Adds a new vertex to the graph having the number equal to the maximum vertex number plus one, and the specified label.intaddWeightedVertex(double weight) Adds a new vertex to the graph having the number equal to the maximum vertex number plus one, and the specified weight.intaddWeightedVertex(int v, double weight) Adds a new vertex to the graph having the specified number and weight.Multigraph<V, E> copy()Creates and returns an identical copy of the graph.findAllEdges(E label) Returns a set containing all the edges having the specified label.findAllVertices(V label) Returns a set containing all the vertex numbers having the specified label.Returns the edge having the specified label.intfindVertex(V label) Returns the number of the vertex having the specified label.default doublegetEdgeData(int dataType, int v, int u) doublegetEdgeData(int dataType, int v, int u, double defaultValue) default doublegetEdgeData(int dataType, Edge e) default doublegetEdgeData(int dataType, Edge e, double defaultValue) getEdgeLabel(int v, int u) Returns the label of a specified edge.doublegetEdgeWeight(int v, int u) Returns the weight of an edge.default doubleReturns the weight of an edge.getVertexLabel(int v) Returns the label of the specified vertex ornullif no label has been set.doublegetVertexWeight(int v) Returns the weight of a vertex.booleanhasEdgeData(int dataType) booleanChecks if the graph has at least one edge that has been assigned a label (is edge labeled).booleanChecks if the graph is has at least one edge that has been assigned a weight (is edge weighted).booleanChecks if the graph has at least one vertex that has been assigned a label (is vertex labeled).booleanChecks if the graph has at least one vertex that has been assigned a weight (is vertex weighted).voidincEdgeData(int dataType, int v, int u, double amount) default booleanisUniversal(int v) Checks if a vertex is universal, meaning that it is adjacent to all other vertices in the graph.default longmaxEdges()Returns the maximum number of edges the graph can have.intmultiplicity(int v, int u) default intmultiplicity(Edge e) voidresetEdgeData(int dataType, double value) voidsetEdgeData(int dataType, int v, int u, double value) voidsetEdgeLabel(int v, int u, E label) Sets the label of a specified edge.voidsetEdgeWeight(int v, int u, double weight) Sets the weight of an edge.voidsetVertexLabel(int v, V label) Sets the label for the specified vertex.voidsetVertexWeight(int v, double weight) Sets the weight of a vertex.Multigraph<V, E> subgraph(Collection<Edge> edges) Creates and returns the subgraph generated by a collection of edges.Multigraph<V, E> Creates and returns the subgraph induced by a set of vertices.The support graph of a multigraph or a pseudograph G is an undirected graph containing all the vertices of G, self loops are removed and multiple edges are merged into a single one.Methods inherited from interface org.graph4j.Graph
addEdge, addEdge, addEdge, addGraph, addVertex, addVertex, addVertices, adjacencyMatrix, adjListPos, complement, containsEdge, containsEdge, containsVertex, contractVertices, copy, copyAsMultigraph, copyAsPseudograph, degree, degrees, duplicateVertex, edge, edgeIterator, edges, edgesOf, getEdgeDataSize, getName, incidenceMatrix, indexOf, isAllowingMultipleEdges, isAllowingSelfLoops, isComplete, isDefaultVertexNumbering, isDirected, isEdgeless, isEmpty, isIsolated, isPendant, isSafeMode, isSimple, maxVertexNumber, neighborIterator, neighborIterator, neighbors, numEdges, numVertices, removeAllEdges, removeEdge, removeEdge, removeVertex, removeVertices, renumberAdding, setEdgeDataSize, setName, setSafeMode, splitEdge, subgraph, vertexAt, vertexIterator, vertices, weightMatrix
-
Method Details
-
supportGraph
The support graph of a multigraph or a pseudograph G is an undirected graph containing all the vertices of G, self loops are removed and multiple edges are merged into a single one. The edge labels are all set to null. In case of directed multigraphs graphs, edge data is removed. For undirected multigraphs, edge data is cumulated.- Returns:
- a new graph, representing the support graph.
-
copy
Multigraph<V,E> copy()Description copied from interface:GraphCreates and returns an identical copy of the graph. -
subgraph
Description copied from interface:GraphCreates and returns the subgraph induced by a set of vertices. -
subgraph
Description copied from interface:GraphCreates and returns the subgraph generated by a collection of edges. -
multiplicity
int multiplicity(int v, int u) - Parameters:
v- a vertex number.u- a vertex number.- Returns:
- how many times u appears in the adjacency list of v.
-
multiplicity
- Parameters:
e- an edge.- Returns:
- how many times an edge appears in the multigraph.
-
isUniversal
default boolean isUniversal(int v) Description copied from interface:GraphChecks if a vertex is universal, meaning that it is adjacent to all other vertices in the graph. In case of simple graphs, it has the degreenumVertices()-1. In case of directed graphs it has the outdegreenumVertices()-1.- Specified by:
isUniversalin interfaceGraph<V,E> - Parameters:
v- a vertex number.- Returns:
trueif v is universal.
-
maxEdges
default long maxEdges()Description copied from interface:GraphReturns the maximum number of edges the graph can have. A simple graph withnvertices can have at mostn*(n-1)/2edges. A directed graph may haven*(n-1)edges (also called arcs). For multigraphs and pseudographs, this method returnsLong.MAX_VALUE. -
addWeightedVertex
int addWeightedVertex(int v, double weight) Adds a new vertex to the graph having the specified number and weight. After the execution of this method, the graph is considered vertex weighted.- Parameters:
v- a vertex number.weight- the weight to be set for vertexv.- Returns:
- the index of the added vertex.
- Throws:
InvalidVertexException- ifvis negative or it is already in the graph.
-
addWeightedVertex
int addWeightedVertex(double weight) Adds a new vertex to the graph having the number equal to the maximum vertex number plus one, and the specified weight. After the execution of this method, the graph is considered vertex weighted.- Parameters:
weight- the weight to be set for the added vertex.- Returns:
- the number of the added vertex.
-
addEdge
int addEdge(int v, int u, double weight) Adds a new weighted edge to the graph. The endpoints of the edge are specified using their vertex numbers. After a successful execution of this method, the graph is considered edge weighted. See alsoGraph.addEdge(int, int).- Parameters:
v- a vertex numberu- a vertex numberweight- the weight to be set for the edge(v,u).- Returns:
- the position of
uin the adjacency list ofvif(v,u)edge was added, or-1if the edge was not added. - Throws:
InvalidVertexException- if either of the two vertices is not in the graph.
-
setVertexWeight
void setVertexWeight(int v, double weight) Sets the weight of a vertex. If at least one vertex has been assigned a weight, the graph is considered vertex weighted. The time complexity of this method isO(1).- Parameters:
v- a vertex number.weight- the weight to be set for vertex v.- Throws:
InvalidVertexException- ifvis not in the graph.
-
getVertexWeight
double getVertexWeight(int v) Returns the weight of a vertex. If no weights have been set (the graph is vertex unweighted) it returnsGraph.DEFAULT_VERTEX_WEIGHT, which is 1. The time complexity of this method isO(1).- Parameters:
v- a vertex number.- Returns:
- the weight of the vertex, 1 if the graph is unweighted.
- Throws:
InvalidVertexException- ifvis not in the graph.
-
setEdgeWeight
void setEdgeWeight(int v, int u, double weight) Sets the weight of an edge. The time complexity of this method isO(degree(v)). It is more efficient to set the weights of the edges while iterating over them, seeGraph.neighborIterator(int)orGraph.edgeIterator().- Parameters:
v- a vertex number.u- a vertex number.weight- the weight to be set for the edge(v,u).- Throws:
InvalidEdgeException- if the graph does not contain the edge(v,u).
-
getEdgeWeight
double getEdgeWeight(int v, int u) Returns the weight of an edge. If no weights have been set on edges (the graph is edge unweighted) it returnsGraph.DEFAULT_EDGE_WEIGHT, which is 1. If the endpoints v and u do not represent an edge, it returnsDouble.POSITIVE_INFINITY. The time complexity of this method isO(degree(v)). It is more efficient to get the weights of the edges while iterating over them, seeGraph.neighborIterator(int)orGraph.edgeIterator().- Parameters:
v- a vertex number.u- a vertex number.- Returns:
- the weight of the edge
(v,u). - Throws:
InvalidEdgeException- if the graph does not contain the edge(v,u).
-
getEdgeWeight
Returns the weight of an edge. If no weights have been set on edges (the graph is edge unweighted) it returnsGraph.DEFAULT_EDGE_WEIGHT, which is 1. If the argument does not represent an edge, it returnsDouble.POSITIVE_INFINITY. The time complexity of this method isO(degree(v)). It is more efficient to get the weights of the edges while iterating over them, seeGraph.neighborIterator(int)orGraph.edgeIterator().- Parameters:
e- an edge.- Returns:
- the weight of the edge
e. - Throws:
InvalidEdgeException- if the graph does not contain the edgee.
-
hasEdgeWeights
boolean hasEdgeWeights()Checks if the graph is has at least one edge that has been assigned a weight (is edge weighted).- Returns:
trueif weights have been set on edges,falseotherwise.
-
hasVertexWeights
boolean hasVertexWeights()Checks if the graph has at least one vertex that has been assigned a weight (is vertex weighted).- Returns:
trueif weights have been set on vertices,falseotherwise.
-
getEdgeData
double getEdgeData(int dataType, int v, int u, double defaultValue) -
getEdgeData
default double getEdgeData(int dataType, int v, int u) -
getEdgeData
-
getEdgeData
-
setEdgeData
void setEdgeData(int dataType, int v, int u, double value) -
incEdgeData
void incEdgeData(int dataType, int v, int u, double amount) -
hasEdgeData
boolean hasEdgeData(int dataType) -
resetEdgeData
void resetEdgeData(int dataType, double value) -
addLabeledVertex
Adds a new vertex to the graph having the specified number and label. After the execution of this method, the graph is considered vertex labeled.- Parameters:
v- a vertex number.label- a vertex label.- Returns:
- the index of the added vertex.
- Throws:
InvalidVertexException- ifvis negative or it is already in the graph.
-
addLabeledVertex
Adds a new vertex to the graph having the number equal to the maximum vertex number plus one, and the specified label. After the execution of this method, the graph is considered vertex labeled.- Parameters:
label- a vertex label.- Returns:
- the number of the added vertex.
-
addLabeledEdge
Adds a new weighted and labeled edge to the graph. The endpoints of the edge are identified using their vertex numbers. See alsoGraph.addEdge(int, int).- Parameters:
v- a vertex number.u- a vertex number.label- edge label.weight- edge weight.- Returns:
- the position of
uin the adjacency list ofvif(v,u)edge was added, or-1if the edge was not added. - Throws:
InvalidVertexException- if either of the two vertices is not in the graph.
-
addLabeledEdge
Adds a new labeled edge to the graph. The endpoints of the edge are identified using their vertex numbers. After a successful execution of this method, the graph is considered edge labeled. See alsoGraph.addEdge(int, int).- Parameters:
v- a vertex numberu- a vertex numberlabel- an edge label.- Returns:
- the position of
uin the adjacency list ofvif(v,u)edge was added, or-1if the edge was not added. - Throws:
InvalidVertexException- if either of the two vertices is not in the graph.
-
addLabeledEdge
Adds a new labeled edge to the graph. The endpoints of the edge are identified using their uniquely identifiable vertex labels. After a successful execution of this method, the graph is considered edge labeled. See alsoGraph.addEdge(int, int).- Parameters:
vLabel- a vertex label.uLabel- a vertex label.edgeLabel- an edge label.- Returns:
- the position of
uin the adjacency list ofvif(v,u)edge was added, or-1if the edge was not added. - Throws:
InvalidVertexException- if either of the two vertices is not in the graph.
-
setVertexLabel
Sets the label for the specified vertex. If at least one vertex has been assigned a label, the graph is considered vertex labeled. The time complexity of this method isO(1).- Parameters:
v- a vertex number.label- a vertex label.- Throws:
InvalidVertexException- ifvis not in the graph.
-
getVertexLabel
Returns the label of the specified vertex ornullif no label has been set. The time complexity of this method isO(1).- Parameters:
v- a vertex number.- Returns:
- the label of the specified vertex.
- Throws:
InvalidVertexException- ifvis not in the graph.
-
setEdgeLabel
Sets the label of a specified edge. The time complexity of this method isO(degree(v)). It is more efficient to set the labels of the edges while iterating over them, seeGraph.neighborIterator(int)orGraph.edgeIterator().- Parameters:
v- a vertex number.u- a vertex number.label- an edge label.- Throws:
InvalidEdgeException- if the graph does not contain the edge(v,u).
-
getEdgeLabel
Returns the label of a specified edge. The time complexity of this method isO(degree(v)). It is more efficient to get the weights of the edges while iterating over them, seeGraph.neighborIterator(int)orGraph.edgeIterator().- Parameters:
v- a vertex number.u- a vertex number.- Returns:
- the label of the edge
(v,u). - Throws:
InvalidEdgeException- if the graph does not contain the edge(v,u).
-
hasEdgeLabels
boolean hasEdgeLabels()Checks if the graph has at least one edge that has been assigned a label (is edge labeled).- Returns:
trueif labels have been set on edges,falseotherwise.
-
hasVertexLabels
boolean hasVertexLabels()Checks if the graph has at least one vertex that has been assigned a label (is vertex labeled).- Returns:
trueif labels have been set on vertices,falseotherwise.
-
findVertex
Returns the number of the vertex having the specified label. If there are more vertices having the specified label, it returns the last one that has been assigned that label. If no vertex has the specified label, it returns-1.- Parameters:
label- a vertex label.- Returns:
- the number of the vertex which has the specified label, or
-1if no such vertex exists.
-
findAllVertices
Returns a set containing all the vertex numbers having the specified label.- Parameters:
label- a vertex label.- Returns:
- all the vertices of the graph which have been assigned the specified label.
-
findEdge
Returns the edge having the specified label. If there are more edges with the specified label, it returns the last one added in the graph.- Parameters:
label- an edge label.- Returns:
- the edge with the specified label.
-
findAllEdges
Returns a set containing all the edges having the specified label.- Parameters:
label- an edge label.- Returns:
- all the edges with the specified label.
-