Package org.movsim.simulator.vehicles

Examples of org.movsim.simulator.vehicles.Vehicle


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

        // set up a vehicle in lane 2
        final Vehicle v1 = newVehicle(293.1, 26.983, Lanes.LANE1, lengthCar);
        // final MOBIL m1 = new MOBIL(v1, minimumGap, safeDeceleration, politeness, thresholdAcceleration, rightBiasAcceleration);
        r0.addVehicle(v1);

        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);

        final Vehicle rV = r1.rearVehicle(Lanes.LANE1, v2.getRearPosition());
        assertEquals(v1.getId(), rV.getId());

        double balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, r1);
        assertTrue(balance < 0.0);
    }
View Full Code Here


    private Vehicle newVehicle(double rearPosition, double speed, int lane) {
        // Vehicle(type, pos, vel, lane, ldm, lcm, length, width, color);
        // return new Vehicle(Vehicle.Type.NONE, pos, vel, lane, idm, null, 5.0, 2.5, 3);
        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, 5.0, 2.5);
        vehicle.setLongitudinalModel(idm);
        vehicle.setSpeedlimit(80.0 / 3.6); // 80 km/h
        return vehicle;
    }
View Full Code Here

        vehicle.setSpeedlimit(80.0 / 3.6); // 80 km/h
        return vehicle;
    }

    private Vehicle newObstacle(double rearPosition, int lane) {
        return new Vehicle(rearPosition, 0.0, lane, 5.0, 2.5);
    }
View Full Code Here

        RoadSegment.resetNextId();
        Vehicle.resetNextId();

        final int laneCount = 1;
        final RoadSegment r0 = new RoadSegment(5000.0, laneCount);
        Vehicle v;

        final Vehicle v0 = newVehicle(3900.0, 1.0, Lanes.LANE1);
        r0.addVehicle(v0);
        v = r0.getVehicle(Lanes.LANE1, 0);
        assertEquals(v0, v);
        final Vehicle v1 = newVehicle(3700.0, 2.0, Lanes.LANE1);
        r0.addVehicle(v1);
        v = r0.getVehicle(Lanes.LANE1, 0);
        assertEquals(v0, v);
        v = r0.getVehicle(Lanes.LANE1, 1);
        assertEquals(v1, v);
        final Vehicle v2 = newVehicle(3100.0, 3.0, Lanes.LANE1);
        r0.addVehicle(v2);
        v = r0.getVehicle(Lanes.LANE1, 0);
        assertEquals(v0, v);
        v = r0.getVehicle(Lanes.LANE1, 1);
        assertEquals(v1, v);
        v = r0.getVehicle(Lanes.LANE1, 2);
        assertEquals(v2, v);

        final Vehicle v1a = newVehicle(3500.0, 4.0, Lanes.LANE1);
        r0.addVehicle(v1a);
        v = r0.getVehicle(Lanes.LANE1, 0);
        assertEquals(v0, v);
        v = r0.getVehicle(Lanes.LANE1, 1);
        assertEquals(v1, v);
View Full Code Here

        RoadSegment.resetNextId();
        Vehicle.resetNextId();
        final double roadLength = 1000.0;
        final int laneCount = 1;
        final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);
        Vehicle vehicle = roadSegment.rearVehicleOnLane(Lanes.LANE1);
        assertEquals(null, vehicle);

        final Vehicle v0 = newVehicle(900.0, 0.0, Lanes.LANE1);
        roadSegment.addVehicle(v0);
        vehicle = roadSegment.rearVehicleOnLane(Lanes.LANE1);
        assertEquals(v0.getId(), vehicle.getId());

        final Vehicle v1 = newVehicle(800.0, 0.0, Lanes.LANE1);
        roadSegment.addVehicle(v1);
        vehicle = roadSegment.rearVehicleOnLane(Lanes.LANE1);
        assertEquals(v1.getId(), vehicle.getId());
    }
