Package org.movsim.simulator.roadnetwork

Examples of org.movsim.simulator.roadnetwork.RoadSegment$LaneSegmentIterator


        // assume this vehicle does not exit on this road segment
        if (roadSegmentId != exitRoadSegmentId) {
            exitRoadSegmentId = ROAD_SEGMENT_ID_NOT_SET;
        }
        if (route != null && routeIndex < route.size()) {
            final RoadSegment routeRoadSegment = route.get(routeIndex);
            ++routeIndex;
            if (routeRoadSegment.id() == roadSegmentId) {
                // this vehicle is on the route
                if (routeIndex < route.size()) {
                    // there is another roadSegment on the route
                    // so check if the next roadSegment is joined to an exit lane
                    // of the current roadSegment
                    final RoadSegment nextRouteRoadSegment = route.get(routeIndex);
                    if (routeRoadSegment.exitsOnto(nextRouteRoadSegment.id())) {
                        // this vehicle needs to exit on this roadSegment
                        exitRoadSegmentId = roadSegmentId;
                    } else {
                        if (routeIndex + 1 < route.size()) {
                            // there is another roadSegment on the route
                            // so check if the next roadSegment is joined to an exit lane
                            // of the current roadSegment
                            final RoadSegment nextNextRouteRoadSegment = route.get(routeIndex + 1);
                            if (nextRouteRoadSegment.exitsOnto(nextNextRouteRoadSegment.id())) {
                                // this vehicle needs to exit on this roadSegment
                                exitRoadSegmentId = roadSegmentId;
                            }
                        }
                    }
View Full Code Here


            exitRoadSegmentId = ROAD_SEGMENT_ID_NOT_SET;
        }

        int routeIndex = 0;
        if (route != null && routeIndex < route.size()) {
            final RoadSegment routeRoadSegment = route.get(routeIndex);
            ++routeIndex;
            if (routeRoadSegment.id() == roadSegmentId) {
                // this vehicle is on the route
                if (routeIndex < route.size()) {
                    // there is another roadSegment on the route
                    // so check if the next roadSegment is joined to an exit lane
                    // of the current roadSegment
                    final RoadSegment nextRouteRoadSegment = route.get(routeIndex);
                    if (routeRoadSegment.exitsOnto(nextRouteRoadSegment.id())) {
                        // this vehicle needs to exit on this roadSegment
                        exitRoadSegmentId = roadSegmentId;
                    } else {
                        if (routeIndex + 1 < route.size()) {
                            // there is another roadSegment on the route
                            // so check if the next roadSegment is joined to an exit lane
                            // of the current roadSegment
                            final RoadSegment nextNextRouteRoadSegment = route.get(routeIndex + 1);
                            if (nextRouteRoadSegment.exitsOnto(nextNextRouteRoadSegment.id())) {
                                // this vehicle needs to exit on this roadSegment
                                exitRoadSegmentId = roadSegmentId;
                            }
                        }
                    }
View Full Code Here

        initialize();
    }

    private void matchRoadSegmentsAndRoadInput(List<Road> roads) {
        for (final Road roadInput : roads) {
            RoadSegment roadSegment = Preconditions.checkNotNull(roadNetwork.findByUserId(roadInput.getId()),
                    "cannot find roadId=" + roadInput.getId()
                            + " from input in constructed roadNetwork. IGNORE DATA!!!");
            addInputToRoadSegment(roadSegment, roadInput);
        }
    }
View Full Code Here

    private void defaultTestingRoadMapping(Road roadInput) {
        LOG.warn("Simulation with test network");
        final int laneCount = 1;
        final double roadLength = 1500;
        final RoadMapping roadMapping = new RoadMappingPolyS(laneCount, 10, 50, 50, 100.0 / Math.PI, roadLength);
        final RoadSegment roadSegment = new RoadSegment(roadMapping);
        addInputToRoadSegment(roadSegment, roadInput);
        roadSegment.setUserId("1");
        roadSegment.addDefaultSink();
        roadNetwork.add(roadSegment);
    }
View Full Code Here

        // setup source which models the re-entrance of vehicles leaving the parking lot
        if (!trafficSink.isSetParking()) {
            return;
        }
        Parking parking = trafficSink.getParking();
        RoadSegment sourceRoadSegment = Preconditions.checkNotNull(roadNetwork.findByUserId(parking.getSourceRoadId()),
                "cannot find roadSegment=" + parking.getSourceRoadId() + " specified as re-entrance from the road="
                        + roadSegment.id());
        TrafficSourceMicro trafficSource = new TrafficSourceMicro(defaultTrafficComposition, sourceRoadSegment);
        if (trafficSink.isLogging()) {
            trafficSource.setRecorder(new FileTrafficSourceData(sourceRoadSegment.userId()));
        }
        sourceRoadSegment.setTrafficSource(trafficSource);
        roadSegment.sink().setupParkingLot(parking, timeOffsetMillis, trafficSource);
    }
View Full Code Here

    public final void testCalcAccelerationBalance2() {
        RoadSegment.resetNextId();
        Vehicle.resetNextId();
        final int laneCount = 2;
        final int exitLaneCount = 1;
        final RoadSegment r0 = new RoadSegment(300.0, laneCount + exitLaneCount);
        final RoadSegment r1 = new RoadSegment(400.0, laneCount);
        r0.setLaneType(Lanes.LANE3, Lanes.Type.EXIT);// so Lane3 is exit lane of r1
        // join r0 and r1 so vehicles move from r0 to r1
        // lane1 of r0 joins to lane1 of r1
        // lane2 of r0 joins to lane2 of r1
        // lane3 of r0 has no successor
        Link.addJoin(r0, r1);
        assertEquals(Lanes.LANE1, r1.sourceLane(Lanes.LANE1));
        assertEquals(Lanes.LANE2, r1.sourceLane(Lanes.LANE2));
        final double lengthCar = 6.0;
        final double minimumGap = 2.0;
        // final double tooSmallGap = 1.0;
        final double safeDeceleration = 4.0;
        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

        // final double lengthTruck = 16.0;
        RoadSegment.resetNextId();
        Vehicle.resetNextId();
        final double roadLength = 1000.0;
        final int laneCount = 2;
        final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);
        final double minimumGap = 2.0;
        final double tooSmallGap = 1.0;
        final double safeDeceleration = 4.0;
        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

        for (Road road : openDriveNetwork.getRoad()) {
            final RoadMapping roadMapping = createRoadMapping(road);
            for (Lanes.LaneSectionType laneSectionType : LaneSectionType.values()) {
                if (hasLaneSectionType(road, laneSectionType)) {
                    RoadSegment roadSegmentRight = createRoadSegment(laneSectionType, roadMapping, road);
                    if (roadSegmentRight != null) {
                        roadNetwork.add(roadSegmentRight);
                    }
                }
            }
View Full Code Here

        return roadMapping;
    }

    private RoadSegment createRoadSegment(LaneSectionType laneType, RoadMapping roadMapping, Road road) {
        // TODO cstr not working for bidirectional case !!
        final RoadSegment roadSegment = new RoadSegment(roadMapping);

        // only one laneSection can be handled
        List<Lane> lanes = (laneType == Lanes.LaneSectionType.LEFT) ? Preconditions.checkNotNull(road.getLanes()
                .getLaneSection().get(0).getLeft().getLane()) : Preconditions.checkNotNull(road.getLanes()
                .getLaneSection().get(0).getRight().getLane());

        if (laneType == Lanes.LaneSectionType.LEFT) {
            LOG.error("left lane section not yet impl. Will be ignored!");
            return null;
        }
        // TODO Left/right handling
        roadSegment.setUserId(road.getId());
        roadSegment.setUserRoadname(road.getName());

        if (road.isSetElevationProfile()) {
            roadSegment.setElevationProfile(road.getElevationProfile());
        }

        checkLaneIndexConventions(laneType, road.getId(), lanes);

        for (Lane lane : lanes) {
            int laneIndex = Math.abs(lane.getId()); // OpenDriveHandlerUtils.rightLaneIdToLaneIndex(roadSegment, laneIndex.getId());
            setLaneType(laneIndex, lane, roadSegment);
            // speed is definied lane-wise, but movsim handles speed limits on road segment level, further
            // entries overwrite previous entry
            if (lane.isSetSpeed()) {
                roadSegment.setSpeedLimits(lane.getSpeed());
            }
        }

        if (road.isSetSignals()) {
            for (Signal signal : road.getSignals().getSignal()) {
                // assure uniqueness of signal id for whole network

                boolean added = uniqueTrafficLightIdsInRoads.add(signal.getId());
                if (!added) {
                    throw new IllegalArgumentException("trafficlight signal with id=" + signal.getId()
                            + " is not unique in xodr network definition.");
                }
                Controller controller = signalIdsToController.get(signal.getId());
                if (controller == null) {
                    throw new IllegalArgumentException("trafficlight signal with id=" + signal.getId()
                            + " is not referenced in xodr <controller> definition.");
                }
                roadSegment.addTrafficLightLocation(new TrafficLightLocation(signal, controller));
            }
        }

        if (road.isSetObjects()) {
            for (OpenDRIVE.Road.Objects.Tunnel tunnel : road.getObjects().getTunnel()) {
View Full Code Here

    }

    private static void joinRoads(OpenDRIVE openDriveNetwork, RoadNetwork roadNetwork) {
        // iterate through all the roads joining them up according to the links
        for (Road road : openDriveNetwork.getRoad()) {
            RoadSegment roadSegment = roadNetwork.findByUserId(road.getId());
            if (roadSegment == null) {
                throw new IllegalArgumentException("cannot find roadSegment in network for road: " + road);
            }

            if (!road.isSetLink()) {
                roadSegment.addDefaultSink();
                continue;
            }

            if (hasRoadPredecessor(road)) {
                RoadSegment sourceRoadSegment = getSourceRoadSegment(roadNetwork, road);
                for (LaneSection laneSection : road.getLanes().getLaneSection()) {
                    if (laneSection.isSetCenter()) {
                        LOG.warn("cannot handle center lane");
                        continue;
                    }
                    List<org.movsim.network.autogen.opendrive.Lane> lanes = laneSection.isSetLeft() ? laneSection
                            .getLeft().getLane() : laneSection.getRight().getLane();
                    for (Lane lane : lanes) {
                        if (lane.isSetLink() && lane.getLink().isSetPredecessor()) {
                            int fromLane = OpenDriveHandlerUtils.laneIdToLaneIndex(sourceRoadSegment, lane.getLink()
                                    .getPredecessor().getId());
                            int toLane = OpenDriveHandlerUtils.laneIdToLaneIndex(roadSegment, lane.getId());
                            Link.addLanePair(fromLane, sourceRoadSegment, toLane, roadSegment);
                        }
                    }
                }
            }

            if (hasRoadSuccessor(road)) {
                RoadSegment sinkRoadSegment = getRoadSuccessor(roadNetwork, road);
                for (LaneSection laneSection : road.getLanes().getLaneSection()) {
                    if (laneSection.isSetCenter()) {
                        LOG.warn("cannot handle center lane");
                        continue;
                    }
View Full Code Here

TOP

Related Classes of org.movsim.simulator.roadnetwork.RoadSegment$LaneSegmentIterator

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.