Package org.movsim.simulator.vehicles

Examples of org.movsim.simulator.vehicles.Vehicle


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

        Vehicle.resetNextId();
        final Vehicle v0 = newVehicle(900.0, 1.0, Lanes.LANE1);
        roadSegment.addVehicle(v0);
        Vehicle fV = roadSegment.frontVehicle(Lanes.LANE1, 900.0);
        assertEquals(null, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 1000.0);
        assertEquals(null, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 901.0);
        assertEquals(null, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 899.0);
        assertEquals(v0, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 0.0);
        assertEquals(v0, fV);

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

        final Vehicle v2 = newVehicle(700.0, 3.0, Lanes.LANE1);
        roadSegment.addVehicle(v2);
        fV = roadSegment.frontVehicle(Lanes.LANE1, v0.getMidPosition());
        assertEquals(null, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, v1.getMidPosition());
        assertEquals(v0, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, v2.getMidPosition());
        assertEquals(v1, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 901.0);
        assertEquals(null, fV);
        fV = roadSegment.frontVehicle(Lanes.LANE1, 899.0);
        assertEquals(v0, fV);
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); // r0=source, r1=sink

        final Vehicle v0 = newVehicle(3900.0, 1.0, Lanes.LANE1);
        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 fV = r1.frontVehicle(Lanes.LANE1, v0.getMidPosition());
        assertEquals(null, fV);
        fV = r1.frontVehicle(Lanes.LANE1, r1.roadLength());
        assertEquals(null, fV);
        fV = r1.frontVehicle(Lanes.LANE1, v1.getMidPosition());
        assertEquals(v0, fV);
        fV = r1.frontVehicle(Lanes.LANE1, v2.getMidPosition());
        assertEquals(v1, fV);

        // vehicle in front of end of road0 is v2
        fV = r0.frontVehicle(Lanes.LANE1, r0.roadLength());
        assertEquals(v2.getId(), fV.getId());
        assertEquals(v2.getMidPosition() + r0.roadLength(), fV.getMidPosition(), delta);
        assertEquals(v2.getSpeed(), fV.getSpeed(), delta);
        // vehicle in front of v3 is v2
        fV = r0.frontVehicle(Lanes.LANE1, v3.getMidPosition());
        assertEquals(v2.getId(), fV.getId());
        fV = r0.frontVehicle(Lanes.LANE1, v4.getMidPosition());
        assertEquals(v3, fV);
        fV = r0.frontVehicle(Lanes.LANE1, 0.0);
        assertEquals(v4, fV);
    }
View Full Code Here

        r1.setLaneType(Lanes.LANE3, Lanes.Type.EXIT);// so Lane1 is exit lane of r1
        // join r0 and r1 so vehicles move from r0 to r1
        Link.addJoin(r0, r1);

        // 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 fV = r0.frontVehicle(Lanes.LANE1, 995.0);
        assertEquals(z0, fV);
        fV = r0.frontVehicle(Lanes.LANE1, 996.0);
        assertEquals(z1.getId(), fV.getId());
        assertEquals(1005.0, fV.getRearPosition(), delta);
        assertEquals(1.0, fV.getSpeed(), delta);
        fV = r0.frontVehicle(Lanes.LANE1, 997.0);
        assertEquals(z1.getId(), fV.getId());

        fV = r0.frontVehicle(Lanes.LANE2, 997.0);
        assertEquals(y0, fV);
        fV = r0.frontVehicle(Lanes.LANE2, 998.0);
        assertEquals(y1.getId(), fV.getId());
        assertEquals(1003.0, fV.getRearPosition(), delta);
        assertEquals(4.0, fV.getSpeed(), delta);
        fV = r0.frontVehicle(Lanes.LANE2, 999.0);
        assertEquals(y1.getId(), fV.getId());
    }
View Full Code Here

        final double speedVeh = veh.getSpeed();
        vSum[laneIndex] += speedVeh;
        occTime[laneIndex] += (speedVeh > 0) ? veh.getLength() / speedVeh : 0;
        sumInvV[laneIndex] += (speedVeh > 0) ? 1. / speedVeh : 0;
        // brut timegap not calculate from local detector data:
        final Vehicle vehFront = laneSegment.frontVehicle(veh);
        final double brutTimegap = (vehFront == null) ? 0 : veh.getBrutDistance(vehFront) / vehFront.getSpeed();
        // "microscopic flow"
        sumInvQ[laneIndex] += (brutTimegap > 0) ? 1. / brutTimegap : 0;
    }