View Full Code Here

        Vehicle.resetNextId();
        final double roadLength = 1000.0;
        final int laneCount = 1;
        final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);

        final Vehicle v0 = newVehicle(900.0, 1.0, Lanes.LANE1);
        roadSegment.addVehicle(v0);
        Vehicle rV = roadSegment.rearVehicle(Lanes.LANE1, 901.0);
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 900.0);
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 899.0);
        assertEquals(null, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 0.0);
        assertEquals(null, rV);

        final Vehicle v1 = newVehicle(800.0, 2.0, Lanes.LANE1);
        roadSegment.addVehicle(v1);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 900.0);
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 800.0);
        assertEquals(v1, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 901.0);
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 899.0);
        assertEquals(v1, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 801.0);
        assertEquals(v1, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 799.0);
        assertEquals(null, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 0.0);
        assertEquals(null, rV);

        final Vehicle v2 = newVehicle(700.0, 3.0, Lanes.LANE1);
        roadSegment.addVehicle(v2);
        assert roadSegment.eachLaneIsSorted();
        rV = roadSegment.rearVehicle(Lanes.LANE1, v0.getMidPosition());
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, v1.getMidPosition());
        assertEquals(v1, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, v2.getMidPosition());
        assertEquals(v2, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 901.0);
        assertEquals(v0, rV);
        rV = roadSegment.rearVehicle(Lanes.LANE1, 899.0);
        assertEquals(v1, rV);
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, 1.0, Lanes.LANE1);
        assertEquals(3900.0, v0.getRearPosition(), delta);
        r1.addVehicle(v0);
        final Vehicle v1 = newVehicle(3700.0, 2.0, Lanes.LANE1);
        r1.addVehicle(v1);
        final Vehicle v2 = newVehicle(3100.0, 3.0, Lanes.LANE1);
        r1.addVehicle(v2);

        final Vehicle v3 = newVehicle(600.0, 4.0, Lanes.LANE1);
        r0.addVehicle(v3);
        final Vehicle v4 = newVehicle(500.0, 5.0, Lanes.LANE1);
        r0.addVehicle(v4);

        Vehicle rV = r1.rearVehicle(Lanes.LANE1, 3901.0);
        assertEquals(v0, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 3900.0);
        assertEquals(v0, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 3700.0);
        assertEquals(v1, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 3101.0);
        assertEquals(v2, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 3100.0);
        assertEquals(v2, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 3099.0);
        assertEquals(v3.getId(), rV.getId());
        assertEquals(-100.0, rV.getRearPosition(), delta); // pos relative to r1
        assertEquals(v3.getSpeed(), rV.getSpeed(), delta);

        rV = r1.rearVehicle(Lanes.LANE1, 3099.0);
        assertEquals(v3.getId(), rV.getId());
        assertEquals(-100.0, rV.getRearPosition(), delta); // pos relative to r1
        rV = r0.rearVehicle(Lanes.LANE1, 601.0);
        assertEquals(v3, rV);
        rV = r0.rearVehicle(Lanes.LANE1, 600.0);
        assertEquals(v3, rV);
        rV = r0.rearVehicle(Lanes.LANE1, 599.0);
View Full Code Here

        assertEquals(r0.id(), r1.sourceRoadSegment(Lanes.LANE1).id());
        assertEquals(r0.id(), r1.sourceRoadSegment(Lanes.LANE2).id());
        assertEquals(null, r1.sourceRoadSegment(Lanes.LANE3));

        // vehicles suffixed 0 are on r0, vehicles suffixed 1 are on r1
        final Vehicle z1 = newVehicle(5.0, 1.0, Lanes.LANE1);
        r1.addVehicle(z1);
        final Vehicle z0 = newVehicle(996.0, 3.0, Lanes.LANE1);
        r0.addVehicle(z0);
        final Vehicle y1 = newVehicle(3.0, 4.0, Lanes.LANE2);
        r1.addVehicle(y1);
        final Vehicle y0 = newVehicle(998.0, 5.0, Lanes.LANE2);
        r0.addVehicle(y0);
        // vehicle in exit lane
        final Vehicle x1 = newVehicle(5.0, 5.0, Lanes.LANE3);
        r1.addVehicle(x1);

        Vehicle rV = r1.rearVehicle(Lanes.LANE1, 6.0);
        assertEquals(z1, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 5.0);
        assertEquals(z1, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 4.0);
        assertEquals(z0.getId(), rV.getId());
        assertEquals(-4.0, rV.getRearPosition(), delta);
        assertEquals(3.0, rV.getSpeed(), delta);
        rV = r1.rearVehicle(Lanes.LANE1, 3.0);
        assertEquals(z0.getId(), rV.getId());

        rV = r1.rearVehicle(Lanes.LANE2, 4.0);
        assertEquals(y1, rV);
        rV = r1.rearVehicle(Lanes.LANE2, 3.0);
        assertEquals(y1, rV);
        rV = r1.rearVehicle(Lanes.LANE2, 2.0);
        assert rV != null;
        assertEquals(y0.getId(), rV.getId());
        assertEquals(-2.0, rV.getRearPosition(), delta);
        assertEquals(5.0, rV.getSpeed(), delta);
        rV = r1.rearVehicle(Lanes.LANE2, 1.0);
        assertEquals(y0.getId(), rV.getId());
    }
