Package edu.uci.ics.jung.graph
Class OrderedKAryTree<V,E>
- java.lang.Object
-
- edu.uci.ics.jung.graph.AbstractGraph<V,E>
-
- edu.uci.ics.jung.graph.AbstractTypedGraph<V,E>
-
- edu.uci.ics.jung.graph.OrderedKAryTree<V,E>
-
- All Implemented Interfaces:
DirectedGraph<V,E>,Forest<V,E>,Graph<V,E>,Hypergraph<V,E>,Tree<V,E>,java.io.Serializable
public class OrderedKAryTree<V,E> extends AbstractTypedGraph<V,E> implements Tree<V,E>
An implementation ofTreein which each vertex has ≤ k children. The value of 'k' is specified by the constructor parameter. A specific child (edge) can be retrieved directly by specifying the index at which the child is located. By default, new (child) vertices are added at the lowest index available, if no index is specified.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classOrderedKAryTree.VertexData
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<E,Pair<V>>edge_vpairsprotected intheightprotected intorderprotected Vrootprotected java.util.Map<V,OrderedKAryTree.VertexData>vertex_data-
Fields inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
edge_type
-
-
Constructor Summary
Constructors Constructor Description OrderedKAryTree(int order)Creates a new instance with the specified order (maximum number of children).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType)Addsedgeto this graph with the specifiedendpointsandEdgeType.booleanaddEdge(E edge, java.util.Collection<? extends V> vertices, EdgeType edge_type)Addsedgeto this graph with typeedge_type.booleanaddEdge(E e, V parent, V child)Adds edgeeto this graph such that it connects vertexv1tov2.booleanaddEdge(E e, V parent, V child, int index)Adds the specifiedchildvertex and edgeeto the graph with the specified parent vertexparent.booleanaddEdge(E e, V v1, V v2, EdgeType edge_type)Adds edgeeto this graph such that it connects vertexv1tov2.booleanaddVertex(V vertex)Addsvertexto this graph.booleancontainsEdge(E edge)Returns true if this graph's edge collection containsedge.booleancontainsVertex(V vertex)Returns true if this graph's vertex collection containsvertex.EfindEdge(V v1, V v2)Returns an edge that connects this vertex tov.java.util.Collection<E>findEdgeSet(V v1, V v2)Returns all edges that connects this vertex tov.VgetChild(V vertex, int index)Returns the child ofvertexat positionindexin this tree, ornullif it has no child at that position.intgetChildCount(V vertex)Returns the number of children thatvertexhas in this tree.EgetChildEdge(V vertex, int index)java.util.Collection<E>getChildEdges(V vertex)Returns the edges connectingvertexto its children in this tree.java.util.Collection<V>getChildren(V vertex)Returns an ordered list ofvertex's child vertices.intgetDepth(V vertex)Returns the (unweighted) distance ofvertexfrom the root of this tree.VgetDest(E directed_edge)Ifdirected_edgeis a directed edge in this graph, returns the destination; otherwise returnsnull.intgetEdgeCount()Returns the number of edges in this graph.java.util.Collection<E>getEdges()Returns a view of all edges in this graph.Pair<V>getEndpoints(E edge)Returns the endpoints ofedgeas aPair.static <V,E>
com.google.common.base.Supplier<DirectedGraph<V,E>>getFactory(int order)intgetHeight()Returns the height of the tree, or -1 if the tree is empty.intgetIncidentCount(E edge)Returns the number of vertices that are incident toedge.java.util.Collection<E>getIncidentEdges(V vertex)Returns the collection of edges in this graph which are connected tovertex.java.util.Collection<V>getIncidentVertices(E edge)Returns the collection of vertices in this graph which are connected toedge.java.util.Collection<E>getInEdges(V vertex)Returns aCollectionview of the incoming edges incident tovertexin this graph.intgetNeighborCount(V vertex)Returns the number of vertices that are adjacent tovertex(that is, the number of vertices that are incident to edges invertex's incident edge set).java.util.Collection<V>getNeighbors(V vertex)Returns the collection of vertices which are connected tovertexvia any edges in this graph.VgetOpposite(V vertex, E edge)Returns the vertex at the other end ofedgefromvertex.java.util.Collection<E>getOutEdges(V vertex)Returns aCollectionview of the outgoing edges incident tovertexin this graph.VgetParent(V vertex)Returns the parent ofvertexin this tree.EgetParentEdge(V vertex)Returns the edge connectingvertexto its parent in this tree.intgetPredecessorCount(V vertex)Returns the number of predecessors thatvertexhas in this graph.java.util.Collection<V>getPredecessors(V vertex)Returns aCollectionview of the predecessors ofvertexin this graph.VgetRoot()Returns the root of this tree.VgetSource(E directed_edge)Ifdirected_edgeis a directed edge in this graph, returns the source; otherwise returnsnull.intgetSuccessorCount(V vertex)Returns the number of successors thatvertexhas in this graph.java.util.Collection<V>getSuccessors(V vertex)Returns aCollectionview of the successors ofvertexin this graph.java.util.Collection<Tree<V,E>>getTrees()Returns a view of this graph as a collection ofTreeinstances.intgetVertexCount()Returns the number of vertices in this graph.java.util.Collection<V>getVertices()Returns a view of all vertices in this graph.intinDegree(V vertex)Returns the number of incoming edges incident tovertex.booleanisDest(V vertex, E edge)Returnstrueifvertexis the destination ofedge.booleanisIncident(V vertex, E edge)Returnstrueifvertexandedgeare incident to each other.booleanisLeaf(V vertex)Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.booleanisNeighbor(V v1, V v2)Returnstrueifv1andv2share an incident edge.booleanisPredecessor(V v1, V v2)Returns true iffv1is the parent ofv2.booleanisRoot(V vertex)Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.booleanisSource(V vertex, E edge)Returnstrueifvertexis the source ofedge.booleanisSuccessor(V v1, V v2)Returnstrueifv1is a successor ofv2in this graph.intoutDegree(V vertex)Returns the number of outgoing edges incident tovertex.booleanremoveEdge(E edge)Removesedgefrom this graph.booleanremoveVertex(V vertex)Removesvertexfrom this graph.-
Methods inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeType
-
Methods inherited from class edu.uci.ics.jung.graph.AbstractGraph
addEdge, addEdge, degree, getValidatedEndpoints, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface edu.uci.ics.jung.graph.Hypergraph
addEdge, degree, getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType
-
-
-
-
Method Detail
-
getFactory
public static <V,E> com.google.common.base.Supplier<DirectedGraph<V,E>> getFactory(int order)
- Type Parameters:
V- the vertex type for the graph SupplierE- the edge type for the graph Supplier- Parameters:
order- the maximum number of children ("k") that any vertex can have- Returns:
- a
Supplierthat creates an instance of this graph type.
-
getChildCount
public int getChildCount(V vertex)
Description copied from interface:ForestReturns the number of children thatvertexhas in this tree. The children of a vertex are defined as being the successors of that vertex on the respective (unique) shortest paths from the root to those vertices. This is syntactic (maple) sugar forgetSuccessorCount(vertex).- Specified by:
getChildCountin interfaceForest<V,E>- Parameters:
vertex- the vertex whose number of children is to be returned- Returns:
- the number of children that
vertexhas - See Also:
Forest.getChildCount(java.lang.Object)
-
getChildEdge
public E getChildEdge(V vertex, int index)
- Parameters:
vertex- the vertex whose child edge is to be returnedindex- the index of the edge to be returned- Returns:
- the child edge of
vertexat indexindex, that is, its ith child edge.
-
getChildEdges
public java.util.Collection<E> getChildEdges(V vertex)
Description copied from interface:ForestReturns the edges connectingvertexto its children in this tree. The children of a vertex are defined as being the successors of that vertex on the respective (unique) shortest paths from the root to those vertices. This is syntactic (maple) sugar forgetOutEdges(vertex).- Specified by:
getChildEdgesin interfaceForest<V,E>- Parameters:
vertex- the vertex whose child edges are to be returned- Returns:
- the
Collectionof edges connectingvertexto its children in this tree - See Also:
Forest.getChildEdges(java.lang.Object)
-
getChildren
public java.util.Collection<V> getChildren(V vertex)
Returns an ordered list ofvertex's child vertices. If there is no child in position i, then the list will containnullin position i. Ifvertexhas no children then the empty set will be returned.- Specified by:
getChildrenin interfaceForest<V,E>- Parameters:
vertex- the vertex whose children are to be returned- Returns:
- the
Collectionof children ofvertexin this tree - See Also:
Forest.getChildren(java.lang.Object)
-
getDepth
public int getDepth(V vertex)
Description copied from interface:TreeReturns the (unweighted) distance ofvertexfrom the root of this tree.- Specified by:
getDepthin interfaceTree<V,E>- Parameters:
vertex- the vertex whose depth is to be returned.- Returns:
- the depth of the vertex in this tree, or -1 if the vertex is not present in this tree
- See Also:
Tree.getDepth(java.lang.Object)
-
getHeight
public int getHeight()
Returns the height of the tree, or -1 if the tree is empty.- Specified by:
getHeightin interfaceTree<V,E>- Returns:
- the maximum depth in this tree
- See Also:
Tree.getHeight()
-
getParent
public V getParent(V vertex)
Description copied from interface:ForestReturns the parent ofvertexin this tree. (Ifvertexis the root, returnsnull.) The parent of a vertex is defined as being its predecessor in the (unique) shortest path from the root to this vertex. This is a convenience method which is equivalent toGraph.getPredecessors(vertex).iterator().next().- Specified by:
getParentin interfaceForest<V,E>- Parameters:
vertex- the vertex whose parent is to be returned- Returns:
- the parent of
vertexin this tree - See Also:
Forest.getParent(java.lang.Object)
-
getParentEdge
public E getParentEdge(V vertex)
Description copied from interface:ForestReturns the edge connectingvertexto its parent in this tree. (Ifvertexis the root, returnsnull.) The parent of a vertex is defined as being its predecessor in the (unique) shortest path from the root to this vertex. This is a convenience method which is equivalent toGraph.getInEdges(vertex).iterator().next(), and also toGraph.findEdge(vertex, getParent(vertex)).- Specified by:
getParentEdgein interfaceForest<V,E>- Parameters:
vertex- the vertex whose incoming edge is to be returned- Returns:
- the edge connecting
vertexto its parent, ornullifvertexis the root - See Also:
Forest.getParentEdge(java.lang.Object)
-
getRoot
public V getRoot()
Description copied from interface:TreeReturns the root of this tree. The root is defined to be the vertex (designated either at the tree's creation time, or as the first vertex to be added) with respect to which vertex depth is measured.- Specified by:
getRootin interfaceTree<V,E>- Returns:
- the root of this tree
- See Also:
Tree.getRoot()
-
getTrees
public java.util.Collection<Tree<V,E>> getTrees()
Description copied from interface:ForestReturns a view of this graph as a collection ofTreeinstances.- Specified by:
getTreesin interfaceForest<V,E>- Returns:
- a view of this graph as a collection of
Trees - See Also:
Forest.getTrees()
-
addEdge
public boolean addEdge(E e, V parent, V child, int index)
Adds the specifiedchildvertex and edgeeto the graph with the specified parent vertexparent. Ifindexis greater than or equal to 0, then the child is placed at positionindex; if it is less than 0, the child is placed at the lowest available position; if it is greater than or equal to the order of this tree, an exception is thrown.- Parameters:
e- the edge to addparent- the source of the edge to be addedchild- the destination of the edge to be addedindex- the position at which e is to be added as a child ofparent- Returns:
trueif the graph has been modified- See Also:
Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)
-
addEdge
public boolean addEdge(E e, V parent, V child)
Description copied from interface:GraphAdds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair(v1, v2)). If this graph does not containv1,v2, or both, implementations may choose to either silently add the vertices to the graph or throw anIllegalArgumentException. If this graph assigns edge types to its edges, the edge type ofewill be the default for this graph. SeeHypergraph.addEdge()for a listing of possible reasons for failure.- Specified by:
addEdgein interfaceGraph<V,E>- Overrides:
addEdgein classAbstractGraph<V,E>- Parameters:
e- the edge to be addedparent- the first vertex to be connectedchild- the second vertex to be connected- Returns:
trueif the add is successful,falseotherwise- See Also:
Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)
-
addEdge
public boolean addEdge(E e, V v1, V v2, EdgeType edge_type)
Description copied from interface:GraphAdds edgeeto this graph such that it connects vertexv1tov2. Equivalent toaddEdge(e, new Pair(v1, v2)). If this graph does not containv1,v2, or both, implementations may choose to either silently add the vertices to the graph or throw anIllegalArgumentException. IfedgeTypeis not legal for this graph, this method will throwIllegalArgumentException. SeeHypergraph.addEdge()for a listing of possible reasons for failure.- Specified by:
addEdgein interfaceGraph<V,E>- Overrides:
addEdgein classAbstractGraph<V,E>- Parameters:
e- the edge to be addedv1- the first vertex to be connectedv2- the second vertex to be connectededge_type- the type to be assigned to the edge- Returns:
trueif the add is successful,falseotherwise- See Also:
Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object, edu.uci.ics.jung.graph.util.EdgeType)
-
getDest
public V getDest(E directed_edge)
Description copied from interface:GraphIfdirected_edgeis a directed edge in this graph, returns the destination; otherwise returnsnull. The destination of a directed edgedis defined to be the vertex incident todfor whichdis an incoming edge.directed_edgeis guaranteed to be a directed edge if itsEdgeTypeisDIRECTED.- Specified by:
getDestin interfaceGraph<V,E>- Specified by:
getDestin interfaceHypergraph<V,E>- Parameters:
directed_edge- the edge whose destination is to be returned- Returns:
- the destination of
directed_edgeif it is a directed edge in this graph, ornullotherwise - See Also:
Graph.getDest(java.lang.Object)
-
getEndpoints
public Pair<V> getEndpoints(E edge)
Description copied from interface:GraphReturns the endpoints ofedgeas aPair.- Specified by:
getEndpointsin interfaceGraph<V,E>- Parameters:
edge- the edge whose endpoints are to be returned- Returns:
- the endpoints (incident vertices) of
edge - See Also:
Graph.getEndpoints(java.lang.Object)
-
getInEdges
public java.util.Collection<E> getInEdges(V vertex)
Description copied from interface:GraphReturns aCollectionview of the incoming edges incident tovertexin this graph.- Specified by:
getInEdgesin interfaceGraph<V,E>- Specified by:
getInEdgesin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose incoming edges are to be returned- Returns:
- a
Collectionview of the incoming edges incident tovertexin this graph - See Also:
Graph.getInEdges(java.lang.Object)
-
getOpposite
public V getOpposite(V vertex, E edge)
Description copied from interface:GraphReturns the vertex at the other end ofedgefromvertex. (That is, returns the vertex incident toedgewhich is notvertex.)- Specified by:
getOppositein interfaceGraph<V,E>- Overrides:
getOppositein classAbstractGraph<V,E>- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
- the vertex at the other end of
edgefromvertex - See Also:
Graph.getOpposite(java.lang.Object, java.lang.Object)
-
getOutEdges
public java.util.Collection<E> getOutEdges(V vertex)
Description copied from interface:GraphReturns aCollectionview of the outgoing edges incident tovertexin this graph.- Specified by:
getOutEdgesin interfaceGraph<V,E>- Specified by:
getOutEdgesin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose outgoing edges are to be returned- Returns:
- a
Collectionview of the outgoing edges incident tovertexin this graph - See Also:
Graph.getOutEdges(java.lang.Object)
-
getPredecessorCount
public int getPredecessorCount(V vertex)
Description copied from interface:GraphReturns the number of predecessors thatvertexhas in this graph. Equivalent tovertex.getPredecessors().size().- Specified by:
getPredecessorCountin interfaceGraph<V,E>- Overrides:
getPredecessorCountin classAbstractGraph<V,E>- Parameters:
vertex- the vertex whose predecessor count is to be returned- Returns:
- 0 if
vertexis the root, -1 if the vertex is not an element of this tree, and 1 otherwise - See Also:
Graph.getPredecessorCount(java.lang.Object)
-
getPredecessors
public java.util.Collection<V> getPredecessors(V vertex)
Description copied from interface:GraphReturns aCollectionview of the predecessors ofvertexin this graph. A predecessor ofvertexis defined as a vertexvwhich is connected tovertexby an edgee, whereeis an outgoing edge ofvand an incoming edge ofvertex.- Specified by:
getPredecessorsin interfaceGraph<V,E>- Specified by:
getPredecessorsin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose predecessors are to be returned- Returns:
- a
Collectionview of the predecessors ofvertexin this graph - See Also:
Graph.getPredecessors(java.lang.Object)
-
getSource
public V getSource(E directed_edge)
Description copied from interface:GraphIfdirected_edgeis a directed edge in this graph, returns the source; otherwise returnsnull. The source of a directed edgedis defined to be the vertex for whichdis an outgoing edge.directed_edgeis guaranteed to be a directed edge if itsEdgeTypeisDIRECTED.- Specified by:
getSourcein interfaceGraph<V,E>- Specified by:
getSourcein interfaceHypergraph<V,E>- Parameters:
directed_edge- the edge whose source is to be returned- Returns:
- the source of
directed_edgeif it is a directed edge in this graph, ornullotherwise - See Also:
Graph.getSource(java.lang.Object)
-
getSuccessorCount
public int getSuccessorCount(V vertex)
Description copied from interface:GraphReturns the number of successors thatvertexhas in this graph. Equivalent tovertex.getSuccessors().size().- Specified by:
getSuccessorCountin interfaceGraph<V,E>- Overrides:
getSuccessorCountin classAbstractGraph<V,E>- Parameters:
vertex- the vertex whose successor count is to be returned- Returns:
- the number of successors that
vertexhas in this graph - See Also:
Graph.getSuccessorCount(java.lang.Object)
-
getSuccessors
public java.util.Collection<V> getSuccessors(V vertex)
Description copied from interface:GraphReturns aCollectionview of the successors ofvertexin this graph. A successor ofvertexis defined as a vertexvwhich is connected tovertexby an edgee, whereeis an incoming edge ofvand an outgoing edge ofvertex.- Specified by:
getSuccessorsin interfaceGraph<V,E>- Specified by:
getSuccessorsin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose predecessors are to be returned- Returns:
- a
Collectionview of the successors ofvertexin this graph - See Also:
Graph.getSuccessors(java.lang.Object)
-
inDegree
public int inDegree(V vertex)
Description copied from interface:GraphReturns the number of incoming edges incident tovertex. Equivalent togetInEdges(vertex).size().- Specified by:
inDegreein interfaceGraph<V,E>- Specified by:
inDegreein interfaceHypergraph<V,E>- Overrides:
inDegreein classAbstractGraph<V,E>- Parameters:
vertex- the vertex whose indegree is to be calculated- Returns:
- the number of incoming edges incident to
vertex - See Also:
Graph.inDegree(java.lang.Object)
-
isDest
public boolean isDest(V vertex, E edge)
Description copied from interface:GraphReturnstrueifvertexis the destination ofedge. Equivalent togetDest(edge).equals(vertex).- Specified by:
isDestin interfaceGraph<V,E>- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
trueiffvertexis the destination ofedge- See Also:
Graph.isDest(java.lang.Object, java.lang.Object)
-
isLeaf
public boolean isLeaf(V vertex)
Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.- Parameters:
vertex- the vertex to be queried- Returns:
trueifoutDegree(vertex)==0
-
isPredecessor
public boolean isPredecessor(V v1, V v2)
Returns true iffv1is the parent ofv2. Note that ifv2is the root andv1isnull, this method returnstrue.- Specified by:
isPredecessorin interfaceGraph<V,E>- Overrides:
isPredecessorin classAbstractGraph<V,E>- Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a predecessor ofv2, and false otherwise.- See Also:
Graph.isPredecessor(java.lang.Object, java.lang.Object)
-
isRoot
public boolean isRoot(V vertex)
Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.- Parameters:
vertex- the vertex to be queried- Returns:
trueifoutDegree(vertex)==0
-
isSource
public boolean isSource(V vertex, E edge)
Description copied from interface:GraphReturnstrueifvertexis the source ofedge. Equivalent togetSource(edge).equals(vertex).- Specified by:
isSourcein interfaceGraph<V,E>- Parameters:
vertex- the vertex to be queriededge- the edge to be queried- Returns:
trueiffvertexis the source ofedge- See Also:
Graph.isSource(java.lang.Object, java.lang.Object)
-
isSuccessor
public boolean isSuccessor(V v1, V v2)
Description copied from interface:GraphReturnstrueifv1is a successor ofv2in this graph. Equivalent tov1.getSuccessors().contains(v2).- Specified by:
isSuccessorin interfaceGraph<V,E>- Overrides:
isSuccessorin classAbstractGraph<V,E>- Parameters:
v1- the first vertex to be queriedv2- the second vertex to be queried- Returns:
trueifv1is a successor ofv2, and false otherwise.- See Also:
Graph.isSuccessor(java.lang.Object, java.lang.Object)
-
outDegree
public int outDegree(V vertex)
Description copied from interface:GraphReturns the number of outgoing edges incident tovertex. Equivalent togetOutEdges(vertex).size().- Specified by:
outDegreein interfaceGraph<V,E>- Specified by:
outDegreein interfaceHypergraph<V,E>- Overrides:
outDegreein classAbstractGraph<V,E>- Parameters:
vertex- the vertex whose outdegree is to be calculated- Returns:
- the number of outgoing edges incident to
vertex - See Also:
Graph.outDegree(java.lang.Object)
-
addEdge
public boolean addEdge(E edge, java.util.Collection<? extends V> vertices, EdgeType edge_type)
Description copied from interface:HypergraphAddsedgeto this graph with typeedge_type. Fails under the following circumstances:edgeis already an element of the graph- either
edgeorverticesisnull verticeshas the wrong number of vertices for the graph typeverticesare already connected by another edge in this graph, and this graph does not accept parallel edgesedge_typeis not legal for this graph
- Specified by:
addEdgein interfaceHypergraph<V,E>- Overrides:
addEdgein classAbstractGraph<V,E>- Parameters:
edge- edge to add to this graphvertices- vertices which are to be connected by this edgeedge_type- type of edge to add- Returns:
trueif the add is successful, andfalseotherwise- See Also:
Hypergraph.addEdge(java.lang.Object, java.util.Collection)
-
addVertex
public boolean addVertex(V vertex)
Description copied from interface:HypergraphAddsvertexto this graph. Fails ifvertexis null or already in the graph.- Specified by:
addVertexin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex to add- Returns:
trueif the add is successful, andfalseotherwise- See Also:
Hypergraph.addVertex(java.lang.Object)
-
isIncident
public boolean isIncident(V vertex, E edge)
Description copied from interface:HypergraphReturnstrueifvertexandedgeare incident to each other. Equivalent togetIncidentEdges(vertex).contains(edge)and togetIncidentVertices(edge).contains(vertex).- Specified by:
isIncidentin interfaceHypergraph<V,E>- Overrides:
isIncidentin classAbstractGraph<V,E>- Parameters:
vertex- vertex to testedge- edge to test- Returns:
trueifvertexandedgeare incident to each other- See Also:
Hypergraph.isIncident(java.lang.Object, java.lang.Object)
-
isNeighbor
public boolean isNeighbor(V v1, V v2)
Description copied from interface:HypergraphReturnstrueifv1andv2share an incident edge. Equivalent togetNeighbors(v1).contains(v2).- Specified by:
isNeighborin interfaceHypergraph<V,E>- Overrides:
isNeighborin classAbstractGraph<V,E>- Parameters:
v1- the first vertex to testv2- the second vertex to test- Returns:
trueifv1andv2share an incident edge- See Also:
Hypergraph.isNeighbor(java.lang.Object, java.lang.Object)
-
containsEdge
public boolean containsEdge(E edge)
Description copied from interface:HypergraphReturns true if this graph's edge collection containsedge. Equivalent togetEdges().contains(edge).- Specified by:
containsEdgein interfaceHypergraph<V,E>- Parameters:
edge- the edge whose presence is being queried- Returns:
- true iff this graph contains an edge
edge - See Also:
Hypergraph.containsEdge(java.lang.Object)
-
containsVertex
public boolean containsVertex(V vertex)
Description copied from interface:HypergraphReturns true if this graph's vertex collection containsvertex. Equivalent togetVertices().contains(vertex).- Specified by:
containsVertexin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose presence is being queried- Returns:
- true iff this graph contains a vertex
vertex - See Also:
Hypergraph.containsVertex(java.lang.Object)
-
findEdge
public E findEdge(V v1, V v2)
Description copied from interface:HypergraphReturns an edge that connects this vertex tov. If this edge is not uniquely defined (that is, if the graph contains more than one edge connectingv1tov2), any of these edges may be returned.findEdgeSet(v1, v2)may be used to return all such edges. Returns null if either of the following is true:v2is not connected tov1- either
v1orv2are not present in this graph
Note: for purposes of this method,
v1is only considered to be connected tov2via a given directed edgeeifv1 == e.getSource() && v2 == e.getDest()evaluates totrue. (v1andv2are connected by an undirected edgeuifuis incident to bothv1andv2.)- Specified by:
findEdgein interfaceHypergraph<V,E>- Overrides:
findEdgein classAbstractGraph<V,E>- Parameters:
v1- the first endpoint of the returned edgev2- the second endpoint of the returned edge- Returns:
- an edge that connects
v1tov2, ornullif no such edge exists (or either vertex is not present) - See Also:
Hypergraph.findEdge(java.lang.Object, java.lang.Object)
-
findEdgeSet
public java.util.Collection<E> findEdgeSet(V v1, V v2)
Description copied from interface:HypergraphReturns all edges that connects this vertex tov. If this edge is not uniquely defined (that is, if the graph contains more than one edge connectingv1tov2), any of these edges may be returned.findEdgeSet(v1, v2)may be used to return all such edges. Returns null ifv2is not connected tov1.
Returns an empty collection if eitherv1orv2are not present in this graph.Note: for purposes of this method,
v1is only considered to be connected tov2via a given directed edgedifv1 == d.getSource() && v2 == d.getDest()evaluates totrue. (v1andv2are connected by an undirected edgeuifuis incident to bothv1andv2.)- Specified by:
findEdgeSetin interfaceHypergraph<V,E>- Overrides:
findEdgeSetin classAbstractGraph<V,E>- Parameters:
v1- the first endpoint of the returned edge setv2- the second endpoint of the returned edge set- Returns:
- a collection containing all edges that connect
v1tov2, ornullif either vertex is not present - See Also:
Hypergraph.findEdgeSet(java.lang.Object, java.lang.Object)
-
getChild
public V getChild(V vertex, int index)
Returns the child ofvertexat positionindexin this tree, ornullif it has no child at that position.- Parameters:
vertex- the vertex to queryindex- the index of the child to return- Returns:
- the child of
vertexat positionindexin this tree, ornullif it has no child at that position - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifindexis not in the range[0, order-1]
-
getEdgeCount
public int getEdgeCount()
Description copied from interface:HypergraphReturns the number of edges in this graph.- Specified by:
getEdgeCountin interfaceHypergraph<V,E>- Returns:
- the number of edges in this graph
- See Also:
Hypergraph.getEdgeCount()
-
getEdges
public java.util.Collection<E> getEdges()
Description copied from interface:HypergraphReturns a view of all edges in this graph. In general, this obeys theCollectioncontract, and therefore makes no guarantees about the ordering of the vertices within the set.- Specified by:
getEdgesin interfaceHypergraph<V,E>- Returns:
- a
Collectionview of all edges in this graph - See Also:
Hypergraph.getEdges()
-
getIncidentCount
public int getIncidentCount(E edge)
Description copied from interface:HypergraphReturns the number of vertices that are incident toedge. For hyperedges, this can be any nonnegative integer; for edges this must be 2 (or 1 if self-loops are permitted).Equivalent to
getIncidentVertices(edge).size().- Specified by:
getIncidentCountin interfaceHypergraph<V,E>- Overrides:
getIncidentCountin classAbstractGraph<V,E>- Parameters:
edge- the edge whose incident vertex count is to be returned- Returns:
- the number of vertices that are incident to
edge. - See Also:
Hypergraph.getIncidentCount(java.lang.Object)
-
getIncidentEdges
public java.util.Collection<E> getIncidentEdges(V vertex)
Description copied from interface:HypergraphReturns the collection of edges in this graph which are connected tovertex.- Specified by:
getIncidentEdgesin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose incident edges are to be returned- Returns:
- the collection of edges which are connected to
vertex, ornullifvertexis not present - See Also:
Hypergraph.getIncidentEdges(java.lang.Object)
-
getIncidentVertices
public java.util.Collection<V> getIncidentVertices(E edge)
Description copied from interface:HypergraphReturns the collection of vertices in this graph which are connected toedge. Note that for some graph types there are guarantees about the size of this collection (i.e., some graphs contain edges that have exactly two endpoints, which may or may not be distinct). Implementations for those graph types may provide alternate methods that provide more convenient access to the vertices.- Specified by:
getIncidentVerticesin interfaceHypergraph<V,E>- Overrides:
getIncidentVerticesin classAbstractGraph<V,E>- Parameters:
edge- the edge whose incident vertices are to be returned- Returns:
- the collection of vertices which are connected to
edge, ornullifedgeis not present - See Also:
Hypergraph.getIncidentVertices(java.lang.Object)
-
getNeighborCount
public int getNeighborCount(V vertex)
Description copied from interface:HypergraphReturns the number of vertices that are adjacent tovertex(that is, the number of vertices that are incident to edges invertex's incident edge set).Equivalent to
getNeighbors(vertex).size().- Specified by:
getNeighborCountin interfaceHypergraph<V,E>- Overrides:
getNeighborCountin classAbstractGraph<V,E>- Parameters:
vertex- the vertex whose neighbor count is to be returned- Returns:
- the number of neighboring vertices
- See Also:
Hypergraph.getNeighborCount(java.lang.Object)
-
getNeighbors
public java.util.Collection<V> getNeighbors(V vertex)
Description copied from interface:HypergraphReturns the collection of vertices which are connected tovertexvia any edges in this graph. Ifvertexis connected to itself with a self-loop, then it will be included in the collection returned.- Specified by:
getNeighborsin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex whose neighbors are to be returned- Returns:
- the collection of vertices which are connected to
vertex, ornullifvertexis not present - See Also:
Hypergraph.getNeighbors(java.lang.Object)
-
getVertexCount
public int getVertexCount()
Description copied from interface:HypergraphReturns the number of vertices in this graph.- Specified by:
getVertexCountin interfaceHypergraph<V,E>- Returns:
- the number of vertices in this graph
- See Also:
Hypergraph.getVertexCount()
-
getVertices
public java.util.Collection<V> getVertices()
Description copied from interface:HypergraphReturns a view of all vertices in this graph. In general, this obeys theCollectioncontract, and therefore makes no guarantees about the ordering of the vertices within the set.- Specified by:
getVerticesin interfaceHypergraph<V,E>- Returns:
- a
Collectionview of all vertices in this graph - See Also:
Hypergraph.getVertices()
-
removeEdge
public boolean removeEdge(E edge)
Description copied from interface:HypergraphRemovesedgefrom this graph. Fails ifedgeis null, or is otherwise not an element of this graph.- Specified by:
removeEdgein interfaceHypergraph<V,E>- Parameters:
edge- the edge to remove- Returns:
trueif the removal is successful,falseotherwise- See Also:
Hypergraph.removeEdge(java.lang.Object)
-
removeVertex
public boolean removeVertex(V vertex)
Description copied from interface:HypergraphRemovesvertexfrom this graph. As a side effect, removes any edgeseincident tovertexif the removal ofvertexwould causeeto be incident to an illegal number of vertices. (Thus, for example, incident hyperedges are not removed, but incident edges--which must be connected to a vertex at both endpoints--are removed.)Fails under the following circumstances:
vertexis not an element of this graphvertexisnull
- Specified by:
removeVertexin interfaceHypergraph<V,E>- Parameters:
vertex- the vertex to remove- Returns:
trueif the removal is successful,falseotherwise- See Also:
Hypergraph.removeVertex(java.lang.Object)
-
addEdge
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType)
Description copied from class:AbstractGraphAddsedgeto this graph with the specifiedendpointsandEdgeType.- Specified by:
addEdgein classAbstractGraph<V,E>- Parameters:
edge- the edge to be addedendpoints- the endpoints to be connected to this edgeedgeType- the type of edge to add- Returns:
- true iff the graph was modified as a result of this call
-
-