예제 #1
0
  public static void main(String[] args) {
    Matrix parkingTimesEC =
        GeneralLib.readStringMatrix(
            "A:/for marina/26. april 2012/parkingTimesAndEnergyConsumptionCH.txt");
    Network network =
        GeneralLib.readNetwork(
            "H:/data/cvs/ivt/studies/switzerland/networks/teleatlas-ivtcheu/network.xml.gz");

    HashMap<String, Id> agentIds = new HashMap();

    BasicPointVisualizer basicPointVisualizer = new BasicPointVisualizer();

    for (int i = 0; i < parkingTimesEC.getNumberOfRows(); i++) {
      String actType = parkingTimesEC.getString(i, 4);
      Id<Link> linkId = Id.create(parkingTimesEC.getString(i, 3), Link.class);
      Link link = network.getLinks().get(linkId);
      if (actType.equalsIgnoreCase("tta")) {
        agentIds.put(parkingTimesEC.getString(i, 0), null);
        // System.out.println("x");
        basicPointVisualizer.addPointCoordinate(
            new Coord(link.getCoord().getX(), link.getCoord().getY()), "", Color.GREEN);
      }
    }

    // for (String agentId:agentIds.keySet()){
    // System.out.println(agentId);
    // }

    basicPointVisualizer.write("c:/temp/abdd.kml");
  }
  public void writeOutParkingOccupancySumPng(Controler controler, int iteration) {
    String fileName =
        controler
            .getControlerIO()
            .getIterationFilename(iteration, "parkingOccupancyAllParking.png");

    double matrix[][] = new double[96][1];
    String title = "parked vehicles at all parkings in the simulation";
    String xLabel = "time";
    String yLabel = "number of vehicles parked";
    String[] seriesLabels = {"all parking occupancy"};
    double[] xValues = new double[96];

    for (int i = 0; i < 96; i++) {
      xValues[i] = i * 0.25;
    }

    for (Id parkingFacilityId : parkingOccupancies.keySet()) {

      int[] occupancy = parkingOccupancies.get(parkingFacilityId).getOccupancy();

      for (int i = 0; i < 96; i++) {
        matrix[i][0] += occupancy[i];
      }
    }

    GeneralLib.writeGraphic(fileName, matrix, title, xLabel, yLabel, seriesLabels, xValues);
  }
예제 #3
0
  /**
   * get parking related walking distance of whole day - average per leg
   *
   * @param plan
   * @param facilities
   * @return
   */
  public static double getParkingRelatedWalkingDistanceOfWholeDayAveragePerLeg(
      Plan plan, ActivityFacilities facilities) {
    double travelDistance = 0;
    int numberOfLegs = 0;

    List<PlanElement> pe = plan.getPlanElements();

    for (int i = 0; i < pe.size(); i++) {
      if (pe.get(i) instanceof ActivityImpl) {
        ActivityImpl parkingActivity = (ActivityImpl) pe.get(i);
        if (parkingActivity.getType().equalsIgnoreCase("parking")) {
          Coord coordParking =
              facilities.getFacilities().get(parkingActivity.getFacilityId()).getCoord();
          Leg nextLeg = (Leg) pe.get(i + 1);
          Leg prevLeg = (Leg) pe.get(i - 1);
          if (nextLeg.getMode().equalsIgnoreCase("walk")) {
            ActivityImpl nextAct = (ActivityImpl) pe.get(i + 2);

            if (nextAct.getFacilityId() != null) {
              Coord nextActFacilityCoord =
                  facilities.getFacilities().get(nextAct.getFacilityId()).getCoord();
              travelDistance += GeneralLib.getDistance(coordParking, nextActFacilityCoord);
            } else {
              Coord nextActLinkCoord = nextAct.getCoord();
              travelDistance += GeneralLib.getDistance(coordParking, nextActLinkCoord);
            }
            numberOfLegs++;
          }
          if (prevLeg.getMode().equalsIgnoreCase("walk")) {
            ActivityImpl prevAct = (ActivityImpl) pe.get(i - 2);

            if (prevAct.getFacilityId() != null) {
              Coord prevActFacilityCoord =
                  facilities.getFacilities().get(prevAct.getFacilityId()).getCoord();
              travelDistance += GeneralLib.getDistance(coordParking, prevActFacilityCoord);
            } else {
              Coord prevActLinkCoord = prevAct.getCoord();
              travelDistance += GeneralLib.getDistance(coordParking, prevActLinkCoord);
            }
            numberOfLegs++;
          }
        }
      }
    }

    return travelDistance / numberOfLegs;
  }
