private static PParking getParkingWithShortestWalkingDistance(
      Coord destCoord, Collection<PParking> parkingsInSurroundings) {
    PParking bestParking = null;
    double currentBestDistance = Double.MAX_VALUE;

    for (PParking parking : parkingsInSurroundings) {
      double distance = GeneralLib.getDistance(destCoord, parking.getCoord());
      if (distance < currentBestDistance) {
        bestParking = parking;
        currentBestDistance = distance;
      }
    }

    return bestParking;
  }
Exemplo n.º 2
0
  private static void logAllParkingToTextFile(LinkedList<PParking> parkings) {
    ArrayList<String> list = new ArrayList<String>();
    list.add("parkingFacilityId\tcapacity\tx-coord\ty-coord");

    for (PParking p : parkings) {
      list.add(
          p.getId().toString()
              + "\t"
              + p.getIntCapacity()
              + "\t"
              + p.getCoord().getX()
              + "\t"
              + p.getCoord().getY());
    }

    GeneralLib.writeList(list, ZHScenarioGlobal.outputFolder + "parkingProperties.txt");
  }
  public static ParkingScoreManager prepareParkingScoreManager(
      RentPrivateParkingModel parkingModule, LinkedList<PParking> parkings) {
    MatsimServices controler = parkingModule.getControler();
    ParkingScoreManager parkingScoreManager =
        new ParkingScoreManager(getWalkTravelTime(controler), controler.getScenario());

    ParkingBetas parkingBetas =
        new ParkingBetas(getHouseHoldIncomeCantonZH(controler.getScenario().getPopulation()));
    parkingBetas.setParkingWalkBeta(
        controler.getConfig().getParam("parkingChoice.ZH", "parkingWalkBeta"));
    parkingBetas.setParkingCostBeta(
        controler.getConfig().getParam("parkingChoice.ZH", "parkingCostBeta"));
    parkingScoreManager.setParkingBetas(parkingBetas);

    double parkingScoreScalingFactor =
        Double.parseDouble(
            controler.getConfig().getParam("parkingChoice.ZH", "parkingScoreScalingFactor"));
    parkingScoreManager.setParkingScoreScalingFactor(parkingScoreScalingFactor);
    double randomErrorTermScalingFactor =
        Double.parseDouble(
            controler.getConfig().getParam("parkingChoice.ZH", "randomErrorTermScalingFactor"));
    parkingScoreManager.setRandomErrorTermScalingFactor(randomErrorTermScalingFactor);

    String epsilonDistribution =
        controler.getConfig().findParam("parkingChoice.ZH", "randomErrorTermEpsilonDistribution");
    if (epsilonDistribution != null) {
      LinkedList<Id> parkingIds = new LinkedList<Id>();
      for (PParking parking : parkings) {
        parkingIds.add(parking.getId());
      }

      int seed =
          Integer.parseInt(
              controler.getConfig().findParam("parkingChoice.ZH", "randomErrorTerm.seed"));

      parkingScoreManager.setRandomErrorTermManger(
          new RandomErrorTermManager(
              epsilonDistribution,
              parkingIds,
              parkingModule.getControler().getScenario().getPopulation().getPersons().values(),
              seed));
    }

    return parkingScoreManager;
  }
Exemplo n.º 4
0
  public static ParkingManagerZH getParkingManagerZH(
      LinkedList<PParking> parkings, Network network, TTMatrix ttMatrix) {
    String cityZonesFilePath = ZHScenarioGlobal.loadStringParam("ParkingLoader.parkingZones");

    ParkingCostCalculator parkingCostCalculator =
        new ParkingCostCalculatorZH(new CityZones(cityZonesFilePath), parkings);

    HashMap<String, HashSet<Id<PParking>>> parkingTypes = new HashMap<>();

    HashSet<Id<PParking>> streetParking = new HashSet<>();
    HashSet<Id<PParking>> garageParking = new HashSet<>();
    HashSet<Id<PParking>> illegalParking = new HashSet<>();
    parkingTypes.put("streetParking", streetParking);
    parkingTypes.put("garageParking", garageParking);
    parkingTypes.put("illeagalParking", illegalParking);

    for (PParking parking : parkings) {
      if (parking.getId().toString().contains("stp-")) {
        streetParking.add(parking.getId());
      }

      if (parking.getId().toString().contains("publicPOutsideCityZH")) {
        streetParking.add(parking.getId());
      }

      if (parking.getId().toString().contains("gp-")) {
        garageParking.add(parking.getId());
      }

      if (parking.getId().toString().contains("illegal-")) {
        illegalParking.add(parking.getId());
      }
    }

    logAllParkingToTextFile(parkings);

    return new ParkingManagerZH(parkingTypes, parkingCostCalculator, parkings, network, ttMatrix);
  }
