package org.opentrafficsim.road.gtu.lane.perception; import java.util.Map; import java.util.SortedSet; import org.djunits.value.vdouble.scalar.Length; import org.opentrafficsim.core.gtu.GTUException; import org.opentrafficsim.core.gtu.GTUType; import org.opentrafficsim.core.gtu.RelativePosition; import org.opentrafficsim.core.network.route.Route; import org.opentrafficsim.road.gtu.lane.LaneBasedGTU; import org.opentrafficsim.road.network.lane.DirectedLanePosition; import org.opentrafficsim.road.network.lane.object.LaneBasedObject; /** * Interface for lane structures. *

* Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version 13 aug. 2018
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel */ public interface LaneStructure { /** * Updates the underlying structure shifting the root position to the input. * @param pos DirectedLanePosition; current position of the GTU * @param route Route; current route of the GTU * @param gtuType GTUType; GTU type * @throws GTUException on a problem while updating the structure */ void update(DirectedLanePosition pos, Route route, GTUType gtuType) throws GTUException; /** * Returns the root record. * @return LaneRecord; root record */ LaneStructureRecord getRootRecord(); /** * Returns the extended cross-section, which includes all lanes for which a first record is present. * @return SortedSet; the cross-section */ SortedSet getExtendedCrossSection(); /** * Returns the first record on the given lane. This is often a record in the current cross section, but it may be one * downstream for a lane that starts further downstream. * @param lane RelativeLane; lane * @return first record on the given lane, or {@code null} if no such record */ LaneStructureRecord getFirstRecord(RelativeLane lane); /** * Retrieve objects of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the * relative position, or as far as the lane structure goes. * @param clazz Class<T>; class of objects to find * @param gtu LaneBasedGTU; gtu * @param pos RelativePosition.TYPE; relative position to start search from * @param type of objects to find * @return Map; sorted set of objects of requested type per lane * @throws GTUException if lane is not in current set */ Map>> getDownstreamObjects(Class clazz, LaneBasedGTU gtu, RelativePosition.TYPE pos) throws GTUException; /** * Retrieve objects on a lane of a specific type. Returns objects over a maximum length of the look ahead distance * downstream from the relative position, or as far as the lane structure goes. * @param lane RelativeLane; lane * @param clazz Class<T>; class of objects to find * @param gtu LaneBasedGTU; gtu * @param pos RelativePosition.TYPE; relative position to start search from * @param type of objects to find * @return SortedSet; sorted set of objects of requested type * @throws GTUException if lane is not in current set */ SortedSet> getDownstreamObjects(RelativeLane lane, Class clazz, LaneBasedGTU gtu, RelativePosition.TYPE pos) throws GTUException; /** * Retrieve objects of a specific type. Returns objects over a maximum length of the look ahead distance downstream from the * relative position, or as far as the lane structure goes. Objects on links not on the route are ignored. * @param clazz Class<T>; class of objects to find * @param gtu LaneBasedGTU; gtu * @param pos RelativePosition.TYPE; relative position to start search from * @param type of objects to find * @param route Route; the route * @return SortedSet; sorted set of objects of requested type per lane * @throws GTUException if lane is not in current set */ Map>> getDownstreamObjectsOnRoute(Class clazz, LaneBasedGTU gtu, RelativePosition.TYPE pos, Route route) throws GTUException; /** * Retrieve objects on a lane of a specific type. Returns objects over a maximum length of the look ahead distance * downstream from the relative position, or as far as the lane structure goes. Objects on links not on the route are * ignored. * @param lane RelativeLane; lane * @param clazz Class<T>; class of objects to find * @param gtu LaneBasedGTU; gtu * @param pos RelativePosition.TYPE; relative position to start search from * @param type of objects to find * @param route Route; the route * @return SortedSet; sorted set of objects of requested type * @throws GTUException if lane is not in current set */ SortedSet> getDownstreamObjectsOnRoute(RelativeLane lane, Class clazz, LaneBasedGTU gtu, RelativePosition.TYPE pos, Route route) throws GTUException; /** * Retrieve objects on a lane of a specific type. Returns upstream objects from the relative position for as far as the lane * structure goes. Distances to upstream objects are given as positive values. * @param lane RelativeLane; lane * @param clazz Class<T>; class of objects to find * @param gtu LaneBasedGTU; gtu * @param pos RelativePosition.TYPE; relative position to start search from * @param type of objects to find * @return SortedSet; sorted set of objects of requested type * @throws GTUException if lane is not in current set */ SortedSet> getUpstreamObjects(RelativeLane lane, Class clazz, LaneBasedGTU gtu, RelativePosition.TYPE pos) throws GTUException; /** * Wrapper to hold lane-based object and it's distance. *

* Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. *
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 15, 2016
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel * @param class of lane based object contained */ class Entry implements Comparable> { /** Distance to lane based object. */ private final Length distance; /** Lane based object. */ private final T laneBasedObject; /** * @param distance Length; distance to lane based object * @param laneBasedObject T; lane based object */ public Entry(final Length distance, final T laneBasedObject) { this.distance = distance; this.laneBasedObject = laneBasedObject; } /** * @return distance. */ public final Length getDistance() { return this.distance; } /** * @return laneBasedObject. */ public final T getLaneBasedObject() { return this.laneBasedObject; } /** {@inheritDoc} */ @Override public final int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.distance == null) ? 0 : this.distance.hashCode()); result = prime * result + ((this.laneBasedObject == null) ? 0 : this.laneBasedObject.hashCode()); return result; } /** {@inheritDoc} */ @Override public final boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Entry other = (Entry) obj; if (this.distance == null) { if (other.distance != null) { return false; } } else if (!this.distance.equals(other.distance)) { return false; } if (this.laneBasedObject == null) { if (other.laneBasedObject != null) { return false; } } // laneBasedObject does not implement equals... else if (!this.laneBasedObject.equals(other.laneBasedObject)) { return false; } return true; } /** {@inheritDoc} */ @Override public final int compareTo(final Entry arg) { int d = this.distance.compareTo(arg.distance); if (d != 0 || this.laneBasedObject.equals(arg.laneBasedObject)) { return d; // different distance (-1 or 1), or same distance but also equal lane based object (0) } return 1; // same distance, unequal lane based object (1) } /** {@inheritDoc} */ @Override public final String toString() { return "LaneStructure.Entry [distance=" + this.distance + ", laneBasedObject=" + this.laneBasedObject + "]"; } } }