Class GeometricGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
- Type Parameters:
N- type of graph node valuesA- type of graph arc values
- Direct Known Subclasses:
AgentGraphPath
GeometricGraphPosition to some other, probably equal
or adjacent, GeometricGraphPosition.- Author:
- Andrey Malykhanov
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an empty graph path, i.e.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.GeometricGraphPath(GraphPath<N, A> path, GeometricGraphPosition<N, A> sourcePosition, GeometricGraphPosition<N, A> destPosition) Creates a new instance of graph path by the specifiedGraphPathprotectedGeometricGraphPath(GeometricGraphPath<N, A> otherPath) GeometricGraphPath(GeometricGraphPosition<N, A> position) Creates a trivial zero-length graph path consisting of single position and a trajectory of one point. -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified node to this path if this path is empty, otherwise throws aIllegalArgumentException.Appends the specified other path to this path.Appends the specified arc and its destination node to this path.booleancontainsNode(N value) Checks if the path contains the specified value in its nodes.booleancontainsPosition(GeometricGraphPosition<N, A> position) Checks whether this path contains the specified position, i.e.booleancontainsPositionOrReverse(GeometricGraphPosition<N, A> position, Graph<N, A> graph) Checks whether this path contains the specified position, i.e.booleanReturns an unmodifiable list ofGeometricGraphArcRecordinstances each of which describes every consecutive arc or arc fragment of this path.Returns the destination position of this path.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.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.getIntersectionOffsets(GeometricGraphPath<N, A> otherPath) Returns anIntervalSetinstance representing intervals of absolute offsets where this path intersects with the specified other path.getIntersectionOffsetsIgnoreDirection(GeometricGraphPath<N, A> otherPath, Graph<N, A> graph) Returns anIntervalSetinstance representing intervals of absolute offsets where this path intersects with the specified other path.doubleReturns the length of this path, i.e.doublegetLengthAlongArc(Graph<N, A>.Arc arc) Returns thePolylinerepresenting the trajectory of this path.getPositionAtOffset(double absoluteOffset) Returns aGeometricGraphPositionpointing to the position at the specified absolute offset from the beginning of this path.getReversePath(Graph<N, A> graph) Returns a reverse path of this path, i.e.Returns the source position of this path.getSubPath(Interval absOffsets) Returns a new instance ofGeometricGraphPath()that is a sub-path of this path between the absolute offsets specified by theIntervalinstance.getSubPathBetweenOffsets(double beginAbsOffset, double endAbsOffset) Returns a new instance ofGeometricGraphPath()that is a sub-path of this path between the specified absolute offsets.getSubPaths(IntervalLike absOffsets) Returns a list of sub-paths specified by a set of intervals of absolute offsets.inthashCode()booleanhasNonZeroIntersection(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.booleanhasNonZeroIntersectionIgnoreDirection(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.static <N extends GeometricGraphNode,A extends GeometricGraphArc>
GeometricGraphPath<N, A> Creates a new instance ofGeometricGraphPathconsisting of zero, one, or several consecutive arcs.static <N extends GeometricGraphNode,A extends GeometricGraphArc>
GeometricGraphPath<N, A> Creates a new zero-length path consisting only of a position at the specified node.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.static <N extends GeometricGraphNode,A extends GeometricGraphArc>
GeometricGraphPath<N, A> Creates a new instance ofGeometricGraphPathconsisting of zero, one, or several consecutive arcs.Prepends the specified other path to this path.prependArc(Graph<N, A>.Arc arc) Prepends the specified arc and its source node to this path.toString()Methods inherited from class com.amalgamasimulation.graph.GraphPath
containsArc, emptyPath, getArc, getArcs, getArcsCount, getCopy, getFirstArc, getFirstNode, getLastArc, getLastNode, getNextArc, getNode, getNodes, getNodesCount, getPrevArc, getSubPath, getSubPathFrom, getSubPathTo, isEmpty
-
Constructor Details
-
GeometricGraphPath
public GeometricGraphPath()Creates an empty graph path, i.e. a path with no nodes and arcs. -
GeometricGraphPath
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
Creates a new instance of graph path consisting of a fraction of the single specified arc located between the specified offsets.- Parameters:
arc- specified arcarcBeginAbsOffset- absolute begin offset along the specified arcarcEndAbsOffset- 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 specifiedGraphPath- Parameters:
path-GraphPathcontaining graph nodes and arcs of this pathsourcePosition- source position of this path, i.e. the position after the possible turning around at the very beginning of movement along this pathdestPosition- destination position of this path, i.e. the position before the possible turning around at the very end of movement along this path
-
GeometricGraphPath
-
-
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 ofGeometricGraphPathconsisting 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
IllegalArgumentExceptionis thrown.If no arcs are specified, an empty path is created
- Type Parameters:
N- type of graph node valuesA- 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 valuesA- 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 valuesA- 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 ofGeometricGraphPathconsisting 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
IllegalArgumentExceptionis thrown.If no arcs are specified, an empty path is created
- Type Parameters:
N- type of graph node valuesA- 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
Description copied from class:GraphPathAdds the specified node to this path if this path is empty, otherwise throws aIllegalArgumentException.- Overrides:
addNodein classGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc> - Parameters:
node- specified node- Returns:
- reference to this instance, for convenience of building new instances
-
appendArc
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 aIllegalArgumentExceptionis 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:
appendArcin classGraphPath<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
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 aIllegalArgumentExceptionis 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:
prependArcin classGraphPath<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
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
IllegalArgumentExceptionis thrown.- Overrides:
appendin classGraphPath<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
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
IllegalArgumentExceptionis thrown.- Overrides:
prependin classGraphPath<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
Returns an unmodifiable list ofGeometricGraphArcRecordinstances each of which describes every consecutive arc or arc fragment of this path.- Returns:
- List of
GeometricGraphArcRecordinstances
-
getLengthAlongArc
-
getSourcePosition
Returns the source position of this path.- Returns:
- source position of this path
-
getDestPosition
Returns the destination position of this path.- Returns:
- destination position of this path
-
getPolyline
Returns thePolylinerepresenting the trajectory of this path.- Returns:
Polylinerepresenting the trajectory of this path
-
getPositionAtOffset
Returns aGeometricGraphPositionpointing 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
IllegalArgumentExceptionwill be thrown.- Parameters:
absoluteOffset- absolute offset from the beginning of this path- Returns:
GeometricGraphPositionpointing to the position at the specified absolute offset from the beginning of this path
-
getReversePath
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
IllegalStateExceptionwill be thrownIf 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
Returns a new instance ofGeometricGraphPath()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 beginsendAbsOffset- 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- ifendAbsOffset < beginAbsOffsetIllegalArgumentException- if either of the specified absolute offsets is negative or greater than the length of this path's trajectory
-
containsPosition
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:
trueif this path contains the specified position,falseotherwise- See Also:
-
containsPositionOrReverse
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 positiongraph- graph which this position belongs to, necessary for determining reverse arcs- Returns:
trueif this path contains the specified position or its reverse position,falseotherwise- 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
Returns a new instance ofGeometricGraphPath()that is a sub-path of this path between the absolute offsets specified by theIntervalinstance.If the intersection between
Interval.of(0, this.getLegth())and the specified interval is empty, returns an empty path. Never returnsnull.- 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
Returns a list of sub-paths specified by a set of intervals of absolute offsets. The returned list contains sub-paths asGeometricGraphPath()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 returnsnull.- Parameters:
absOffsets-IntervalLikeinstance 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
Returns anIntervalSetinstance 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
IntervalSetinstance 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 asGeometricGraphPath()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
Description copied from class:GraphPathChecks if the path contains the specified value in its nodes.- Overrides:
containsNodein classGraphPath<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 anIntervalSetinstance 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 intersectiongraph- graph which this path belongs to, necessary for determining reverse arcs- Returns:
- an
IntervalSetinstance 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)andgetIntersectionIgnoreDirection(GeometricGraphPath, Graph)methods.- Parameters:
otherPath- the path with which we are checking the intersectiongraph- graph which this path belongs to, necessary for determining reverse arcs- Returns:
trueif this path contains a non-zero length intersection with the specified other path, ignoring the direction of the other path's arcs;falseotherwise- See Also:
-
hasNonZeroIntersection
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)andgetIntersection(GeometricGraphPath, Graph)methods.- Parameters:
otherPath- specified path- Returns:
trueif this path contains non-zero length intersection with the other specified path,falseotherwise- 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 intersectiongraph- 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
- Overrides:
equalsin classGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
-
hashCode
public int hashCode()- Overrides:
hashCodein classGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
-
toString
- Overrides:
toStringin classGraphPath<N extends GeometricGraphNode,A extends GeometricGraphArc>
-