예제 #4
0
 public static void main(String[] args) {
   ArrayList<String> outputList = new ArrayList<String>();
   outputList.add("<parkinglots>");
   collectStreetParkings(outputList);
   collectGarageParkings(outputList);
   outputList.add("</parkinglots>");
   GeneralLib.writeList(outputList, Config.getOutputFolder() + "parkingLots.xml");
 }
예제 #5
0
 public static void main(String[] args) {
   Network network =
       GeneralLib.readNetwork(
           "c:/data/parkingSearch/psim/zurich/inputs/ktiRun24/output_network.xml.gz");
   TTMatrix ttMatrix =
       new TTMatrixFromStoredTable(
           "C:/data/parkingSearch/psim/zurich/inputs/it.50.3600secBin.ttMatrix.txt", network);
   getParkingManagerZH(network, ttMatrix);
 }
예제 #6
0
  public static void writeArrayToFile(double[] array, String fileName, String headerLine) {
    double matrix[][] = new double[array.length][1];

    for (int i = 0; i < array.length; i++) {
      matrix[i][0] = array[i];
    }

    GeneralLib.writeMatrix(matrix, fileName, headerLine);
  }
예제 #7
0
  public static DoubleValueHashMap<Id<Person>> readIncome(String fileName) {
    DoubleValueHashMap<Id<Person>> houseHoldIncome = new DoubleValueHashMap<>();

    Matrix morningMatrix = GeneralLib.readStringMatrix(fileName, "\t");

    for (int i = 1; i < morningMatrix.getNumberOfRows(); i++) {
      Id<Person> id = Id.create(morningMatrix.getString(i, 0), Person.class);
      double income = morningMatrix.getDouble(i, 1);
      houseHoldIncome.put(id, income);
    }
    return houseHoldIncome;
  }
예제 #8
0
  public static void main(String[] args) {
    String basePath = "H:/data/experiments/TRBAug2012/runs/run77/output/";
    String fileName = basePath + "houseHoldIncome.txt";

    DoubleValueHashMap<Id<Person>> income = readIncome(fileName);

    int iterationNumber = 35;

    // String fileNameInputFile = ".walkTimes.txt";
    String fileNameInputFile = ".parkingCostLog.txt";

    String walkTimesFile =
        basePath + "ITERS/it." + iterationNumber + "/" + iterationNumber + fileNameInputFile;

    IntegerValueHashMap<Id> numberOfParkingActs = new IntegerValueHashMap<Id>();
    DoubleValueHashMap<Id> walkTimes = new DoubleValueHashMap<Id>();
    Matrix walkTimesMatrix = GeneralLib.readStringMatrix(walkTimesFile, "\t");

    for (int i = 1; i < walkTimesMatrix.getNumberOfRows(); i++) {
      String parkingIdString = walkTimesMatrix.getString(i, 1);
      if (parkingIdString.contains("gp") || parkingIdString.contains("stp")) {
        Id<Person> personId = Id.create(walkTimesMatrix.getString(i, 0), Person.class);
        double walkTime = walkTimesMatrix.getDouble(i, 2);

        if (walkTime != 0) {
          numberOfParkingActs.increment(personId);
          walkTimes.incrementBy(personId, walkTime);
        }
      }
    }

    for (Id<Person> personId : walkTimes.keySet()) {
      double averageWalkTime = walkTimes.get(personId) / numberOfParkingActs.get(personId);
      walkTimes.put(personId, averageWalkTime);
    }

    IntegerValueHashMap<Integer> categoryFrequency = new IntegerValueHashMap<Integer>();
    DoubleValueHashMap<Integer> categorySum = new DoubleValueHashMap<Integer>();
    for (Id<Person> personId : walkTimes.keySet()) {
      int incomeCategory = getIncomeCategory(income.get(personId));
      categorySum.incrementBy(incomeCategory, walkTimes.get(personId));
      categoryFrequency.increment(incomeCategory);
    }

    for (Integer incomeCategory : categorySum.keySet()) {
      categorySum.put(
          incomeCategory, categorySum.get(incomeCategory) / categoryFrequency.get(incomeCategory));
    }

    categorySum.printToConsole();
  }
