Class ComplementaryGraph<U>
java.lang.Object
es.uam.eps.ir.relison.graph.complementary.ComplementaryGraph<U>
- Type Parameters:
U- type of the users.
- All Implemented Interfaces:
Graph<U>,java.io.Serializable
- Direct Known Subclasses:
DirectedUnweightedComplementaryGraph,DirectedWeightedComplementaryGraph,UndirectedUnweightedComplementaryGraph,UndirectedWeightedComplementaryGraph
public abstract class ComplementaryGraph<U> extends java.lang.Object implements Graph<U>
Wrapper for the complementary graph of another one given. Since this is the complementary
of another graph, no nodes nor edges can be removed. Every time the original graph is modified,
so this graph will be.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ComplementaryGraph(Graph<U> graph)Constructor -
Method Summary
Modifier and Type Method Description booleanaddEdge(U nodeA, U nodeB, double weight, int type, boolean insertNodes)Adds a weighted edge to the graph.booleanaddNode(U node)Adds a new node to the graph.Graph<U>complement()Complements the graphbooleancontainsEdge(U nodeA, U nodeB)Checks if an edge exists in the graph.booleancontainsVertex(U node)Checks if a vertex exists in the graph.double[][]getAdjacencyMatrix(EdgeOrientation direction)Gets the adjacency matrix.Index<U>getAdjacencyMatrixMap()For an adjacency matrix, obtains the mapping between indexes and nodes.intgetAdjacentEdgesCount(U node)Calculates the number of adjacent edges of a node (not necessarily equal to the out-degree).java.util.stream.Stream<Weight<U,java.lang.Integer>>getAdjacentMutualNodesTypes(U node)Given a node, finds the types of the edges towards the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getAdjacentMutualNodesWeights(U node)Given a node, finds the weights of the edges towards the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.java.util.stream.Stream<U>getAdjacentNodes(U node)Given a node, finds all the nodes u such that the edge (node to u) is in the graph.java.util.stream.Stream<Weight<U,java.lang.Integer>>getAdjacentNodesTypes(U node)Given a node, finds the types of the edges towards the nodes u such that the edge (node to u) is in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getAdjacentNodesWeights(U node)Given a node, finds the weights of the edges towards the nodes u such that the edge (node to u) is in the graph.java.util.stream.Stream<U>getAllNodes()Gets all the nodes in the graph.longgetEdgeCount()Measures the number of edges in the network.intgetEdgeType(U nodeA, U nodeB)Obtains the type of an edge in the graphdoublegetEdgeWeight(U nodeA, U nodeB)Obtains the weight of an edge in the graphintgetIncidentEdgesCount(U node)Calculates the number of incident edges of a node (not necessarily equal to the in-degree).java.util.stream.Stream<Weight<U,java.lang.Integer>>getIncidentMutualNodesTypes(U node)Given a node, finds the types of the edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getIncidentMutualNodesWeights(U node)Given a node, finds the weights of the edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.java.util.stream.Stream<U>getIncidentNodes(U node)Given a node, finds all the nodes u such that the edge (u to node) is in the graph.java.util.stream.Stream<Weight<U,java.lang.Integer>>getIncidentNodesTypes(U node)Given a node, finds the types of the edges from the nodes u such that the edge (u to node) is in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getIncidentNodesWeights(U node)Given a node, finds the weights of the edges from the nodes u such that the edge (u to node) is in the graph.java.util.stream.Stream<U>getIsolatedNodes()Obtains the set of nodes without edges.intgetMutualEdgesCount(U node)Calculates the total number of adjacent edges of a node such that there is an incident reciprocal link towards the node.java.util.stream.Stream<U>getMutualNodes(U node)Given a node, finds all the nodes u such that the edges (node to u) and (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Integer>>getMutualNodesTypes(U node)Given a node, find the types of edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getMutualNodesWeights(U node)Given a node, finds the weights of the edges towards and from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.intgetNeighbourEdgesCount(U node)Calculates the total number of edges which reach a node or start from it (not necessarily equal to the degree).java.util.stream.Stream<U>getNeighbourhood(U node, EdgeOrientation direction)Gets all the nodes in the neighbourhood of a node given by a direction.intgetNeighbourhoodSize(U node, EdgeOrientation direction)Gets all the nodes in the neighbourhood of a node given by a direction.java.util.stream.Stream<Weight<U,java.lang.Integer>>getNeighbourhoodTypes(U node, EdgeOrientation direction)Gets all the types of the edges in the neighbourhood of a node given by a direction.java.util.stream.Stream<Weight<U,java.lang.Double>>getNeighbourhoodWeights(U node, EdgeOrientation direction)Gets all the weights of the edges in the neighbourhood of a node given by a direction.java.util.stream.Stream<U>getNeighbourNodes(U node)Given a node, finds all the nodes u so that either (node to u) or (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Integer>>getNeighbourNodesTypes(U node)Given a node, finds the types of the edges from the nodes u such that the edge (node to u) or the edge (u to node) are in the graph.java.util.stream.Stream<Weight<U,java.lang.Double>>getNeighbourNodesWeights(U node)Given a node, finds the weights of the edges from the nodes u such that the edge (node to u) or the edge (u to node) are in the graph.java.util.stream.Stream<U>getNodesWithAdjacentNeighbors()Obtains the set of nodes which have adjacent edges.java.util.stream.Stream<U>getNodesWithIncidentNeighbors()Obtains the set of nodes which have incident edges.java.util.stream.Stream<U>getNodesWithMutualNeighbors()Obtains the set of nodes having mutual edges.java.util.stream.Stream<U>getNodesWithNeighbors()Obtains the set of nodes having either incident or adjacent edges.java.util.stream.Stream<U>getNodesWithNeighbors(EdgeOrientation direction)Obtains the set of nodes with edges in a particular direction.longgetVertexCount()Measures the number of nodes in the network.booleanhasAdjacentNeighbors(U u)Checks if the user has adjacent edges or not.booleanhasIncidentNeighbors(U u)Checks if the user has incident edges or not.booleanhasMutualNeighbors(U u)Checks if the user has mutual edges.booleanhasNeighbors(U u)Checks if the user shares at least an edge with other user.booleanisDirected()Indicates if the graph is directed.booleanisWeighted()Indicates if the graph is weighted.booleanremoveEdge(U nodeA, U nodeB)Removes an edge from the graph.booleanremoveNode(U node)Removes a node from the graph.booleanupdateEdgeType(U orig, U dest, int type)Updates the type of an edge.booleanupdateEdgeWeight(U orig, U dest, double weight)Updates the weight of an edge.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface es.uam.eps.ir.relison.graph.Graph
addEdge, addEdge, addEdge, addEdge, addEdge, degree, degree, getAdjacentNodesCount, getIncidentNodesCount, getMutualNodesCount, getNeighbourNodesCount, hasNeighbors, inDegree, isMultigraph, isMutual, mutualDegree, outDegree
-
Field Details
-
graph
Original graph.
-
-
Constructor Details
-
ComplementaryGraph
Constructor- Parameters:
graph- Original graph.
-
-
Method Details
-
addNode
Description copied from interface:GraphAdds a new node to the graph. -
addEdge
Description copied from interface:GraphAdds a weighted edge to the graph.- Specified by:
addEdgein interfaceGraph<U>- Parameters:
nodeA- The incident node.nodeB- The adjacent node.weight- The weight.type- The edge type.insertNodes- If true, nodes will be inserted if they do not exist. If false, the edge will only be added if both nodes are inserted.- Returns:
- if the edge is correctly added, false if not.
-
removeNode
Description copied from interface:GraphRemoves a node from the graph.- Specified by:
removeNodein interfaceGraph<U>- Parameters:
node- Node to remove.- Returns:
- true if the edge is correctly removed, false if not.
-
removeEdge
Description copied from interface:GraphRemoves an edge from the graph.- Specified by:
removeEdgein interfaceGraph<U>- Parameters:
nodeA- The incident node of the edge to remove.nodeB- The adjacent node of the edge to remove.- Returns:
- true if everything went ok, false if not.
-
getAllNodes
Description copied from interface:GraphGets all the nodes in the graph.- Specified by:
getAllNodesin interfaceGraph<U>- Returns:
- a stream of all the nodes in the graph.
-
getIncidentNodes
Description copied from interface:GraphGiven a node, finds all the nodes u such that the edge (u to node) is in the graph.- Specified by:
getIncidentNodesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream of the incident nodes.
-
getAdjacentNodes
Description copied from interface:GraphGiven a node, finds all the nodes u such that the edge (node to u) is in the graph.- Specified by:
getAdjacentNodesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing the adjacent nodes.
-
getNeighbourNodes
Description copied from interface:GraphGiven a node, finds all the nodes u so that either (node to u) or (u to node) are in the graph.- Specified by:
getNeighbourNodesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood.
-
getMutualNodes
Description copied from interface:GraphGiven a node, finds all the nodes u such that the edges (node to u) and (u to node) are in the graph.- Specified by:
getMutualNodesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes which share reciprocal links.
-
getNeighbourhood
Description copied from interface:GraphGets all the nodes in the neighbourhood of a node given by a direction.- Specified by:
getNeighbourhoodin interfaceGraph<U>- Parameters:
node- The node.direction- The direction of the links.- Returns:
- A stream containing the corresponding neighbourhood.
-
getIncidentEdgesCount
Description copied from interface:GraphCalculates the number of incident edges of a node (not necessarily equal to the in-degree).- Specified by:
getIncidentEdgesCountin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- the number of incident neighbours of the node if it is contained in the graph, -1 if not.
-
getAdjacentEdgesCount
Description copied from interface:GraphCalculates the number of adjacent edges of a node (not necessarily equal to the out-degree).- Specified by:
getAdjacentEdgesCountin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- the degree of the node if it is contained in the graph, -1 if not.
-
getNeighbourEdgesCount
Description copied from interface:GraphCalculates the total number of edges which reach a node or start from it (not necessarily equal to the degree).- Specified by:
getNeighbourEdgesCountin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- the degree of the node if it is contained in the graph, -1 if not.
-
getMutualEdgesCount
Description copied from interface:GraphCalculates the total number of adjacent edges of a node such that there is an incident reciprocal link towards the node.- Specified by:
getMutualEdgesCountin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- the number of reciprocal links starting from the node.
-
getNeighbourhoodSize
Description copied from interface:GraphGets all the nodes in the neighbourhood of a node given by a direction.- Specified by:
getNeighbourhoodSizein interfaceGraph<U>- Parameters:
node- The node.direction- The direction of the links.- Returns:
- A stream containing the corresponding neighbourhood.
-
containsVertex
Description copied from interface:GraphChecks if a vertex exists in the graph.- Specified by:
containsVertexin interfaceGraph<U>- Parameters:
node- The vertex to check.- Returns:
- true if the vertex is contained in the graph, false if not.
-
containsEdge
Description copied from interface:GraphChecks if an edge exists in the graph.- Specified by:
containsEdgein interfaceGraph<U>- Parameters:
nodeA- The incident node.nodeB- The adjacent node.- Returns:
- true if the edge is contained in the graph, false if not.
-
getEdgeWeight
Description copied from interface:GraphObtains the weight of an edge in the graph- Specified by:
getEdgeWeightin interfaceGraph<U>- Parameters:
nodeA- The incident node.nodeB- The adjacent node.- Returns:
- The corresponding weight. If the edge does not exist, NaN
-
getIncidentNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges from the nodes u such that the edge (u to node) is in the graph.- Specified by:
getIncidentNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing the adjacent nodes and weights.
-
getAdjacentNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges towards the nodes u such that the edge (node to u) is in the graph.- Specified by:
getAdjacentNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing the adjacent nodes and weights.
-
getNeighbourNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges from the nodes u such that the edge (node to u) or the edge (u to node) are in the graph.- Specified by:
getNeighbourNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and weights.
-
getMutualNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges towards and from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph. It finds the average value of the outgoing and incoming links.- Specified by:
getMutualNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and weights.
-
getAdjacentMutualNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges towards the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.- Specified by:
getAdjacentMutualNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and weights.
-
getIncidentMutualNodesWeights
Description copied from interface:GraphGiven a node, finds the weights of the edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.- Specified by:
getIncidentMutualNodesWeightsin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and weights.
-
getNeighbourhoodWeights
public java.util.stream.Stream<Weight<U,java.lang.Double>> getNeighbourhoodWeights(U node, EdgeOrientation direction)Description copied from interface:GraphGets all the weights of the edges in the neighbourhood of a node given by a direction. In the mutual case, just returns the average of the edge weights.- Specified by:
getNeighbourhoodWeightsin interfaceGraph<U>- Parameters:
node- The node.direction- The direction of the links- Returns:
- A stream containing the corresponding neighbourhood and weights.
-
getEdgeType
Description copied from interface:GraphObtains the type of an edge in the graph- Specified by:
getEdgeTypein interfaceGraph<U>- Parameters:
nodeA- The incident node.nodeB- The adjacent node.- Returns:
- The corresponding type. If the edge does not exist, -1.
-
getIncidentNodesTypes
Description copied from interface:GraphGiven a node, finds the types of the edges from the nodes u such that the edge (u to node) is in the graph.- Specified by:
getIncidentNodesTypesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream of the incident nodes and types.
-
getAdjacentNodesTypes
Description copied from interface:GraphGiven a node, finds the types of the edges towards the nodes u such that the edge (node to u) is in the graph.- Specified by:
getAdjacentNodesTypesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing the adjacent nodes and types.
-
getNeighbourNodesTypes
Description copied from interface:GraphGiven a node, finds the types of the edges from the nodes u such that the edge (node to u) or the edge (u to node) are in the graph.- Specified by:
getNeighbourNodesTypesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and types.
-
getMutualNodesTypes
Description copied from interface:GraphGiven a node, find the types of edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.- Specified by:
getMutualNodesTypesin interfaceGraph<U>- Parameters:
node- the node.- Returns:
- a stream containing all the nodes in the neighbourhood and types.
-
getAdjacentMutualNodesTypes
Description copied from interface:GraphGiven a node, finds the types of the edges towards the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.- Specified by:
getAdjacentMutualNodesTypesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and types.
-
getIncidentMutualNodesTypes
Description copied from interface:GraphGiven a node, finds the types of the edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.- Specified by:
getIncidentMutualNodesTypesin interfaceGraph<U>- Parameters:
node- The node.- Returns:
- A stream containing all the nodes in the neighbourhood and types.
-
getNeighbourhoodTypes
public java.util.stream.Stream<Weight<U,java.lang.Integer>> getNeighbourhoodTypes(U node, EdgeOrientation direction)Description copied from interface:GraphGets all the types of the edges in the neighbourhood of a node given by a direction. In the mutual case, it does not work (types are categorical values), so an empty stream is returned.- Specified by:
getNeighbourhoodTypesin interfaceGraph<U>- Parameters:
node- The node.direction- The direction of the links.- Returns:
- A stream containing the corresponding neighbourhood.
-
isDirected
public boolean isDirected()Description copied from interface:GraphIndicates if the graph is directed.- Specified by:
isDirectedin interfaceGraph<U>- Returns:
- true if it is, false if not.
-
isWeighted
public boolean isWeighted()Description copied from interface:GraphIndicates if the graph is weighted.- Specified by:
isWeightedin interfaceGraph<U>- Returns:
- true if it is, false if not.
-
getVertexCount
public long getVertexCount()Description copied from interface:GraphMeasures the number of nodes in the network.- Specified by:
getVertexCountin interfaceGraph<U>- Returns:
- the number of nodes.
-
getEdgeCount
public long getEdgeCount()Description copied from interface:GraphMeasures the number of edges in the network.- Specified by:
getEdgeCountin interfaceGraph<U>- Returns:
- the number of edges.
-
getAdjacencyMatrix
Description copied from interface:GraphGets the adjacency matrix.- Specified by:
getAdjacencyMatrixin interfaceGraph<U>- Parameters:
direction- The direction of the edges.- Returns:
- the adjacency matrix.
-
complement
Description copied from interface:GraphComplements the graph- Specified by:
complementin interfaceGraph<U>- Returns:
- the complementary graph.
-
updateEdgeWeight
Description copied from interface:GraphUpdates the weight of an edge.- Specified by:
updateEdgeWeightin interfaceGraph<U>- Parameters:
orig- The incident node.dest- The adjacent node.weight- The new weight.- Returns:
- true if everything goes OK, false if the edge does not exist or something fails.
-
updateEdgeType
Description copied from interface:GraphUpdates the type of an edge.- Specified by:
updateEdgeTypein interfaceGraph<U>- Parameters:
orig- The incident node.dest- The adjacent node.type- The new type.- Returns:
- true if everything goes OK, false if the edge does not exist or something fails.
-
getIsolatedNodes
Description copied from interface:GraphObtains the set of nodes without edges.- Specified by:
getIsolatedNodesin interfaceGraph<U>- Returns:
- the set of nodes without edges.
-
getNodesWithNeighbors
Description copied from interface:GraphObtains the set of nodes with edges in a particular direction.- Specified by:
getNodesWithNeighborsin interfaceGraph<U>- Parameters:
direction- the particular direction- Returns:
- the set of nodes with edges in the given direction.
-
getNodesWithAdjacentNeighbors
Description copied from interface:GraphObtains the set of nodes which have adjacent edges.- Specified by:
getNodesWithAdjacentNeighborsin interfaceGraph<U>- Returns:
- the set of nodes which have adjacent edges.
-
getNodesWithIncidentNeighbors
Description copied from interface:GraphObtains the set of nodes which have incident edges.- Specified by:
getNodesWithIncidentNeighborsin interfaceGraph<U>- Returns:
- the set of nodes which have incident edges.
-
getNodesWithNeighbors
Description copied from interface:GraphObtains the set of nodes having either incident or adjacent edges.- Specified by:
getNodesWithNeighborsin interfaceGraph<U>- Returns:
- the set of nodes which have incident or adjacent edges.
-
getNodesWithMutualNeighbors
Description copied from interface:GraphObtains the set of nodes having mutual edges.- Specified by:
getNodesWithMutualNeighborsin interfaceGraph<U>- Returns:
- the set of nodes which have mutual edges.
-
hasAdjacentNeighbors
Description copied from interface:GraphChecks if the user has adjacent edges or not.- Specified by:
hasAdjacentNeighborsin interfaceGraph<U>- Parameters:
u- The user.- Returns:
- true if the user has adjacent edges, false if it is a sink or isolated node.
-
hasIncidentNeighbors
Description copied from interface:GraphChecks if the user has incident edges or not.- Specified by:
hasIncidentNeighborsin interfaceGraph<U>- Parameters:
u- the user.- Returns:
- true if the user has incident edges, false if it is a source or isolated node.
-
hasNeighbors
Description copied from interface:GraphChecks if the user shares at least an edge with other user.- Specified by:
hasNeighborsin interfaceGraph<U>- Parameters:
u- The user.- Returns:
- true if the user is not isolated, false otherwise.
-
hasMutualNeighbors
Description copied from interface:GraphChecks if the user has mutual edges.- Specified by:
hasMutualNeighborsin interfaceGraph<U>- Parameters:
u- The user.- Returns:
- true if the user has mutual edges, false otherwise.
-
getAdjacencyMatrixMap
Description copied from interface:GraphFor an adjacency matrix, obtains the mapping between indexes and nodes.- Specified by:
getAdjacencyMatrixMapin interfaceGraph<U>- Returns:
- the mapping between indexes and nodes.
-