コード例 #1
0
  private TwoWayCSStation findClosestAvailableTWCar(Id<Link> linkId) {

    // find the closest available car in the quad tree(?) reserve it (make it unavailable)
    // if no cars within certain radius return null
    Link link = scenario.getNetwork().getLinks().get(linkId);

    Collection<TwoWayCSStation> location =
        this.carSharingVehicles
            .getRoundTripVehicles()
            .getQuadTree()
            .getDisk(
                link.getCoord().getX(),
                link.getCoord().getY(),
                Double.parseDouble(
                    scenario
                        .getConfig()
                        .getModule("TwoWayCarsharing")
                        .getParams()
                        .get("searchDistanceTwoWayCarsharing")));
    if (location.isEmpty()) return null;
    double distanceSearch =
        Double.parseDouble(
            scenario
                .getConfig()
                .getModule("TwoWayCarsharing")
                .getParams()
                .get("searchDistanceTwoWayCarsharing"));
    TwoWayCSStation closest = null;
    for (TwoWayCSStation station : location) {
      if (CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord())
              < distanceSearch
          && station.getNumberOfVehicles() > 0) {
        closest = station;
        distanceSearch =
            CoordUtils.calcEuclideanDistance(link.getCoord(), station.getLink().getCoord());
      }
    }

    return closest;
  }
コード例 #2
0
  private void initializeTwoWayCarsharingStartWalkLeg(Leg leg, double now) {

    this.state = MobsimAgent.State.LEG;
    Route route = leg.getRoute();

    TwoWayCSStation station = findClosestAvailableTWCar(route.getStartLinkId());

    if (station == null) {
      this.state = MobsimAgent.State.ABORT;
      this.simulation
          .getEventsManager()
          .processEvent(new NoVehicleCarSharingEvent(now, route.getStartLinkId(), "rt"));
      return;
    }

    startLinkTW = station.getLink();
    twVehId = station.getIDs().get(0);
    this.carSharingVehicles.getRoundTripVehicles().removeVehicle(station, station.getIDs().get(0));

    mapTW.put(scenario.getNetwork().getLinks().get(leg.getRoute().getStartLinkId()), startLinkTW);
    initializeCSWalkLeg(
        "walk_rb", now, scenario.getNetwork().getLinks().get(route.getStartLinkId()), startLinkTW);
  }