View Full Code Here

        LOG.debug("laneNumber={}, roadSegmentId={}", laneNumber, roadSegment.userId());
        if (lane.getType().equals(Lanes.Type.TRAFFIC.getOpenDriveIdentifier())) {
            roadSegment.setLaneType(laneNumber, Lanes.Type.TRAFFIC);
        } else if (lane.getType().equals(Lanes.Type.ENTRANCE.getOpenDriveIdentifier())) {
            roadSegment.setLaneType(laneNumber, Lanes.Type.ENTRANCE);
            Vehicle obstacle = new Vehicle(roadSegment.roadLength(), 0.0, laneNumber, 1.0, 1.0);
            obstacle.setType(Vehicle.Type.OBSTACLE);
            roadSegment.addObstacle(obstacle);
        } else if (lane.getType().equals(Lanes.Type.EXIT.getOpenDriveIdentifier())) {
            roadSegment.setLaneType(laneNumber, Lanes.Type.EXIT);
        } else if (lane.getType().equals(Lanes.Type.SHOULDER.getOpenDriveIdentifier())) {
            roadSegment.setLaneType(laneNumber, org.movsim.simulator.roadnetwork.Lanes.Type.SHOULDER);
View Full Code Here

    private void writeOutput(double simulationTime) {
        for (final RoadSegment roadSegment : route) {
            for (Vehicle vehicle : roadSegment) {
                PrintWriter writer = checkFloatingCar(vehicle);
                if (writer != null) {
                    final Vehicle frontVeh = roadSegment.frontVehicleOnLane(vehicle);
                    FileFloatingCars.writeData(simulationTime, vehicle, frontVeh, writer);
                }
            }
        }
    }
View Full Code Here

        }
        // TODO assure priority for lane changes from slow to fast lanes
        for (final LaneSegment laneSegment : laneSegments) {
            assert laneSegment.assertInvariant();
            for (Iterator<Vehicle> vehIterator = laneSegment.iterator(); vehIterator.hasNext();) {
                Vehicle vehicle = vehIterator.next();
                assert vehicle.roadSegmentId() == id;
                if (vehicle.considerLaneChange(dt, this)) {
                    final int targetLane = vehicle.getTargetLane();
                    assert targetLane != Lanes.NONE;
                    assert laneSegments[targetLane - 1].type() != Lanes.Type.ENTRANCE;
                    // iteratorRemove avoids ConcurrentModificationException
                    vehIterator.remove();
                    vehicle.setLane(targetLane);
                    laneSegments[targetLane - 1].addVehicle(vehicle);
                }
            }
        }
    }
View Full Code Here

            for (Vehicle vehicle : laneSegment) {
                index++;
                if (vehicle.type() == Vehicle.Type.OBSTACLE) {
                    continue;
                }
                final Vehicle vehFront = laneSegment.frontVehicle(vehicle);
                final double netDistance = vehicle.getNetDistance(vehFront);
                if (netDistance < 0) {
                    LOG.error("Crash happened!!!");
                    final StringBuilder sb = new StringBuilder("\n");
                    sb.append(String.format("Crash of Vehicle i=%d (id=%d) at x=%.4f ", index, vehicle.getId(),
                            vehicle.getFrontPosition()));
                    if (vehFront != null) {
                        sb.append(String.format("with veh (id=%d) in front at x=%.4f on lane=%d\n", vehFront.getId(),
                                vehFront.getFrontPosition(), vehicle.lane()));
                    }
                    sb.append("roadID=").append(id);
                    sb.append(", user roadID=").append(userId);
                    sb.append(", net distance=").append(netDistance);
                    sb.append(", lane=").append(laneSegment.lane());
                    sb.append(", container.size=").append(laneSegment.vehicleCount());
                    sb.append(", obstacles=").append(laneSegment.obstacleCount());
                    sb.append("\n");

                    for (int j = Math.max(0, index - 8), M = laneSegment.vehicleCount(); j <= Math
                            .min(index + 8, M - 1); j++) {
                        final Vehicle veh = laneSegment.getVehicle(j);
                        sb.append(String
                                .format("veh=%d, pos=%6.2f, speed=%4.2f, accModel=%4.3f, acc=%4.3f, length=%3.1f, lane=%d, id=%d%n",
                                        j, veh.getFrontPosition(), veh.getSpeed(), veh.accModel(), veh.getAcc(),
                                        veh.getLength(), veh.lane(), veh.getId()));
                    }
                    LOG.error(sb.toString());
                    if (isWithCrashExit) {
                        LOG.error(" !!! exit after crash !!! ");
                        System.exit(-99);
View Full Code Here

        if (vehicleQueue.isEmpty()) {
            return;
        }
        Long entryTime = vehicleQueue.firstKey();
        if (simulationTime >= entryTime.longValue()) {
            Vehicle vehicle = vehicleQueue.get(entryTime);
            int testLane = (vehicle.lane() != Vehicle.LANE_NOT_SET) ? vehicle.lane()
                    : getNewCyclicLaneForEntering(laneEnterLast);
            LaneSegment laneSegment = roadSegment.laneSegment(testLane);
            final boolean isEntered = tryEnteringNewVehicle(vehicle, laneSegment);
            if (isEntered) {
                vehicleQueue.remove(entryTime);
View Full Code Here

            }
        }
    }

    private boolean tryEnteringNewVehicle(Vehicle vehicle, LaneSegment laneSegment) {
        Vehicle leader = laneSegment.rearVehicle();
        double vEnter = vehicle.getSpeed();
        if (leader == null) {
            enterVehicle(laneSegment, vEnter, vehicle);
            return true;
        }
        vEnter = Math.min(vEnter, leader.getSpeed());
        // check if gap to leader is sufficiently large (xEnter of road section is assumed to be zero)
        final double netGapToLeader = leader.getRearPosition();
        // very crude approximation for minimum gap
        double minRequiredGap = vehicle.getEffectiveLength() + 2 * vehicle.getLongitudinalModel().getDesiredSpeed();
        if (vehicle.getLongitudinalModel().isCA()) {
            minRequiredGap = leader.getSpeed();
        }
        if (netGapToLeader > minRequiredGap) {
            enterVehicle(laneSegment, vEnter, vehicle);
            return true;
        }
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.