Class GraphIterator<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>

  • Type Parameters:
    PT - is the type of node in the graph
    ST - is the type of edge in the graph
    All Implemented Interfaces:
    Iterator<ST>
    Direct Known Subclasses:
    DepthGraphIterator, RoadNetworkIterator

    public class GraphIterator<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
    extends Object
    implements Iterator<ST>
    This class is an iterator on a graph.

    The behaviour of the iterator is strongly influenced by the constructor's parameters. The two most important parameters are allowManyReplies and assumeOrientedSegments.

    The allowManyReplies parameter indicates if a segment could be replied many types, or not, by the iterator. This parameter permits to control the behaviour of the iterator against graph cycles.

    The assumeOrientedSegments parameter indicates how the segments are considered by the iterator. If assumeOrientedSegments is true it means that a segment reached by one of its end point is different than the same segment reached by the other end point. If assumeOrientedSegments is false it means that the end points of the segments are not take into account. This parameter is usefull only if allowManyReplies is set to false.

    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
    • Constructor Detail

      • GraphIterator

        public GraphIterator​(Graph<ST,​PT> graph1,
                             ST segment,
                             PT point,
                             boolean allowManyReplies1,
                             boolean assumeOrientedSegments1,
                             double distanceToReachStartingPoint)
        Constructor.
        Parameters:
        graph1 - is the graph associated to this iterator.
        segment - is the segment from which to start.
        point - is the segment's point indicating the direction.
        allowManyReplies1 - may be true to allow to reply many times the same segment, otherwhise false.
        assumeOrientedSegments1 - may be true 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 is false to assume that the end points of a segment are not distinguished.
        distanceToReachStartingPoint - is the distance to reach the starting point. It must be negative or nul.
      • GraphIterator

        public GraphIterator​(Graph<ST,​PT> graph1,
                             GraphCourseModel<ST,​PT> courseModel1,
                             ST segment,
                             PT point,
                             boolean allowManyReplies1,
                             boolean assumeOrientedSegments1,
                             double distanceToReachStartingPoint)
        Constructor.
        Parameters:
        graph1 - is the graph associated to this iterator.
        courseModel1 - is the course model to use.
        segment - is the segment from which to start.
        point - is the segment's point indicating the direction.
        allowManyReplies1 - may be true to allow to reply many times the same segment, otherwhise false.
        assumeOrientedSegments1 - may be true 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 is false to assume that the end points of a segment are not distinguished.
        distanceToReachStartingPoint - is the distance to reach the starting point. It must be negative or nul.
      • GraphIterator

        protected GraphIterator​(Graph<ST,​PT> graph1,
                                GraphCourseModel<ST,​PT> courseModel,
                                ST segment,
                                PT point,
                                boolean allowManyReplies,
                                boolean assumeOrientedSegments,
                                double distanceToReachStartingPoint,
                                double distanceToConsumeAfter,
                                DynamicDepthUpdater<ST,​PT> dynamicDepthUpdater)
        Constructor.
        Parameters:
        graph1 - is the graph associated to this iterator.
        courseModel - is the course model to use.
        segment - is the segment from which to start.
        point - is the segment's point indicating the direction.
        allowManyReplies - may be true to allow to reply many times the same segment, otherwhise false.
        assumeOrientedSegments - may be true 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 is false to assume that the end points of a segment are not distinguished.
        distanceToReachStartingPoint - is the distance to reach the starting point.
        distanceToConsumeAfter - is the distance to consume after traversing the segment. It must be negative or nul.
        dynamicDepthUpdater - if not null, it is used to dynamically update the distanceToConsumeAfter.
    • Method Detail

      • createVisitedSegmentComparator

        @Pure
        protected Comparator<GraphIterationElement<ST,​PT>> createVisitedSegmentComparator​(boolean assumeOrientedSegments1)
        Invoked when a comparator on visited segments is required.
        Parameters:
        assumeOrientedSegments1 - may be true 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 is false to assume that the end points of a segment are not distinguished.
        Returns:
        the graph element iterator, or null to use the default comparation behaviour of the GraphIterationElement.
      • getGraph

        @Pure
        Graph<ST,​PT> getGraph()
        Replies the graph on which this iterator is iterating.
        Returns:
        the graph.
      • clear

        void clear()
        Clear the temporary buffers of this graph iterator.
      • getNextSegments

        protected final Iterable<GraphIterationElement<ST,​PT>> getNextSegments​(boolean avoid_visited_segments,
                                                                                     GraphIterationElement<ST,​PT> element)
        Replies the next segments.
        Parameters:
        avoid_visited_segments - is true to avoid to reply already visited segments, otherwise false
        element - is the element from which the next segments must be replied.
        Returns:
        the list of the following segments
        See Also:
        next()
      • getNextElement

        protected GraphIterationElement<ST,​PT> getNextElement()
        Replies the next element without removing it from the iterator list.
        Returns:
        the next element without removing it from the iterator list.
      • nextElement

        public final GraphIterationElement<ST,​PT> nextElement()
        Replies the next segment.
        Returns:
        the next segment
      • newIterationElement

        protected GraphIterationElement<ST,​PT> newIterationElement​(ST previousSegment,
                                                                         ST segment,
                                                                         PT point,
                                                                         boolean fromStartPoint,
                                                                         double distanceToReach,
                                                                         double distanceToConsume)
        Create an instance of GraphIterationElement.
        Parameters:
        previousSegment - is the previous element that permits to reach this object during an iteration
        segment - is the current segment
        point - is the point on which the iteration arrived on the current segment.
        fromStartPoint - indicates if the current search is reached from its start point. This parameter is useful when the current segment is connected to the same road connected with its start point and its end point.
        distanceToReach - is the distance that is already consumed to reach the segment.
        distanceToConsume - is the rest of distance to consume including the segment.
        Returns:
        a graph iteration element.
      • canGotoIntoElement

        @Pure
        protected boolean canGotoIntoElement​(GraphIterationElement<ST,​PT> element)
        Replies if the specified element could be added into the list of futher elements.
        Parameters:
        element - the element to test.
        Returns:
        true if the given element is addable into the associated list.
      • ignoreElementsAfter

        public void ignoreElementsAfter​(GraphIterationElement<ST,​PT> element)
        Ignore the elements after the specified element.
        Parameters:
        element - the reference element.
      • ignoreElementsAfter

        public void ignoreElementsAfter()
        Ignore the elements after the specified element.
      • isManySegmentReplyEnabled

        @Pure
        public final boolean isManySegmentReplyEnabled()
        Replies if this iterator is assumed that a segment may be replied many times.
        Returns:
        true if this iterator allows cycles, otherwise false
      • isOrientedSegmentSupportEnabled

        @Pure
        public final boolean isOrientedSegmentSupportEnabled()
        Replies if this iterator is assumed oriented segments or not.
        Returns:
        true if this iterator assumes oriented segments, otherwise false