Package org.movsim.simulator.vehicles

Examples of org.movsim.simulator.vehicles.Vehicle


            for (Vehicle vehicle : laneSegment) {
                evaluateVehicle(vehicle, laneSegment, testVehicle, gapCandidates);
            }

            // check also rear vehicles of next downstream segment
            Vehicle rearVehicleNextLaneSegment = laneSegment.sinkLaneSegment().rearVehicle();
            if (rearVehicleNextLaneSegment != null) {
                evaluateVehicle(rearVehicleNextLaneSegment, laneSegment, testVehicle, gapCandidates);
            }
            if (rearVehicleNextLaneSegment == null && laneSegment.vehicleCountWithoutObstacles() == 0) {
                gapCandidates.add(new GapCandidate(MovsimConstants.GAP_INFINITY, laneSegment.lane(), 0.5
View Full Code Here


        if (vehicle.getRearPosition() < testVehicle.length() + MINIMUM_GAP_BOUNDARY) {
            // available upstream road segment too small
            LOG.debug("no sufficient upstream gap: rearPosition={}", vehicle.getRearPosition());
            return;
        }
        Vehicle rearVehicle = laneSegment.rearVehicle(vehicle.getRearPosition() - 1); // TODO finds not rear vehicle but
                                                                                      // itself !!!
                                                                                      // if (rearVehicle == vehicle) {
        // System.out.println("!!! rear vehicle is identical to vehicle!");
        // }
        final double gap = vehicle.getNetDistanceToRearVehicle(rearVehicle);
View Full Code Here

     *            the q bc
     * @return true, if successful
     */
    private boolean tryEnteringNewVehicle(TestVehicle testVehicle, LaneSegment laneSegment, double time, double qBC) {

        final Vehicle leader = laneSegment.rearVehicle();

        // (1) empty road
        if (leader == null) {
            enterVehicleOnEmptyRoad(laneSegment, time, testVehicle);
            return true;
        }
        // (2) check if gap to leader is sufficiently large origin of road section is assumed to be zero
        final double netGapToLeader = leader.getRearPosition();
        final double gapAtQMax = 1. / testVehicle.getRhoQMax();

        // minimal distance set to 80% of 1/rho at flow maximum in fundamental diagram
        double minRequiredGap = 0.8 * gapAtQMax;
        if (testVehicle.getLongitudinalModel().isCA()) {
            minRequiredGap = leader.getSpeed();
        }
        if (netGapToLeader > minRequiredGap) {
            enterVehicle(laneSegment, time, minRequiredGap, testVehicle, leader);
            return true;
        }
View Full Code Here

    public void removeVehicle(Vehicle vehicleToRemove) {
        // TODO improve primitive implementation
        final long vehicleId = vehicleToRemove.getId();
        final int count = vehicles.size();
        for (int i = 0; i < count; ++i) {
            final Vehicle vehicle = vehicles.get(i);
            if (vehicle.getId() == vehicleId) {
                vehicles.remove(i);
                return;
            }
        }
    }
View Full Code Here

        assert vehicle.roadSegmentId() == roadSegment.id();
        assert laneIsSorted();
        assert assertInvariant();
        if (DEBUG) {
            if (vehicles.size() > 0) {
                final Vehicle lastVehicle = vehicles.get(vehicles.size() - 1);
                if (lastVehicle.getRearPosition() < vehicle.getRearPosition()) {
                    assert false;
                }
            }
        }
        vehicles.add(vehicle);
View Full Code Here

        // index == laneVehicles[lane].size() - 1 || insertionPoint == laneVehicles[lane].size()
        // subject vehicle is rear vehicle on this road segment, so check source road segment
        if (sourceLaneSegment != null) {
            // didn't find a rear vehicle in the current road segment, so
            // check the previous (source) road segment
            final Vehicle sourceFrontVehicle = sourceLaneSegment.frontVehicle();
            if (sourceFrontVehicle != null) {
                // return a copy of the front vehicle on the source road segment, with its
                // position set relative to the current road segment
                final Vehicle rearVehicle = new Vehicle(sourceFrontVehicle);
                rearVehicle.setFrontPosition(rearVehicle.getFrontPosition() - sourceLaneSegment.roadLength());
                return rearVehicle;
            }
        }
        return null;
    }
View Full Code Here

        // subject vehicle is front vehicle on this road segment, so check sink road segment
        if (sinkLaneSegment == null) {
            return null;
        }
        // find the rear vehicle in the sink lane on the sink lane segment
        final Vehicle sinkRearVehicle = sinkLaneSegment.rearVehicle();
        if (sinkRearVehicle == null) {
            return null;
        }
        // return a copy of the rear vehicle on the sink road segment, with its position
        // set relative to the current road segment
        final Vehicle ret = new Vehicle(sinkRearVehicle);
        ret.setFrontPosition(ret.getFrontPosition() + roadSegment.roadLength());
        return ret;
    }
View Full Code Here

        if (sinkLaneVehicleCount < 2) {
            // should actually check sinkLane of sinkLane, but as long as sinkLane not
            // outrageously short, the assumption that there is no vehicle is reasonable
            return null;
        }
        final Vehicle vehicle = sinkLaneSegment.getVehicle(sinkLaneVehicleCount - 2);
        // return a copy of the rear vehicle on the sink lane segment, with its position
        // set relative to the current road segment
        final Vehicle ret = new Vehicle(vehicle);
        ret.setFrontPosition(ret.getFrontPosition() + roadSegment.roadLength());
        return ret;
    }
View Full Code Here

        // on sink lane segment
        if (sinkLaneSegment != null) {
            // didn't find a front vehicle in the current road segment, so
            // check the next (sink) road segment
            // find the rear vehicle in the sink lane on the sink road segment
            final Vehicle sinkRearVehicle = sinkLaneSegment.rearVehicle();
            if (sinkRearVehicle != null) {
                // return a copy of the rear vehicle on the sink road segment, with its position
                // set relative to the current road segment
                final Vehicle frontVehicle = new Vehicle(sinkRearVehicle);
                frontVehicle.setFrontPosition(frontVehicle.getFrontPosition() + roadSegment.roadLength());
                return frontVehicle;
            }
        }
        return null;
    }
