File |
Line |
org\opentrafficsim\graphs\FundamentalDiagram.java |
296 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java |
286 |
sample.addData(gtu.getSpeed());
}
/**
* Set up a JFreeChart axis.
* @param valueAxis ValueAxis; the axis to set up
* @param axis Axis; the Axis that provides the data to setup the ValueAxis
*/
private static void configureAxis(final ValueAxis valueAxis, final Axis axis)
{
valueAxis.setLabel("\u2192 " + axis.getName());
valueAxis.setRange(axis.getMinimumValue().getInUnit(), axis.getMaximumValue().getInUnit());
}
/**
* Redraw this TrajectoryGraph (after the underlying data has been changed, or to change axes).
*/
public final void reGraph()
{
NumberAxis numberAxis = new NumberAxis();
configureAxis(numberAxis, this.xAxis);
this.chartPanel.getXYPlot().setDomainAxis(numberAxis);
this.chartPanel.getPlot().axisChanged(new AxisChangeEvent(numberAxis));
numberAxis = new NumberAxis();
configureAxis(numberAxis, this.yAxis);
this.chartPanel.getXYPlot().setRangeAxis(numberAxis);
this.chartPanel.getPlot().axisChanged(new AxisChangeEvent(numberAxis));
notifyListeners(new DatasetChangeEvent(this, null)); // This guess work actually works!
}
/**
* Notify interested parties of an event affecting this TrajectoryPlot.
* @param event DatasetChangedEvent
*/
private void notifyListeners(final DatasetChangeEvent event)
{
for (DatasetChangeListener dcl : this.listenerList.getListeners(DatasetChangeListener.class))
{
dcl.datasetChanged(event);
}
}
/** {@inheritDoc} */
@Override
public final int getSeriesCount()
{
return 1;
}
/** {@inheritDoc} */
@Override
public final Comparable<Integer> getSeriesKey(final int series)
{
return series;
}
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public final int indexOf(final Comparable seriesKey)
{
if (seriesKey instanceof Integer)
{
return (Integer) seriesKey;
}
return -1;
}
/** {@inheritDoc} */
@Override
public final void addChangeListener(final DatasetChangeListener listener)
{
this.listenerList.add(DatasetChangeListener.class, listener);
}
/** {@inheritDoc} */
@Override
public final void removeChangeListener(final DatasetChangeListener listener)
{
this.listenerList.remove(DatasetChangeListener.class, listener);
}
/** {@inheritDoc} */
@Override
public final DatasetGroup getGroup()
{
return this.datasetGroup;
}
/** {@inheritDoc} */
@Override
public final void setGroup(final DatasetGroup group)
{
this.datasetGroup = group;
}
/** {@inheritDoc} */
@Override
public final DomainOrder getDomainOrder()
{
return DomainOrder.ASCENDING;
}
/** {@inheritDoc} */
@Override
public final int getItemCount(final int series)
{
return this.samples.size();
}
/**
* Retrieve a value from the recorded samples.
* @param item Integer; the rank number of the sample
* @param axis Axis; the axis that determines which quantity to retrieve
* @return Double; the requested value, or Double.NaN if the sample does not (yet) exist
*/
private Double getSample(final int item, final Axis axis)
{
if (item >= this.samples.size())
{
return Double.NaN;
}
double result = this.samples.get(item).getValue(axis);
/*-
System.out.println(String.format("getSample(item=%d, axis=%s) returns %f", item, axis.name,
result));
*/
return result;
}
/** {@inheritDoc} */
@Override
public final Number getX(final int series, final int item)
{
return getXValue(series, item);
}
/** {@inheritDoc} */
@Override
public final double getXValue(final int series, final int item)
{
return getSample(item, this.xAxis);
}
/** {@inheritDoc} */
@Override
public final Number getY(final int series, final int item)
{
return getYValue(series, item);
}
/** {@inheritDoc} */
@Override
public final double getYValue(final int series, final int item)
{
return getSample(item, this.yAxis);
}
/** {@inheritDoc} */
@Override |
File |
Line |
org\opentrafficsim\road\gtu\lane\perception\categories\DefaultSimplePerception.java |
645 |
org\opentrafficsim\road\gtu\lane\perception\categories\NeighborsPerception.java |
665 |
}
/**************************************************************************************************************************/
/**************************************************** HEADWAY ALGORITHMS **************************************************/
/**************************************************************************************************************************/
/**
* Determine which GTU is in front of this GTU. This method looks in all lanes where this GTU is registered, and not further
* than the value of the given maxDistance. The minimum headway is returned of all Lanes where the GTU is registered. When
* no GTU is found within the given maxDistance, a HeadwayGTU with <b>null</b> as the gtuId and maxDistance as the distance
* is returned. The search will extend into successive lanes if the maxDistance is larger than the remaining length on the
* lane. When Lanes (or underlying CrossSectionLinks) diverge, a route planner may be used to determine which kinks and
* lanes to take into account and which ones not. When the Lanes (or underlying CrossSectionLinks) converge, "parallel"
* traffic is not taken into account in the headway calculation. Instead, gap acceptance algorithms or their equivalent
* should guide the merging behavior.<br>
* <b>Note:</b> Headway is the net headway and calculated on a front-to-back basis.
* @param maxDistance the maximum distance to look for the nearest GTU; positive values search forwards; negative values
* search backwards
* @return HeadwayGTU; the headway and the GTU information
* @throws GTUException when there is an error with the next lanes in the network.
* @throws NetworkException when there is a problem with the route planner
*/
private Headway forwardHeadway(final Length maxDistance) throws GTUException, NetworkException
{
LanePathInfo lpi = getLanePathInfo();
return forwardHeadway(lpi, maxDistance);
}
/**
* Determine which GTU is in front of this GTU. This method uses a given lanePathInfo to look forward, but not further than
* the value of the given maxDistance. The minimum headway is returned of all Lanes where the GTU is registered. When no GTU
* is found within the given maxDistance, a HeadwayGTU with <b>null</b> as the gtuId and maxDistance as the distance is
* returned. The search will extend into successive lanes if the maxDistance is larger than the remaining length on the
* lane. When Lanes (or underlying CrossSectionLinks) diverge, a route planner may be used to determine which kinks and
* lanes to take into account and which ones not. When the Lanes (or underlying CrossSectionLinks) converge, "parallel"
* traffic is not taken into account in the headway calculation. Instead, gap acceptance algorithms or their equivalent
* should guide the merging behavior.<br>
* <b>Note:</b> Headway is the net headway and calculated on a front-to-back basis.
* @param lpi the lanePathInfo object that informs the headway algorithm in which lanes to look, and from which position on
* the first lane.
* @param maxDistance the maximum distance to look for the nearest GTU; positive values search forwards; negative values
* search backwards
* @return HeadwayGTU; the headway and the GTU information
* @throws GTUException when there is an error with the next lanes in the network.
* @throws NetworkException when there is a problem with the route planner
*/
private Headway forwardHeadway(final LanePathInfo lpi, final Length maxDistance) throws GTUException, NetworkException
{
Throw.when(maxDistance.le(Length.ZERO), GTUException.class, "forwardHeadway: maxDistance should be positive");
int ldIndex = 0;
LaneDirection ld = lpi.getReferenceLaneDirection();
double gtuPosFrontSI = lpi.getReferencePosition().si;
if (lpi.getReferenceLaneDirection().getDirection().isPlus())
{
gtuPosFrontSI += getGtu().getFront().getDx().si;
}
else
{
gtuPosFrontSI -= getGtu().getFront().getDx().si;
}
// TODO end of lanepath
while ((gtuPosFrontSI > ld.getLane().getLength().si || gtuPosFrontSI < 0.0)
&& ldIndex < lpi.getLaneDirectionList().size() - 1)
{
ldIndex++;
if (ld.getDirection().isPlus()) // e.g. 1005 on length of lane = 1000
{
if (lpi.getLaneDirectionList().get(ldIndex).getDirection().isPlus())
{
gtuPosFrontSI -= ld.getLane().getLength().si;
}
else
{
gtuPosFrontSI = lpi.getLaneDirectionList().get(ldIndex).getLane().getLength().si - gtuPosFrontSI;
}
ld = lpi.getLaneDirectionList().get(ldIndex);
}
else
// e.g. -5 on lane of whatever length
{
if (lpi.getLaneDirectionList().get(ldIndex).getDirection().isPlus())
{
gtuPosFrontSI += ld.getLane().getLength().si;
}
else
{
gtuPosFrontSI += lpi.getLaneDirectionList().get(ldIndex).getLane().getLength().si;
}
ld = lpi.getLaneDirectionList().get(ldIndex);
}
} |
File |
Line |
org\opentrafficsim\road\gtu\lane\perception\categories\DefaultSimplePerception.java |
849 |
org\opentrafficsim\road\gtu\lane\perception\categories\NeighborsPerception.java |
822 |
}
/**
* Calculate the minimum headway, possibly on subsequent lanes, in backward direction (so between our back, and the other
* GTU's front). Note: this method returns a POSITIVE number.
* @param lane the lane where we are looking right now
* @param direction the direction we are driving on that lane
* @param lanePositionSI from which position on this lane do we start measuring? This is the current position of the rear of
* the GTU when we measure in the lane where the original GTU is positioned, and lane.getLength() for each
* subsequent lane.
* @param cumDistanceSI the distance we have already covered searching on previous lanes. Note: This is a POSITIVE number.
* @param maxDistanceSI the maximum distance to look for in SI units; stays the same in subsequent calls. Note: this is a
* POSITIVE number.
* @param when the current or future time for which to calculate the headway
* @return the headway in SI units when we have found the GTU, or a null GTU with a distance of Double.MAX_VALUE meters when
* no other GTU could not be found within maxDistanceSI meters
* @throws GTUException when there is a problem with the geometry of the network
*/
private Headway headwayRecursiveBackwardSI(final Lane lane, final GTUDirectionality direction, final double lanePositionSI,
final double cumDistanceSI, final double maxDistanceSI, final Time when) throws GTUException
{
LaneBasedGTU otherGTU =
lane.getGtuBehind(new Length(lanePositionSI, LengthUnit.SI), direction, RelativePosition.FRONT, when);
if (otherGTU != null)
{
double distanceM = cumDistanceSI + lanePositionSI - otherGTU.position(lane, otherGTU.getFront(), when).getSI();
if (distanceM > 0 && distanceM <= maxDistanceSI)
{
return new HeadwayGTUSimple(otherGTU.getId(), otherGTU.getGTUType(), new Length(distanceM, LengthUnit.SI),
otherGTU.getLength(), otherGTU.getSpeed(), null);
}
return new HeadwayDistance(Double.MAX_VALUE);
}
// Continue search on predecessor lanes.
if (cumDistanceSI + lanePositionSI < maxDistanceSI)
{
// is there a predecessor link?
if (lane.prevLanes(getGtu().getGTUType()).size() > 0)
{
Headway foundMaxGTUDistanceSI = new HeadwayDistance(Double.MAX_VALUE);
for (Lane prevLane : lane.prevLanes(getGtu().getGTUType()).keySet())
{
// What is behind us is INDEPENDENT of the followed route!
double traveledDistanceSI = cumDistanceSI + lanePositionSI;
// WRONG - adapt method to forward perception method!
Headway closest = headwayRecursiveBackwardSI(prevLane, direction, prevLane.getLength().getSI(),
traveledDistanceSI, maxDistanceSI, when);
if (closest.getDistance().si < maxDistanceSI
&& closest.getDistance().si < foundMaxGTUDistanceSI.getDistance().si)
{
foundMaxGTUDistanceSI = closest;
}
}
return foundMaxGTUDistanceSI;
}
}
// No other GTU was not on one of the current lanes or their successors.
return new HeadwayDistance(Double.MAX_VALUE);
} |
File |
Line |
org\opentrafficsim\road\gtu\lane\perception\categories\DefaultSimplePerception.java |
807 |
org\opentrafficsim\road\gtu\lane\perception\categories\NeighborsPerception.java |
785 |
}
/**
* Determine which GTU is behind this GTU. This method looks in all lanes where this GTU is registered, and not further back
* than the absolute value of the given maxDistance. The minimum net headway is returned of all Lanes where the GTU is
* registered. When no GTU is found within the given maxDistance, <b>null</b> is returned. The search will extend into
* successive lanes if the maxDistance is larger than the remaining length on the lane. When Lanes (or underlying
* CrossSectionLinks) diverge, the headway algorithms have to look at multiple Lanes and return the minimum headway in each
* of the Lanes. When the Lanes (or underlying CrossSectionLinks) converge, "parallel" traffic is not taken into account in
* the headway calculation. Instead, gap acceptance algorithms or their equivalent should guide the merging behavior.<br>
* <b>Note:</b> Headway is the net headway and calculated on a back-to-front basis.
* @param maxDistance the maximum distance to look for the nearest GTU; it should have a negative value to search backwards
* @return HeadwayGTU; the headway and the GTU information
* @throws GTUException when there is an error with the next lanes in the network.
* @throws NetworkException when there is a problem with the route planner
*/
private Headway backwardHeadway(final Length maxDistance) throws GTUException, NetworkException
{
Throw.when(maxDistance.ge(Length.ZERO), GTUException.class, "backwardHeadway: maxDistance should be negative");
Time time = getGtu().getSimulator().getSimulatorTime().getTime();
double maxDistanceSI = maxDistance.si;
Headway foundHeadway = new HeadwayDistance(-maxDistanceSI);
for (Lane lane : getGtu().positions(getGtu().getRear()).keySet())
{
Headway closest = headwayRecursiveBackwardSI(lane, getGtu().getDirection(lane),
getGtu().position(lane, getGtu().getRear(), time).getSI(), 0.0, -maxDistanceSI, time);
if (closest.getDistance().si < -maxDistanceSI && closest.getDistance().si < -foundHeadway.getDistance().si)
{
foundHeadway = closest;
}
}
if (foundHeadway instanceof AbstractHeadwayGTU)
{
return new HeadwayGTUSimple(foundHeadway.getId(), ((AbstractHeadwayGTU) foundHeadway).getGtuType(),
foundHeadway.getDistance().multiplyBy(-1.0), foundHeadway.getLength(), foundHeadway.getSpeed(), null);
} |
File |
Line |
org\opentrafficsim\graphs\FundamentalDiagram.java |
208 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java |
194 |
@Override
void updateHint(final double domainValue, final double rangeValue)
{
if (Double.isNaN(domainValue))
{
setStatusText(" ");
return;
}
String s1 = String.format(getXAxisFormat(), domainValue);
String s2 = String.format(getYAxisFormat(), rangeValue);
setStatusText(s1 + ", " + s2);
}
};
cp.addMouseMotionListener(ph);
cp.addMouseListener(ph);
cp.setMouseWheelEnabled(true);
final JMenu subMenu = new JMenu("Set layout");
final ButtonGroup group = new ButtonGroup();
final JRadioButtonMenuItem defaultItem = addMenuItem(subMenu, group, getDensityAxis(), this.flowAxis, true);
addMenuItem(subMenu, group, this.flowAxis, this.speedAxis, false);
addMenuItem(subMenu, group, this.densityAxis, this.speedAxis, false);
actionPerformed(new ActionEvent(this, 0, defaultItem.getActionCommand()));
final JPopupMenu popupMenu = cp.getPopupMenu();
popupMenu.insert(subMenu, 0);
this.add(cp, BorderLayout.CENTER);
this.statusLabel = new JLabel(" ", SwingConstants.CENTER);
this.add(this.statusLabel, BorderLayout.SOUTH); |
File |
Line |
org\opentrafficsim\graphs\FundamentalDiagram.java |
523 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java |
438 |
}
/** {@inheritDoc} */
@SuppressFBWarnings("ES_COMPARING_STRINGS_WITH_EQ")
@Override
public final void actionPerformed(final ActionEvent actionEvent)
{
final String command = actionEvent.getActionCommand();
// System.out.println("command is \"" + command + "\"");
final String[] fields = command.split("[/]");
if (fields.length == 2)
{
for (String field : fields)
{
if (field.equalsIgnoreCase(this.densityAxis.getShortName()))
{
if (field == fields[0])
{
this.yAxis = this.densityAxis;
}
else
{
this.xAxis = this.densityAxis;
}
}
else if (field.equalsIgnoreCase(this.flowAxis.getShortName()))
{
if (field == fields[0])
{
this.yAxis = this.flowAxis;
}
else
{
this.xAxis = this.flowAxis;
}
}
else if (field.equalsIgnoreCase(this.speedAxis.getShortName()))
{
if (field == fields[0])
{
this.yAxis = this.speedAxis;
}
else
{
this.xAxis = this.speedAxis;
}
}
else
{
throw new Error("Cannot find axis name: " + field);
}
}
reGraph();
}
else
{
throw new Error("Unknown ActionEvent");
}
} |
File |
Line |
org\opentrafficsim\road\gtu\lane\tactical\following\IDMOld.java |
78 |
org\opentrafficsim\road\gtu\lane\tactical\following\IDMPlusOld.java |
84 |
public IDMOld(final Acceleration a, final Acceleration b, final Length s0, final Duration tSafe, final double delta)
{
this.a = a;
this.b = b;
this.s0 = s0;
this.tSafe = tSafe;
this.delta = delta;
}
/**
* Desired speed (taking into account the urge to drive a little faster or slower than the posted speed limit).
* @param speedLimit DoubleScalarAbs<SpeedUnit>; the speed limit
* @param followerMaximumSpeed Speed; the maximum speed that the follower can drive
* @return DoubleScalarRel<SpeedUnit>; the desired speed
*/
private Speed vDes(final Speed speedLimit, final Speed followerMaximumSpeed)
{
return new Speed(Math.min(this.delta * speedLimit.getSI(), followerMaximumSpeed.getSI()), SpeedUnit.SI);
}
/** {@inheritDoc} */
public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
final Speed leaderSpeed, final Length headway, final Speed speedLimit)
{
return computeAcceleration(followerSpeed, followerMaximumSpeed, leaderSpeed, headway, speedLimit, this.stepSize);
}
/** {@inheritDoc} */
public final Acceleration computeAcceleration(final Speed followerSpeed, final Speed followerMaximumSpeed,
final Speed leaderSpeed, final Length headway, final Speed speedLimit, final Duration stepSize)
{ |
File |
Line |
org\opentrafficsim\road\gtu\lane\tactical\following\IDMOld.java |
157 |
org\opentrafficsim\road\gtu\lane\tactical\following\IDMPlusOld.java |
175 |
}
/** {@inheritDoc} */
@Override
public final String getLongName()
{
return String.format("%s (a=%.1fm/s\u00b2, b=%.1fm/s\u00b2, s0=%.1fm, tSafe=%.1fs, delta=%.2f)", getName(), this.a
.getSI(), this.b.getSI(), this.s0.getSI(), this.tSafe.getSI(), this.delta);
}
// The following is inherited from CarFollowingModel
/** {@inheritDoc} */
@Override
public final Speed desiredSpeed(final BehavioralCharacteristics behavioralCharacteristics, final SpeedLimitInfo speedInfo)
throws ParameterException
{
return null;
}
/** {@inheritDoc} */
@Override
public final Length desiredHeadway(final BehavioralCharacteristics behavioralCharacteristics, final Speed speed)
throws ParameterException
{
return null;
}
/** {@inheritDoc} */
@Override
public final Acceleration followingAcceleration(final BehavioralCharacteristics behavioralCharacteristics,
final Speed speed, final SpeedLimitInfo speedInfo, final SortedMap<Length, Speed> leaders) throws ParameterException
{
return null;
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "IDMOld [s0=" + this.s0 + ", a=" + this.a + ", b=" + this.b + ", tSafe=" + this.tSafe + ", stepSize=" |
File |
Line |
org\opentrafficsim\graphs\ContourPlot.java |
131 |
org\opentrafficsim\graphs\TrajectoryPlot.java |
135 |
for (int i = 0; i < path.size(); i++)
{
Lane lane = path.get(i);
lane.addListener(this, Lane.GTU_ADD_EVENT, true);
lane.addListener(this, Lane.GTU_REMOVE_EVENT, true);
try
{
// register the current GTUs on the lanes (if any) for statistics sampling.
for (LaneBasedGTU gtu : lane.getGtuList())
{
notify(new TimedEvent<OTSSimTimeDouble>(Lane.GTU_ADD_EVENT, lane, new Object[] { gtu.getId(), gtu },
gtu.getSimulator().getSimulatorTime()));
}
}
catch (RemoteException exception)
{
exception.printStackTrace();
}
cumulativeLength += lane.getLength().getSI();
endLengths[i] = cumulativeLength;
} |
File |
Line |
org\opentrafficsim\road\network\factory\LaneFactory.java |
218 |
org\opentrafficsim\road\network\factory\LaneFactory.java |
291 |
final CrossSectionLink link = makeLink(network, name, from, to, intermediatePoints, direction);
Lane[] result = new Lane[laneCount];
Length width = new Length(4.0, LengthUnit.METER);
for (int laneIndex = 0; laneIndex < laneCount; laneIndex++)
{
// Be ware! LEFT is lateral positive, RIGHT is lateral negative.
Length latPosAtStart = new Length((-0.5 - laneIndex - laneOffsetAtStart) * width.getSI(), LengthUnit.SI);
Length latPosAtEnd = new Length((-0.5 - laneIndex - laneOffsetAtEnd) * width.getSI(), LengthUnit.SI);
result[laneIndex] = makeLane(link, "lane." + laneIndex, laneType, latPosAtStart, latPosAtEnd, width, speedLimit,
simulator, direction);
}
return result;
} |
File |
Line |
org\opentrafficsim\road\gtu\lane\tactical\AbstractLaneBasedTacticalPlanner.java |
389 |
org\opentrafficsim\road\gtu\lane\tactical\AbstractLaneBasedTacticalPlanner.java |
543 |
if (lastGtuDir.equals(GTUDirectionality.DIR_PLUS))
{
if (lastLink.getEndNode().equals(link.getStartNode()))
{
// -----> O ----->, GTU moves ---->
lastGtuDir = GTUDirectionality.DIR_PLUS;
lastNode = lastLink.getEndNode();
}
else
{
// -----> O <-----, GTU moves ---->
lastGtuDir = GTUDirectionality.DIR_MINUS;
lastNode = lastLink.getEndNode();
}
}
else
{
if (lastLink.getStartNode().equals(link.getStartNode()))
{
// <----- O ----->, GTU moves ---->
lastNode = lastLink.getStartNode();
lastGtuDir = GTUDirectionality.DIR_PLUS;
}
else
{
// <----- O <-----, GTU moves ---->
lastNode = lastLink.getStartNode();
lastGtuDir = GTUDirectionality.DIR_MINUS;
}
}
lastLink = links.iterator().next(); |
File |
Line |
org\opentrafficsim\road\network\lane\changing\OvertakingConditions.java |
380 |
org\opentrafficsim\road\network\lane\changing\OvertakingConditions.java |
442 |
public LeftSet(final Collection<GTUType> overtakingGTUs, final Collection<GTUType> overtakenGTUs)
{
this.overtakingGTUs = overtakingGTUs;
this.overtakenGTUs = overtakenGTUs;
}
/** {@inheritDoc} */
@Override
public final OvertakingDirection checkOvertaking(final Lane lane, final LaneBasedGTU gtu,
final LaneBasedGTU predecessorGTU)
{
if ((this.overtakingGTUs.contains(GTUType.ALL) || this.overtakingGTUs.contains(gtu.getGTUType())
&& (this.overtakenGTUs.contains(GTUType.ALL) || this.overtakenGTUs.contains(predecessorGTU.getGTUType()))))
{
return OvertakingDirection.LEFT; |
File |
Line |
org\opentrafficsim\graphs\FlowContourPlot.java |
74 |
org\opentrafficsim\graphs\SpeedContourPlot.java |
82 |
this.cumulativeLengths.add(new MutablePositionVector(new double[this.getYAxis().getBinCount()],
LengthUnit.METER, StorageType.DENSE));
}
catch (ValueException exception)
{
exception.printStackTrace();
}
}
}
/** {@inheritDoc} */
@Override
public final void incrementBinData(final int timeBin, final int distanceBin, final double duration,
final double distanceCovered, final double acceleration)
{
if (timeBin < 0 || distanceBin < 0 || 0 == duration || distanceBin >= this.getYAxis().getBinCount())
{
return;
} |