The following document contains the results of PMD's CPD 5.3.5.
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 170 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 247 |
Set<Lane> leftLanes = perception.getAccessibleAdjacentLanesLeft().get(lanePathInfo.getReferenceLane()); if (nextSplitInfo.isSplit()) { leftLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); } if (!leftLanes.isEmpty() && laneBasedGTU.getVelocity().si > 4.0) // XXX we are driving... { perception.updateBackwardHeadwayGTU(); perception.updateParallelGTUsLeft(); perception.updateLaneTrafficLeft(); if (perception.getParallelGTUsLeft().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.LEFT, sameLaneTraffic, perception.getNeighboringGTUsLeft(), laneBasedGTU.getBehavioralCharacteristics() .getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(1.0, AccelerationUnit.SI), new Acceleration(0.5, AccelerationUnit.SI), new Time.Rel( LANECHANGETIME, TimeUnit.SECOND)); if (dlms.getLaneChange() != null) { gtu.setTurnIndicatorStatus(TurnIndicatorStatus.LEFT); OperationalPlan laneChangePlan = makeLaneChangePlanMobil(laneBasedGTU, perception, lanePathInfo, LateralDirectionality.LEFT); if (laneChangePlan != null) { return laneChangePlan; } } } } // Step 3. Do we want to change lanes to the right because of traffic rules? Set<Lane> rightLanes = perception.getAccessibleAdjacentLanesRight().get(lanePathInfo.getReferenceLane()); if (nextSplitInfo.isSplit()) { rightLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); } if (!rightLanes.isEmpty() && laneBasedGTU.getVelocity().si > 4.0) // XXX we are driving... { perception.updateBackwardHeadwayGTU(); perception.updateParallelGTUsRight(); perception.updateLaneTrafficRight(); if (perception.getParallelGTUsRight().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.RIGHT, sameLaneTraffic, perception.getNeighboringGTUsRight(), laneBasedGTU.getBehavioralCharacteristics() .getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(1.0, AccelerationUnit.SI), new Acceleration(0.5, AccelerationUnit.SI), new Time.Rel( LANECHANGETIME, TimeUnit.SECOND)); if (dlms.getLaneChange() != null) { gtu.setTurnIndicatorStatus(TurnIndicatorStatus.RIGHT); OperationalPlan laneChangePlan = makeLaneChangePlanMobil(laneBasedGTU, perception, lanePathInfo, LateralDirectionality.RIGHT); if (laneChangePlan != null) { return laneChangePlan; } } } } return currentLanePlan(laneBasedGTU, startTime, locationAtStartTime, lanePathInfo); } /** * Make a plan for the current lane. * @param laneBasedGTU the gtu to generate the plan for * @param startTime the time from which the new operational plan has to be operational * @param locationAtStartTime the location of the GTU at the start time of the new plan * @param lanePathInfo the lane path for the current lane. * @return An operation plan for staying in the current lane. * @throws OperationalPlanException when there is a problem planning a path in the network * @throws GTUException when there is a problem with the state of the GTU when planning a path */ private OperationalPlan currentLanePlan(final LaneBasedGTU laneBasedGTU, final Time.Abs startTime, final DirectedPoint locationAtStartTime, final LanePathInfo lanePathInfo) throws OperationalPlanException, GTUException { LanePerception perception = laneBasedGTU.getPerception(); GTUFollowingModelOld gfm = laneBasedGTU.getBehavioralCharacteristics().getGTUFollowingModel(); // No lane change. Continue on current lane. AccelerationStep accelerationStep; HeadwayGTU headwayGTU = perception.getForwardHeadwayGTU(); Length.Rel maxDistance = lanePathInfo.getPath().getLength().minus(laneBasedGTU.getLength().multiplyBy(2.0)); if (headwayGTU.getGtuId() == null) { headwayGTU = new HeadwayGTU("ENDPATH", Speed.ZERO, maxDistance, GTUType.NONE); } accelerationStep = gfm.computeAccelerationStep(laneBasedGTU, headwayGTU.getGtuSpeed(), headwayGTU.getDistance(), maxDistance, perception.getSpeedLimit()); // see if we have to continue standing still. In that case, generate a stand still plan if (accelerationStep.getAcceleration().si < 1E-6 && laneBasedGTU.getVelocity().si < OperationalPlan.DRIFTING_SPEED_SI) { return new OperationalPlan(laneBasedGTU, locationAtStartTime, startTime, accelerationStep.getDuration()); } // build a list of lanes forward, with a maximum headway. List<Segment> operationalPlanSegmentList = new ArrayList<>(); if (accelerationStep.getAcceleration().si == 0.0) { Segment segment = new OperationalPlan.SpeedSegment(accelerationStep.getDuration()); operationalPlanSegmentList.add(segment); } else { Segment segment = new OperationalPlan.AccelerationSegment(accelerationStep.getDuration(), accelerationStep.getAcceleration()); operationalPlanSegmentList.add(segment); } OperationalPlan op = new OperationalPlan(laneBasedGTU, lanePathInfo.getPath(), startTime, laneBasedGTU.getVelocity(), operationalPlanSegmentList); return op; } /** * We are not on a lane that leads to our destination. Determine whether the lateral direction to go is left or right. * @param laneBasedGTU the gtu * @param nextSplitInfo the information about the next split * @return the lateral direction to go, or null if this cannot be determined */ private LateralDirectionality determineLeftRight(final LaneBasedGTU laneBasedGTU, final NextSplitInfo nextSplitInfo) { // are the lanes in nextSplitInfo.getCorrectCurrentLanes() left or right of the current lane(s) of the GTU? for (Lane correctLane : nextSplitInfo.getCorrectCurrentLanes()) { for (Lane currentLane : laneBasedGTU.getLanes().keySet()) { if (correctLane.getParentLink().equals(currentLane.getParentLink())) { double deltaOffset = correctLane.getDesignLineOffsetAtBegin().si - currentLane.getDesignLineOffsetAtBegin().si; if (laneBasedGTU.getLanes().get(currentLane).equals(GTUDirectionality.DIR_PLUS)) { return deltaOffset > 0 ? LateralDirectionality.LEFT : LateralDirectionality.RIGHT; } else { return deltaOffset < 0 ? LateralDirectionality.LEFT : LateralDirectionality.RIGHT; } } } } return null; } /** * Make a lane change in the given direction if possible, and return the operational plan, or null if a lane change is not * possible. * @param gtu the GTU that has to make the lane change * @param perception the perception, where forward headway, accessible lanes and speed limit have been assessed * @param lanePathInfo the information for the path on the current lane * @param direction the lateral direction, either LEFT or RIGHT * @return the operational plan for the required lane change, or null if a lane change is not possible. * @throws NetworkException when there is a network inconsistency in updating the perception * @throws GTUException when there is an issue retrieving GTU information for the perception update */ private OperationalPlan makeLaneChangePlanMobil(final LaneBasedGTU gtu, final LanePerception perception, final LanePathInfo lanePathInfo, final LateralDirectionality direction) throws GTUException, NetworkException { Collection<HeadwayGTU> otherLaneTraffic; perception.updateForwardHeadwayGTU(); perception.updateBackwardHeadwayGTU(); if (direction.isLeft()) { perception.updateParallelGTUsLeft(); perception.updateLaneTrafficLeft(); otherLaneTraffic = perception.getNeighboringGTUsLeft(); } else { perception.updateParallelGTUsRight(); perception.updateLaneTrafficRight(); otherLaneTraffic = perception.getNeighboringGTUsRight(); } if (!perception.parallelGTUs(direction).isEmpty()) { return null; } Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } Length.Rel maxDistance = lanePathInfo.getPath().getLength().minus(gtu.getLength().multiplyBy(2.0)); sameLaneTraffic.add(new HeadwayGTU("ENDPATH", Speed.ZERO, maxDistance, GTUType.NONE)); otherLaneTraffic.add(new HeadwayGTU("ENDPATH", Speed.ZERO, maxDistance, GTUType.NONE)); // TODO if we move from standstill, create a longer plan, e.g. 4-5 seconds, with high acceleration! // TODO make type of plan (Egoistic, Altruistic) parameter of the class DirectedLaneChangeModel dlcm = new DirectedEgoistic(); // TODO make the elasticities 2.0 and 0.1 parameters of the class DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(gtu, direction, sameLaneTraffic, otherLaneTraffic, gtu .getBehavioralCharacteristics().getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(2.0, AccelerationUnit.SI), new Acceleration(0.1, AccelerationUnit.SI), new Time.Rel( LANECHANGETIME, TimeUnit.SECOND)); if (dlms.getLaneChange() == null) { return null; } Lane startLane = getReferenceLane(gtu); Set<Lane> adjacentLanes = startLane.accessibleAdjacentLanes(direction, gtu.getGTUType()); // TODO take the widest (now a random one) Lane adjacentLane = adjacentLanes.iterator().next(); Length.Rel startPosition = gtu.position(startLane, gtu.getReference()); double fraction2 = startLane.fraction(startPosition); LanePathInfo lanePathInfo2 = buildLanePathInfo(gtu, gtu.getBehavioralCharacteristics().getForwardHeadwayDistance(), adjacentLane, fraction2, gtu.getLanes().get(startLane)); // interpolate the path for the most conservative one AccelerationStep accelerationStep = dlms.getGfmr(); Speed v0 = gtu.getVelocity(); double t = accelerationStep.getDuration().si; double distanceSI = v0.si * t + 0.5 * accelerationStep.getAcceleration().si * t * t; Speed vt = v0.plus(accelerationStep.getAcceleration().multiplyBy(accelerationStep.getDuration())); // XXX if the distance is too small, do not build a path. Minimum = 0.5 * vehicle length // TODO this should be solved in the time domain, not in the distance domain... if (distanceSI < 2.0) // XXX arbitrary... { return null; } if (perception.getForwardHeadwayGTU() == null || (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getDistance().si < 5.0)) { return null; } OTSLine3D path; try { path = interpolateScurve(lanePathInfo.getPath(), lanePathInfo2.getPath(), distanceSI); } catch (OTSGeometryException exception) { System.err.println("GTU : " + gtu); System.err.println("LanePathInfo : " + lanePathInfo.getPath()); System.err.println("LanePathInfo2: " + lanePathInfo2.getPath()); System.err.println("distanceSI : " + distanceSI); System.err.println("v0, t, vt, a : " + v0 + ", " + t + ", " + vt + ", " + accelerationStep.getAcceleration()); throw new GTUException(exception); } try { double a = accelerationStep.getAcceleration().si; // recalculate based on actual path length... if (path.getLengthSI() > distanceSI * 1.5) // XXX arbitrary... { a = (path.getLengthSI() - v0.si) / LANECHANGETIME; vt = new Speed(v0.si + LANECHANGETIME * a, SpeedUnit.SI); } // enter the other lane(s) at the same fractional position as the current position on the lane(s) // schedule leaving the current lane(s) that do not overlap with the target lane(s) for (Lane lane : gtu.getLanes().keySet()) { gtu.getSimulator().scheduleEventRel(new Time.Rel(LANECHANGETIME - 0.001, TimeUnit.SI), this, gtu, "leaveLane", new Object[]{lane}); } // also leave the lanes that we will still ENTER from the 'old' lanes: for (LaneDirection laneDirection : lanePathInfo.getLaneDirectionList()) { if (!gtu.getLanes().keySet().contains(laneDirection.getLane())) { gtu.getSimulator().scheduleEventRel(new Time.Rel(LANECHANGETIME - 0.001, TimeUnit.SI), this, gtu, "leaveLane", new Object[]{laneDirection.getLane()}); } } gtu.enterLane(adjacentLane, adjacentLane.getLength().multiplyBy(fraction2), gtu.getLanes().get(startLane)); System.out.println("gtu " + gtu.getId() + " entered lane " + adjacentLane + " at pos " + adjacentLane.getLength().multiplyBy(fraction2)); List<Segment> operationalPlanSegmentList = new ArrayList<>(); if (a == 0.0) { Segment segment = new OperationalPlan.SpeedSegment(new Time.Rel(LANECHANGETIME, TimeUnit.SI)); operationalPlanSegmentList.add(segment); } else { Segment segment = new OperationalPlan.AccelerationSegment(new Time.Rel(LANECHANGETIME, TimeUnit.SI), new Acceleration(a, AccelerationUnit.SI)); operationalPlanSegmentList.add(segment); } OperationalPlan op = new OperationalPlan(gtu, path, gtu.getSimulator().getSimulatorTime().getTime(), v0, operationalPlanSegmentList); this.earliestNexLaneChangeTime = gtu.getSimulator().getSimulatorTime().getTime().plus(new Time.Rel(17, TimeUnit.SECOND)); // make sure out turn indicator is on! gtu.setTurnIndicatorStatus(direction.isLeft() ? TurnIndicatorStatus.LEFT : TurnIndicatorStatus.RIGHT); return op; } catch (OperationalPlanException | SimRuntimeException exception) { throw new GTUException(exception); } } /** * Linearly interpolate between two lines. * @param line1 first line * @param line2 second line * @param lengthSI length of the interpolation (at this point 100% line 2) * @return a line between line 1 and line 2 * @throws OTSGeometryException when interpolation fails */ private static OTSLine3D interpolateLinear(OTSLine3D line1, OTSLine3D line2, final double lengthSI) throws OTSGeometryException { OTSLine3D l1 = line1.extract(0, lengthSI); OTSLine3D l2 = line2.extract(0, lengthSI); List<OTSPoint3D> line = new ArrayList<>(); int num = 32; for (int i = 0; i <= num; i++) { double f0 = 1.0 * i / num; double f1 = 1.0 - f0; DirectedPoint p1 = l1.getLocationFraction(f0); DirectedPoint p2 = l2.getLocationFraction(f0); line.add(new OTSPoint3D(p1.x * f1 + p2.x * f0, p1.y * f1 + p2.y * f0, p1.z * f1 + p2.z * f0)); } return new OTSLine3D(line); } /** * S-curve interpolation between two lines. We use a 5th order Bezier curve for this. * @param line1 first line * @param line2 second line * @param lengthSI length of the interpolation (at this point 100% line 2) * @return a line between line 1 and line 2 * @throws OTSGeometryException when interpolation fails */ private static OTSLine3D interpolateScurve(OTSLine3D line1, OTSLine3D line2, final double lengthSI) throws OTSGeometryException { OTSLine3D l1 = line1.extract(0, lengthSI); OTSLine3D l2 = line2.extract(0, lengthSI); List<OTSPoint3D> line = new ArrayList<>(); int num = 64; for (int i = 0; i <= num; i++) { double factor = SCURVE[i]; DirectedPoint p1 = l1.getLocationFraction(i / 64.0); DirectedPoint p2 = l2.getLocationFraction(i / 64.0); line.add(new OTSPoint3D(p1.x + factor * (p2.x - p1.x), p1.y + factor * (p2.y - p1.y), p1.z + factor * (p2.z - p1.z))); } return new OTSLine3D(line); } } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\AbstractLaneBasedGTU.java | 425 |
org\opentrafficsim\road\gtu\lane\CopyOfAbstractLaneBasedGTU.java | 414 |
return pos.minus(relativePosition.getDx()); } } } throw new GTUException(this + " is not on any lane of Link " + link); } /** {@inheritDoc} */ @Override public final Length.Rel position(final Lane lane, final RelativePosition relativePosition, final Time.Abs when) throws GTUException { if (null == lane) { throw new GTUException("lane is null"); } synchronized (this.lock) { if (!this.lanes.containsKey(lane)) { throw new GTUException("position() : GTU " + toString() + " is not on lane " + lane); } if (!this.fractionalLinkPositions.containsKey(lane.getParentLink())) { // DO NOT USE toString() here, as it will cause an endless loop... throw new GTUException(this + " does not have a fractional position on " + lane.toString()); } Length.Rel longitudinalPosition = lane.position(this.fractionalLinkPositions.get(lane.getParentLink())); if (longitudinalPosition == null) { // According to FindBugs; this cannot happen; PK is unsure whether FindBugs is correct. throw new GTUException("position(): GTU " + toString() + " no position for lane " + lane); } if (getOperationalPlan() == null) { // no valid operational plan, e.g. during generation of a new plan return longitudinalPosition.plus(relativePosition.getDx()); } Length.Rel loc; try { if (this.lanes.get(lane).equals(GTUDirectionality.DIR_PLUS)) { loc = longitudinalPosition.plus(getOperationalPlan().getTraveledDistance(when)).plus( relativePosition.getDx()); } else { loc = longitudinalPosition.minus(getOperationalPlan().getTraveledDistance(when)).minus( relativePosition.getDx()); } } catch (Exception e) { e.printStackTrace(); System.err.println(toString()); System.err.println(this.lanes); System.err.println(this.fractionalLinkPositions); throw new GTUException(e); } if (Double.isNaN(loc.getSI())) { System.out.println("loc is NaN"); } return loc; } } /** * Schedule the triggers for this GTU that are going to happen until the next evaluation time. Also schedule the * registration and deregistration of lanes when the vehicle enters or leaves them, at the exact right time. <br> * Note: when the GTU makes a lane change, the vehicle will be registered for both lanes during the entire maneuver. * @throws NetworkException on network inconsistency * @throws SimRuntimeException should never happen * @throws GTUException when a branch is reached where the GTU does not know where to go next */ private void scheduleTriggers() throws NetworkException, SimRuntimeException, GTUException { /* * Move the vehicle into any new lanes with the front, and schedule entrance during this time step and calculate the * current position based on the fractional position, because THE POSITION METHOD DOES NOT WORK FOR THIS. IT CALCULATES * THE POSITION BASED ON THE NEWLY CALCULATED ACCELERATION AND VELOCITY AND CAN THEREFORE MAKE AN ERROR. */ double timestep = getOperationalPlan().getTotalDuration().si; // TODO WRONG - should be based on timeAtPosition() as the plan can have acc/dec/const segments double moveSI = getVelocity().getSI() * timestep + 0.5 * getAcceleration().getSI() * timestep * timestep; Map<Lane, GTUDirectionality> lanesCopy = new LinkedHashMap<Lane, GTUDirectionality>(this.lanes); for (Lane lane : lanesCopy.keySet()) // use a copy because this.lanes can change { // schedule triggers on this lane double referenceStartSI = this.fractionalLinkPositions.get(lane.getParentLink()) * lane.getLength().getSI(); double sign = lanesCopy.get(lane).equals(GTUDirectionality.DIR_PLUS) ? 1.0 : -1.0; if (lanesCopy.get(lane).equals(GTUDirectionality.DIR_PLUS)) { lane.scheduleTriggers(this, referenceStartSI, moveSI); } else { // TODO extra argument for DIR_MINUS driving direction? lane.scheduleTriggers(this, referenceStartSI - moveSI, moveSI); } // determine when our FRONT will pass the end of this registered lane in case of driving DIR_PLUS or // the start of this registered lane when driving DIR_MINUS. // if the time is earlier than the end of the timestep: schedule the enterLane method. // TODO look if more lanes are entered in one timestep, and continue the algorithm with the remainder of the time... double frontPosSI = referenceStartSI + sign * getFront().getDx().getSI(); double nextFrontPosSI = frontPosSI + sign * moveSI; // LANE WE COME FROM IS IN PLUS DIRECTION if (lanesCopy.get(lane).equals(GTUDirectionality.DIR_PLUS)) { if (frontPosSI <= lane.getLength().si && nextFrontPosSI > lane.getLength().si) { Lane nextLane = determineNextLane(lane); GTUDirectionality direction = lane.nextLanes(getGTUType()).get(nextLane); /* * We have to register the position at the previous timestep to keep calculations consistent. And we have to * correct for the position of the reference point. The idea is that we register the vehicle 'before' the * entrance of the new lane at the time of the last timestep, so for a DIR_PLUS on a negative position, and * for a DIR_MINUS on a position beyond the length of the next lane. */ if (direction.equals(GTUDirectionality.DIR_PLUS)) { Length.Rel refPosAtLastTimestep = new Length.Rel(-(lane.getLength().si - frontPosSI) - getFront().getDx().si, LengthUnit.SI); enterLane(nextLane, refPosAtLastTimestep, direction); // schedule any sensor triggers on this lane for the remainder time nextLane.scheduleTriggers(this, refPosAtLastTimestep.getSI(), moveSI); } else if (direction.equals(GTUDirectionality.DIR_MINUS)) { Length.Rel refPosAtLastTimestep = new Length.Rel(nextLane.getLength().si + (lane.getLength().si - frontPosSI) + getFront().getDx().si, LengthUnit.SI); enterLane(nextLane, refPosAtLastTimestep, direction); // schedule any sensor triggers on this lane for the remainder time // TODO extra argument for DIR_MINUS driving direction? nextLane.scheduleTriggers(this, refPosAtLastTimestep.getSI() - moveSI, moveSI); } else { throw new NetworkException("scheduleTriggers DIR_PLUS for GTU " + toString() + ", nextLane " + nextLane + ", direction not DIR_PLUS or DIR_MINUS"); } } } // LANE WE COME FROM IS IN MINUS DIRECTION else if (lanesCopy.get(lane).equals(GTUDirectionality.DIR_MINUS)) { if (frontPosSI >= 0.0 && nextFrontPosSI < 0.0) { Lane prevLane = determinePrevLane(lane); GTUDirectionality direction = lane.prevLanes(getGTUType()).get(prevLane); /* * We have to register the position at the previous timestep to keep calculations consistent. And we have to * correct for the position of the reference point. The idea is that we register the vehicle 'before' the * entrance of the new lane at the time of the last timestep, so for a DIR_MINUS on a negative position, and * for a DIR_PLUS on a position beyond the length of the next lane. */ if (direction.equals(GTUDirectionality.DIR_MINUS)) { Length.Rel refPosAtLastTimestep = new Length.Rel(prevLane.getLength().si + frontPosSI + getFront().getDx().si, LengthUnit.SI); enterLane(prevLane, refPosAtLastTimestep, direction); // schedule any sensor triggers on this lane for the remainder time prevLane.scheduleTriggers(this, refPosAtLastTimestep.getSI() - moveSI, moveSI); } else if (direction.equals(GTUDirectionality.DIR_PLUS)) { Length.Rel refPosAtLastTimestep = new Length.Rel(-frontPosSI - getFront().getDx().si, LengthUnit.SI); enterLane(prevLane, refPosAtLastTimestep, direction); // schedule any sensor triggers on this lane for the remainder time // TODO extra argument for DIR_MINUS driving direction? prevLane.scheduleTriggers(this, refPosAtLastTimestep.getSI(), moveSI); } else { throw new NetworkException("scheduleTriggers DIR_MINUS for GTU " + toString() + ", prevLane " + prevLane + ", direction not DIR_PLUS or DIR_MINUS"); } } } else { throw new NetworkException("scheduleTriggers for GTU " + toString() + ", lane " + lane + ", direction not DIR_PLUS or DIR_MINUS"); } } // move the vehicle out of any lanes with the BACK, and schedule exit during this time step for (Lane lane : this.lanes.keySet()) { // Determine when our REAR will pass the end of this registered lane. // TODO look if more lanes are exited in one timestep, and continue the algorithm with the remainder of the time... double referenceStartSI = this.fractionalLinkPositions.get(lane.getParentLink()) * lane.getLength().getSI(); double sign = this.lanes.get(lane).equals(GTUDirectionality.DIR_PLUS) ? 1.0 : -1.0; double rearPosSI = referenceStartSI + sign * getRear().getDx().getSI(); if (this.lanes.get(lane).equals(GTUDirectionality.DIR_PLUS)) { if (rearPosSI <= lane.getLength().si && rearPosSI + moveSI > lane.getLength().si) { double distanceToLeave = lane.getLength().si - rearPosSI; Time.Abs exitTime = getOperationalPlan().timeAtDistance(new Length.Rel(distanceToLeave, LengthUnit.SI)); SimEvent<OTSSimTimeDouble> event = new SimEvent<OTSSimTimeDouble>(new OTSSimTimeDouble(exitTime), this, this, "leaveLane", new Object[]{lane, new Boolean(false)}); getSimulator().scheduleEvent(event); addTrigger(lane, event); // XXXXXXXXXXXXXXXXXX Minus one ULP is not safe if you want to add the current time // XXXXXXXXXXXXXXXXXX Should compute the time time at which the rear of the GTU exits the lane??? // getSimulator().scheduleEventRel(new Time.Rel(timestep - Math.ulp(timestep), TimeUnit.SI), this, this, // "leaveLane", new Object[] { lane, new Boolean(true) }); // TODO should be false? } } else { if (rearPosSI >= 0.0 && rearPosSI - moveSI < 0.0) { double distanceToLeave = rearPosSI; Time.Abs exitTime = getOperationalPlan().timeAtDistance(new Length.Rel(distanceToLeave, LengthUnit.SI)); SimEvent<OTSSimTimeDouble> event = new SimEvent<OTSSimTimeDouble>(new OTSSimTimeDouble(exitTime), this, this, "leaveLane", new Object[]{lane, new Boolean(false)}); getSimulator().scheduleEvent(event); addTrigger(lane, event); // getSimulator().scheduleEventRel(new Time.Rel(timestep - Math.ulp(timestep), TimeUnit.SI), this, this, // "leaveLane", new Object[] { lane, new Boolean(true) }); // XXX: should be false? } } } } /** * XXX: direction dependent... <br> * @param lane the lane to find the successor for * @return the next lane for this GTU * @throws NetworkException when no next lane exists or the route branches into multiple next lanes * @throws GTUException when no route could be found or the routeNavigator returns null */ private Lane determineNextLane(final Lane lane) throws NetworkException, GTUException { Lane nextLane = null; if (lane.nextLanes(getGTUType()).size() == 0) { throw new NetworkException(this + " - lane " + lane + " does not have a successor"); } if (lane.nextLanes(getGTUType()).size() == 1) { nextLane = lane.nextLanes(getGTUType()).keySet().iterator().next(); } else { if (!(getStrategicalPlanner() instanceof LaneBasedStrategicalRoutePlanner)) { throw new GTUException(this + " reaches branch but has no route navigator"); } Node nextNode = ((LaneBasedStrategicalRoutePlanner) getStrategicalPlanner()).nextNode(lane.getParentLink(), GTUDirectionality.DIR_PLUS, getGTUType()); if (null == nextNode) { throw new GTUException(this + " reaches branch and the route returns null as nextNodeToVisit"); } int continuingLaneCount = 0; for (Lane candidateLane : lane.nextLanes(getGTUType()).keySet()) { if (null != this.lanes.get(candidateLane)) { continue; // Already on this lane } // XXX Hack - this should be done more considerate -- fails at loops... if (nextNode == candidateLane.getParentLink().getEndNode() || nextNode == candidateLane.getParentLink().getStartNode()) { nextLane = candidateLane; continuingLaneCount++; } } if (continuingLaneCount == 0) { throw new NetworkException(this + " reached branch and the route specifies a nextNodeToVisit (" + nextNode + ") that is not a next node " + "at this branch at (" + lane.getParentLink().getEndNode() + ")"); } if (continuingLaneCount > 1) { throw new NetworkException(this + " reached branch and the route specifies multiple lanes to continue on at this branch (" + lane.getParentLink().getEndNode() + "). This is not yet supported"); } } return nextLane; } /** * XXX: direction dependent... <br> * @param lane the lane to find the predecessor for * @return the next lane for this GTU * @throws NetworkException when no next lane exists or the route branches into multiple next lanes * @throws GTUException when no route could be found or the routeNavigator returns null */ private Lane determinePrevLane(final Lane lane) throws NetworkException, GTUException { Lane prevLane = null; if (lane.prevLanes(getGTUType()).size() == 0) { throw new NetworkException(this + " - lane " + lane + " does not have a predecessor"); } if (lane.prevLanes(getGTUType()).size() == 1) { prevLane = lane.prevLanes(getGTUType()).keySet().iterator().next(); } else { if (!(getStrategicalPlanner() instanceof LaneBasedStrategicalRoutePlanner)) { throw new GTUException(this + " reaches branch but has no route navigator"); } Node prevNode = ((LaneBasedStrategicalRoutePlanner) getStrategicalPlanner()).nextNode(lane.getParentLink(), GTUDirectionality.DIR_MINUS, getGTUType()); if (null == prevNode) { throw new GTUException(this + " reaches branch and the route returns null as nextNodeToVisit"); } int continuingLaneCount = 0; for (Lane candidateLane : lane.prevLanes(getGTUType()).keySet()) { if (null != this.lanes.get(candidateLane)) { continue; // Already on this lane } // XXX Hack - this should be done more considerate -- fails at loops... if (prevNode == candidateLane.getParentLink().getEndNode() || prevNode == candidateLane.getParentLink().getStartNode()) { prevLane = candidateLane; continuingLaneCount++; } } if (continuingLaneCount == 0) { throw new NetworkException(this + " reached branch and the route specifies a nextNodeToVisit (" + prevNode + ") that is not a next node " + "at this branch at (" + lane.getParentLink().getStartNode() + ")"); } if (continuingLaneCount > 1) { throw new NetworkException(this + " reached branch and the route specifies multiple lanes to continue on at this branch (" + lane.getParentLink().getStartNode() + "). This is not yet supported"); } } return prevLane; } /** {@inheritDoc} */ @Override public final Map<Lane, Double> fractionalPositions(final RelativePosition relativePosition) throws GTUException { return fractionalPositions(relativePosition, getSimulator().getSimulatorTime().getTime()); } /** {@inheritDoc} */ @Override public final Map<Lane, Double> fractionalPositions(final RelativePosition relativePosition, final Time.Abs when) throws GTUException { Map<Lane, Double> positions = new LinkedHashMap<>(); for (Lane lane : this.lanes.keySet()) { positions.put(lane, fractionalPosition(lane, relativePosition, when)); } return positions; } /** {@inheritDoc} */ @Override public final double fractionalPosition(final Lane lane, final RelativePosition relativePosition, final Time.Abs when) throws GTUException { return position(lane, relativePosition, when).getSI() / lane.getLength().getSI(); } /** {@inheritDoc} */ @Override public final double fractionalPosition(final Lane lane, final RelativePosition relativePosition) throws GTUException { return position(lane, relativePosition).getSI() / lane.getLength().getSI(); } /** {@inheritDoc} */ @Override public LanePerceptionFull getPerception() { return (LanePerceptionFull) super.getPerception(); } /** {@inheritDoc} */ @Override public LaneBasedStrategicalPlanner getStrategicalPlanner() { return (LaneBasedStrategicalPlanner) super.getStrategicalPlanner(); } /** {@inheritDoc} */ @Override public LaneBasedBehavioralCharacteristics getBehavioralCharacteristics() { return getStrategicalPlanner().getDrivingCharacteristics(); } /** {@inheritDoc} */ public void addTrigger(final Lane lane, final SimEvent<OTSSimTimeDouble> event) { List<SimEvent<OTSSimTimeDouble>> list = this.pendingTriggers.get(lane); if (null == list) { list = new ArrayList<SimEvent<OTSSimTimeDouble>>(); } list.add(event); this.pendingTriggers.put(lane, list); } /** {@inheritDoc} */ @Override @SuppressWarnings("checkstyle:designforextension") public void destroy() { synchronized (this.lock) { Set<Lane> laneSet = new HashSet<>(this.lanes.keySet()); // Operate on a copy of the key set for (Lane lane : laneSet) { try { leaveLane(lane, true); } catch (GTUException e) { // ignore. not important at destroy } } } super.destroy(); } /** {@inheritDoc} */ @Override public final Bounds getBounds() { double dx = 0.5 * getLength().doubleValue(); double dy = 0.5 * getWidth().doubleValue(); return new BoundingBox(new Point3d(-dx, -dy, 0.0), new Point3d(dx, dy, 0.0)); } /** {@inheritDoc} */ public String toString() { return String.format("GTU " + getId()); } } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\AbstractLaneBasedGTU.java | 122 |
org\opentrafficsim\road\gtu\lane\CopyOfAbstractLaneBasedGTU.java | 122 |
public AbstractLaneBasedGTU(final String id, final GTUType gtuType, final Set<DirectedLanePosition> initialLongitudinalPositions, final Speed initialSpeed, final OTSDEVSSimulatorInterface simulator, final LaneBasedStrategicalPlanner strategicalPlanner, final LanePerception perception, final OTSNetwork network) throws NetworkException, SimRuntimeException, GTUException, OTSGeometryException { super(id, gtuType, simulator, strategicalPlanner, perception, verifyInitialLocation(initialLongitudinalPositions), initialSpeed, network); // register the GTU in the perception module getPerception().setGTU(this); // register the GTU on the lanes for (DirectedLanePosition directedLanePosition : initialLongitudinalPositions) { Lane lane = directedLanePosition.getLane(); if (!this.fractionalLinkPositions.containsKey(lane.getParentLink())) { // initially registered on parallel or overlapping lanes this.fractionalLinkPositions.put(lane.getParentLink(), lane.fraction(directedLanePosition.getPosition())); } this.lanes.put(lane, directedLanePosition.getGtuDirection()); lane.addGTU(this, lane.fraction(directedLanePosition.getPosition())); } } /** * Throw a GTUException if the provided set of initial longitudinal positions is null or empty. * @param initialLongitudinalPositions Set<DirectedLanePosition>; the set of initial longitudinal positions to check * @return Set<DirectedLanePosition>; the argument of this method * @throws GTUException when the provided set is null or empty */ private static DirectedPoint verifyInitialLocation(Set<DirectedLanePosition> initialLongitudinalPositions) throws GTUException { GTUException.failIf(null == initialLongitudinalPositions, "InitialLongitudinalPositions is null"); GTUException.failIf(0 == initialLongitudinalPositions.size(), "InitialLongitudinalPositions is empty set"); DirectedPoint lastPoint = null; for (DirectedLanePosition pos : initialLongitudinalPositions) { GTUException.failIf(lastPoint != null && pos.getLocation().distance(lastPoint) > 1E-6, "initial locations for GTU have distance > 1 mm"); lastPoint = pos.getLocation(); } return lastPoint; } /** {@inheritDoc} */ @Override public final void enterLane(final Lane lane, final Length.Rel position, final GTUDirectionality gtuDirection) throws GTUException { GTUException.failIf(!MOVEMENT_LANE_BASED, "MOVEMENT_LANE_BASED is true, but enterLane() is called"); if (lane == null || gtuDirection == null || position == null) { throw new GTUException("enterLane - one of the arguments is null"); } if (this.lanes.containsKey(lane)) { System.err.println(this + " is already registered on lane: " + lane + " at fractional position " + this.fractionalPosition(lane, RelativePosition.REFERENCE_POSITION) + " intended position is " + position + " length of lane is " + lane.getLength()); return; } // if the GTU is already registered on a lane of the same link, do not change its fractional position, as // this might lead to a "jump". if (!this.fractionalLinkPositions.containsKey(lane.getParentLink())) { this.fractionalLinkPositions.put(lane.getParentLink(), lane.fraction(position)); } this.lanes.put(lane, gtuDirection); lane.addGTU(this, position); } /** {@inheritDoc} */ @Override public final void leaveLane(final Lane lane) throws GTUException { leaveLane(lane, false); } /** * Leave a lane but do not complain about having no lanes left when beingDestroyed is true. * @param lane the lane to leave * @param beingDestroyed if true, no complaints about having no lanes left * @throws GTUException in case leaveLane should not be called */ public final void leaveLane(final Lane lane, final boolean beingDestroyed) throws GTUException { GTUException.failIf(!MOVEMENT_LANE_BASED, "MOVEMENT_LANE_BASED is true, but leaveLane() is called"); if (null == this.lanes.get(lane)) { // No problem -- this method can be scheduled and the GTU can already have left the lane } this.lanes.remove(lane); List<SimEvent<OTSSimTimeDouble>> pending = this.pendingTriggers.get(lane); if (null != pending) { for (SimEvent<OTSSimTimeDouble> event : pending) { if (event.getAbsoluteExecutionTime().get().ge(getSimulator().getSimulatorTime().get())) { // System.out.println(this + ": Cancelling trigger " + event); boolean result = getSimulator().cancelEvent(event); if (!result && event.getAbsoluteExecutionTime().get().ne(getSimulator().getSimulatorTime().get())) { System.err.println("NOTHING REMOVED"); } } } // System.out.println(this + ": Removing list of triggers for lane " + lane); this.pendingTriggers.remove(lane); } // check of there are any lanes for this link left. If not, remove the link. boolean found = false; for (Lane l : this.lanes.keySet()) { if (l.getParentLink().equals(lane.getParentLink())) { found = true; } } if (!found) { this.fractionalLinkPositions.remove(lane.getParentLink()); } lane.removeGTU(this); if (this.lanes.size() == 0 && !beingDestroyed) { System.err.println("lanes.size() = 0 for GTU " + getId()); } } /** {@inheritDoc} */ @Override public final Map<Lane, GTUDirectionality> getLanes() { return new HashMap<Lane, GTUDirectionality>(this.lanes); } /** {@inheritDoc} */ @Override protected final void move(final DirectedPoint fromLocation) throws SimRuntimeException, GTUException, OperationalPlanException, NetworkException { if (MOVEMENT_LANE_BASED) { // Only carry out move() if we still have lane(s) to drive on. // Note: a (Sink) trigger can have 'destroyed' us between the previous evaluation step and this one. if (this.lanes.isEmpty()) { destroy(); return; // Done; do not re-schedule execution of this move method. } for (Link link : this.fractionalLinkPositions.keySet()) { double d = this.fractionalLinkPositions.get(link); double fractionalExcess = d < 0 ? -d : (d - 1); if (fractionalExcess > 0) { double excess = fractionalExcess * link.getLength().si; OperationalPlan op = this.getOperationalPlan(); double maxLength = this.getLength().si + op.getTraveledDistanceSI(op.getTotalDuration()); if (excess > maxLength) // if (d < -0.1 || d > 1.1) { System.err.println(this + " has extreme fractional position on Link " + link + ": " + d + " (" + excess + "m), time is " + this.getSimulator().getSimulatorTime().get()); } } } // store the new positions, and sample statistics Map<Link, Double> newLinkPositions = new HashMap<>(); for (Lane lane : this.lanes.keySet()) { lane.sample(this); newLinkPositions.put(lane.getParentLink(), lane.fraction(position(lane, getReference()))); } // generate the next operational plan and carry it out super.move(fromLocation); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 198 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 201 |
URL url = URLResource.getResource("/NASAames.xodr"); // URL url = URLResource.getResource("/OpenDrive.xodr"); this.simulator.setPauseOnError(false); OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator); OTSNetwork network = null; try { network = nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } URL gisURL = URLResource.getResource("/gis/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); // TODO parse these from the xodr-file. // double latCenter = 37.40897623275873, lonCenter = -122.0246091728831;//sunnyvale // double latCenter = 37.419933552777, lonCenter = -122.05752616111000;//nasa double latCenter = nlp.getHeaderTag().getOriginLat().si, lonCenter = nlp.getHeaderTag().getOriginLong().si; CoordinateTransform latLonToXY = new CoordinateTransformLonLatToXY(lonCenter, latCenter); new GisRenderable2D(this.simulator, gisURL, latLonToXY); // Make a GTU Type GTUType carType = GTUType.makeGTUType("Car"); // new ReceiverThread(this.simulator).run(); // stream StreamInterface stream = new MersenneTwister(1); Length.Rel M25 = new Length.Rel(25.0, LengthUnit.METER); Length.Rel M0 = new Length.Rel(0.0, LengthUnit.METER); // distributions ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> initialSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 0.0), SpeedUnit.SI); ContinuousDistDoubleScalar.Rel<Time.Rel, TimeUnit> iatDist = new ContinuousDistDoubleScalar.Rel<>(new DistExponential(stream, 30.0), TimeUnit.SECOND); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> lengthDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 4.0, 5.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> widthDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 2.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maxSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistTriangular(stream, 30.0, 35.0, 40.0), SpeedUnit.MILE_PER_HOUR); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> initialPosDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 0.0, 1.0), LengthUnit.METER); // default colorer // put some generators and sinks on the outer edges of the network for (Link link : network.getLinkMap().values()) { CrossSectionLink csLink = (CrossSectionLink) link; // look if start node is isolated if (link.getStartNode().getLinks().size() == 1) // only ourselves... { // put generators and sinks 25 m from the edge of the link for (CrossSectionElement cse : csLink.getCrossSectionElementList()) { if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { Lane lane = (Lane) cse; if (Integer.parseInt(lane.getId()) < 0) { // make a generator Time.Abs startTime = Time.Abs.ZERO; Time.Abs endTime = new Time.Abs(Double.MAX_VALUE, TimeUnit.SI); Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_PLUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; Sensor sensor = new SinkSensor(lane, position, this.simulator); try { lane.addSensor(sensor, GTUType.ALL); } catch (NetworkException exception) { exception.printStackTrace(); } } } } } else if (link.getEndNode().getLinks().size() == 1) // only ourselves... { // put generators and sinks 25 m from the edge of the link for (CrossSectionElement cse : csLink.getCrossSectionElementList()) { if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { Lane lane = (Lane) cse; if (Integer.parseInt(lane.getId()) > 0) { // make a generator Time.Abs startTime = Time.Abs.ZERO; Time.Abs endTime = new Time.Abs(Double.MAX_VALUE, TimeUnit.SI); Length.Rel position = lane.getLength().lt(M25) ? lane.getLength() : lane.getLength().minus(M25); String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_MINUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? lane.getLength() : lane.getLength().minus(M25); Sensor sensor = new SinkSensor(lane, position, this.simulator); try { lane.addSensor(sensor, GTUType.ALL); } catch (NetworkException exception) { exception.printStackTrace(); } } } } } } CrossSectionLink link1 = (CrossSectionLink) network.getLink("54059"); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 108 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 111 |
TestOpenDriveParserNoRTI xmlModel = new TestOpenDriveParserNoRTI(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestOpenDriveModel(); } /** {@inheritDoc} */ @Override protected final Rectangle2D.Double makeAnimationRectangle() { return new Rectangle2D.Double(-1000, -1000, 2000, 2000); } /** * Model to test the XML parser. * <p> * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br> * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim * License</a>. * <p> * $LastChangedDate: 2015-08-05 15:55:21 +0200 (Wed, 05 Aug 2015) $, @version $Revision: 1199 $, by $Author: averbraeck $, * initial version un 27, 2015 <br> * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> */ class TestOpenDriveModel implements OTSModelInterface { /** */ private static final long serialVersionUID = 20150811L; /** The simulator. */ private OTSDEVSSimulatorInterface simulator; private List<LaneBasedIndividualGTU> rtiCars; /** {@inheritDoc} */ @Override public final void constructModel( final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator) throws SimRuntimeException { this.simulator = (OTSDEVSSimulatorInterface) pSimulator; this.rtiCars = new ArrayList<LaneBasedIndividualGTU>(); // URL url = URLResource.getResource("/NASAames.xodr"); URL url = URLResource.getResource("/testod.xodr"); this.simulator.setPauseOnError(false); OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator); OTSNetwork network = null; try { network = nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } URL gisURL = URLResource.getResource("/gis/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); double latCenter = nlp.getHeaderTag().getOriginLat().si, lonCenter = nlp.getHeaderTag().getOriginLong().si; CoordinateTransform latLonToXY = new CoordinateTransformLonLatToXY(lonCenter, latCenter); new GisRenderable2D(this.simulator, gisURL, latLonToXY); // Make a GTU Type GTUType carType = GTUType.makeGTUType("Car"); // new ReceiverThread(this.simulator).run(); // stream StreamInterface stream = new MersenneTwister(1); Length.Rel M25 = new Length.Rel(25.0, LengthUnit.METER); Length.Rel M0 = new Length.Rel(0.0, LengthUnit.METER); // distributions ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> initialSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 0.0), SpeedUnit.SI); ContinuousDistDoubleScalar.Rel<Time.Rel, TimeUnit> iatDist = new ContinuousDistDoubleScalar.Rel<>(new DistExponential(stream, 30.0), TimeUnit.SECOND); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> lengthDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 4.0, 5.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> widthDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 2.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maxSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistTriangular(stream, 30.0, 35.0, 40.0), SpeedUnit.MILE_PER_HOUR); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> initialPosDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 0.0, 1.0), LengthUnit.METER); // default colorer // put some generators and sinks on the outer edges of the network for (Link link : network.getLinkMap().values()) { CrossSectionLink csLink = (CrossSectionLink) link; // look if start node is isolated if (link.getStartNode().getLinks().size() == 1) // only ourselves... { // put generators and sinks 25 m from the edge of the link for (CrossSectionElement cse : csLink.getCrossSectionElementList()) { if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { Lane lane = (Lane) cse; if (Integer.parseInt(lane.getId()) < 0) { // make a generator Time.Abs startTime = Time.Abs.ZERO; Time.Abs endTime = new Time.Abs(Double.MAX_VALUE, TimeUnit.SI); Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedGTUFollowingLaneChangeTacticalPlanner()); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 324 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 330 |
new LaneBasedGTUFollowingLaneChangeTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_MINUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? lane.getLength() : lane.getLength().minus(M25); Sensor sensor = new SinkSensor(lane, position, this.simulator); try { lane.addSensor(sensor, GTUType.ALL); } catch (NetworkException exception) { exception.printStackTrace(); } } } } } } CrossSectionLink link1 = (CrossSectionLink) network.getLink("3766054.5"); CrossSectionLink link2 = (CrossSectionLink) network.getLink("3766059.7"); CrossSectionLink link3 = (CrossSectionLink) network.getLink("3766068.3"); CrossSectionLink link4 = (CrossSectionLink) network.getLink("3766038.5"); CrossSectionLink link5 = (CrossSectionLink) network.getLink("3766043.3"); CrossSectionLink link6 = (CrossSectionLink) network.getLink("3766064.2"); CrossSectionLink link7 = (CrossSectionLink) network.getLink("3766046.3"); CrossSectionLink link8 = (CrossSectionLink) network.getLink("3766050.3"); CompleteRoute cr1 = null, cr2 = null, cr3 = null, cr4 = null, cr5 = null, cr6 = null; List<Node> nodesVia1 = new ArrayList<Node>(); nodesVia1.add(link2.getStartNode()); nodesVia1.add(link3.getEndNode()); nodesVia1.add(link4.getStartNode()); nodesVia1.add(link5.getEndNode()); nodesVia1.add(link7.getEndNode()); nodesVia1.add(link8.getStartNode()); try { cr1 = network.getShortestRouteBetween(GTUType.ALL, link1.getStartNode(), link1.getStartNode(), nodesVia1); Collections.reverse(nodesVia1); cr2 = network.getShortestRouteBetween(GTUType.ALL, link1.getStartNode(), link1.getStartNode(), nodesVia1); } catch (NetworkException exception) { exception.printStackTrace(); } List<Node> nodesVia2 = new ArrayList<Node>(); nodesVia2.add(link3.getEndNode()); nodesVia2.add(link5.getEndNode()); try { cr3 = network.getShortestRouteBetween(GTUType.ALL, link3.getStartNode(), link3.getStartNode(), nodesVia2); Collections.reverse(nodesVia2); cr4 = network.getShortestRouteBetween(GTUType.ALL, link3.getStartNode(), link3.getStartNode(), nodesVia2); } catch (NetworkException exception) { exception.printStackTrace(); } List<Node> nodesVia3 = new ArrayList<Node>(); nodesVia3.add(link7.getEndNode()); nodesVia3.add(link8.getEndNode()); try { cr5 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); Collections.reverse(nodesVia3); cr6 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); } catch (NetworkException exception) { exception.printStackTrace(); } List<CompleteRoute> cRoutes = new ArrayList<>(); cRoutes.add(cr1); cRoutes.add(cr2); cRoutes.add(cr3); cRoutes.add(cr4); cRoutes.add(cr5); cRoutes.add(cr6); Random routeRandom = new Random(); List<CrossSectionLink> links = new ArrayList<>(); links.add(link1); links.add(link2); links.add(link3); links.add(link4); links.add(link5); links.add(link6); links.add(link7); links.add(link8); for (int i = 0; i < 1; i++) // 52; i++) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 408 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 413 |
nodesVia3.add(link5.getEndNode()); nodesVia3.add(link8.getEndNode()); try { cr5 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); Collections.reverse(nodesVia3); cr6 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); } catch (NetworkException exception) { exception.printStackTrace(); } List<CompleteRoute> cRoutes = new ArrayList<>(); cRoutes.add(cr1); cRoutes.add(cr2); cRoutes.add(cr3); cRoutes.add(cr4); cRoutes.add(cr5); cRoutes.add(cr6); Random routeRandom = new Random(); List<CrossSectionLink> links = new ArrayList<>(); links.add(link1); links.add(link2); links.add(link3); links.add(link4); links.add(link5); links.add(link6); links.add(link7); links.add(link8); for (int i = 0; i < 52; i++) { CompleteRoute cr = cRoutes.get(routeRandom.nextInt(6)); CrossSectionLink link; while (true) { link = links.get(routeRandom.nextInt(8)); if (cr.getNodes().contains(link.getStartNode())) break; } GTUDirectionality dir = GTUDirectionality.DIR_PLUS; Lane lane = null; while (true) { CrossSectionElement cse = link.getCrossSectionElementList().get( routeRandom.nextInt(link.getCrossSectionElementList().size())); if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { lane = (Lane) cse; break; } } if (lane.getDirectionality(carType).equals(LongitudinalDirectionality.DIR_MINUS)) { dir = GTUDirectionality.DIR_MINUS; } LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner sPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); DirectedLanePosition directedLanePosition = null; try { directedLanePosition = new DirectedLanePosition(lane, initialPosDist.draw().multiplyBy( lane.getCenterLine().getLengthSI()), dir); } catch (GTUException exception1) { exception1.printStackTrace(); } Set<DirectedLanePosition> lanepositionSet = new HashSet<DirectedLanePosition>(); lanepositionSet.add(directedLanePosition); Length.Rel carLength = lengthDist.draw(); double genPosSI = directedLanePosition.getPosition().getSI(); double lengthSI = lane.getLength().getSI(); double frontNew = (genPosSI + carLength.getSI()) / lengthSI; double rearNew = genPosSI / lengthSI; boolean isEnoughSpace = true; for (LaneBasedGTU gtu : lane.getGtuList()) { double frontGTU = 0; try { frontGTU = gtu.fractionalPosition(lane, gtu.getFront()); } catch (GTUException exception) { exception.printStackTrace(); } double rearGTU = 0; try { rearGTU = gtu.fractionalPosition(lane, gtu.getRear()); } catch (GTUException exception) { exception.printStackTrace(); } if ((frontNew >= rearGTU && frontNew <= frontGTU) || (rearNew >= rearGTU && rearNew <= frontGTU) || (frontGTU >= rearNew && frontGTU <= frontNew) || (rearGTU >= rearNew && rearGTU <= frontNew)) isEnoughSpace = false; } if (isEnoughSpace) { try { |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\AbstractLaneBasedGTU.java | 314 |
org\opentrafficsim\road\gtu\lane\CopyOfAbstractLaneBasedGTU.java | 309 |
this.fractionalLinkPositions = newLinkPositions; // schedule triggers and determine when to enter lanes with front and leave lanes with rear scheduleTriggers(); } else // MOVEMENT_PATH_BASED { try { // 1. generate the next operational plan and carry it out super.move(fromLocation); // 2. split the movement into a number of steps, so that each steps overlaps with the half GTU length int steps = Math.max(5, (int) (2.0 * getOperationalPlan().getPath().getLengthSI() / getLength().si)); DirectedPoint[] points = new DirectedPoint[steps + 1]; OTSShape[] rects = new OTSShape[steps + 1]; for (int i = 0; i <= steps; i++) { points[i] = getOperationalPlan().getPath().getLocationFraction(1.0 * i / steps); double x = points[i].x; double y = points[i].y; double l = getLength().si; double w = getWidth().si; Rectangle2D rect = new Rectangle2D.Double(-l / 2.0, -w / 2.0, l, w); Path2D.Double path = new Path2D.Double(rect); AffineTransform t = new AffineTransform(); t.translate(x, y); t.rotate(points[i].getRotZ()); path.transform(t); rects[i] = new OTSShape(path); } // 3. determine for each rectangle with which lanes there is an overlap List<Lane>[] laneLists = new ArrayList[steps + 1]; Set<Lane> laneSet = new HashSet<>(); OTSNetwork network = (OTSNetwork) getPerceivableContext(); for (int i = 0; i < rects.length; i++) { laneLists[i] = new ArrayList<Lane>(); for (Link link : network.getLinkMap().values()) { if (link instanceof CrossSectionLink) { for (Lane lane : ((CrossSectionLink) link).getLanes()) { if (lane.getContour().intersects(rects[i])) { laneLists[i].add(lane); laneSet.add(lane); } } } } } System.out.println(this + " will be on lanes: " + laneSet); } catch (OTSGeometryException e) { throw new GTUException(e); } } } /** {@inheritDoc} */ @Override public final Map<Lane, Length.Rel> positions(final RelativePosition relativePosition) throws GTUException { return positions(relativePosition, getSimulator().getSimulatorTime().getTime()); } /** {@inheritDoc} */ @Override public final Map<Lane, Length.Rel> positions(final RelativePosition relativePosition, final Time.Abs when) throws GTUException { Map<Lane, Length.Rel> positions = new LinkedHashMap<>(); for (Lane lane : this.lanes.keySet()) { positions.put(lane, position(lane, relativePosition, when)); } return positions; } /** {@inheritDoc} */ @Override public final Length.Rel position(final Lane lane, final RelativePosition relativePosition) throws GTUException { return position(lane, relativePosition, getSimulator().getSimulatorTime().getTime()); } /** {@inheritDoc} */ public final Length.Rel projectedPosition(final Lane projectionLane, final RelativePosition relativePosition, final Time.Abs when) throws GTUException { // do not make a wedge in a curve of the projected position! CrossSectionLink link = projectionLane.getParentLink(); for (CrossSectionElement cse : link.getCrossSectionElementList()) { if (cse instanceof Lane) { Lane cseLane = (Lane) cse; if (null != this.lanes.get(cseLane)) { double fractionalPosition = fractionalPosition(cseLane, RelativePosition.REFERENCE_POSITION, when); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 198 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 198 |
URL url = URLResource.getResource("/NASAames.xodr"); // URL url = URLResource.getResource("/OpenDrive.xodr"); this.simulator.setPauseOnError(false); OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator); OTSNetwork network = null; try { network = nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } URL gisURL = URLResource.getResource("/gis/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); // TODO parse these from the xodr-file. // double latCenter = 37.40897623275873, lonCenter = -122.0246091728831;//sunnyvale // double latCenter = 37.419933552777, lonCenter = -122.05752616111000;//nasa double latCenter = nlp.getHeaderTag().getOriginLat().si, lonCenter = nlp.getHeaderTag().getOriginLong().si; CoordinateTransform latLonToXY = new CoordinateTransformLonLatToXY(lonCenter, latCenter); new GisRenderable2D(this.simulator, gisURL, latLonToXY); // Make a GTU Type GTUType carType = GTUType.makeGTUType("Car"); // new ReceiverThread(this.simulator).run(); // stream StreamInterface stream = new MersenneTwister(1); Length.Rel M25 = new Length.Rel(25.0, LengthUnit.METER); Length.Rel M0 = new Length.Rel(0.0, LengthUnit.METER); // distributions ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> initialSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 0.0), SpeedUnit.SI); ContinuousDistDoubleScalar.Rel<Time.Rel, TimeUnit> iatDist = new ContinuousDistDoubleScalar.Rel<>(new DistExponential(stream, 30.0), TimeUnit.SECOND); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> lengthDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 4.0, 5.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> widthDist = new ContinuousDistDoubleScalar.Rel<>(new DistConstant(stream, 2.0), LengthUnit.METER); ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maxSpeedDist = new ContinuousDistDoubleScalar.Rel<>(new DistTriangular(stream, 30.0, 35.0, 40.0), SpeedUnit.MILE_PER_HOUR); ContinuousDistDoubleScalar.Rel<Length.Rel, LengthUnit> initialPosDist = new ContinuousDistDoubleScalar.Rel<>(new DistUniform(stream, 0.0, 1.0), LengthUnit.METER); // default colorer // put some generators and sinks on the outer edges of the network for (Link link : network.getLinkMap().values()) { CrossSectionLink csLink = (CrossSectionLink) link; // look if start node is isolated if (link.getStartNode().getLinks().size() == 1) // only ourselves... { // put generators and sinks 25 m from the edge of the link for (CrossSectionElement cse : csLink.getCrossSectionElementList()) { if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { Lane lane = (Lane) cse; if (Integer.parseInt(lane.getId()) < 0) { // make a generator Time.Abs startTime = Time.Abs.ZERO; Time.Abs endTime = new Time.Abs(Double.MAX_VALUE, TimeUnit.SI); Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); |
File | Line |
---|---|
org\opentrafficsim\graphs\FundamentalDiagram.java | 284 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java | 278 |
sample.addData(gtu.getVelocity(detectionTime)); } /** * 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); } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 478 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 482 |
new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); DirectedLanePosition directedLanePosition = null; try { directedLanePosition = new DirectedLanePosition(lane, initialPosDist.draw().multiplyBy( lane.getCenterLine().getLengthSI()), dir); } catch (GTUException exception1) { exception1.printStackTrace(); } Set<DirectedLanePosition> lanepositionSet = new HashSet<DirectedLanePosition>(); lanepositionSet.add(directedLanePosition); Length.Rel carLength = lengthDist.draw(); double genPosSI = directedLanePosition.getPosition().getSI(); double lengthSI = lane.getLength().getSI(); double frontNew = (genPosSI + carLength.getSI()) / lengthSI; double rearNew = genPosSI / lengthSI; boolean isEnoughSpace = true; for (LaneBasedGTU gtu : lane.getGtuList()) { double frontGTU = 0; try { frontGTU = gtu.fractionalPosition(lane, gtu.getFront()); } catch (GTUException exception) { exception.printStackTrace(); } double rearGTU = 0; try { rearGTU = gtu.fractionalPosition(lane, gtu.getRear()); } catch (GTUException exception) { exception.printStackTrace(); } if ((frontNew >= rearGTU && frontNew <= frontGTU) || (rearNew >= rearGTU && rearNew <= frontGTU) || (frontGTU >= rearNew && frontGTU <= frontNew) || (rearGTU >= rearNew && rearGTU <= frontNew)) isEnoughSpace = false; } if (isEnoughSpace) { try { LaneBasedIndividualGTU car = new LaneBasedIndividualGTU(String.valueOf(i), carType, lanepositionSet, new Speed(0.0, SpeedUnit.METER_PER_SECOND), carLength, widthDist.draw(), maxSpeedDist.draw(), this.simulator, sPlanner, perception, network); this.rtiCars.add(car); } catch (NamingException | NetworkException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } } else { i = i - 1; } } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 276 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 272 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 278 |
new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_PLUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; Sensor sensor = new SinkSensor(lane, position, this.simulator); try { lane.addSensor(sensor, GTUType.ALL); } catch (NetworkException exception) { exception.printStackTrace(); } } } } } else if (link.getEndNode().getLinks().size() == 1) // only ourselves... { // put generators and sinks 25 m from the edge of the link for (CrossSectionElement cse : csLink.getCrossSectionElementList()) { if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { Lane lane = (Lane) cse; if (Integer.parseInt(lane.getId()) > 0) { // make a generator Time.Abs startTime = Time.Abs.ZERO; Time.Abs endTime = new Time.Abs(Double.MAX_VALUE, TimeUnit.SI); Length.Rel position = lane.getLength().lt(M25) ? lane.getLength() : lane.getLength().minus(M25); String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 143 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 157 |
} } } } // Condition, if we have just changed lane, let's not change immediately again. // TODO make direction dependent! if (gtu.getSimulator().getSimulatorTime().getTime().lt(this.earliestNexLaneChangeTime)) { return currentLanePlan(laneBasedGTU, startTime, locationAtStartTime, lanePathInfo); } // Step 2. Do we want to change lanes to the left because of our predecessor on the current lane? // does the lane left of us [TODO: driving direction] bring us to our destination as well? Set<Lane> leftLanes = perception.getAccessibleAdjacentLanesLeft().get(lanePathInfo.getReferenceLane()); if (nextSplitInfo.isSplit()) { leftLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); } if (!leftLanes.isEmpty() && laneBasedGTU.getVelocity().si > 4.0) // XXX we are driving... { perception.updateBackwardHeadwayGTU(); perception.updateParallelGTUsLeft(); perception.updateLaneTrafficLeft(); if (perception.getParallelGTUsLeft().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.LEFT, sameLaneTraffic, perception.getNeighboringGTUsLeft(), laneBasedGTU .getBehavioralCharacteristics().getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(1.0, AccelerationUnit.SI), new Acceleration(0.5, AccelerationUnit.SI), new Time.Rel(0.5, TimeUnit.SECOND)); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 299 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 286 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 363 |
if (accelerationStep.getAcceleration().si < 1E-6 && laneBasedGTU.getVelocity().si < OperationalPlan.DRIFTING_SPEED_SI) { return new OperationalPlan(laneBasedGTU, locationAtStartTime, startTime, accelerationStep.getDuration()); } // build a list of lanes forward, with a maximum headway. List<Segment> operationalPlanSegmentList = new ArrayList<>(); if (accelerationStep.getAcceleration().si == 0.0) { Segment segment = new OperationalPlan.SpeedSegment(accelerationStep.getDuration()); operationalPlanSegmentList.add(segment); } else { Segment segment = new OperationalPlan.AccelerationSegment(accelerationStep.getDuration(), accelerationStep.getAcceleration()); operationalPlanSegmentList.add(segment); } OperationalPlan op = new OperationalPlan(laneBasedGTU, lanePathInfo.getPath(), startTime, laneBasedGTU.getVelocity(), operationalPlanSegmentList); return op; } /** * We are not on a lane that leads to our destination. Determine whether the lateral direction to go is left or right. * @param laneBasedGTU the gtu * @param nextSplitInfo the information about the next split * @return the lateral direction to go, or null if this cannot be determined */ private LateralDirectionality determineLeftRight(final LaneBasedGTU laneBasedGTU, final NextSplitInfo nextSplitInfo) { // are the lanes in nextSplitInfo.getCorrectCurrentLanes() left or right of the current lane(s) of the GTU? for (Lane correctLane : nextSplitInfo.getCorrectCurrentLanes()) { for (Lane currentLane : laneBasedGTU.getLanes().keySet()) { if (correctLane.getParentLink().equals(currentLane.getParentLink())) { double deltaOffset = correctLane.getDesignLineOffsetAtBegin().si - currentLane.getDesignLineOffsetAtBegin().si; if (laneBasedGTU.getLanes().get(currentLane).equals(GTUDirectionality.DIR_PLUS)) { return deltaOffset > 0 ? LateralDirectionality.LEFT : LateralDirectionality.RIGHT; } else { return deltaOffset < 0 ? LateralDirectionality.LEFT : LateralDirectionality.RIGHT; } } } } return null; } /** * See if a lane change in the given direction if possible. * @param gtu the GTU that has to make the lane change * @param perception the perception, where forward headway, accessible lanes and speed limit have been assessed * @param lanePathInfo the information for the path on the current lane * @param direction the lateral direction, either LEFT or RIGHT * @return whether a lane change is possible. * @throws NetworkException when there is a network inconsistency in updating the perception * @throws GTUException when there is an issue retrieving GTU information for the perception update */ private boolean canChange(final LaneBasedGTU gtu, final LanePerception perception, final LanePathInfo lanePathInfo, |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 482 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 483 |
+ ", route = " + cr); LanePerceptionFull perception = new LanePerceptionFull(); DirectedLanePosition directedLanePosition = null; try { directedLanePosition = new DirectedLanePosition(lane, initialPosDist.draw().multiplyBy( lane.getCenterLine().getLengthSI()), dir); } catch (GTUException exception1) { exception1.printStackTrace(); } Set<DirectedLanePosition> lanepositionSet = new HashSet<DirectedLanePosition>(); lanepositionSet.add(directedLanePosition); Length.Rel carLength = lengthDist.draw(); double genPosSI = directedLanePosition.getPosition().getSI(); double lengthSI = lane.getLength().getSI(); double frontNew = (genPosSI + carLength.getSI()) / lengthSI; double rearNew = genPosSI / lengthSI; boolean isEnoughSpace = true; for (LaneBasedGTU gtu : lane.getGtuList()) { double frontGTU = 0; try { frontGTU = gtu.fractionalPosition(lane, gtu.getFront()); } catch (GTUException exception) { exception.printStackTrace(); } double rearGTU = 0; try { rearGTU = gtu.fractionalPosition(lane, gtu.getRear()); } catch (GTUException exception) { exception.printStackTrace(); } if ((frontNew >= rearGTU && frontNew <= frontGTU) || (rearNew >= rearGTU && rearNew <= frontGTU) || (frontGTU >= rearNew && frontGTU <= frontNew) || (rearGTU >= rearNew && rearGTU <= frontNew)) isEnoughSpace = false; } if (isEnoughSpace) { try { |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 109 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 108 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 111 |
TestOpenDriveParserNASA xmlModel = new TestOpenDriveParserNASA(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestOpenDriveModel(); } /** {@inheritDoc} */ @Override protected final Rectangle2D.Double makeAnimationRectangle() { return new Rectangle2D.Double(-1000, -1000, 2000, 2000); } /** * Model to test the XML parser. * <p> * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br> * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim * License</a>. * <p> * $LastChangedDate: 2015-08-05 15:55:21 +0200 (Wed, 05 Aug 2015) $, @version $Revision: 1199 $, by $Author: averbraeck $, * initial version un 27, 2015 <br> * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> */ class TestOpenDriveModel implements OTSModelInterface { /** */ private static final long serialVersionUID = 20150811L; /** The simulator. */ private OTSDEVSSimulatorInterface simulator; private List<LaneBasedIndividualGTU> rtiCars; /** {@inheritDoc} */ @Override public final void constructModel( final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator) throws SimRuntimeException { this.simulator = (OTSDEVSSimulatorInterface) pSimulator; this.rtiCars = new ArrayList<LaneBasedIndividualGTU>(); URL url = URLResource.getResource("/NASAames.xodr"); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\ElevationTag.java | 58 |
org\opentrafficsim\road\network\factory\opendrive\SuperElevationTag.java | 59 |
ElevationTag elevationTag = new ElevationTag(); Node s = attributes.getNamedItem("s"); if (s == null) throw new SAXException("Geometry: missing attribute s"); elevationTag.s = new Length.Rel(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER); Node a = attributes.getNamedItem("a"); if (a == null) throw new SAXException("Geometry: missing attribute a"); elevationTag.a = new Length.Rel(Double.parseDouble(a.getNodeValue().trim()), LengthUnit.METER); Node b = attributes.getNamedItem("b"); if (b == null) throw new SAXException("Geometry: missing attribute b"); elevationTag.b = new Length.Rel(Double.parseDouble(b.getNodeValue().trim()), LengthUnit.METER); Node c = attributes.getNamedItem("c"); if (c == null) throw new SAXException("Geometry: missing attribute c"); elevationTag.c = new Length.Rel(Double.parseDouble(c.getNodeValue().trim()), LengthUnit.METER); Node d = attributes.getNamedItem("d"); if (d == null) throw new SAXException("Geometry: missing attribute d"); elevationTag.d = new Length.Rel(Double.parseDouble(d.getNodeValue().trim()), LengthUnit.METER); |
File | Line |
---|---|
org\opentrafficsim\graphs\FundamentalDiagram.java | 191 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java | 180 |
renderer.setBaseItemLabelsVisible(true); final ChartPanel cp = new ChartPanel(this.chartPanel); PointerHandler ph = new PointerHandler() { /** {@inheritDoc} */ @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\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 197 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 206 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 283 |
} } } } // Step 3. Do we want to change lanes to the right because of TODO traffic rules? Set<Lane> rightLanes = perception.getAccessibleAdjacentLanesRight().get(lanePathInfo.getReferenceLane()); if (nextSplitInfo.isSplit()) { rightLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); } if (!rightLanes.isEmpty() && laneBasedGTU.getVelocity().si > 4.0) // XXX we are driving... { perception.updateBackwardHeadwayGTU(); perception.updateParallelGTUsRight(); perception.updateLaneTrafficRight(); if (perception.getParallelGTUsRight().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.RIGHT, sameLaneTraffic, perception.getNeighboringGTUsRight(), laneBasedGTU .getBehavioralCharacteristics().getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(1.0, AccelerationUnit.SI), new Acceleration(0.5, AccelerationUnit.SI), new Time.Rel(0.5, TimeUnit.SECOND)); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 157 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 247 |
Set<Lane> leftLanes = perception.getAccessibleAdjacentLanesLeft().get(lanePathInfo.getReferenceLane()); if (nextSplitInfo.isSplit()) { leftLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); } if (!leftLanes.isEmpty() && laneBasedGTU.getVelocity().si > 4.0) // XXX we are driving... { perception.updateBackwardHeadwayGTU(); perception.updateParallelGTUsLeft(); perception.updateLaneTrafficLeft(); if (perception.getParallelGTUsLeft().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.LEFT, sameLaneTraffic, perception.getNeighboringGTUsLeft(), laneBasedGTU .getBehavioralCharacteristics().getForwardHeadwayDistance(), perception.getSpeedLimit(), new Acceleration(1.0, AccelerationUnit.SI), new Acceleration(0.5, AccelerationUnit.SI), new Time.Rel(0.5, TimeUnit.SECOND)); |
File | Line |
---|---|
org\opentrafficsim\road\test\FourStop.java | 61 |
org\opentrafficsim\road\test\TestNetwork2.java | 59 |
org\opentrafficsim\road\test\TestXMLParser.java | 59 |
FourStop xmlModel = new FourStop(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestXMLModel(); } /** {@inheritDoc} */ @Override protected final Double makeAnimationRectangle() { return new Rectangle2D.Double(-1000, -1000, 2000, 2000); } /** * Model to test the XML parser. * <p> * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br> * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim * License</a>. * <p> * $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $, * initial version un 27, 2015 <br> * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> */ class TestXMLModel implements OTSModelInterface { /** */ private static final long serialVersionUID = 20141121L; /** The simulator. */ private OTSDEVSSimulatorInterface simulator; /** {@inheritDoc} */ @Override public final void constructModel( final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator) throws SimRuntimeException { this.simulator = (OTSDEVSSimulatorInterface) pSimulator; URL url = URLResource.getResource("/4-stop.xml"); |
File | Line |
---|---|
org\opentrafficsim\graphs\FundamentalDiagram.java | 518 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java | 430 |
} /** {@inheritDoc} */ @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"); } } /** * Internal Sensor class. * <p> * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. * <p> * $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, @version $Revision: 1401 $, by $Author: averbraeck $, * initial version feb. 2015 <br> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> */ class FundamentalDiagramSensor extends AbstractSensor |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 408 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 407 |
nodesVia3.add(link5.getEndNode()); nodesVia3.add(link8.getEndNode()); try { cr5 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); Collections.reverse(nodesVia3); cr6 = network.getShortestRouteBetween(GTUType.ALL, link6.getStartNode(), link6.getStartNode(), nodesVia3); } catch (NetworkException exception) { exception.printStackTrace(); } List<CompleteRoute> cRoutes = new ArrayList<>(); cRoutes.add(cr1); cRoutes.add(cr2); cRoutes.add(cr3); cRoutes.add(cr4); cRoutes.add(cr5); cRoutes.add(cr6); Random routeRandom = new Random(); List<CrossSectionLink> links = new ArrayList<>(); links.add(link1); links.add(link2); links.add(link3); links.add(link4); links.add(link5); links.add(link6); links.add(link7); links.add(link8); for (int i = 0; i < 52; i++) |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 99 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 114 |
{ // ask Perception for the local situation LaneBasedGTU laneBasedGTU = (LaneBasedGTU) gtu; LanePerception perception = laneBasedGTU.getPerception(); LaneBasedBehavioralCharacteristics drivingCharacteristics = laneBasedGTU.getBehavioralCharacteristics(); // start with the turn indicator off -- this can change during the method laneBasedGTU.setTurnIndicatorStatus(TurnIndicatorStatus.NONE); // if the GTU's maximum speed is zero (block), generate a stand still plan for one second if (laneBasedGTU.getMaximumVelocity().si < OperationalPlan.DRIFTING_SPEED_SI) { return new OperationalPlan(gtu, locationAtStartTime, startTime, new Time.Rel(1.0, TimeUnit.SECOND)); } // perceive the forward headway, accessible lanes and speed limit. perception.updateForwardHeadwayGTU(); perception.updateAccessibleAdjacentLanesLeft(); perception.updateAccessibleAdjacentLanesRight(); perception.updateSpeedLimit(); // find out where we are going Length.Rel forwardHeadway = drivingCharacteristics.getForwardHeadwayDistance(); LanePathInfo lanePathInfo = buildLanePathInfo(laneBasedGTU, forwardHeadway); NextSplitInfo nextSplitInfo = determineNextSplit(laneBasedGTU, forwardHeadway); Set<Lane> correctLanes = laneBasedGTU.getLanes().keySet(); correctLanes.retainAll(nextSplitInfo.getCorrectCurrentLanes()); // Step 1: Do we want to change lanes because of the current lane not leading to our destination? if (lanePathInfo.getPath().getLength().lt(forwardHeadway)) { if (correctLanes.isEmpty()) { LateralDirectionality direction = determineLeftRight(laneBasedGTU, nextSplitInfo); if (direction != null) { gtu.setTurnIndicatorStatus(direction.isLeft() ? TurnIndicatorStatus.LEFT : TurnIndicatorStatus.RIGHT); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 109 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 108 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTINew.java | 115 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 111 |
TestOpenDriveParserNASA xmlModel = new TestOpenDriveParserNASA(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestOpenDriveModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestOpenDriveModel(); } /** {@inheritDoc} */ @Override protected final Rectangle2D.Double makeAnimationRectangle() { return new Rectangle2D.Double(-1000, -1000, 2000, 2000); } /** * Model to test the XML parser. * <p> * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br> * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim * License</a>. * <p> * $LastChangedDate: 2015-08-05 15:55:21 +0200 (Wed, 05 Aug 2015) $, @version $Revision: 1199 $, by $Author: averbraeck $, * initial version un 27, 2015 <br> * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> */ class TestOpenDriveModel implements OTSModelInterface { /** */ private static final long serialVersionUID = 20150811L; /** The simulator. */ private OTSDEVSSimulatorInterface simulator; private List<LaneBasedIndividualGTU> rtiCars; |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\object\AbstractCSEObject.java | 51 |
org\opentrafficsim\road\gtu\lane\object\AbstractCSEObject.java | 86 |
double a = cp.getRotZ(); double l2ca = l2 * Math.cos(a); double l2sa = l2 * Math.sin(a); double w2ca = w2 * Math.cos(a + Math.PI / 2.0); double w2sa = w2 * Math.sin(a + Math.PI / 2.0); OTSPoint3D p1 = new OTSPoint3D(cp.x - l2ca - w2ca, cp.y - l2sa - w2sa, cp.z + height.si); OTSPoint3D p3 = new OTSPoint3D(cp.x + l2ca + w2ca, cp.y + l2sa + w2sa, cp.z + height.si); OTSPoint3D p2 = new OTSPoint3D(cp.x + l2ca - w2ca, cp.y + l2sa - w2sa, cp.z + height.si); OTSPoint3D p4 = new OTSPoint3D(cp.x - l2ca + w2ca, cp.y - l2sa + w2sa, cp.z + height.si); return new OTSLine3D(p1, p2, p3, p4, p1); } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 186 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTINew.java | 239 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 189 |
@Override public final void constructModel( final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator) throws SimRuntimeException { this.simulator = (OTSDEVSSimulatorInterface) pSimulator; this.rtiCars = new ArrayList<LaneBasedIndividualGTU>(); // URL url = URLResource.getResource("/NASAames.xodr"); URL url = URLResource.getResource("/testod.xodr"); this.simulator.setPauseOnError(false); OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator); OTSNetwork network = null; try { network = nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } URL gisURL = URLResource.getResource("/gis/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); double latCenter = nlp.getHeaderTag().getOriginLat().si, lonCenter = nlp.getHeaderTag().getOriginLong().si; CoordinateTransform latLonToXY = new CoordinateTransformLonLatToXY(lonCenter, latCenter); new GisRenderable2D(this.simulator, gisURL, latLonToXY); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\following\IDMOld.java | 69 |
org\opentrafficsim\road\gtu\lane\tactical\following\IDMPlusOld.java | 75 |
public IDMOld(final Acceleration a, final Acceleration b, final Length.Rel s0, final Time.Rel 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.Rel 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.Rel headway, final Speed speedLimit, final Time.Rel stepSize) { |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 442 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 441 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 447 |
for (int i = 0; i < 52; i++) { CompleteRoute cr = cRoutes.get(routeRandom.nextInt(6)); CrossSectionLink link; while (true) { link = links.get(routeRandom.nextInt(8)); if (cr.getNodes().contains(link.getStartNode())) break; } GTUDirectionality dir = GTUDirectionality.DIR_PLUS; Lane lane = null; while (true) { CrossSectionElement cse = link.getCrossSectionElementList().get( routeRandom.nextInt(link.getCrossSectionElementList().size())); if (cse instanceof Lane && !(cse instanceof NoTrafficLane)) { lane = (Lane) cse; break; } } if (lane.getDirectionality(carType).equals(LongitudinalDirectionality.DIR_MINUS)) { dir = GTUDirectionality.DIR_MINUS; } LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner sPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 282 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 349 |
OTSPoint3D point = new OTSPoint3D(currentGeometryTag.x.doubleValue(), currentGeometryTag.y.doubleValue(), currentGeometryTag.z.doubleValue()); if (points.size() == 0) points.add(point); else { if (point.x != points.get(points.size() - 1).x && point.y != points.get(points.size() - 1).y) points.add(point); } OTSPoint3D lastPoint = new OTSPoint3D(points.get(points.size() - 1)); if (currentGeometryTag.interLine != null) { for (OTSPoint3D point1 : currentGeometryTag.interLine.getPoints()) { /* * double xDiff = lastPoint.x - point.x; double yDiff = lastPoint.y - point.y; double distance = * (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); */ if (lastPoint.x != point.x && lastPoint.y != point.y) { points.add(point1); lastPoint = point1; } } } |
File | Line |
---|---|
org\opentrafficsim\graphs\FundamentalDiagram.java | 331 |
org\opentrafficsim\graphs\FundamentalDiagramLane.java | 325 |
org\opentrafficsim\graphs\TrajectoryPlot.java | 576 |
} /** {@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(); |
File | Line |
---|---|
org\opentrafficsim\road\test\FourStop.java | 61 |
org\opentrafficsim\road\test\LMRSTests.java | 61 |
org\opentrafficsim\road\test\TestLaneDirections.java | 59 |
org\opentrafficsim\road\test\TestNetwork2.java | 59 |
org\opentrafficsim\road\test\TestXMLParser.java | 59 |
FourStop xmlModel = new FourStop(); // 1 hour simulation run for testing xmlModel.buildAnimator(new Time.Abs(0.0, TimeUnit.SECOND), new Time.Rel(0.0, TimeUnit.SECOND), new Time.Rel(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true); } catch (SimRuntimeException | NamingException | OTSSimulationException exception) { exception.printStackTrace(); } } }); } /** {@inheritDoc} */ @Override public final String shortName() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final String description() { return "TestXMLModel"; } /** {@inheritDoc} */ @Override public final void stopTimersThreads() { super.stopTimersThreads(); } /** {@inheritDoc} */ @Override protected final JPanel makeCharts() { return null; } /** {@inheritDoc} */ @Override protected final OTSModelInterface makeModel(final GTUColorer colorer) { return new TestXMLModel(); } /** {@inheritDoc} */ @Override protected final Double makeAnimationRectangle() { return new Rectangle2D.Double(-1000, -1000, 2000, 2000); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 539 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 545 |
catch (NamingException | NetworkException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } } else { i = i - 1; } } try { new Thread(new ReceiverThread(this.simulator, carType, this.rtiCars, network)).start(); } catch (SocketException exception1) { exception1.printStackTrace(); } } /** {@inheritDoc} */ @Override public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator() { return this.simulator; } /** * @return a GTUColorer */ private GTUColorer makeSwitchableGTUColorer() { GTUColorer[] gtuColorers = new GTUColorer[]{ new IDGTUColorer(), new VelocityGTUColorer(new Speed(100.0, SpeedUnit.KM_PER_HOUR)), new AccelerationGTUColorer(new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2), new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2))}; return new SwitchableGTUColorer(0, gtuColorers); } } } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedCFLCTacticalPlanner.java | 395 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedCFLCTacticalPlanner.java | 463 |
private Length.Rel laneDrop(final LaneBasedGTU gtu, final LateralDirectionality direction) throws NetworkException, GTUException { Lane lane = null; Length.Rel longitudinalPosition = null; Map<Lane, Length.Rel> positions = gtu.positions(RelativePosition.REFERENCE_POSITION); if (null == direction) { for (Lane l : gtu.getLanes().keySet()) { if (l.getLaneType().isCompatible(gtu.getGTUType())) { lane = l; } } if (null == lane) { throw new NetworkException(this + " is not on any compatible lane"); } longitudinalPosition = positions.get(lane); } else { lane = positions.keySet().iterator().next(); longitudinalPosition = positions.get(lane); lane = gtu.getPerception().bestAccessibleAdjacentLane(lane, direction, longitudinalPosition); // XXX correct?? |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 971 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 1034 |
if (!openDriveNetworkLaneParser.trafficLightsByLanes.containsKey(roadTag.id)) { Set<AbstractTrafficLightNew> lights = new HashSet<AbstractTrafficLightNew>(); openDriveNetworkLaneParser.trafficLightsByLanes.put(roadTag.id, lights); } openDriveNetworkLaneParser.trafficLightsBySignals.get(signalTag.id).add(trafficLight); openDriveNetworkLaneParser.trafficLightsByLanes.get(roadTag.id).add(trafficLight); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { throw new NetworkException( "Traffic Light: CLASS NAME " + OldTrafficLight.class.getName() + " for " + signalTag.id + " on lane " + lane.toString() + " -- class not found or constructor not right", exception); } } else if (signalTag.type.equals("206") && signalTag.dynamic.equals("no"))// generate stop sign { } else System.err.println("Unknown signals"); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedCFLCTacticalPlanner.java | 238 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedCFLCTacticalPlanner.java | 265 |
if (lcmr.getGfmr().getAcceleration().si < 1E-6 && laneBasedGTU.getVelocity().si < OperationalPlan.DRIFTING_SPEED_SI) { // TODO Make a 100% lateral move from standing still... return new OperationalPlan(gtu, locationAtStartTime, startTime, duration); } // TODO make a gradual lateral move OTSLine3D path = lanePathInfo.getPath(); List<Segment> operationalPlanSegmentList = new ArrayList<>(); if (lcmr.getGfmr().getAcceleration().si == 0.0) { Segment segment = new OperationalPlan.SpeedSegment(duration); operationalPlanSegmentList.add(segment); } else { Segment segment = new OperationalPlan.AccelerationSegment(duration, lcmr.getGfmr().getAcceleration()); operationalPlanSegmentList.add(segment); } OperationalPlan op = new OperationalPlan(gtu, path, startTime, gtu.getVelocity(), operationalPlanSegmentList); return op; } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 244 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 281 |
{ OTSPoint3D point = new OTSPoint3D(currentGeometryTag.x.doubleValue(), currentGeometryTag.y.doubleValue(), currentGeometryTag.z.doubleValue()); if (points.size() == 0) points.add(point); else { if (point.x != points.get(points.size() - 1).x && point.y != points.get(points.size() - 1).y) points.add(point); } OTSPoint3D lastPoint = new OTSPoint3D(points.get(points.size() - 1)); if (currentGeometryTag.interLine != null) { for (OTSPoint3D point1 : currentGeometryTag.interLine.getPoints()) { // double xDiff = lastPoint.x - point.x; // double yDiff = lastPoint.y - point.y; // double distance = (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); if (lastPoint.x != point1.x && lastPoint.y != point1.y) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\vissim\VissimANMNetworkLaneParser.java | 123 |
org\opentrafficsim\road\network\factory\xml\XmlNetworkLaneParser.java | 128 |
throw new SAXException("XmlNetworkLaneParser.build: File url.getFile() does not exist"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setXIncludeAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(url.openStream()); NodeList networkNodeList = document.getDocumentElement().getChildNodes(); if (!document.getDocumentElement().getNodeName().equals("NETWORK")) throw new SAXException( "XmlNetworkLaneParser.build: XML document does not start with an NETWORK tag, found " + document.getDocumentElement().getNodeName() + " instead"); // there should be some definitions using DEFINITIONS tags (could be more than one due to include files) List<Node> definitionNodes = XMLParser.getNodes(networkNodeList, "DEFINITIONS"); if (definitionNodes.size() == 0) throw new SAXException("XmlNetworkLaneParser.build: XML document does not have a DEFINITIONS tag"); // make the GTUTypes ALL and NONE to get started this.gtuTypes.put("ALL", GTUType.ALL); this.gtuTypes.put("NONE", GTUType.NONE); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\xml\units\LaneAttributes.java | 100 |
org\opentrafficsim\road\network\factory\xml\units\LaneAttributes.java | 126 |
else if (ocStr.startsWith("LEFTSET")) { int lset1 = ocStr.indexOf('[') + 1; int rset1 = ocStr.indexOf(']', lset1); int lset2 = ocStr.indexOf('[', ocStr.indexOf("OVERTAKE")) + 1; int rset2 = ocStr.indexOf(']', lset2); if (lset1 == -1 || rset1 == -1 || rset1 - lset1 < 3 || lset2 == -1 || rset2 == -1 || rset2 - lset2 < 3) { throw new NetworkException("Sets in overtaking conditions string: '" + ocStr + "' not coded right"); } Set<GTUType> overtakingGTUs = parseGTUTypeSet(ocStr.substring(lset1, rset1), parser); Set<GTUType> overtakenGTUs = parseGTUTypeSet(ocStr.substring(lset2, rset2), parser); if (ocStr.contains("RIGHTSPEED")) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 245 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 349 |
OTSPoint3D point = new OTSPoint3D(currentGeometryTag.x.doubleValue(), currentGeometryTag.y.doubleValue(), currentGeometryTag.z.doubleValue()); if (points.size() == 0) points.add(point); else { if (point.x != points.get(points.size() - 1).x && point.y != points.get(points.size() - 1).y) points.add(point); } OTSPoint3D lastPoint = new OTSPoint3D(points.get(points.size() - 1)); if (currentGeometryTag.interLine != null) { for (OTSPoint3D point1 : currentGeometryTag.interLine.getPoints()) { // double xDiff = lastPoint.x - point.x; // double yDiff = lastPoint.y - point.y; // double distance = (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); if (lastPoint.x != point1.x && lastPoint.y != point1.y) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\LaneFactory.java | 213 |
org\opentrafficsim\road\network\factory\LaneFactory.java | 287 |
final CrossSectionLink link = makeLink(name, from, to, intermediatePoints, direction); Lane[] result = new Lane[laneCount]; Length.Rel width = new Length.Rel(4.0, LengthUnit.METER); for (int laneIndex = 0; laneIndex < laneCount; laneIndex++) { // Be ware! LEFT is lateral positive, RIGHT is lateral negative. Length.Rel latPosAtStart = new Length.Rel((-0.5 - laneIndex - laneOffsetAtStart) * width.getSI(), LengthUnit.SI); Length.Rel latPosAtEnd = new Length.Rel((-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\network\factory\opendrive\Controller.java | 89 |
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 110 |
for (AbstractTrafficLightNew light : this.trafficLights.get(3)) { try { // System.out.println("traffic light 3 at time " + this.simulator.getSimulatorTime() + " is " + // ((TrafficLight) light).getTrafficLightColor().toString()); this.simulator.scheduleEventRel(new Time.Rel(0.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.GREEN}); this.simulator.scheduleEventRel(new Time.Rel(15.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.YELLOW}); this.simulator.scheduleEventRel(new Time.Rel(24.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.RED}); } catch (SimRuntimeException exception) { exception.printStackTrace(); } } } if (this.trafficLights.containsKey(4)) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 129 |
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 150 |
for (AbstractTrafficLightNew light : this.trafficLights.get(6)) { try { // System.out.println("traffic light 6 at time " + this.simulator.getSimulatorTime()); this.simulator.scheduleEventRel(new Time.Rel(24.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.GREEN}); this.simulator.scheduleEventRel(new Time.Rel(39.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.YELLOW}); this.simulator.scheduleEventRel(new Time.Rel(48.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.RED}); } catch (SimRuntimeException exception) { exception.printStackTrace(); } } } if (this.trafficLights.containsKey(7)) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 169 |
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 190 |
for (AbstractTrafficLightNew light : this.trafficLights.get(9)) { try { // System.out.println("traffic light 9 at time " + this.simulator.getSimulatorTime()); this.simulator.scheduleEventRel(new Time.Rel(48.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.GREEN}); this.simulator.scheduleEventRel(new Time.Rel(63.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.YELLOW}); this.simulator.scheduleEventRel(new Time.Rel(72.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.RED}); } catch (SimRuntimeException exception) { exception.printStackTrace(); } } } if (this.trafficLights.containsKey(10)) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 198 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTINew.java | 251 |
URL url = URLResource.getResource("/NASAames.xodr"); // URL url = URLResource.getResource("/OpenDrive.xodr"); this.simulator.setPauseOnError(false); OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator); OTSNetwork network = null; try { network = nlp.build(url); } catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException | GTUException | OTSGeometryException exception) { exception.printStackTrace(); } URL gisURL = URLResource.getResource("/gis/map.xml"); System.err.println("GIS-map file: " + gisURL.toString()); // TODO parse these from the xodr-file. // double latCenter = 37.40897623275873, lonCenter = -122.0246091728831;//sunnyvale // double latCenter = 37.419933552777, lonCenter = -122.05752616111000;//nasa double latCenter = nlp.getHeaderTag().getOriginLat().si, lonCenter = nlp.getHeaderTag().getOriginLong().si; CoordinateTransform latLonToXY = new CoordinateTransformLonLatToXY(lonCenter, latCenter); new GisRenderable2D(this.simulator, gisURL, latLonToXY); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 328 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 324 |
new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_MINUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? lane.getLength() : lane.getLength().minus(M25); Sensor sensor = new SinkSensor(lane, position, this.simulator); try { lane.addSensor(sensor, GTUType.ALL); } catch (NetworkException exception) { exception.printStackTrace(); } } } } } } CrossSectionLink link1 = (CrossSectionLink) network.getLink("54059"); |
File | Line |
---|---|
org\opentrafficsim\graphs\ContourPlot.java | 128 |
org\opentrafficsim\graphs\TrajectoryPlot.java | 134 |
this.path = new ArrayList<Lane>(path); // make a copy double[] endLengths = new double[path.size()]; double cumulativeLength = 0; LengthVector.Rel lengths = null; for (int i = 0; i < path.size(); i++) { Lane lane = path.get(i); lane.addSampler(this); cumulativeLength += lane.getLength().getSI(); endLengths[i] = cumulativeLength; } try { lengths = new LengthVector.Rel(endLengths, LengthUnit.SI, StorageType.DENSE); } catch (ValueException exception) { exception.printStackTrace(); } this.cumulativeLengths = lengths; this.xAxis = xAxis; |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\osm\output\Convert.java | 300 |
org\opentrafficsim\road\network\factory\osm\output\Convert.java | 415 |
if (osmLink.getLanes() == 1 && !osmLink.isOneway()) { laneAttributes = new LaneAttributes(laneType, Color.GREEN, LongitudinalDirectionality.DIR_BOTH); structure.put(0, laneAttributes); } else { for (int i = 0 - backwards; i < forwards; i++) { if (i < 0) { laneAttributes = new LaneAttributes(laneType, Color.GREEN, LongitudinalDirectionality.DIR_MINUS); structure.put(i, laneAttributes); } if (i >= 0) { laneAttributes = new LaneAttributes(laneType, Color.GREEN, LongitudinalDirectionality.DIR_PLUS); structure.put(i, laneAttributes); } } } } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 143 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 218 |
if (lanePathInfo.getPath().getLength().lt(forwardHeadway)) { if (correctLanes.isEmpty()) { LateralDirectionality direction = determineLeftRight(laneBasedGTU, nextSplitInfo); if (direction != null) { gtu.setTurnIndicatorStatus(direction.isLeft() ? TurnIndicatorStatus.LEFT : TurnIndicatorStatus.RIGHT); OperationalPlan laneChangePlan = makeLaneChangePlanMobil(laneBasedGTU, perception, lanePathInfo, direction); if (laneChangePlan != null) { return laneChangePlan; } } } } // Condition, if we have just changed lane, let's not change immediately again. if (gtu.getSimulator().getSimulatorTime().getTime().lt(this.earliestNexLaneChangeTime)) { return currentLanePlan(laneBasedGTU, startTime, locationAtStartTime, lanePathInfo); } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\AbstractLaneBasedTacticalPlanner.java | 489 |
org\opentrafficsim\road\gtu\lane\tactical\AbstractLaneBasedTacticalPlanner.java | 642 |
if (lastGtuDir.equals(GTUDirectionality.DIR_PLUS)) { if (lastLink.getEndNode().equals(link.getStartNode())) { // -----> O ----->, GTU moves ----> lastGtuDir = GTUDirectionality.DIR_PLUS; lastNode = (OTSNode) lastLink.getEndNode(); } else { // -----> O <-----, GTU moves ----> lastGtuDir = GTUDirectionality.DIR_MINUS; lastNode = (OTSNode) lastLink.getEndNode(); } } else { if (lastLink.getStartNode().equals(link.getStartNode())) { // <----- O ----->, GTU moves ----> lastNode = (OTSNode) lastLink.getStartNode(); lastGtuDir = GTUDirectionality.DIR_PLUS; } else { // <----- O <-----, GTU moves ----> lastNode = (OTSNode) lastLink.getStartNode(); lastGtuDir = GTUDirectionality.DIR_MINUS; } } lastLink = links.iterator().next(); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 209 |
org\opentrafficsim\road\network\factory\opendrive\Controller.java | 230 |
for (AbstractTrafficLightNew light : this.trafficLights.get(12)) { try { // System.out.println("traffic light 12 at time " + this.simulator.getSimulatorTime()); this.simulator.scheduleEventRel(new Time.Rel(72.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.GREEN}); this.simulator.scheduleEventRel(new Time.Rel(87.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.YELLOW}); this.simulator.scheduleEventRel(new Time.Rel(96.0, TimeUnit.SECOND), this, light, "setTrafficLightColor", new Object[]{TrafficLightColor.RED}); } catch (SimRuntimeException exception) { exception.printStackTrace(); } } } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\xml\CrossSectionElementTag.java | 124 |
org\opentrafficsim\road\network\factory\xml\CrossSectionElementTag.java | 199 |
org\opentrafficsim\road\network\factory\xml\CrossSectionElementTag.java | 250 |
if (attributes.getNamedItem("OFFSET") != null) cseTag.offset = LengthUnits.parseLengthRel(attributes.getNamedItem("OFFSET").getNodeValue()); else throw new SAXException("ROADTYPE.LANE: missing attribute OFFSET for lane " + roadTypeTag.name + "." + name); if (attributes.getNamedItem("WIDTH") != null) cseTag.width = LengthUnits.parseLengthRel(attributes.getNamedItem("WIDTH").getNodeValue()); else if (roadTypeTag.width != null) cseTag.width = roadTypeTag.width; else if (parser.globalTag.defaultLaneWidth != null) cseTag.width = parser.globalTag.defaultLaneWidth; else throw new SAXException("ROADTYPE.LANE: cannot determine WIDTH for lane: " + roadTypeTag.name + "." + name); |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 518 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 727 |
.plus(lastLane.getWidth(factor).multiplyBy(0.5)).plus(width.multiplyBy(0.5)); relativeLength = currentLink.getLength().multiplyBy(factor); CrossSectionSlice slice = new CrossSectionSlice(relativeLength, offSet, width); crossSectionSlices.add(slice); } else { CrossSectionSlice lastSlice = crossSectionSlices.get(crossSectionSlices.size() - 1); Length.Rel width = lastSlice.getWidth(); Length.Rel offSet = lastSlice.getDesignLineOffset(); relativeLength = currentLink.getLength(); CrossSectionSlice slice = new CrossSectionSlice(relativeLength, offSet, width); crossSectionSlices.add(slice); break; } } } OvertakingConditions overtakingConditions = null; Speed speed = null; if (leftLane.speedTags.size() > 0) |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 504 |
org\opentrafficsim\road\network\factory\opendrive\RoadTag.java | 713 |
for (WidthTag widthTag : leftLane.widthTags) { Length.Rel relativeLength = widthTag.sOffst; double factor = relativeLength.divideBy(lengthofLane).doubleValue(); if (factor < 0.98) { Length.Rel width = widthTag.a.plus(widthTag.b.multiplyBy(relativeLength.doubleValue())) .plus(widthTag.c.multiplyBy(Math.pow(relativeLength.doubleValue(), 2))) .plus(widthTag.d.multiplyBy(Math.pow(relativeLength.doubleValue(), 3))); Length.Rel offSet = lastLane.getLateralCenterPosition(factor) .plus(lastLane.getWidth(factor).multiplyBy(0.5)).plus(width.multiplyBy(0.5)); |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 105 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 114 |
public LaneBasedGTUFollowingLaneChangeTacticalPlanner() { super(); } /** {@inheritDoc} */ @Override public OperationalPlan generateOperationalPlan(final GTU gtu, final Time.Abs startTime, final DirectedPoint locationAtStartTime) throws OperationalPlanException, NetworkException, GTUException { // ask Perception for the local situation LaneBasedGTU laneBasedGTU = (LaneBasedGTU) gtu; LanePerception perception = laneBasedGTU.getPerception(); LaneBasedBehavioralCharacteristics drivingCharacteristics = laneBasedGTU.getBehavioralCharacteristics(); // start with the turn indicator off -- this can change during the method laneBasedGTU.setTurnIndicatorStatus(TurnIndicatorStatus.NONE); // if the GTU's maximum speed is zero (block), generate a stand still plan for one second if (laneBasedGTU.getMaximumVelocity().si < OperationalPlan.DRIFTING_SPEED_SI) { return new OperationalPlan(gtu, locationAtStartTime, startTime, new Time.Rel(1.0, TimeUnit.SECOND)); } // perceive the forward headway, accessible lanes and speed limit. perception.updateForwardHeadwayGTU(); perception.updateAccessibleAdjacentLanesLeft(); |
File | Line |
---|---|
org\opentrafficsim\graphs\FlowContourPlot.java | 67 |
org\opentrafficsim\graphs\SpeedContourPlot.java | 76 |
this.cumulativeLengths.add(new MutableLengthVector.Abs(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; } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 167 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 213 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 180 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 222 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 257 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 299 |
if (perception.getParallelGTUsLeft().isEmpty()) { Collection<HeadwayGTU> sameLaneTraffic = new HashSet<>(); if (perception.getForwardHeadwayGTU() != null && perception.getForwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getForwardHeadwayGTU()); } if (perception.getBackwardHeadwayGTU() != null && perception.getBackwardHeadwayGTU().getGtuId() != null) { sameLaneTraffic.add(perception.getBackwardHeadwayGTU()); } DirectedLaneChangeModel dlcm = new DirectedAltruistic(); DirectedLaneMovementStep dlms = dlcm.computeLaneChangeAndAcceleration(laneBasedGTU, LateralDirectionality.LEFT, |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 271 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 323 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 273 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 325 |
String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedCFLCTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_PLUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 267 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 319 |
String id = lane.getParentLink().getId() + "." + lane.getId(); LaneBasedBehavioralCharacteristics drivingCharacteristics = new LaneBasedBehavioralCharacteristics(new IDMPlusOld(), new Altruistic()); LaneBasedStrategicalPlanner strategicalPlanner = new LaneBasedStrategicalRoutePlanner(drivingCharacteristics, new LaneBasedGTUFollowingLaneChangeTacticalPlanner()); LanePerceptionFull perception = new LanePerceptionFull(); // new GTUGeneratorIndividual(id, this.simulator, carType, LaneBasedIndividualCar.class, // initialSpeedDist, iatDist, lengthDist, widthDist, maxSpeedDist, Integer.MAX_VALUE, // startTime, endTime, lane, position, GTUDirectionality.DIR_PLUS, // makeSwitchableGTUColorer(), strategicalPlanner, perception); try { new GeneratorAnimation(lane, position, this.simulator); } catch (RemoteException | NamingException | OTSGeometryException exception) { exception.printStackTrace(); } } else { // make a sink Length.Rel position = lane.getLength().lt(M25) ? M0 : M25; |
File | Line |
---|---|
org\opentrafficsim\road\network\lane\changing\OvertakingConditions.java | 239 |
org\opentrafficsim\road\network\lane\changing\OvertakingConditions.java | 292 |
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\road\network\factory\TestOpenDriveParserNASA.java | 558 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 554 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 564 |
} } /** {@inheritDoc} */ @Override public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator() { return this.simulator; } /** * @return a GTUColorer */ private GTUColorer makeSwitchableGTUColorer() { GTUColorer[] gtuColorers = new GTUColorer[]{ new IDGTUColorer(), new VelocityGTUColorer(new Speed(100.0, SpeedUnit.KM_PER_HOUR)), new AccelerationGTUColorer(new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2), new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2))}; return new SwitchableGTUColorer(0, gtuColorers); } } } |
File | Line |
---|---|
org\opentrafficsim\road\network\factory\TestOpenDriveParserNASA.java | 560 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTI.java | 570 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserNoRTINew.java | 831 |
org\opentrafficsim\road\network\factory\TestOpenDriveParserSV.java | 580 |
} /** {@inheritDoc} */ @Override public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator() { return this.simulator; } /** * @return a GTUColorer */ private GTUColorer makeSwitchableGTUColorer() { GTUColorer[] gtuColorers = new GTUColorer[]{ new IDGTUColorer(), new VelocityGTUColorer(new Speed(100.0, SpeedUnit.KM_PER_HOUR)), new AccelerationGTUColorer(new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2), new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2))}; return new SwitchableGTUColorer(0, gtuColorers); } } } |
File | Line |
---|---|
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingChange0TacticalPlanner.java | 367 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner.java | 355 |
org\opentrafficsim\road\gtu\lane\tactical\LaneBasedGTUFollowingLaneChangeTacticalPlanner2.java | 432 |
private boolean canChange(final LaneBasedGTU gtu, final LanePerception perception, final LanePathInfo lanePathInfo, final LateralDirectionality direction) throws GTUException, NetworkException { Collection<HeadwayGTU> otherLaneTraffic; perception.updateForwardHeadwayGTU(); perception.updateBackwardHeadwayGTU(); if (direction.isLeft()) { perception.updateParallelGTUsLeft(); perception.updateLaneTrafficLeft(); otherLaneTraffic = perception.getNeighboringGTUsLeft(); } else { perception.updateParallelGTUsRight(); perception.updateLaneTrafficRight(); otherLaneTraffic = perception.getNeighboringGTUsRight(); } if (!perception.parallelGTUs(direction).isEmpty()) { return false; |