Package org.movsim.simulator.vehicles

Examples of org.movsim.simulator.vehicles.Vehicle


     * @return true if the vehicle array is sorted
     */
    public boolean laneIsSorted() {
        final int count = vehicles.size();
        if (count > 1) { // if zero or one vehicles in lane then it is necessarily sorted
            Vehicle frontVehicle = vehicles.get(0);
            for (int i = 1; i < count; ++i) {
                final Vehicle vehicle = vehicles.get(i);
                if (frontVehicle.getRearPosition() < vehicle.getRearPosition()) {
                    return false;
                }
                // current vehicle is front vehicle next time around
                frontVehicle = vehicle;
            }
View Full Code Here


        final int count = vehicles.size();
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = 1; i < count; ++i) {
                final Vehicle front = vehicles.get(i - 1);
                final Vehicle rear = vehicles.get(i);
                if (rear.getRearPosition() > front.getRearPosition()) {
                    sorted = false;
                    // swap the two vehicles
                    vehicles.set(i - 1, rear);
                    vehicles.set(i, front);
                }
View Full Code Here

            LOG.error("no valid lines from {} lines in input file parsed!", input.size());
        }
    }

    private Vehicle createVehicle(MicroInflowRecord record) {
        final Vehicle vehicle = trafficSource.vehGenerator.createVehicle(record.getTypeLabel());
        if (record.hasRouteOrDestination()) {
            Route route = routing.hasRoute(record.getRouteOrDestination()) ? routing
                    .get(record.getRouteOrDestination()) : routing.findRoute(trafficSource.roadSegment.userId(),
                    record.getRouteOrDestination());
            LOG.info("overwrites vehicle's default route by route provided by input file: route={}", route.getName());
            vehicle.setRoute(route);
        }
        if (record.hasComment()) {
            vehicle.setInfoComment(record.getComment());
        }
        if (record.hasLength()) {
            vehicle.setLength(record.getLength());
        }
        if (record.hasWeight()) {
            vehicle.setWeight(record.getWeight());
        }
        if (record.hasLength() || record.hasWeight()) {
            LOG.info("and set individual length or weight: length={}, weight={}", vehicle.getLength(),
                    vehicle.getWeight());
        }
        if (record.hasSpeed()) {
            vehicle.setSpeed(record.getSpeed());
        }
        return vehicle;
    }
View Full Code Here

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

        // set up an obstacle directly in front of a vehicle, so the vehicle will change lanes
        // Obstacle(pos, lane, length, width, color) {
        final Vehicle obstacle = newObstacle(600.0, Lanes.LANE1);
        r0.addVehicle(obstacle);
        final Vehicle v0 = newVehicle(593.0, 5.0, Lanes.LANE1);
        final LaneChangeModel lcm = newLaneChangeModel(v0);
        v0.setLaneChangeModel(lcm);
        r0.addVehicle(v0);
        final double dt = 0.25;
        final double simulationTime = 0.0;
        final long iterationCount = 0;
        r0.makeLaneChanges(dt, simulationTime, iterationCount);
        assertEquals(Lanes.LANE1, obstacle.lane());
        assertEquals(Lanes.LANE2, v0.lane());
        assertEquals(1, r0.laneSegment(Lanes.LANE1).vehicleCount());
        assertEquals(1, r0.laneSegment(Lanes.LANE2).vehicleCount());
    }
View Full Code Here

        // Vehicle.setIntegrationType(Vehicle.IntegrationType.EULER);
        final double roadLength = 1000.0;
        final int laneCount = 1;
        final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);

        final Vehicle v0 = newVehicle(900.0, 10.0, Lanes.LANE1);
        roadSegment.addVehicle(v0);
        final Vehicle v1 = newVehicle(800.0, 20.0, Lanes.LANE1);
        roadSegment.addVehicle(v1);
        final Vehicle v2 = newVehicle(700.0, 30.0, Lanes.LANE1);
        roadSegment.addVehicle(v2);

        final double dt = 0.25;
        roadSegment.updateVehiclePositionsAndSpeeds(dt, 0.0, 0);
        assertEquals(902.5, v0.getRearPosition(), delta);
        assertEquals(805.0, v1.getRearPosition(), delta);
        assertEquals(707.5, v2.getRearPosition(), delta);
    }