Exemplo n.º 5
0
  public static LinkedList<PParking> getParkingsForScenario(String parkingDataBase) {

    LinkedList<PParking> parkingCollection = getParkingCollectionZHCity(parkingDataBase);
    String parkingsFile = parkingDataBase + "publicParkingsOutsideZHCity.xml";

    readParkings(parkingsOutsideZHCityScaling, parkingsFile, parkingCollection);

    LinkedList<PParking> parkingWithNonPositveCapacity = new LinkedList<PParking>();
    for (PParking parking : parkingCollection) {
      if (parking.getIntCapacity() <= 0) {
        parkingWithNonPositveCapacity.add(parking);
      }
    }
    parkingCollection.removeAll(parkingWithNonPositveCapacity);

    int numberOfStreetParking = 0;
    int numberOfGarageParking = 0;
    int numberOfPrivateParking = 0;

    for (PParking parking : parkingCollection) {
      if (parking.getId().toString().contains("stp")) {
        numberOfStreetParking += parking.getIntCapacity();
      } else if (parking.getId().toString().contains("gp")) {
        numberOfGarageParking += parking.getIntCapacity();
      } else if (parking.getId().toString().contains("private")) {
        numberOfPrivateParking += parking.getIntCapacity();
      }
    }

    double totalNumberOfParkingZH =
        numberOfStreetParking + numberOfGarageParking + numberOfPrivateParking;

    System.out.println(
        "streetParking to garageParking (%): "
            + numberOfStreetParking / 1.0 / numberOfGarageParking
            + " - ref: 3.03");
    System.out.println(
        "numberOfStreetParking (%): "
            + numberOfStreetParking / totalNumberOfParkingZH * 100
            + " - ref: 18.5 - ["
            + numberOfStreetParking
            + "]");
    System.out.println(
        "numberOfGarageParking (%):"
            + numberOfGarageParking / totalNumberOfParkingZH * 100
            + " - ref: 6.1 - ["
            + numberOfGarageParking
            + "]");
    System.out.println(
        "numberOfPrivateParking (%):"
            + numberOfPrivateParking / totalNumberOfParkingZH * 100
            + " - ref: 75.4 - ["
            + numberOfPrivateParking
            + "]");

    System.out.println(
        "totalNumberOfParkingZH: "
            + (totalNumberOfParkingZH / 1000)
            + "k - ref: "
            + 267000 * populationScalingFactor / 1000
            + "k");

    return parkingCollection;
  }
  public static void prepare(RentPrivateParkingModel parkingModule, MatsimServices controler) {

    Config config = controler.getConfig();

    String baseDir = config.getParam("parkingChoice.ZH", "parkingDataDirectory");

    LinkedList<PParking> parkings = getParking(config, baseDir);

    parkingScoreManager = prepareParkingScoreManager(parkingModule, parkings);

    //		EventsManager events = EventsUtils.createEventsManager();
    //		EventWriterXML eventsWriter = new EventWriterXML("c:\\tmp\\events.xml.gz");
    //		events.addHandler(eventsWriter);
    //
    //		events.resetHandlers(0);
    //		eventsWriter.init("c:\\tmp\\events.xml.gz");

    ParkingInfrastructureManager pim = new ParkingInfrastructureManager(parkingScoreManager, null);

    ParkingCostModel pcm = new ParkingCostModelZH(config, parkings);
    LinkedList<PublicParking> publicParkings = new LinkedList<PublicParking>();
    LinkedList<PPRestrictedToFacilities> ppRestrictedToFacilities =
        new LinkedList<PPRestrictedToFacilities>();
    LinkedList<RentableParking> rentableParkings = new LinkedList<>();
    for (PParking parking : parkings) {
      String groupName = null;
      if (parking.getId().toString().contains("stp")) {
        groupName = "streetParking";
      } else if (parking.getId().toString().contains("gp")) {
        groupName = "garageParking";
      } else if (parking.getId().toString().contains("publicPOutsideCity")) {
        groupName = "publicPOutsideCity";
      }
      if (groupName != null) {
        PublicParking publicParking =
            new PublicParking(
                Id.create(parking.getId(), PC2Parking.class),
                parking.getIntCapacity(),
                parking.getCoord(),
                pcm,
                groupName);
        publicParkings.add(publicParking);
      } else {
        PrivateParking pp = (PrivateParking) parking;
        HashSet<Id<ActivityFacility>> hs = new HashSet<>();
        hs.add(pp.getActInfo().getFacilityId());
        groupName = "privateParking";
        PPRestrictedToFacilities PPRestrictedToFacilitiesTmp =
            new PPRestrictedToFacilities(
                Id.create(parking.getId(), PC2Parking.class),
                parking.getIntCapacity(),
                parking.getCoord(),
                pcm,
                groupName,
                hs);
        ppRestrictedToFacilities.add(PPRestrictedToFacilitiesTmp);
      }
    }

    // TODO:
    // fill in "rentableParking"
    RentableParking rp =
        new RentableParking(
            Id.create("rentableParking", PC2Parking.class),
            1,
            new Coord(682922.588, 247474.957),
            null,
            "rentableParking");
    rp.setStartRentableTime(1000);
    rp.setEndRentableTime(70000);
    rp.setOwnerId(Id.create("dummyUser", Person.class));
    rp.setRentingPricePerHourInCurrencyUnit(0.0);
    rentableParkings.add(rp);

    // =====================

    publicParkings.addAll(rentableParkings);

    pim.setPublicParkings(publicParkings);
    pim.setPrivateParkingRestrictedToFacilities(ppRestrictedToFacilities);
    pim.setRentableParking(rentableParkings);

    parkingModule.setParkingInfrastructurManager(pim);
    parkingModule.setParkingScoreManager(parkingScoreManager);
    // appendScoringFactory(parkingModule);
  }