package org.opentrafficsim.road.network.lane; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.djutils.event.TimedEventType; import org.djutils.exceptions.Throw; import org.djutils.exceptions.Try; import org.djutils.metadata.MetaData; import org.djutils.metadata.ObjectDescriptor; import org.opentrafficsim.core.geometry.OTSLine3D; import org.opentrafficsim.core.geometry.OTSPoint3D; import org.opentrafficsim.core.network.LinkType; import org.opentrafficsim.core.network.NetworkException; import org.opentrafficsim.core.network.OTSLink; import org.opentrafficsim.core.network.OTSNetwork; import org.opentrafficsim.road.network.OTSRoadNetwork; import org.opentrafficsim.road.network.RoadNetwork; import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy; import org.opentrafficsim.core.geometry.DirectedPoint; /** * A CrossSectionLink is a link with lanes where GTUs can possibly switch between lanes. *
* 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.
*
* $LastChangedDate: 2015-09-16 19:20:07 +0200 (Wed, 16 Sep 2015) $, @version $Revision: 1405 $, by $Author: averbraeck $,
* initial version Aug 19, 2014
* Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 12 dec. 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Guus Tamminga
*/
public class CrossSectionLink extends OTSLink implements Serializable
{
/** */
private static final long serialVersionUID = 20141015L;
/** List of cross-section elements. */
private final List
* Payload: Object[] { String networkId, String linkId, String LaneId, int laneNumber }
* TODO work in a different way with lane numbers to align to standard lane numbering.
*/
public static final TimedEventType LANE_ADD_EVENT = new TimedEventType("LINK.LANE.ADD",
new MetaData("Lane data", "Lane data",
new ObjectDescriptor[] { new ObjectDescriptor("Network id", "Network id", String.class),
new ObjectDescriptor("Link id", "Link id", String.class),
new ObjectDescriptor("Lane id", "Lane id", String.class),
new ObjectDescriptor("Lane number", "Lane number", Integer.class) }));
/**
* The (regular, not timed) event type for pub/sub indicating the removal of a Lane from a CrossSectionLink.
* Payload: Object[] { String networkId, String linkId, String LaneId }
* TODO allow for the removal of a Lane; currently this is not possible.
*/
public static final TimedEventType LANE_REMOVE_EVENT = new TimedEventType("LINK.LANE.REMOVE",
new MetaData("Lane data", "Lane data",
new ObjectDescriptor[] { new ObjectDescriptor("Network id", "Network id", String.class),
new ObjectDescriptor("Link id", "Link id", String.class),
new ObjectDescriptor("Lane id", "Lane id", String.class),
new ObjectDescriptor("Lane number", "Lane number", Integer.class) }));
/**
* Construction of a cross section link.
* @param network OTSRoadNetwork; the network
* @param id String; the link id.
* @param startNode OTSRoadNode; the start node (directional).
* @param endNode OTSRoadNode; the end node (directional).
* @param linkType LinkType; the link type
* @param designLine OTSLine3D; the design line of the Link
* @param laneKeepingPolicy LaneKeepingPolicy; the policy to generally keep left, keep right, or keep lane
* @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
* or the end node of the link are not registered in the network.
*/
@SuppressWarnings("checkstyle:parameternumber")
public CrossSectionLink(final OTSRoadNetwork network, final String id, final OTSRoadNode startNode,
final OTSRoadNode endNode, final LinkType linkType, final OTSLine3D designLine,
final LaneKeepingPolicy laneKeepingPolicy) throws NetworkException
{
super(network, id, startNode, endNode, linkType, designLine);
this.laneKeepingPolicy = laneKeepingPolicy;
}
/**
* Clone a CrossSectionLink for a new network.
* @param newNetwork Network; the new network to which the clone belongs
* @param link CrossSectionLink; the link to clone from
* @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
* or the end node of the link are not registered in the network.
*/
protected CrossSectionLink(final OTSRoadNetwork newNetwork, final CrossSectionLink link) throws NetworkException
{
super(newNetwork, link);
this.laneKeepingPolicy = link.laneKeepingPolicy;
for (CrossSectionElement cse : link.crossSectionElementList)
{
cse.clone(this, newNetwork.getSimulator());
// the CrossSectionElement will add itself to the Link (OTS-237)
}
}
/** {@inheritDoc} */
@Override
public OTSRoadNetwork getNetwork()
{
return (OTSRoadNetwork) super.getNetwork();
}
/**
* Add a cross section element at the end of the list.
* Note: LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction.
* @param cse CrossSectionElement; the cross section element to add.
*/
protected final void addCrossSectionElement(final CrossSectionElement cse)
{
this.crossSectionElementList.add(cse);
if (cse instanceof Lane)
{
this.lanes.add((Lane) cse);
fireTimedEvent(LANE_ADD_EVENT, new Object[] { getNetwork().getId(), getId(), cse.getId(), this.lanes.indexOf(cse) },
getSimulator().getSimulatorTime());
}
}
/**
* Retrieve a safe copy of the cross section element list.
* @return List<CrossSectionElement>; the cross section element list.
*/
public final List
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public enum Priority
{
/** Traffic has priority. */
PRIORITY,
/** No priority. */
NONE,
/** Turn on red. */
TURN_ON_RED,
/** Yield. */
YIELD,
/** Need to stop. */
STOP,
/** Priority according to all-stop rules. */
ALL_STOP,
/** Priority at bus stop, i.e. bus has right of way if it wants to leave the bus stop. */
BUS_STOP;
/**
* Returns whether this is priority.
* @return whether this is priority
*/
public boolean isPriority()
{
return this.equals(PRIORITY);
}
/**
* Returns whether this is none.
* @return whether this is none
*/
public boolean isNone()
{
return this.equals(NONE);
}
/**
* Returns whether this is turn on red.
* @return whether this is turn on red
*/
public boolean isTurnOnRed()
{
return this.equals(TURN_ON_RED);
}
/**
* Returns whether this is yield.
* @return whether this is yield
*/
public boolean isYield()
{
return this.equals(YIELD);
}
/**
* Returns whether this is stop.
* @return whether this is stop
*/
public boolean isStop()
{
return this.equals(STOP);
}
/**
* Returns whether this is all-stop.
* @return whether this is all-stop
*/
public boolean isAllStop()
{
return this.equals(ALL_STOP);
}
/**
* Returns whether this is bus stop.
* @return whether this is bus stop
*/
public boolean isBusStop()
{
return this.equals(BUS_STOP);
}
}
}