예제 #9
0
  public static void writeHashMapToFile(HashMap hm, String headerLine, String fileName) {
    ArrayList<String> list = new ArrayList<String>();
    list.add(headerLine);

    for (Object key : hm.keySet()) {
      StringBuffer stringBuffer = new StringBuffer();
      stringBuffer.append(key.toString());
      stringBuffer.append("\t");
      stringBuffer.append(hm.get(key).toString());
      list.add(stringBuffer.toString());
    }

    GeneralLib.writeList(list, fileName);
  }
  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;
  }
예제 #11
0
  private static void collectGarageParkings(ArrayList<String> outputList) {
    Matrix garageParkingData = GeneralLib.readStringMatrix(Config.baseFolder + "../parkhäuser.txt");

    int totalCapacity = 0;
    for (int i = 1; i < garageParkingData.getNumberOfRows(); i++) {
      double x = garageParkingData.getDouble(i, 0);
      double y = garageParkingData.getDouble(i, 1);

      if (Config.isInsideStudyArea(x, y)) {
        int capacity = Integer.parseInt(garageParkingData.getString(i, 2));
        totalCapacity += capacity;
        outputList.add(getParkingString("gp-" + i, x, y, capacity));
      }
    }
    System.out.println("total number of garage parking in the scenario:" + totalCapacity);
  }
예제 #12
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");
  }
예제 #13
0
  public static void main(String[] args) {
    Matrix matrix = GeneralLib.readStringMatrix("c:/tmp/homeDemand.txt", "\t");

    LinkedList<WeightedDemand> demand = new LinkedList<WeightedDemand>();
    LinkedList<Coord> possibleChargingLocations = new LinkedList<Coord>();
    int maxNumberOfChargingLocations = 1;

    for (int i = 1; i < matrix.getNumberOfRows(); i++) {
      WeightedDemand wd = new WeightedDemand();
      wd.demandCount = matrix.getInteger(i, 1);
      wd.coord = new Coord(matrix.getDouble(i, 2), matrix.getDouble(i, 3));
      demand.add(wd);
      possibleChargingLocations.add(wd.coord);
    }

    SimpleLocationOptimizer slo = new SimpleLocationOptimizer();
    slo.solveSingleChargingLocation(demand, possibleChargingLocations);
    System.out.println(slo.scoreSolution(demand, possibleChargingLocations));
  }
  public static void main(String[] args) {
    String inputNetworkPath =
        "H:/data/experiments/ARTEMIS/zh/dumb charging/output/run2/output_network.xml.gz";
    String outputFilePath =
        "H:/data/experiments/ARTEMIS/zh/dumb charging/output/run2/analysis/linksWithEnergyConsumpHigherThanThreshholdValue.kml";

    LinkedList<Id<Link>> selectedLinks = new LinkedList<Id<Link>>();

    selectedLinks.add(Id.create("17560000662724TF", Link.class));
    selectedLinks.add(Id.create("17560002226916TF", Link.class));
    selectedLinks.add(Id.create("17560000114875TF", Link.class));
    selectedLinks.add(Id.create("17560000082333TF", Link.class));
    selectedLinks.add(Id.create("17560002149918FT", Link.class));
    selectedLinks.add(Id.create("17560000368213FT", Link.class));
    selectedLinks.add(Id.create("17560002188272FT", Link.class));
    selectedLinks.add(Id.create("17560001856956FT", Link.class));
    selectedLinks.add(Id.create("17560001229496TF", Link.class));
    selectedLinks.add(Id.create("17560001363425TF", Link.class));
    selectedLinks.add(Id.create("17560001607380FT-1", Link.class));
    selectedLinks.add(Id.create("17560000045386TF", Link.class));
    selectedLinks.add(Id.create("17560000109095TF", Link.class));
    selectedLinks.add(Id.create("17560001227588FT", Link.class));
    selectedLinks.add(Id.create("17560000043382FT", Link.class));
    selectedLinks.add(Id.create("17560000105015FT", Link.class));
    selectedLinks.add(Id.create("17560000109323TF", Link.class));
    selectedLinks.add(Id.create("17560001594646FT", Link.class));
    selectedLinks.add(Id.create("17560001380278TF", Link.class));

    BasicPointVisualizer basicPointVisualizer = new BasicPointVisualizer();

    Network network = GeneralLib.readNetwork(inputNetworkPath);

    for (Link link : network.getLinks().values()) {
      if (selectedLinks.contains(link.getId())) {
        basicPointVisualizer.addPointCoordinate(
            link.getCoord(), link.getId().toString(), Color.GREEN);
      }
    }

    basicPointVisualizer.write(outputFilePath);
  }