View Full Code Here

        assertEquals(Lanes.NONE, r0.sinkLane(Lanes.LANE3));
        assertEquals(Lanes.LANE1, r0.sinkLane(Lanes.LANE1));
        assertEquals(Lanes.LANE2, r0.sinkLane(Lanes.LANE2));

        // vehicles suffixed 0 are on r0, vehicles suffixed 1 are on r1
        final Vehicle z1 = newVehicle(5.0, 1.0, Lanes.LANE1);
        r1.addVehicle(z1);
        final Vehicle z0 = newVehicle(996.0, 3.0, Lanes.LANE1);
        r0.addVehicle(z0);
        final Vehicle y1 = newVehicle(3.0, 4.0, Lanes.LANE2);
        r1.addVehicle(y1);
        final Vehicle y0 = newVehicle(998.0, 5.0, Lanes.LANE2);
        r0.addVehicle(y0);
        // vehicle in exit lane
        final Vehicle x0 = newVehicle(5.0, 5.0, Lanes.LANE3);
        r0.addVehicle(x0);

        Vehicle rV = r1.rearVehicle(Lanes.LANE1, 6.0);
        assertEquals(z1, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 5.0);
        assertEquals(z1, rV);
        rV = r1.rearVehicle(Lanes.LANE1, 4.0);
        assertEquals(z0.getId(), rV.getId());
        assertEquals(-4.0, rV.getRearPosition(), delta);
        assertEquals(3.0, rV.getSpeed(), delta);
        rV = r1.rearVehicle(Lanes.LANE1, 3.0);
        assertEquals(z0.getId(), rV.getId());

        rV = r1.rearVehicle(Lanes.LANE2, 4.0);
        assertEquals(y1, rV);
        rV = r1.rearVehicle(Lanes.LANE2, 3.0);
        assertEquals(y1, rV);
        rV = r1.rearVehicle(Lanes.LANE2, 2.0);
        assert rV != null;
        assertEquals(y0.getId(), rV.getId());
        assertEquals(-2.0, rV.getRearPosition(), delta);
        assertEquals(5.0, rV.getSpeed(), delta);
        rV = r1.rearVehicle(Lanes.LANE2, 1.0);
        assertEquals(y0.getId(), rV.getId());
    }
View Full Code Here

        RoadSegment.resetNextId();
        Vehicle.resetNextId();
        final double roadLength = 1000.0;
        final int laneCount = 1;
        final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);
        Vehicle vehicle = roadSegment.frontVehicleOnLane(Lanes.LANE1);
        assertEquals(null, vehicle);

        final Vehicle v0 = newVehicle(900.0, 0.0, Lanes.LANE1);
        roadSegment.addVehicle(v0);
        vehicle = roadSegment.frontVehicleOnLane(Lanes.LANE1);
        assertEquals(v0.getId(), vehicle.getId());

        final Vehicle v1 = newVehicle(800.0, 0.0, Lanes.LANE1);
        roadSegment.addVehicle(v1);
        vehicle = roadSegment.frontVehicleOnLane(Lanes.LANE1);
        assertEquals(v0.getId(), vehicle.getId());
    }
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.