Package org.movsim.simulator.vehicles

Examples of org.movsim.simulator.vehicles.Vehicle


        Vehicle.resetNextId();

        final int laneCount = 3;
        final RoadSegment r0 = new RoadSegment(1000.0, laneCount);

        final Vehicle v0 = newVehicle(800.0, 1.0, Lanes.LANE1);
        r0.addVehicle(v0);
        final Vehicle v1 = newVehicle(700.0, 1.0, Lanes.LANE1);
        r0.addVehicle(v1);
        final Vehicle v2 = newVehicle(600.0, 1.0, Lanes.LANE3);
        r0.addVehicle(v2);
        final Iterator<Vehicle> iterator = r0.iterator();
        assertEquals(true, iterator.hasNext());
        assertEquals(v0, iterator.next());
        assertEquals(true, iterator.hasNext());
View Full Code Here


        if (leftLaneSegment == null) {
            return accInOwnLane;
        }

        // check left-vehicle's speed
        final Vehicle newFrontLeft = leftLaneSegment.frontVehicle(me);
        if (newFrontLeft == null) {
            return accInOwnLane;
        }
        final double speedFront = newFrontLeft.getSpeed();
        if (speedFront <= vCritEur) {
            return accInOwnLane;
        }

        // condition me.getSpeed() > speedFront will be evaluated by softer tanh
View Full Code Here

     * @return the calculated acceleration
     */
    public double calcAcc(Vehicle me, LaneSegment laneSegment, double alphaT, double alphaV0, double alphaA) {
        // By default only consider the vehicle in front when calculating acceleration.
        // LDMs that consider more than the front vehicle should override this method.
        final Vehicle frontVehicle = laneSegment.frontVehicle(me);
        return calcAcc(me, frontVehicle, alphaT, alphaV0, alphaA);
    }
View Full Code Here

    }

    private static double calcEffectiveFrontVehicleLengths(Vehicle me, TrafficLight trafficLight,
            double distanceToSecondTrafficlight) {
        double sumEffectiveLengths = 0;
        Vehicle frontVehicle = trafficLight.roadSegment().laneSegment(me.lane()).frontVehicle(me);
        while (frontVehicle != null && me.getBrutDistance(frontVehicle) < distanceToSecondTrafficlight) {
            sumEffectiveLengths += frontVehicle.getEffectiveLength();
            Vehicle prevFront = frontVehicle;
            frontVehicle = trafficLight.roadSegment().laneSegment(frontVehicle.lane()).frontVehicle(frontVehicle);
            if (frontVehicle != null && prevFront.getId() == frontVehicle.getId()) {
                // FIXME seems to be a real bug: get back the *same* vehicle when its entered the downstream roadsegment
                break;
            }
        }
        return sumEffectiveLengths;
View Full Code Here

        return false;
    }

    private boolean vehicleIsInFrontOfLight(TrafficLight trafficLight) {
        for (LaneSegment laneSegment : trafficLight.roadSegment().laneSegments()) {
            Vehicle vehicle = laneSegment.rearVehicle(trafficLight.position());
            if (vehicle != null && (trafficLight.position() - vehicle.getFrontPosition() < conditionRange)) {
                LOG.debug("condition check: vehicle is in front of trafficlight: vehPos={}, trafficlightPos={}",
                        vehicle.getFrontPosition(), trafficLight.position());
                return true;
            }
        }
        return false;
    }
View Full Code Here

        return false;
    }

    private boolean vehicleIsInFrontOfLightAndDriving(TrafficLight trafficLight) {
        for (LaneSegment laneSegment : trafficLight.roadSegment().laneSegments()) {
            Vehicle vehicle = laneSegment.rearVehicle(trafficLight.position());
            if (vehicle != null && (trafficLight.position() - vehicle.getFrontPosition() < conditionRange)
                    && vehicle.getSpeed() > 0) {
                LOG.debug("condition check: vehicle is in front of trafficlight: vehPos={}, trafficlightPos={}",
                        vehicle.getFrontPosition(), trafficLight.position());
                return true;
            }
        }
        return false;
    }