예제 #15
0
  private static void addIllegalParking(Network network, LinkedList<PParking> parkings) {
    double shareOfLinksWithIllegalParking =
        ZHScenarioGlobal.loadDoubleParam("ParkingLoader.shareOfLinksWithIllegalParking");
    Coord coordinatesLindenhofZH = ParkingHerbieControler.getCoordinatesLindenhofZH();
    Random rand =
        new Random(
            19873); // fixing seed (scenarios with different simulation seeds should still have same
                    // illegal parking infrastructure)

    int i = 0;
    for (Link link : network.getLinks().values()) {
      if (GeneralLib.getDistance(coordinatesLindenhofZH, link.getCoord()) < 7000
          && rand.nextDouble() < shareOfLinksWithIllegalParking) {
        PublicParking parking = new PublicParking(link.getCoord());
        parking.setMaxCapacity(1.0);
        parking.setParkingId(Id.create("illegal-" + i, PParking.class));
        parking.setType("public");
        parkings.add(parking);
        i++;
      }
    }
    System.out.println("number of illegal parking added: " + i / 1000.0 + "k");
  }
예제 #16
0
  private static void collectStreetParkings(ArrayList<String> outputList) {
    String streetParkings = Config.baseFolder + "../streetpark_facilities.xml";
    ActivityFacilities streetParkingFacilities = GeneralLib.readActivityFacilities(streetParkings);

    int totalCapacity = 0;
    for (Id facilityId : streetParkingFacilities.getFacilities().keySet()) {
      ActivityFacilityImpl facilityImpl =
          (ActivityFacilityImpl) streetParkingFacilities.getFacilities().get(facilityId);

      Map<String, ActivityOption> activityOptions = facilityImpl.getActivityOptions();

      if (Config.isInsideStudyArea(facilityImpl.getCoord())) {
        long capacity = Math.round(activityOptions.get("parking").getCapacity());
        totalCapacity += capacity;
        outputList.add(
            getParkingString(
                "sp-" + facilityId.toString(),
                facilityImpl.getCoord().getX(),
                facilityImpl.getCoord().getY(),
                capacity));
      }
    }
    System.out.println("total number of street parking in the scenario:" + totalCapacity);
  }
  public void writeOutParkingOccupanciesTxt(
      Controler controler, IntegerValueHashMap<Id> facilityCapacities, int iteration) {
    String iterationFilename =
        controler.getControlerIO().getIterationFilename(iteration, "parkingOccupancy.txt");

    ArrayList<String> list = new ArrayList<String>();

    // create header line
    StringBuffer row = new StringBuffer("name\tcapacity");

    for (int i = 0; i < 96; i++) {
      row.append("\t");
      row.append("bin-" + i);
    }

    list.add(row.toString());

    // content
    for (Id parkingFacilityId : parkingOccupancies.keySet()) {

      ParkingOccupancyBins parkingOccupancyBins = parkingOccupancies.get(parkingFacilityId);
      row = new StringBuffer(parkingFacilityId.toString());

      row.append("\t");
      row.append(facilityCapacities.get(parkingFacilityId));

      for (int i = 0; i < 96; i++) {
        row.append("\t");
        row.append(parkingOccupancyBins.getOccupancy(i * 900));
      }

      list.add(row.toString());
    }

    GeneralLib.writeList(list, iterationFilename);
  }
