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>>
iterationNotOrientedElementComparator
Comparator of graph iteration element on not-oriented segments.protected Comparator<GraphIterationElement<ST,PT>>
iterationOrientedElementComparator
Comparator of graph iteration element on oriented segments.
-
Constructor Summary
Constructors Modifier Constructor Description protected
SubGraph(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 aWeakArrayList
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
build(GraphIterator<ST,PT> iterator)
Build a subgraph from the specified graph.void
build(GraphIterator<ST,PT> iterator, SubGraphBuildListener<ST,PT> listener)
Build a subgraph from the specified graph.boolean
contains(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.int
getPointCount()
Replies the count of points in this graph.int
getSegmentCount()
Replies the count of segments in this graph.boolean
isEmpty()
Replies if this graph is empty or not.protected boolean
isTerminalPoint(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 PT
wrapPoint(PT point, ST segment, boolean isTerminal)
Create a wrapping point for the given graph point.protected ST
wrapSegment(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 aWeakArrayList
instance.- 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
SubGraph
class 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:
true
if 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
segment
itself.
-
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
point
itself.
-
isEmpty
@Pure public boolean isEmpty()
Description copied from interface:Graph
Replies if this graph is empty or not.- Specified by:
isEmpty
in interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>
- Returns:
true
if the graph is empty, otherwisefalse
.
-
contains
@Pure public boolean contains(Object obj)
Description copied from interface:Graph
Replies is this graph contains the given segment. The test is based onObject.equals(Object)
.- Specified by:
contains
in interfaceGraph<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>
- Parameters:
obj
- the object to search for.- Returns:
true
if the graph contains the segment, otherwisefalse
.
-
getSegmentCount
@Pure public final int getSegmentCount()
Description copied from interface:Graph
Replies the count of segments in this graph.- Specified by:
getSegmentCount
in 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:Graph
Replies the count of points in this graph.- Specified by:
getPointCount
in 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:Graph
Replies 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:
depthIterator
in 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 betrue
to allow to reply many times the same segment, otherwhisefalse
.assumeOrientedSegments
- may betrue
to 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 isfalse
to 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:Graph
Replies 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:
iterator
in 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 betrue
to allow to reply many times the same segment, otherwhisefalse
.assumeOrientedSegments
- may betrue
to 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 isfalse
to assume that the end points of a segment are not distinguished.- Returns:
- the iterator.
-
-