View Full Code Here

        // remove any vehicles that have gone past the end of this lane segment
        if (sinkLaneSegment != null) {
            int count = vehicles.size();
            // remove any vehicles that have gone past the end of this road segment
            while (count > 0) {
                final Vehicle vehicle = vehicles.get(0);
                if (vehicle.getRearPosition() < roadLength) {
                    break;
                }
                // if the vehicle is past the end of this road segment then move it onto the
                // sink lane for its lane
                // TODO - check previous lane correct (used for drawing vehicle when changing lanes)
                // final int prevLaneOnNewRoadSegment = lane;
                // final int prevLaneOnNewRoadSegment = sinkLane[vehicle.previousLane()];
                final double rearPositionOnNewRoadSegment = vehicle.getRearPosition() - roadLength;
                double exitEndPos = Vehicle.EXIT_POSITION_NOT_SET;
                if (sinkLaneSegment.type() == Lanes.Type.TRAFFIC) {
                    final int exitRoadSegmentId = vehicle.exitRoadSegmentId();
                    if (exitRoadSegmentId == sinkLaneSegment.roadSegment.id()) {
                        // vehicle is on exit exit road segment, so exit end pos is end of this
                        // road segment
                        exitEndPos = sinkLaneSegment.roadLength();
                    } else {
                        // check if next segment is exit segment
                        final RoadSegment sinkSinkRoad = sinkLaneSegment.roadSegment();
                        if (sinkSinkRoad != null && sinkSinkRoad.id() == exitRoadSegmentId) {
                            // next road segment is exit road segment
                            exitEndPos = sinkLaneSegment.roadLength() + sinkSinkRoad.roadLength();
                        }
                    }
                }
                final int laneOnNewRoadSegment = sinkLaneSegment.lane();
                vehicle.moveToNewRoadSegment(sinkLaneSegment.roadSegment(), laneOnNewRoadSegment,
                        rearPositionOnNewRoadSegment, exitEndPos);
                // remove vehicle from this road segment
                vehicles.remove(0);
                --count;
                ++removedVehicleCount;
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.