Package org.planit.graph
Class GraphImpl<V extends Vertex,E extends Edge>
- java.lang.Object
-
- org.planit.graph.GraphImpl<V,E>
-
- All Implemented Interfaces:
GraphModifier<V,E>
,Graph<V,E>
- Direct Known Subclasses:
DirectedGraphImpl
public class GraphImpl<V extends Vertex,E extends Edge> extends Object implements Graph<V,E>, GraphModifier<V,E>
A graph implementation consisting of vertices and edges- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Edges<E>
edges
class instance containing all edgesprotected GraphBuilder<V,E>
graphBuilder
Graph builder responsible for constructing all graph related (derived) instancesprotected Vertices<V>
vertices
class instance containing all vertices
-
Constructor Summary
Constructors Constructor Description GraphImpl(IdGroupingToken groupId, GraphBuilder<V,E> graphBuilder)
Graph Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<Long,Set<E>>
breakEdgesAt(List<? extends E> edgesToBreak, V vertexToBreakAt)
Break the passed in edges by inserting the passed in vertex in between.Edges<E>
getEdges()
collect edges of graphIdGroupingToken
getGraphIdGroupingToken()
Collect the id grouping token used for all entities registered on the graph, i.e., this network's specific identifier for generating ids unique and contiguous within this network and this network onlylong
getId()
collect the id of this graphVertices<V>
getVertices()
collect vertices of graphprotected Set<V>
processSubNetworkVertex(V referenceVertex)
helper function for subnetwork identification (deliberately NOT recursive to avoid stack overflow on large networks)void
recreateIds()
this method will recreate all ids of the graph's main components, e.g., vertices, edges, and potentially other eligible components of derived graph implementations.void
removeDanglingSubGraphs(Integer belowsize, Integer abovesize, boolean alwaysKeepLargest)
remove any dangling subgraphs below a given size from the graph if they exist and subsequently reorder the internal ids if neededvoid
removeSubGraph(Set<? extends V> subGraphToRemove, boolean recreateIds)
remove the subgraph identified by the passed in verticesvoid
removeSubGraphOf(V referenceVertex, boolean recreateIds)
remove the (sub)graph in which the passed in vertex resides.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.planit.utils.graph.Graph
transformGeometries, validate
-
Methods inherited from interface org.planit.graph.GraphModifier
removeDanglingSubGraphs
-
-
-
-
Field Detail
-
graphBuilder
protected final GraphBuilder<V extends Vertex,E extends Edge> graphBuilder
Graph builder responsible for constructing all graph related (derived) instances
-
-
Constructor Detail
-
GraphImpl
public GraphImpl(IdGroupingToken groupId, GraphBuilder<V,E> graphBuilder)
Graph Constructor- Parameters:
groupId
- contiguous id generation within this group for instances of this classgraphBuilder
- the builder to be used to create this network
-
-
Method Detail
-
processSubNetworkVertex
protected Set<V> processSubNetworkVertex(V referenceVertex) throws PlanItException
helper function for subnetwork identification (deliberately NOT recursive to avoid stack overflow on large networks)- Parameters:
referenceVertex
- to process- Returns:
- all vertices in the subnetwork connected to passed in reference vertex
- Throws:
PlanItException
- thrown if parameters are null
-
getId
public long getId()
collect the id of this graph
-
getGraphIdGroupingToken
public IdGroupingToken getGraphIdGroupingToken()
Collect the id grouping token used for all entities registered on the graph, i.e., this network's specific identifier for generating ids unique and contiguous within this network and this network only- Returns:
- the graph id grouping token
-
removeDanglingSubGraphs
public void removeDanglingSubGraphs(Integer belowsize, Integer abovesize, boolean alwaysKeepLargest) throws PlanItException
remove any dangling subgraphs below a given size from the graph if they exist and subsequently reorder the internal ids if needed- Specified by:
removeDanglingSubGraphs
in interfaceGraphModifier<V extends Vertex,E extends Edge>
- Parameters:
belowsize
- remove subgraphs below the given sizeabovesize
- remove subgraphs above the given size (typically set to maximum value)alwaysKeepLargest
- indicate if the largest of the subgraphs is always to be kept even if it does not match the criteria- Throws:
PlanItException
- thrown if error
-
removeSubGraph
public void removeSubGraph(Set<? extends V> subGraphToRemove, boolean recreateIds)
remove the subgraph identified by the passed in vertices- Specified by:
removeSubGraph
in interfaceGraphModifier<V extends Vertex,E extends Edge>
- Parameters:
subGraphToRemove
- the one to removerecreateIds
- indicate if the ids of the graph entities are to be recreated, if false gaps will occur so it is expected to be handled by the user afterwards in this case
-
removeSubGraphOf
public void removeSubGraphOf(V referenceVertex, boolean recreateIds) throws PlanItException
remove the (sub)graph in which the passed in vertex resides. Apply reordering of internal ids of remaining network.- Specified by:
removeSubGraphOf
in interfaceGraphModifier<V extends Vertex,E extends Edge>
- Parameters:
referenceVertex
- to identify subnetwork byrecreateIds
- indicate if the ids of the graph entities are to be recreated, if false gaps will occur so it is expected to be handled by the user afterwards in this case- Throws:
PlanItException
- thrown if error
-
breakEdgesAt
public Map<Long,Set<E>> breakEdgesAt(List<? extends E> edgesToBreak, V vertexToBreakAt) throws PlanItException
Break the passed in edges by inserting the passed in vertex in between. After completion the original edges remain as (VertexA,VertexToBreakAt), and new edges are inserted for (VertexToBreakAt,VertexB).- Specified by:
breakEdgesAt
in interfaceGraphModifier<V extends Vertex,E extends Edge>
- Parameters:
edgesToBreak
- the links to breakvertexToBreakAt
- the node to break at- Returns:
- affectedEdges the list of all result edges of the breaking of links by their original link id
- Throws:
PlanItException
- thrown if error
-
recreateIds
public void recreateIds()
this method will recreate all ids of the graph's main components, e.g., vertices, edges, and potentially other eligible components of derived graph implementations. Can be used in conjunctions with the removal of subgraphs in case the recreation of ids was switched off manually for some reason.- Specified by:
recreateIds
in interfaceGraphModifier<V extends Vertex,E extends Edge>
-
-