Class GeometricGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>

java.lang.Object
com.amalgamasimulation.graph.GraphPath<N,A>
com.amalgamasimulation.graphagent.GeometricGraphPath<N,A>
Type Parameters:
N - type of graph node values
A - type of graph arc values
Direct Known Subclasses:
AgentGraphPath

public class GeometricGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc> extends GraphPath<N,A>
Path from some GeometricGraphPosition to some other, probably equal or adjacent, GeometricGraphPosition.
Author:
Andrey Malykhanov
  • Constructor Details

    • GeometricGraphPath

      public GeometricGraphPath()
      Creates an empty graph path, i.e. a path with no nodes and arcs.
    • GeometricGraphPath

      public GeometricGraphPath(GeometricGraphPosition<N,A> position)
      Creates a trivial zero-length graph path consisting of single position and a trajectory of one point.
      Parameters:
      position - position of start and end of the zero-length movement
    • GeometricGraphPath

      public GeometricGraphPath(Graph<N,A>.Arc arc, double arcBeginAbsOffset, double arcEndAbsOffset)
      Creates a new instance of graph path consisting of a fraction of the single specified arc located between the specified offsets.
      Parameters:
      arc - specified arc
      arcBeginAbsOffset - absolute begin offset along the specified arc
      arcEndAbsOffset - absolute end offset along the specified arc
    • GeometricGraphPath

      public GeometricGraphPath(GraphPath<N,A> path, GeometricGraphPosition<N,A> sourcePosition, GeometricGraphPosition<N,A> destPosition)
      Creates a new instance of graph path by the specified GraphPath
      Parameters:
      path - GraphPath containing graph nodes and arcs of this path
      sourcePosition - source position of this path, i.e. the position after the possible turning around at the very beginning of movement along this path
      destPosition - destination position of this path, i.e. the position before the possible turning around at the very end of movement along this path
    • GeometricGraphPath

      protected GeometricGraphPath(GeometricGraphPath<N,A> otherPath)
  • Method Details

    • of

      @SafeVarargs public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPath<N,A> of(Graph<N,A>.Arc... arcs)
      Creates a new instance of GeometricGraphPath consisting of zero, one, or several consecutive arcs. The source position of the created path is the source node of the first specified arc; the destination position of the created path is the destination node of the last specified arc.

      if the arcs are not consecutive, an IllegalArgumentException is thrown.

      If no arcs are specified, an empty path is created

      Type Parameters:
      N - type of graph node values
      A - type of graph arc values
      Parameters:
      arcs - consecutive arcs, destination node of every arc must be the same as the source node of the next arc
      Returns:
      a new instance of GeometricGraphPath
    • of

      public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPath<N,A> of(GeometricGraphPosition<N,A> position)
      Creates a new zero-length path consisting only of the specified position.
      Type Parameters:
      N - type of graph node values
      A - type of graph arc values
      Parameters:
      position - position which the created path consists of
      Returns:
      a new instance of GeometricGraphPath
    • of

      public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPath<N,A> of(Graph<N,A>.Node node)
      Creates a new zero-length path consisting only of a position at the specified node.
      Type Parameters:
      N - type of graph node values
      A - type of graph arc values
      Parameters:
      node - node of the position which the created path consists of
      Returns:
      a new instance of GeometricGraphPath
    • of

      public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPath<N,A> of(List<Graph<N,A>.Arc> arcs)
      Creates a new instance of GeometricGraphPath consisting of zero, one, or several consecutive arcs. The source position of the created path is the source node of the first specified arc; the destination position of the created path is the destination node of the last specified arc.

      if the arcs are not consecutive, an IllegalArgumentException is thrown.

      If no arcs are specified, an empty path is created

      Type Parameters:
      N - type of graph node values
      A - type of graph arc values
      Parameters:
      arcs - list of consecutive arcs, destination node of every arc must be the same as the source node of the next arc
      Returns:
      a new instance of GeometricGraphPath
    • addNode

      public GeometricGraphPath<N,A> addNode(Graph<N,A>.Node node)
      Description copied from class: GraphPath
      Adds the specified node to this path if this path is empty, otherwise throws a IllegalArgumentException.
      Overrides:
      addNode in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      node - specified node
      Returns:
      reference to this instance, for convenience of building new instances
    • appendArc

      public GeometricGraphPath<N,A> appendArc(Graph<N,A>.Arc arc)
      Appends the specified arc and its destination node to this path. Source node of the specified arc must be the same as the last node of this path, otherwise a IllegalArgumentException is thrown.

      If this arc is empty, simply adds the specified arc and both nodes to this path.

      Sets the destination position of path equal to the destination node of the specified arc.

      If the path is empty, then the source position of the path is also set equal to the source node of the specified arc.

      Overrides:
      appendArc in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      arc - arc being appended to this path
      Returns:
      reference to this instance, for convenience of building new instances
    • prependArc

      public GeometricGraphPath<N,A> prependArc(Graph<N,A>.Arc arc)
      Prepends the specified arc and its source node to this path. Destination node of the specified arc must be the same as the first node of this path, otherwise a IllegalArgumentException is thrown.

      If this arc is empty, simply adds the specified arc and both nodes to this path.

      Sets the source position of path equal to the source node of the specified arc.

      If the path is empty, then the destination position of the path is also set equal to the destination node of the specified arc.

      Overrides:
      prependArc in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      arc - arc being prepended to this path
      Returns:
      reference to this instance, for convenience of building new instances
    • append

      public GeometricGraphPath<N,A> append(GraphPath<N,A> otherPath)
      Appends the specified other path to this path. This path gets mutated as result of call to this method.

      The source position of the specified other path must be the same as the destination position of this path, otherwise an IllegalArgumentException is thrown.

      Overrides:
      append in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      otherPath - other path being appended to this one
      Returns:
      reference to this instance, for convenience of building new instances
    • prepend

      public GeometricGraphPath<N,A> prepend(GraphPath<N,A> otherPath)
      Prepends the specified other path to this path. This path gets mutated as result of call to this method.

      The destination position of the specified other path must be the same as the source position of this path, otherwise an IllegalArgumentException is thrown.

      Overrides:
      prepend in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      otherPath - other path being prepended to this one
      Returns:
      reference to this instance, for convenience of building new instances
    • getArcRecords

      public List<GeometricGraphArcRecord<N,A>> getArcRecords()
      Returns an unmodifiable list of GeometricGraphArcRecord instances each of which describes every consecutive arc or arc fragment of this path.
      Returns:
      List of GeometricGraphArcRecord instances
    • getLengthAlongArc

      public double getLengthAlongArc(Graph<N,A>.Arc arc)
    • getSourcePosition

      public GeometricGraphPosition<N,A> getSourcePosition()
      Returns the source position of this path.
      Returns:
      source position of this path
    • getDestPosition

      public GeometricGraphPosition<N,A> getDestPosition()
      Returns the destination position of this path.
      Returns:
      destination position of this path
    • getPolyline

      public Polyline getPolyline()
      Returns the Polyline representing the trajectory of this path.
      Returns:
      Polyline representing the trajectory of this path
    • getPositionAtOffset

      public GeometricGraphPosition<N,A> getPositionAtOffset(double absoluteOffset)
      Returns a GeometricGraphPosition pointing to the position at the specified absolute offset from the beginning of this path.

      If the specified absolute offset is negative or greater than the length of this path's trajectory, an IllegalArgumentException will be thrown.

      Parameters:
      absoluteOffset - absolute offset from the beginning of this path
      Returns:
      GeometricGraphPosition pointing to the position at the specified absolute offset from the beginning of this path
    • getReversePath

      public GeometricGraphPath<N,A> getReversePath(Graph<N,A> graph)
      Returns a reverse path of this path, i.e. the path along all the opposite arcs in the reversed order.

      If this path contains at least one arc that does not have a reverse arc, a IllegalStateException will be thrown

      If this path is a zero-length path, the returned path will also be a zero-length path

      Returns:
      a new instance of GeometricGraphPath() that is reverse path of this one
    • getSubPathBetweenOffsets

      public GeometricGraphPath<N,A> getSubPathBetweenOffsets(double beginAbsOffset, double endAbsOffset)
      Returns a new instance of GeometricGraphPath() that is a sub-path of this path between the specified absolute offsets.
      • If beginAbsOffset == endAbsOffset, returns a zero-length path consisting of the position at the specified offset
      • If beginAbsOffset == 0 and endAbsOffset equals the length of this path, returns a copy of this path
      • If this path is a zero-length path, and both arguments are zeros, returns a copy of this path
      Parameters:
      beginAbsOffset - absolute offset from the beginning of this path where the returned sub-path begins
      endAbsOffset - absolute offset from the beginning of this path where the returned sub-path ends
      Returns:
      new instance of GeometricGraphPath() that is a sub-path of this path between the specified absolute offsets
      Throws:
      IllegalArgumentException - if endAbsOffset < beginAbsOffset
      IllegalArgumentException - if either of the specified absolute offsets is negative or greater than the length of this path's trajectory
    • containsPosition

      public boolean containsPosition(GeometricGraphPosition<N,A> position)
      Checks whether this path contains the specified position, i.e. the specified position belongs to this path. Reverse position is not checked by this method, if this is required, containsPositionOrReverse(GeometricGraphPosition, Graph) method should be used.
      Parameters:
      position - specified position
      Returns:
      true if this path contains the specified position, false otherwise
      See Also:
    • containsPositionOrReverse

      public boolean containsPositionOrReverse(GeometricGraphPosition<N,A> position, Graph<N,A> graph)
      Checks whether this path contains the specified position, i.e. the specified position belongs to this path. Allows to include or exclude the checking of the reverse position.
      Parameters:
      position - specified position
      graph - graph which this position belongs to, necessary for determining reverse arcs
      Returns:
      true if this path contains the specified position or its reverse position, false otherwise
      See Also:
    • getLength

      public double getLength()
      Returns the length of this path, i.e. the length of trajectory of this path. Length of an empty path is zero
      Returns:
      length of this path
    • getSubPath

      public GeometricGraphPath<N,A> getSubPath(Interval absOffsets)
      Returns a new instance of GeometricGraphPath() that is a sub-path of this path between the absolute offsets specified by the Interval instance.

      If the intersection between Interval.of(0, this.getLegth()) and the specified interval is empty, returns an empty path. Never returns null.

      Parameters:
      absOffsets - absolute offsets of the returned sub-path
      Returns:
      new instance of GeometricGraphPath() that is a sub-path of this path between the absolute offsets specified by the interval, possibly empty
      See Also:
    • getSubPaths

      public List<GeometricGraphPath<N,A>> getSubPaths(IntervalLike absOffsets)
      Returns a list of sub-paths specified by a set of intervals of absolute offsets. The returned list contains sub-paths as GeometricGraphPath() instances sorted by the begin absolute offset of every sub-path.

      If the intersection between Interval.of(0, this.getLegth()) and the specified interval or interval set is empty, returns an empty list. Never returns null.

      Parameters:
      absOffsets - IntervalLike instance specifying interval or interval set specifying absolute offsets of the returned sub-paths
      Returns:
      a list of sub-paths specified by a set of intervals, possibly empty
      See Also:
    • getIntersectionOffsets

      public IntervalSet getIntersectionOffsets(GeometricGraphPath<N,A> otherPath)
      Returns an IntervalSet instance representing intervals of absolute offsets where this path intersects with the specified other path. When detecting intersection, includes only the cases when arcs of both paths are co-directed and does not consider reverse arcs of the other path.

      If this path and the specified other one do not intersect, returns an IntervalSet.EMPTY.

      The returned interval set can contain zero length intervals that represent the cases where this path touches the other path at some graph node.

      Parameters:
      otherPath - the path with which we are searching the intersection
      Returns:
      an IntervalSet instance representing absolute offsets where this path intersects with the specified other path
      See Also:
    • getIntersection

      public List<GeometricGraphPath<N,A>> getIntersection(GeometricGraphPath<N,A> otherPath, Graph<N,A> graph)
      Returns a list of sub-paths representing fragments of this path where it intersects with the specified other path. When detecting intersection, includes only the cases when arcs of both paths are co-directed and does not consider reverse arcs of the other path. The returned list contains sub-paths of this path as GeometricGraphPath() instances sorted by the begin absolute offset of every sub-path.

      If this path and the specified other one do not intersect, returns an empty list.

      The returned list can contain zero length paths that represent the cases where this path touches the other path at some graph node.

      Parameters:
      otherPath - the path with which we are searching the intersection
      Returns:
      list of sub-paths representing fragments of this path where it intersects with the specified other path, possibly empty
      See Also:
    • containsNode

      public boolean containsNode(N value)
      Description copied from class: GraphPath
      Checks if the path contains the specified value in its nodes.
      Overrides:
      containsNode in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
      Parameters:
      value - The specified value
      Returns:
      True if the graph contains the specified value, false otherwise
    • getIntersectionOffsetsIgnoreDirection

      public IntervalSet getIntersectionOffsetsIgnoreDirection(GeometricGraphPath<N,A> otherPath, Graph<N,A> graph)
      Returns an IntervalSet instance representing intervals of absolute offsets where this path intersects with the specified other path. When detecting intersection, includes the cases when this path intersect with a reverse arc (or its respective reverse part) of the specified path. In other words, ignores direction of the other path when detecting the intersection.

      If this path and the specified other one do not intersect, returns an IntervalSet.EMPTY.

      The returned interval set can contain zero length intervals that represent the cases where this path touches the other path at some graph node.

      Parameters:
      otherPath - the path with which we are searching the intersection
      graph - graph which this path belongs to, necessary for determining reverse arcs
      Returns:
      an IntervalSet instance representing absolute offsets where this path intersects with the specified other path, ignoring the direction of the other path's arcs
      See Also:
    • hasNonZeroIntersectionIgnoreDirection

      public boolean hasNonZeroIntersectionIgnoreDirection(GeometricGraphPath<N,A> otherPath, Graph<N,A> graph)
      Checks whether this path has a non-zero length intersection with the specified other path, ignoring the direction of the paths' arcs. In other words, checks whether the two paths actually overlap but not just touch each other at some points.

      Ignoring direction means that intersection is detected not only on the same arcs but also on their respective reverse arcs.

      This method is intended for fast existence checks. If the actual intersection offsets or intersecting sub-paths are required, use getIntersectionOffsetsIgnoreDirection(GeometricGraphPath, Graph) and getIntersectionIgnoreDirection(GeometricGraphPath, Graph) methods.

      Parameters:
      otherPath - the path with which we are checking the intersection
      graph - graph which this path belongs to, necessary for determining reverse arcs
      Returns:
      true if this path contains a non-zero length intersection with the specified other path, ignoring the direction of the other path's arcs; false otherwise
      See Also:
    • hasNonZeroIntersection

      public boolean hasNonZeroIntersection(GeometricGraphPath<N,A> otherPath)
      Checks whether this path has a non-zero length intersection with the other specified path, considering the direction on bi-directional arcs, if any. In other words, checks whether the two paths actually overlap but not just touch each other at some points.

      Considering direction means that intersection is detected only when both paths overlap along the same arcs in the same direction.

      This method is intended for fast existence checks. If the actual intersection offsets or intersecting sub-paths are required, use getIntersectionOffsets(GeometricGraphPath) and getIntersection(GeometricGraphPath, Graph) methods.

      Parameters:
      otherPath - specified path
      Returns:
      true if this path contains non-zero length intersection with the other specified path, false otherwise
      See Also:
    • getIntersectionIgnoreDirection

      public List<GeometricGraphPath<N,A>> getIntersectionIgnoreDirection(GeometricGraphPath<N,A> otherPath, Graph<N,A> graph)
      Returns a list of sub-paths representing fragments of this path where it intersects with the specified other path. When detecting intersection, includes the cases when this path intersect with a reverse arc (or its respective reverse part) of the specified path. In other words, ignores direction of the other path when detecting the intersection.

      The returned list contains sub-paths of this path as GeometricGraphPath() instances sorted by the begin absolute offset of every sub-path.

      If this path and the specified other one do not intersect, returns an empty list.

      The returned list can contain zero length paths that represent the cases where this path touches the other path at some graph node.

      Parameters:
      otherPath - the path with which we are searching the intersection
      graph - graph which this path belongs to, necessary for determining reverse arcs
      Returns:
      list of sub-paths representing fragments of this path where it intersects with the specified other path, possibly empty
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
    • toString

      public String toString()
      Overrides:
      toString in class GraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>