View Full Code Here

                    LOG.debug("no vehicle added at x={} for vanishing initial localDensity={}.", position, rhoLocal);
                    position -= 50; // move on in upstream direction
                    continue;
                }

                final Vehicle veh = vehGenerator.createVehicle(testVehicle);
                final double meanDistanceInLane = 1. / (rhoLocal + MovsimConstants.SMALL_VALUE);
                // TODO icMacro for ca
                // final double minimumGap = veh.getLongitudinalModel().isCA() ? veh.getLength() : veh.getLength() +
                // veh.getLongitudinalModel().getS0();
                final double minimumGap = veh.getLength() + veh.getLongitudinalModel().getMinimumGap();
                final double posDecrement = Math.max(meanDistanceInLane, minimumGap);
                position -= posDecrement;

                if (position <= posDecrement) {
                    LOG.debug("leave minimum gap at origin of road segment and start with next lane, pos={}", position);
                    break;
                }
                final Vehicle leader = laneSegment.rearVehicle();
                final double gapToLeader = (leader == null) ? MovsimConstants.GAP_INFINITY : leader.getRearPosition()
                        - position;

                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format(
                            "meanDistance=%.3f, minimumGap=%.2f, posDecrement=%.3f, gapToLeader=%.3f\n",
View Full Code Here

        LOG.debug(("choose micro initial conditions"));
        int vehicleNumber = 1;
        for (final MicroIC ic : initialMicroConditions) {
            // TODO counter
            final String vehTypeFromFile = ic.getLabel();
            final Vehicle veh = (vehTypeFromFile.length() == 0) ? vehGenerator.createVehicle() : vehGenerator
                    .createVehicle(vehTypeFromFile);
            veh.setVehNumber(vehicleNumber);
            vehicleNumber++;
            // testwise:
            veh.setFrontPosition(Math.round(ic.getPosition() / veh.physicalQuantities().getxScale()));
            veh.setSpeed(Math.round(ic.getSpeed() / veh.physicalQuantities().getvScale()));
            final int lane = ic.getLane();
            if (lane < Lanes.MOST_INNER_LANE || lane > roadSegment.laneCount()) {
                throw new IllegalArgumentException("lane=" + lane
                        + " given in initial condition does not exist for road=" + roadSegment.id()
                        + " which has a laneCount of " + roadSegment.laneCount());
            }
            veh.setLane(lane);
            roadSegment.addVehicle(veh);
            LOG.info(String.format("set vehicle with label = %s on lane=%d with front at x=%.2f, speed=%.2f",
                    veh.getLabel(), veh.lane(), veh.getFrontPosition(), veh.getSpeed()));
            if (veh.getLongitudinalModel().isCA()) {
                LOG.info(String.format("and for the CA in physical quantities: front position at x=%.2f, speed=%.2f",
                        veh.physicalQuantities().getFrontPosition(), veh.physicalQuantities().getSpeed()));
            }
        }
    }
View Full Code Here

public class MOBILTest {
    private static final double delta = 0.00001;

    private Vehicle newVehicle(double rearPosition, double speed, int lane, double length) {
        final IDM idm = new IDM(33.0, 0.5, 3.0, 1.5, 2.0, 5.0);
        final Vehicle vehicle = new Vehicle(rearPosition, speed, lane, length, 2.5);
        vehicle.setLongitudinalModel(idm);
        vehicle.setSpeedlimit(80.0 / 3.6); // 80 km/h
        return vehicle;
    }
View Full Code Here

        final double politeness = 0.1;
        final double thresholdAcceleration = 0.2;
        final double rightBiasAcceleration = 0.3;

        // set up a vehicle in most inner lane (left lane)
        final Vehicle v1 = newVehicle(900.0, 0.0, Lanes.LANE1, lengthCar);
        final MOBIL m1 = new MOBIL(v1, createModelParameterMOBIL(minimumGap, safeDeceleration, politeness,
                thresholdAcceleration, rightBiasAcceleration));
        final LaneChangeModel lcm1 = new LaneChangeModel(v1, createLaneChangeModelType(m1.getParameter()));
        v1.setLaneChangeModel(lcm1);
        roadSegment.addVehicle(v1);

        // set up a vehicle in right lane
        final Vehicle v2 = newVehicle(900.0 - lengthCar - tooSmallGap, 0.0, Lanes.LANE2, lengthCar);
        final MOBIL m2 = new MOBIL(v2, createModelParameterMOBIL(minimumGap, safeDeceleration, politeness,
                thresholdAcceleration, rightBiasAcceleration));
        final LaneChangeModel lcm2 = new LaneChangeModel(v2, createLaneChangeModelType(m2.getParameter()));
        v2.setLaneChangeModel(lcm2);
        roadSegment.addVehicle(v2);

        // vehicles too close together, so acceleration balance should be large negative
        double balance = m1.calcAccelerationBalance(v1, Lanes.TO_RIGHT, roadSegment);
        assertEquals(-Double.MAX_VALUE, balance, delta);
        balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
        assertEquals(-Double.MAX_VALUE, balance, delta);

        // now set up with sufficient gap between vehicles, but v2 needs to decelerate, so it is not
        // favourable to change lanes
        roadSegment.clearVehicles();
        v2.setFrontPosition(v1.getRearPosition() - 2 * minimumGap);
        v2.setSpeed(80.0 / 3.6);
        roadSegment.addVehicle(v1);
        roadSegment.addVehicle(v2);
        balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
        assertTrue(balance < 0.0);

        // now set up with sufficient gap between vehicles, but v1 needs to brake heavily, so it is not
        // safe to change lanes
        roadSegment.clearVehicles();
        v2.setRearPosition(v1.getFrontPosition() + 2 * minimumGap);
        v2.setSpeed(80.0 / 3.6); // 80 km/h
        v1.setSpeed(120.0 / 3.6); // 120 km/h
        roadSegment.addVehicle(v1);
        roadSegment.addVehicle(v2);
        balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
        assertEquals(-Double.MAX_VALUE, balance, delta);
View Full Code Here

TOP

Related Classes of org.movsim.simulator.vehicles.Vehicle

Copyright © 2018 www.massapicom. 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.