Examples of LaneSegment


Examples of org.movsim.simulator.roadnetwork.LaneSegment

        if (exitRoadSegmentId == roadSegment.id() && lane() != Lanes.LANE1) {
            // the vehicle is in the exit road segment, but not in the exit lane
            // react to vehicle ahead in exit lane
            // TODO this reaction is in same situations too short-sighted so that the vehicle in the exit lane must be
            // considered already in the upstream segment
            final LaneSegment exitLaneSegment = roadSegment.laneSegment(roadSegment.trafficLaneMax());
            if (exitLaneSegment != null && exitLaneSegment.type() == Lanes.Type.EXIT) {
                // this front vehicle could also result in negative net distances
                // but the deceleration is limited anyway
                Vehicle frontVehicle = exitLaneSegment.frontVehicle(this);
                double accToVehicleInExitLane = longitudinalModel.calcAcc(this, frontVehicle);
                final double decelLimit = 4.0;
                accToVehicleInExitLane = Math.max(accToVehicleInExitLane, -decelLimit);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(String
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

        final Vehicle v2 = newVehicle(6.3, 5.589, Lanes.LANE2, lengthCar);
        final MOBIL m2 = new MOBIL(v2, createModelParameterMOBIL(minimumGap, safeDeceleration, politeness,
                thresholdAcceleration, rightBiasAcceleration));
        r1.addVehicle(v2);
        final LaneSegment sls = r1.sourceLaneSegment(Lanes.LANE1);
        assertEquals(1, sls.vehicleCount());

        final Vehicle v3 = newVehicle(25.0, 4.0, Lanes.LANE2, lengthCar);
        // final MOBIL m3 = new MOBIL(v3, minimumGap, safeDeceleration, politeness, thresholdAcceleration, rightBiasAcceleration);
        r1.addVehicle(v3);
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

        // set prospectiveBalance to large negative to indicate no lane change when not safe
        double prospectiveBalance = -Double.MAX_VALUE;
        final int currentLane = me.lane();
        final int newLane = currentLane + direction;
        assert newLane >= Lanes.MOST_INNER_LANE && newLane <= roadSegment.laneCount();
        final LaneSegment newLaneSegment = roadSegment.laneSegment(newLane);
        if (newLaneSegment.type() == Lanes.Type.ENTRANCE) {
            // never change lane into an entrance lane
            return prospectiveBalance;
        }

        final Vehicle newFront = newLaneSegment.frontVehicle(me);
        if (newFront != null) {
            if (newFront.inProcessOfLaneChange()) {
                return prospectiveBalance;
            }
            final double gapFront = me.getNetDistance(newFront);
            if (gapFront < param.getMinimumGap()) {
                return prospectiveBalance;
            }
        }
        final Vehicle newBack = newLaneSegment.rearVehicle(me);
        if (newBack != null) {
            if (newBack.inProcessOfLaneChange()) {
                return prospectiveBalance;
            }
            final double gapRear = newBack.getNetDistance(me);
            if (gapRear < param.getMinimumGap()) {
                return prospectiveBalance;
            }
        }
        final LaneSegment currentLaneSegment = roadSegment.laneSegment(currentLane);
        final Vehicle oldFront = currentLaneSegment.frontVehicle(me);
        if (oldFront != null) {
            if (oldFront.inProcessOfLaneChange()) {
                return prospectiveBalance;
            }
        }

        // new situation: newBack with me as leader and following left lane cases
        // TO_LEFT --> just the actual situation
        // TO_RIGHT --> consideration of left-lane (with me's leader) has no effect
        // temporarily add the current vehicle to the new lane to calculate the new accelerations
        me.setLane(newLane);
        final int index = newLaneSegment.addVehicleTemp(me);
        final double newBackNewAcc = newBack == null ? 0 : newBack.calcAccModel(newLaneSegment, null);
        final double meNewAcc = me.calcAccModel(newLaneSegment, null);
        newLaneSegment.removeVehicle(index);
        me.setLane(currentLane);

        if (safetyCheckAcceleration(newBackNewAcc)) {
            return prospectiveBalance;
        }

        // check now incentive criterion
        // consider three vehicles: me, oldBack, newBack

        // old situation for me
        final double meOldAcc = me.calcAccModel(currentLaneSegment, null);

        // old situation for old back
        // in old situation same left lane as me
        final Vehicle oldBack = currentLaneSegment.rearVehicle(me);
        final double oldBackOldAcc = (oldBack != null) ? oldBack.calcAccModel(currentLaneSegment, null) : 0.0;

        // old situation for new back: just provides the actual left-lane situation
        final double newBackOldAcc = (newBack != null) ? newBack.calcAccModel(newLaneSegment, null) : 0.0;

        // new situation for new back:
        final double oldBackNewAcc;
        if (oldBack == null) {
            oldBackNewAcc = 0.0;
        } else {
            // cannot temporarily remove the current vehicle from the current lane, since we are in a loop
            // that iterates over the vehicles in the current lane. So calculate oldBackNewAcc based on just
            // the front vehicle.
            if (currentLaneSegment.frontVehicle(me) != null) { // TODO remove quickhack for avoiding nullpointer
                oldBackNewAcc = oldBack.getLongitudinalModel().calcAcc(oldBack, currentLaneSegment.frontVehicle(me));
            } else {
                oldBackNewAcc = 0.0;
            }

            // currentLaneSegment.removeVehicle(me);
            // oldBackNewAcc = oldBack.calcAccModel(currentLaneSegment, null);
            // currentLaneSegment.addVehicle(me);
        }

        // MOBIL trade-off for driver and neighborhood
        final double oldBackDiffAcc = oldBackNewAcc - oldBackOldAcc;
        final double newBackDiffAcc = newBackNewAcc - newBackOldAcc;
        final double meDiffAcc = meNewAcc - meOldAcc;

        final int changeTo = newLaneSegment.lane() - currentLaneSegment.lane();

        // hack for CCS
        if (me.getLongitudinalModel().modelName() == ModelName.CCS) {
            double biasForced = 10000;
            double biasNormal = 0.02;
            double bias;
            final int laneCount = roadSegment.laneCount();

            if (roadSegment.laneSegment(currentLane).type() == Lanes.Type.ENTRANCE) {
                double factor = (currentLane > 0.5 * (laneCount - 1)) ? (laneCount - currentLane) : (currentLane + 1);
                // System.out.println("currentLane: " + currentLane + " factor*biasForced=" + factor * biasForced);
                return biasForced * factor;
            }

            // assume increasing lane index from right to left
            bias = +2 * biasNormal / (laneCount - 1) * (currentLane - (0.5 * (laneCount - 1)));

            prospectiveBalance = meDiffAcc + param.getPoliteness() * (oldBackDiffAcc + newBackDiffAcc)
                    - param.getThresholdAcceleration() - bias * direction;

            // ###########################################################
            // new hack: bias considering BOTH the plus and the minus lane

            // Parameter considering BOTH the plus and the minus lane
            double vc = 0.5; // maximum speed for the method to be effective
            double biasmax = 50; // maximum bias
            double fracCoop = 0.8; // fraction of cooperative runners/vehicles
            double b = 10; // normal deceleration (=b in acc models)
            double dt = 0.2; // !! get elsewhere!!

            // local variables need for both (1) and (2)

            int lanePlus = currentLane + direction;
            int laneMinus = currentLane - direction;
            if ((Math.min(lanePlus, laneMinus) < Lanes.MOST_INNER_LANE) || (Math.max(lanePlus, laneMinus) > laneCount)) {
                return prospectiveBalance;
            }

            final LaneSegment laneSegmentPlus = roadSegment.laneSegment(lanePlus);
            final LaneSegment laneSegmentMinus = roadSegment.laneSegment(laneMinus);
            final Vehicle frontPlus = laneSegmentPlus.frontVehicle(me);
            final Vehicle rearPlus = laneSegmentPlus.rearVehicle(me);
            final Vehicle frontMinus = laneSegmentMinus.frontVehicle(me);
            final Vehicle rearMinus = laneSegmentMinus.rearVehicle(me);
            if ((frontPlus == null) || (frontMinus == null) || (rearPlus == null) || (rearMinus == null)) {
                return prospectiveBalance;
            }

            double vPlus = Math.min(frontPlus.getSpeed(), rearPlus.getSpeed());
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

        // initialize with largest possible deceleration
        double accToLeft = -Double.MAX_VALUE;
        double accToRight = -Double.MAX_VALUE;
        // consider lane-changing to right-hand side lane
        if (currentLane + Lanes.TO_RIGHT <= roadSegment.trafficLaneMax()) {
            final LaneSegment newLaneSegment = roadSegment.laneSegment(currentLane + Lanes.TO_RIGHT);
            if (newLaneSegment.type() == Lanes.Type.TRAFFIC) {
                // only consider lane changes into traffic lanes, other lane changes are handled by mandatory lane
                // changing
                accToRight = lcModelMOBIL.calcAccelerationBalance(me, Lanes.TO_RIGHT, roadSegment);
            }
        }

        // consider lane-changing to left-hand side lane
        if (currentLane + Lanes.TO_LEFT >= Lanes.MOST_INNER_LANE) {
            final LaneSegment newLaneSegment = roadSegment.laneSegment(currentLane + Lanes.TO_LEFT);
            if (newLaneSegment.type() == Lanes.Type.TRAFFIC) {
                // only consider lane changes into traffic lanes, other lane changes are handled by mandatory lane
                // changing
                accToLeft = lcModelMOBIL.calcAccelerationBalance(me, Lanes.TO_LEFT, roadSegment);
            }
        }
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

        return LaneChangeDecision.STAY_IN_LANE;
    }

    private LaneChangeDecision checkForMandatoryLaneChangeAtEntrance(RoadSegment roadSegment) {
        final int currentLane = me.lane();
        final LaneSegment currentLaneSegment = roadSegment.laneSegment(currentLane);

        if (currentLaneSegment.type() == Lanes.Type.ENTRANCE) {
            final int direction = (currentLane == roadSegment.laneCount()) ? Lanes.TO_LEFT : Lanes.TO_RIGHT;
            if (currentLane + direction >= Lanes.MOST_INNER_LANE) {
                final LaneSegment newLaneSegment = roadSegment.laneSegment(currentLane + direction);
                if (isSafeLaneChange(newLaneSegment)) {
                    double distanceToRoadSegmentEnd = me.getDistanceToRoadSegmentEnd();
                    if (distanceToRoadSegmentEnd < 0) {
                        // just a hack. should not happen.
                        LOG.info("check this: roadSegmentLength not set. Do mandatory lane change anyway.");
                        return (direction == Lanes.TO_LEFT) ? LaneChangeDecision.MANDATORY_TO_LEFT
                                : LaneChangeDecision.MANDATORY_TO_RIGHT;
                    }
                    // evaluate additional motivation to leave entrance lane
                    double accInCurrentLane = me.getLongitudinalModel()
                            .calcAcc(me, currentLaneSegment.frontVehicle(me));
                    double accInNewLane = me.getLongitudinalModel().calcAcc(me, newLaneSegment.frontVehicle(me));
                    double bias = biasForMandatoryChange(distanceToRoadSegmentEnd);
                    if (accInNewLane + bias > accInCurrentLane) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(String
                                    .format("change lane: veh.id=%d, distanceToRoadSegmentEnd=%.2f, accInCurrentLane=%.2f, accInNewLane=%.2f, bias=%.2f",
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

                    && roadSegment.laneSegment(roadSegment.laneCount()).type() == Lanes.Type.EXIT) {
                // already in exit lane, so do not move out of it
                return LaneChangeDecision.MANDATORY_STAY_IN_LANE;
            } else if (currentLane < roadSegment.laneCount()) {
                // evaluate situation on the right lane
                final LaneSegment newLaneSegment = roadSegment.laneSegment(currentLane + Lanes.TO_RIGHT);
                if (isSafeLaneChange(newLaneSegment)) {
                    return LaneChangeDecision.MANDATORY_TO_RIGHT;
                }
                return LaneChangeDecision.MANDATORY_STAY_IN_LANE;
            }
        }

        // consider mandatory lane-change to exit on next road segment ahead
        final LaneSegment sinkLaneSegment = roadSegment.laneSegment(currentLane).sinkLaneSegment();
        if (sinkLaneSegment != null && me.exitRoadSegmentId() == sinkLaneSegment.roadSegment().id()) {
            // next road segment is the exit segment
            final double distanceToExit = roadSegment.roadLength() - me.getFrontPosition();
            if (distanceToExit < distanceBeforeExitMustChangeLanes) {
                if (currentLane == roadSegment.laneCount()) {
                    // already in exit lane, so do not move out of it
                    return LaneChangeDecision.MANDATORY_STAY_IN_LANE;
                } else if (currentLane < roadSegment.laneCount()) {
                    final LaneSegment newLaneSegment = roadSegment.laneSegment(currentLane + Lanes.TO_RIGHT);
                    if (isSafeLaneChange(newLaneSegment)) {
                        return LaneChangeDecision.MANDATORY_TO_RIGHT;
                    }
                    return LaneChangeDecision.MANDATORY_STAY_IN_LANE;
                }
View Full Code Here

Examples of org.movsim.simulator.roadnetwork.LaneSegment

                            .format("next to entrance lane: pos=%.2f, lane=%d, netGap=%.2f, ownSpeed=%.2f, dv=%.2f, calcAccToFront=%.2f",
                                    me.getFrontPosition(), currentLane, me.getNetDistance(frontVehicle), me.getSpeed(),
                                    me.getRelSpeed(frontVehicle), accToFront));
                }
                final int newLane = currentLane + Lanes.TO_LEFT;
                final LaneSegment newLaneSegment = roadSegment.laneSegment(newLane);

                if (newLaneSegment.type() == Lanes.Type.ENTRANCE) {
                    // never change lane into an entrance lane
                    return LaneChangeDecision.NONE;
                }
                final Vehicle newFront = newLaneSegment.frontVehicle(me);
                if (newFront != null) {
                    if (newFront.inProcessOfLaneChange()) {
                        return LaneChangeDecision.NONE;
                    }
                    final double gapFront = me.getNetDistance(newFront);
                    if (gapFront < lcModelMOBIL.getParameter().getMinimumGap()) {
                        return LaneChangeDecision.NONE;
                    }
                }
                final Vehicle newBack = newLaneSegment.rearVehicle(me);
                if (newBack != null) {
                    if (newBack.inProcessOfLaneChange()) {
                        return LaneChangeDecision.NONE;
                    }
                    final double gapRear = newBack.getNetDistance(me);
                    if (gapRear < lcModelMOBIL.getParameter().getMinimumGap()) {
                        return LaneChangeDecision.NONE;
                    }
                }
                me.setLane(newLane);
                final int index = newLaneSegment.addVehicleTemp(me);
                final double newBackNewAcc = newBack == null ? 0 : newBack.calcAccModel(newLaneSegment, null);
                final double meNewAcc = me.calcAccModel(newLaneSegment, null);
                newLaneSegment.removeVehicle(index);
                me.setLane(currentLane);

                if (lcModelMOBIL.safetyCheckAcceleration(newBackNewAcc) || lcModelMOBIL.safetyCheckAcceleration(meNewAcc)) {
                    return LaneChangeDecision.NONE;
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.