View Full Code Here

        final RoadSegment r0 = new RoadSegment(700.0, laneCount);
        final RoadSegment r1 = new RoadSegment(5100.0, laneCount);
        // join r0 and r1 so vehicles move from r0 to r1
        Link.addJoin(r0, r1);

        final Vehicle v0 = newVehicle(3900.0, 10.0, Lanes.LANE1);
        r1.addVehicle(v0);
        final Vehicle v1 = newVehicle(3700.0, 20.0, Lanes.LANE1);
        r1.addVehicle(v1);
        final Vehicle v2 = newVehicle(3100.0, 30.0, Lanes.LANE1);
        r1.addVehicle(v2);

        final Vehicle v3 = newVehicle(695.0, 40.0, Lanes.LANE1);
        r0.addVehicle(v3);
        final Vehicle v4 = newVehicle(500.0, 50.0, Lanes.LANE1);
        r0.addVehicle(v4);

        final double dt = 0.25;
        final double simulationTime = 0.0;
        final long iterationCount = 0;
        r0.updateVehiclePositionsAndSpeeds(dt, simulationTime, iterationCount);
        assertEquals(705.0, v3.getRearPosition(), delta);
        assertEquals(512.5, v4.getRearPosition(), delta);

        r1.updateVehiclePositionsAndSpeeds(dt, simulationTime, iterationCount);
        assertEquals(3902.5, v0.getRearPosition(), delta);
        assertEquals(3705.0, v1.getRearPosition(), delta);
        assertEquals(3107.5, v2.getRearPosition(), delta);
View Full Code Here

        final int laneCount = 1;
        final RoadSegment r0 = new RoadSegment(3900.0, laneCount);
        // join r0 and r1 so vehicles move from r0 to r1
        Link.addJoin(r0, r0);

        final Vehicle v0 = newVehicle(3895.0, 80.0, Lanes.LANE1);
        r0.addVehicle(v0);
        final Vehicle v1 = newVehicle(3700.0, 20.0, Lanes.LANE1);
        r0.addVehicle(v1);
        final Vehicle v2 = newVehicle(3100.0, 30.0, Lanes.LANE1);
        r0.addVehicle(v2);

        final Vehicle v3 = newVehicle(695.0, 40.0, Lanes.LANE1);
        r0.addVehicle(v3);
        final Vehicle v4 = newVehicle(500.0, 50.0, Lanes.LANE1);
        r0.addVehicle(v4);

        final double dt = 0.25;
        final double simulationTime = 0.0;
        final long iterationCount = 0;
        r0.updateVehiclePositionsAndSpeeds(dt, simulationTime, iterationCount);
        assertEquals(true, r0.eachLaneIsSorted());
        r0.outFlow(dt, simulationTime, iterationCount);

        assertEquals(15.0, v0.getRearPosition(), delta);
        assertEquals(3705.0, v1.getRearPosition(), delta);
        assertEquals(3107.5, v2.getRearPosition(), delta);
        assertEquals(705.0, v3.getRearPosition(), delta);
        assertEquals(512.5, v4.getRearPosition(), delta);
        assertEquals(true, r0.eachLaneIsSorted());
    }
View Full Code Here

        final RoadSegment r0 = new RoadSegment(1000.0, laneCount);
        final RoadSegment r1 = new RoadSegment(5000.0, laneCount);
        // join r0 and r1 so vehicles move from r0 to r1
        Link.addJoin(r0, r1);

        final Vehicle v0 = newVehicle(999.0, 40.0, Lanes.LANE1);
        r0.addVehicle(v0);
        final double dt = 0.25;
        final double simulationTime = 0.0;
        final long iterationCount = 0;
        r0.updateVehiclePositionsAndSpeeds(dt, simulationTime, iterationCount);
        assertEquals(1009.0, v0.getRearPosition(), delta);
        r0.outFlow(dt, simulationTime, iterationCount);
        assertEquals(0, r0.getVehicleCount());
        assertEquals(1, r1.getVehicleCount());
        final Vehicle v = r1.getVehicle(Lanes.LANE1, 0);
        assertEquals(9.0, v.getRearPosition(), delta);
    }
View Full Code Here

        final RoadSegment r1 = new RoadSegment(5000.0, laneCount + 1);
        r1.setLaneType(Lanes.LANE1, Lanes.Type.ENTRANCE);
        // join r0 and r1 so vehicles move from r0 to r1
        Link.addJoin(r0, r1);

        final Vehicle v1 = newVehicle(999.0, 40.0, Lanes.LANE1);
        r0.addVehicle(v1);
        final Vehicle v2 = newVehicle(998.0, 40.0, Lanes.LANE2);
        r0.addVehicle(v2);
        final Vehicle v3 = newVehicle(997.0, 40.0, Lanes.LANE3);
        r0.addVehicle(v3);

        final double dt = 0.25;
        final double simulationTime = 0.0;
        final long iterationCount = 0;
View Full Code Here

        Vehicle.resetNextId();

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

        final Vehicle v0 = newVehicle(800.0, 1.0, Lanes.LANE2);
        r0.addVehicle(v0);
        final Vehicle v1 = newVehicle(700.0, 1.0, Lanes.LANE3);
        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

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.