Package org.arakhne.afc.math.graph
Class SubGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>,GP extends GraphPath<GP,ST,PT>>
- java.lang.Object
-
- org.arakhne.afc.math.graph.SubGraph<ST,PT,GP>
-
- Type Parameters:
PT- is the type of node in the graphST- is the type of edge in the graphGP- is the type of graph path
- Direct Known Subclasses:
SubRoadNetwork
public class SubGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>,GP extends GraphPath<GP,ST,PT>> extends Object implements Graph<ST,PT>
A subgraph.The segments is the subgraph are weak references to the segments to the complete graph.
- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:42
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathgraph
-
-
Field Summary
Fields Modifier and Type Field Description protected Comparator<GraphIterationElement<ST,PT>>iterationNotOrientedElementComparatorComparator of graph iteration element on not-oriented segments.protected Comparator<GraphIterationElement<ST,PT>>iterationOrientedElementComparatorComparator of graph iteration element on oriented segments.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSubGraph(Collection<ST> segments1, int pointNumber1, Comparator<GraphIterationElement<ST,PT>> orientedIterator, Comparator<GraphIterationElement<ST,PT>> notOrientedIterator)Constructor.SubGraph(GraphIterationElementComparator<ST,PT> orientedIterator, GraphIterationElementComparator<ST,PT> notOrientedIterator)Build a subgraph in which graph segments are stored inside aWeakArrayListinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuild(GraphIterator<ST,PT> iterator)Build a subgraph from the specified graph.voidbuild(GraphIterator<ST,PT> iterator, SubGraphBuildListener<ST,PT> listener)Build a subgraph from the specified graph.booleancontains(Object obj)Replies is this graph contains the given segment.GraphIterator<ST,PT>depthIterator(ST startingSegment, double depth, double positionFromStartingPoint, PT startingPoint, boolean allowManyReplies, boolean assumeOrientedSegments, DynamicDepthUpdater<ST,PT> dynamicDepthUpdater)Replies an iterator that permits to move along the segment's graph starting from the specified segment and from the specified starting point.protected Collection<ST>getGraphSegments()Replies the segments in this subgraph.protected Graph<ST,PT>getParentGraph()Replies the parent graph is this subgraph was built.intgetPointCount()Replies the count of points in this graph.intgetSegmentCount()Replies the count of segments in this graph.booleanisEmpty()Replies if this graph is empty or not.protected booleanisTerminalPoint(PT point)Replies if the given point is a terminal point.Iterator<ST>iterator()GraphIterator<ST,PT>iterator(ST startingSegment, PT startingPoint, boolean allowManyReplies, boolean assumeOrientedSegments)Replies an iterator that permits to move along the road segment's graph starting from this road segment and from the specified starting point.protected PTwrapPoint(PT point, ST segment, boolean isTerminal)Create a wrapping point for the given graph point.protected STwrapSegment(ST segment)Create a wrapping segment for the given graph segment.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.arakhne.afc.math.graph.Graph
depthIterator
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
iterationOrientedElementComparator
protected final Comparator<GraphIterationElement<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>> iterationOrientedElementComparator
Comparator of graph iteration element on oriented segments.
-
iterationNotOrientedElementComparator
protected final Comparator<GraphIterationElement<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>> iterationNotOrientedElementComparator
Comparator of graph iteration element on not-oriented segments.
-
-
Constructor Detail
-
SubGraph
protected SubGraph(Collection<ST> segments1, int pointNumber1, Comparator<GraphIterationElement<ST,PT>> orientedIterator, Comparator<GraphIterationElement<ST,PT>> notOrientedIterator)
Constructor.- Parameters:
segments1- is the collection to use to store the segments.pointNumber1- is the number of connection points in the subgraph described by thesegments.orientedIterator- is a comparator which may be used by this subgraph.notOrientedIterator- is a comparator which may be used by this subgraph.
-
SubGraph
public SubGraph(GraphIterationElementComparator<ST,PT> orientedIterator, GraphIterationElementComparator<ST,PT> notOrientedIterator)
Build a subgraph in which graph segments are stored inside aWeakArrayListinstance.- Parameters:
orientedIterator- is a comparator which may be used by this subgraph.notOrientedIterator- is a comparator which may be used by this subgraph.
-
-
Method Detail
-
getParentGraph
@Pure protected final Graph<ST,PT> getParentGraph()
Replies the parent graph is this subgraph was built.- Returns:
- the parent graph or
null
-
getGraphSegments
@Pure protected final Collection<ST> getGraphSegments()
Replies the segments in this subgraph.Caution: the replied collection is the real reference to the internal collection. Any change in this collection outside this
SubGraphclass may causes invalid behaviour (no event...).- Returns:
- the internal data structure that contains all the segments in this subgraph.
-
build
public final void build(GraphIterator<ST,PT> iterator)
Build a subgraph from the specified graph.- Parameters:
iterator- is the iterator on the graph.
-
build
public final void build(GraphIterator<ST,PT> iterator, SubGraphBuildListener<ST,PT> listener)
Build a subgraph from the specified graph.- Parameters:
iterator- is the iterator on the graph.listener- is the listener invoked each time a segment was added to the subgraph.
-
isTerminalPoint
@Pure protected final boolean isTerminalPoint(PT point)
Replies if the given point is a terminal point.- Parameters:
point- the point to test.- Returns:
trueif the point is terminal otherwisefalse
-
wrapSegment
@Pure protected ST wrapSegment(ST segment)
Create a wrapping segment for the given graph segment.- Parameters:
segment- the segment to wrap.- Returns:
- a wrapping segment or the
segmentitself.
-
wrapPoint
@Pure protected PT wrapPoint(PT point, ST segment, boolean isTerminal)
Create a wrapping point for the given graph point.- Parameters:
point- the point to wrap.segment- is the segment connected to the point.isTerminal- indicates if this point should be a terminal point.- Returns:
- a wrapping point or the
pointitself.
-
isEmpty
@Pure public boolean isEmpty()
Description copied from interface:GraphReplies if this graph is empty or not.- Specified by:
isEmptyin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Returns:
trueif the graph is empty, otherwisefalse.
-
contains
@Pure public boolean contains(Object obj)
Description copied from interface:GraphReplies is this graph contains the given segment. The test is based onObject.equals(Object).- Specified by:
containsin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Parameters:
obj- the object to search for.- Returns:
trueif the graph contains the segment, otherwisefalse.
-
getSegmentCount
@Pure public final int getSegmentCount()
Description copied from interface:GraphReplies the count of segments in this graph.- Specified by:
getSegmentCountin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Returns:
- the count of segments in this graph.
-
getPointCount
@Pure public final int getPointCount()
Description copied from interface:GraphReplies the count of points in this graph.- Specified by:
getPointCountin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Returns:
- the count of points in this graph.
-
depthIterator
@Pure public GraphIterator<ST,PT> depthIterator(ST startingSegment, double depth, double positionFromStartingPoint, PT startingPoint, boolean allowManyReplies, boolean assumeOrientedSegments, DynamicDepthUpdater<ST,PT> dynamicDepthUpdater)
Description copied from interface:GraphReplies an iterator that permits to move along the segment's graph starting from the specified segment and from the specified starting point. If the specified starting point is not one of the ends of the segment, this function assumes to start from the point replied byGraphSegment.getBeginPoint().This function does not allow the cycles during the iterations.
- Specified by:
depthIteratorin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Parameters:
startingSegment- is the first segment to iterate.depth- is the maximal depth to reach.positionFromStartingPoint- is the starting position from thestartingPoint.startingPoint- is the starting point of the iterations.allowManyReplies- may betrueto allow to reply many times the same segment, otherwhisefalse.assumeOrientedSegments- may betrueto assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalseto assume that the end points of a segment are not distinguished.dynamicDepthUpdater- if notnull, it is a lambda that is used for dynamically updating the maximal depth.- Returns:
- the iterator.
- See Also:
Graph.depthIterator(GraphSegment, double, double, GraphPoint, boolean, boolean)
-
iterator
@Pure public GraphIterator<ST,PT> iterator(ST startingSegment, PT startingPoint, boolean allowManyReplies, boolean assumeOrientedSegments)
Description copied from interface:GraphReplies an iterator that permits to move along the road segment's graph starting from this road segment and from the specified starting point.- Specified by:
iteratorin interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>- Parameters:
startingSegment- is the first segment to iterate.startingPoint- is the starting point of the iterations.allowManyReplies- may betrueto allow to reply many times the same segment, otherwhisefalse.assumeOrientedSegments- may betrueto assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalseto assume that the end points of a segment are not distinguished.- Returns:
- the iterator.
-
-