예제 #18
0
  public static boolean isInsideCordon(Coord coord) {
    Coord center = new Coord(683400.75, 247500.0687);
    double radius = 1000;

    return GeneralLib.getDistance(center, coord) < radius;
  }
예제 #19
0
  /** @param args */
  public static void main(String[] args) {
    String basePath = "H:/data/experiments/ARTEMIS/output/run2/";
    String plansFile = basePath + "output_plans.xml.gz";
    String networkFile = basePath + "output_network.xml.gz";
    String facilititiesPath = basePath + "output_facilities.xml.gz";
    MutableScenario scenario =
        (MutableScenario) GeneralLib.readScenario(plansFile, networkFile, facilititiesPath);

    int nuberTripsWorkRelated = 0;
    int numberOfTripsShopAndLeisureRelated = 0;

    Population population = scenario.getPopulation();

    for (Person person : population.getPersons().values()) {
      Plan plan = person.getSelectedPlan();

      Activity prevAct = null;
      Leg prevLeg = null;

      for (PlanElement pe : plan.getPlanElements()) {
        if (pe instanceof Activity) {
          Activity activity = (Activity) pe;
          if (prevLeg != null && prevLeg.getMode().equalsIgnoreCase("car")) {

            // a) COMING FROM OC TO C FOR WORK
            if (!isInsideCordon(prevAct) && isInsideCordon(activity)) {
              if (equalsActType(activity, "work")) {
                nuberTripsWorkRelated++;
              }
            }

            // b)LEAVING C FROM WORK TO OC
            if (isInsideCordon(prevAct) && !isInsideCordon(activity)) {
              if (equalsActType(prevAct, "work")) {
                nuberTripsWorkRelated++;
              }
            }

            // c)COMING FROM C TO C FOR WORK
            if (isInsideCordon(prevAct) && isInsideCordon(activity)) {
              if (equalsActType(activity, "work")) {
                nuberTripsWorkRelated++;
              }
            }

            // d) LEAVING C FROM WORK TO C
            if (isInsideCordon(prevAct) && isInsideCordon(activity)) {
              if (equalsActType(prevAct, "work")) {
                nuberTripsWorkRelated++;
              }
            }

            // e) COMING FROM OC TO C FOR ACT (shop/leisure)
            if (!isInsideCordon(prevAct) && isInsideCordon(activity)) {
              if (equalsActType(activity, "shop") || equalsActType(activity, "leisure")) {
                numberOfTripsShopAndLeisureRelated++;
              }
            }

            // f) COMING FROM C TO C FOR ACT
            if (isInsideCordon(prevAct) && isInsideCordon(activity)) {
              if (equalsActType(activity, "shop") || equalsActType(activity, "leisure")) {
                numberOfTripsShopAndLeisureRelated++;
              }
            }
          }

          prevAct = activity;
        }

        if (pe instanceof Leg) {
          prevLeg = (Leg) pe;
        }
      }
    }

    System.out.println("nuberTripsWorkRelated:" + nuberTripsWorkRelated);
    System.out.println("numberOfTripsShopAndLeisureRelated:" + numberOfTripsShopAndLeisureRelated);
  }
예제 #20
0
 public static double getDistance(Coord coord, Link link) {
   return GeneralLib.getDistance(coord, link.getCoord());
 }
예제 #21
0
  public static int getTimeBinIndex(double time, double binSizeInSeconds) {

    time = GeneralLib.projectTimeWithin24Hours(time);

    return Math.round((float) Math.floor(time / binSizeInSeconds));
  }