Ejemplo n.º 1
0
  public void write(String outputFilenameBase) {
    SimpleWriter writer = new SimpleWriter(outputFilenameBase + "txt");
    writer.writeln("timeBin\twaitTimeOutofBus\twaitTimeInBus");
    StackedBarChart chart =
        new StackedBarChart(
            "arrivalTimeAtBusStop<->WaitTimeOutOfBus or WaitTimeInBus",
            "arrivalTimeAtBusStops",
            "waitTime[s]",
            PlotOrientation.VERTICAL);
    Object[] bins = wtobSums.keySet().toArray();
    // System.out.println("bins length=\t" + bins.length);
    int firstBin = (Integer) bins[0], lastBin = (Integer) bins[bins.length - 1];
    String[] times = new String[lastBin - firstBin + 1];
    double[][] values = new double[2][lastBin - firstBin + 1];
    for (int i = firstBin; i <= lastBin; i++) {
      // System.out.println(">>>>> i=\t" + i);
      int wtob = (int) (wtobCounts.containsKey(i) ? wtobSums.get(i) / wtobCounts.get(i) : 0);
      int wib = (int) (wibCounts.containsKey(i) ? wibSums.get(i) / wibCounts.get(i) : 0);
      String time = Time.writeTime(i * binSize);
      writer.writeln(time + "\t" + Time.writeTime(wtob) + "\t" + Time.writeTime(wib));
      times[i - firstBin] = time;
      values[0][i - firstBin] = wtob;
      values[1][i - firstBin] = wib;
    }
    writer.close();

    chart.addSeries(new String[] {"waitTimeOutOfBus", "waitTimeInBus"}, times, values);
    chart.saveAsPng(outputFilenameBase + "png", 1024, 768);
  }
Ejemplo n.º 2
0
  /** @param args */
  public static void main(String[] args) {
    String //
        // netFilename = "../matsim/test/scenarios/chessboard/network.xml", //
        // popFilename = "../matsim/test/scenarios/chessboard/plans.xml", //
        facilitiesFilename = "../matsim/test/scenarios/chessboard/facilities.xml", //
        facilitiesTxtFilename = "../matsimTests/locationChoice/chessboard/facilities.txt";

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    // new MatsimNetworkReader(scenario).readFile(netFilename);
    new MatsimFacilitiesReader((ScenarioImpl) scenario).readFile(facilitiesFilename);

    SimpleWriter writer = new SimpleWriter(facilitiesTxtFilename);
    writer.writeln("Id\tx\ty\tacts\tcapacities");

    ActivityFacilities facilities = scenario.getActivityFacilities();
    for (ActivityFacility facility : facilities.getFacilities().values()) {
      Coord coord = facility.getCoord();
      writer.write(facility.getId() + "\t" + coord.getX() + "\t" + coord.getY() + "\t");

      Map<String, ? extends ActivityOption> activityOptions = facility.getActivityOptions();
      // acts
      writer.write(activityOptions.keySet());
      // capacities
      for (ActivityOption activityOption : activityOptions.values()) {
        writer.write("\t" + activityOption.getCapacity());
      }
      writer.writeln();
      writer.flush();
    }

    writer.close();
  }
Ejemplo n.º 3
0
 public void write(final String outputFilename) {
   SimpleWriter sw = new SimpleWriter(outputFilename + ".txt");
   sw.writeln("car_avail--always");
   sw.writeln(
       "\tmale\tfemale\tage<30\t30<=age<50\t50<=age<70\tage>70\twith license\twithout license\tis employed\tnot employed");
   sw.writeln(
       "\t"
           + male_al
           + "\t"
           + female_al
           + "\t"
           + ageA_al
           + "\t"
           + ageB_al
           + "\t"
           + ageC_al
           + "\t"
           + ageD_al
           + "\t"
           + withLicense_al
           + "\t"
           + withoutLicense_al
           + "\t"
           + isEmployed_al
           + "\t"
           + notEmployed_al);
   sw.writeln("-----------------------------");
   sw.writeln("car_avail--sometimes");
   sw.writeln(
       "\tmale\tfemale\tage<30\t30<=age<50\t50<=age<70\tage>70\twith license\twithout license\tis employed\tnot employed");
   sw.writeln(
       "\t"
           + male_so
           + "\t"
           + female_so
           + "\t"
           + ageA_so
           + "\t"
           + ageB_so
           + "\t"
           + ageC_so
           + "\t"
           + ageD_so
           + "\t"
           + withLicense_so
           + "\t"
           + withoutLicense_so
           + "\t"
           + isEmployed_so
           + "\t"
           + notEmployed_so);
   sw.writeln("-----------------------------");
   sw.writeln("car_avail--never");
   sw.writeln(
       "\tmale\tfemale\tage<30\t30<=age<50\t50<=age<70\tage>70\twith license\twithout license\tis employed\tnot employed");
   sw.writeln(
       "\t"
           + male_ne
           + "\t"
           + female_ne
           + "\t"
           + ageA_ne
           + "\t"
           + ageB_ne
           + "\t"
           + ageC_ne
           + "\t"
           + ageD_ne
           + "\t"
           + withLicense_ne
           + "\t"
           + withoutLicense_ne
           + "\t"
           + isEmployed_ne
           + "\t"
           + notEmployed_ne);
   sw.writeln("-----------------------------");
   sw.close();
   BarChart chart =
       new BarChart(
           "Car Avail",
           "categories",
           "Car Availability %",
           new String[] {
             "male",
             "female",
             "age<30",
             "30<=age<50",
             "50<=age<70",
             "age>70",
             "with license",
             "without license",
             "is employed",
             "not employed"
           });
   chart.addSeries(
       "always",
       new double[] {
         male_al / (male_al + male_ne + male_so) * 100.0,
         female_al / (female_al + female_ne + female_so) * 100.0,
         ageA_al / (ageA_al + ageA_ne + ageA_so) * 100.0,
         ageB_al / (ageB_al + ageB_ne + ageB_so) * 100.0,
         ageC_al / (ageC_al + ageC_ne + ageC_so) * 100.0,
         ageD_al / (ageD_al + ageD_ne + ageD_so) * 100.0,
         withLicense_al / (withLicense_al + withLicense_ne + withLicense_so) * 100.0,
         withoutLicense_al / (withoutLicense_al + withoutLicense_ne + withoutLicense_so) * 100.0,
         isEmployed_al / (isEmployed_al + isEmployed_ne + isEmployed_so) * 100.0,
         notEmployed_al / (notEmployed_al + notEmployed_ne + notEmployed_so) * 100.0
       });
   chart.addSeries(
       "sometimes",
       new double[] {
         male_so / (male_al + male_ne + male_so) * 100.0,
         female_so / (female_al + female_ne + female_so) * 100.0,
         ageA_so / (ageA_al + ageA_ne + ageA_so) * 100.0,
         ageB_so / (ageB_al + ageB_ne + ageB_so) * 100.0,
         ageC_so / (ageC_al + ageC_ne + ageC_so) * 100.0,
         ageD_so / (ageD_al + ageD_ne + ageD_so) * 100.0,
         withLicense_so / (withLicense_al + withLicense_ne + withLicense_so) * 100.0,
         withoutLicense_so / (withoutLicense_al + withoutLicense_ne + withoutLicense_so) * 100.0,
         isEmployed_so / (isEmployed_al + isEmployed_ne + isEmployed_so) * 100.0,
         notEmployed_so / (notEmployed_al + notEmployed_ne + notEmployed_so) * 100.0
       });
   chart.addSeries(
       "never",
       new double[] {
         male_ne / (male_al + male_ne + male_so) * 100.0,
         female_ne / (female_al + female_ne + female_so) * 100.0,
         ageA_ne / (ageA_al + ageA_ne + ageA_so) * 100.0,
         ageB_ne / (ageB_al + ageB_ne + ageB_so) * 100.0,
         ageC_ne / (ageC_al + ageC_ne + ageC_so) * 100.0,
         ageD_ne / (ageD_al + ageD_ne + ageD_so) * 100.0,
         withLicense_ne / (withLicense_al + withLicense_ne + withLicense_so) * 100.0,
         withoutLicense_ne / (withoutLicense_al + withoutLicense_ne + withoutLicense_so) * 100.0,
         isEmployed_ne / (isEmployed_al + isEmployed_ne + isEmployed_so) * 100.0,
         notEmployed_ne / (notEmployed_al + notEmployed_ne + notEmployed_so) * 100.0
       });
   chart.addMatsimLogo();
   chart.saveAsPng(outputFilename + ".png", 1200, 900);
 }
Ejemplo n.º 4
0
  public void write(final String outputFilename) {
    double sum = carTime + ptTime + othersTime + wlkTime + bikeTime;

    SimpleWriter sw = new SimpleWriter(outputFilename + "dailyEnRouteTime.txt");
    sw.writeln("\tDaily En Route Time\tn_agents\t" + count);
    sw.writeln("\tavg.[min]\t%\tsum.[min]");

    double avgCarTime = carTime / count;
    double avgPtTime = ptTime / count;
    double avgWlkTime = wlkTime / count;
    double avgBikeTime = bikeTime / count;
    double avgOtherTime = othersTime / count;

    sw.writeln("car\t" + avgCarTime + "\t" + carTime / sum * 100.0 + "\t" + carTime);
    sw.writeln("pt\t" + avgPtTime + "\t" + ptTime / sum * 100.0 + "\t" + ptTime);
    sw.writeln("walk\t" + avgWlkTime + "\t" + wlkTime / sum * 100.0 + "\t" + wlkTime);
    sw.writeln("bike\t" + avgBikeTime + "\t" + bikeTime / sum * 100.0 + "\t" + bikeTime);
    sw.writeln("others\t" + avgOtherTime + "\t" + othersTime / sum * 100.0 + "\t" + othersTime);

    PieChart pieChart = new PieChart("Avg. Daily En Route Time -- Modal Split");
    pieChart.addSeries(
        new String[] {CAR, "pt", "wlk", BIKE, OTHERS},
        new double[] {avgCarTime, avgPtTime, avgWlkTime, avgBikeTime, avgOtherTime});
    pieChart.saveAsPng(outputFilename + "dailyEnRouteTimeModalSplitPie.png", 800, 600);

    sw.writeln("--travel destination and modal split--daily on route time--");
    sw.writeln("\twork\teducation\tshopping\tleisure\thome\tother...");
    sw.writeln(
        "car\t"
            + carWorkTime
            + "\t"
            + carEducTime
            + "\t"
            + carShopTime
            + "\t"
            + carLeisTime
            + "\t"
            + carHomeTime
            + "\t"
            + carOtherTime);
    sw.writeln(
        "pt\t"
            + ptWorkTime
            + "\t"
            + ptEducTime
            + "\t"
            + ptShopTime
            + "\t"
            + ptLeisTime
            + "\t"
            + ptHomeTime
            + "\t"
            + ptOtherTime);
    sw.writeln(
        "walk\t"
            + wlkWorkTime
            + "\t"
            + wlkEducTime
            + "\t"
            + wlkShopTime
            + "\t"
            + wlkLeisTime
            + "\t"
            + wlkHomeTime
            + "\t"
            + wlkOtherTime);
    sw.writeln(
        "bike\t"
            + bikeWorkTime
            + "\t"
            + bikeEducTime
            + "\t"
            + bikeShopTime
            + "\t"
            + bikeLeisTime
            + "\t"
            + bikeHomeTime
            + "\t"
            + bikeOtherTime);
    sw.writeln(
        "others\t"
            + othersWorkTime
            + "\t"
            + othersEducTime
            + "\t"
            + othersShopTime
            + "\t"
            + othersLeisTime
            + "\t"
            + othersHomeTime
            + "\t"
            + othersOtherTime);
    sw.writeln(
        "total\t"
            + (carWorkTime + ptWorkTime + wlkWorkTime + bikeWorkTime + othersWorkTime)
            + "\t"
            + (carEducTime + ptEducTime + wlkEducTime + bikeEducTime + othersEducTime)
            + "\t"
            + (carShopTime + ptShopTime + wlkShopTime + bikeShopTime + othersShopTime)
            + "\t"
            + (carLeisTime + ptLeisTime + wlkLeisTime + bikeLeisTime + othersLeisTime)
            + "\t"
            + (carHomeTime + ptHomeTime + wlkHomeTime + bikeHomeTime + othersHomeTime)
            + "\t"
            + (carOtherTime + ptOtherTime + wlkOtherTime + bikeOtherTime + othersOtherTime));

    BarChart barChart =
        new BarChart(
            "travel destination and modal split--daily En Route Time",
            "travel destination",
            "daily En Route Time [min]",
            new String[] {"work", "education", "shopping", "leisure", "home", OTHERS});
    barChart.addSeries(
        CAR,
        new double[] {
          carWorkTime, carEducTime, carShopTime, carLeisTime, carHomeTime, carOtherTime
        });

    double[] ptDestinationTime =
        new double[] {ptWorkTime, ptEducTime, ptShopTime, ptLeisTime, ptHomeTime, ptOtherTime};
    if (CollectionMath.getSum(ptDestinationTime) > 0) barChart.addSeries("pt", ptDestinationTime);

    double[] wlkDestinationTime =
        new double[] {
          wlkWorkTime, wlkEducTime, wlkShopTime, wlkLeisTime, wlkHomeTime, wlkOtherTime
        };
    if (CollectionMath.getSum(wlkDestinationTime) > 0)
      barChart.addSeries("walk", wlkDestinationTime);

    double[] bikeDestinationTime =
        new double[] {
          bikeWorkTime, bikeEducTime, bikeShopTime, bikeLeisTime, bikeHomeTime, bikeOtherTime
        };
    if (CollectionMath.getSum(bikeDestinationTime) > 0)
      barChart.addSeries(BIKE, bikeDestinationTime);

    double[] othersDestinationTime =
        new double[] {
          othersWorkTime,
          othersEducTime,
          othersShopTime,
          othersLeisTime,
          othersHomeTime,
          othersOtherTime
        };
    if (CollectionMath.getSum(othersDestinationTime) > 0)
      barChart.addSeries(OTHERS, othersDestinationTime);

    barChart.addMatsimLogo();
    barChart.saveAsPng(outputFilename + "dailyEnRouteTimeTravelDistination.png", 1200, 900);

    double x[] = new double[101];
    for (int i = 0; i < 101; i++) x[i] = i;
    double yTotal[] = new double[101];
    double yCar[] = new double[101];
    double yPt[] = new double[101];
    double yWlk[] = new double[101];
    double yBike[] = new double[101];
    double yOthers[] = new double[101];
    for (int i = 0; i < 101; i++) {
      yTotal[i] = totalDayEnRouteTimeCounts[i] / count * 100.0;
      yCar[i] = carDayEnRouteTimeCounts[i] / count * 100.0;
      yPt[i] = ptDayEnRouteTimeCounts[i] / count * 100.0;
      yWlk[i] = wlkDayEnRouteTimeCounts[i] / count * 100.0;
      yBike[i] = bikeDayEnRouteTimeCounts[i] / count * 100.0;
      yOthers[i] = othersDayEnRouteTimeCounts[i] / count * 100.0;
    }
    XYLineChart chart =
        new XYLineChart(
            "Daily En Route Time Distribution",
            "Daily En Route Time in min",
            "fraction of persons with daily en route time longer than x... in %");
    chart.addSeries(CAR, x, yCar);
    if (CollectionMath.getSum(yPt) > 0) chart.addSeries("pt", x, yPt);
    if (CollectionMath.getSum(yWlk) > 0) chart.addSeries("walk", x, yWlk);
    if (CollectionMath.getSum(yBike) > 0) chart.addSeries(BIKE, x, yBike);
    if (CollectionMath.getSum(yOthers) > 0) chart.addSeries(OTHERS, x, yOthers);
    chart.addSeries("total", x, yTotal);
    chart.saveAsPng(outputFilename + "dailyEnRouteTimeDistribution.png", 800, 600);

    sw.writeln("\n--Modal split -- leg duration--");
    sw.writeln(
        "leg Duration [min]\tcar legs no.\tpt legs no.\twalk legs no.\tbike legs no.\tothers legs no.\t"
            + "car fraction [%]\tpt fraction [%]\twalk fraction [%]\tbike fraction [%]\tothers fraction [%]");

    double xs[] = new double[101];
    double yCarFracs[] = new double[101];
    double yPtFracs[] = new double[101];
    double yWlkFracs[] = new double[101];
    double yBikeFracs[] = new double[101];
    double yOthersFracs[] = new double[101];
    for (int i = 0; i < 101; i++) {
      double sumOfLegTimeCounts =
          carLegTimeCounts[i]
              + ptLegTimeCounts[i]
              + wlkLegTimeCounts[i]
              + bikeLegTimeCounts[i]
              + othersLegTimeCounts[i];
      xs[i] = i * 2;
      if (sumOfLegTimeCounts > 0) {
        yCarFracs[i] = carLegTimeCounts[i] / sumOfLegTimeCounts * 100.0;
        yPtFracs[i] = ptLegTimeCounts[i] / sumOfLegTimeCounts * 100.0;
        yWlkFracs[i] = wlkLegTimeCounts[i] / sumOfLegTimeCounts * 100.0;
        yBikeFracs[i] = bikeLegTimeCounts[i] / sumOfLegTimeCounts * 100.0;
        yOthersFracs[i] = othersLegTimeCounts[i] / sumOfLegTimeCounts * 100.0;
      } else {
        yCarFracs[i] = 0;
        yPtFracs[i] = 0;
        yWlkFracs[i] = 0;
        yBikeFracs[i] = 0;
        yOthersFracs[i] = 0;
      }
      sw.writeln(
          i
              + "+\t"
              + carLegTimeCounts[i]
              + "\t"
              + ptLegTimeCounts[i]
              + "\t"
              + wlkLegTimeCounts[i]
              + "\t"
              + bikeLegTimeCounts[i]
              + "\t"
              + othersLegTimeCounts[i]
              + "\t"
              + yCarFracs[i]
              + "\t"
              + yPtFracs[i]
              + "\t"
              + yWlkFracs[i]
              + "\t"
              + yBikeFracs[i]
              + "\t"
              + yOthersFracs[i]);
    }
    XYLineChart chart2 =
        new XYLineChart("Modal Split -- leg Duration", "leg Duration [min]", "mode fraction [%]");
    chart2.addSeries(CAR, xs, yCarFracs);
    if (CollectionMath.getSum(yPtFracs) > 0) chart2.addSeries("pt", xs, yPtFracs);
    if (CollectionMath.getSum(yWlkFracs) > 0) chart2.addSeries("walk", xs, yWlkFracs);
    if (CollectionMath.getSum(yBikeFracs) > 0) chart2.addSeries(BIKE, xs, yBikeFracs);
    if (CollectionMath.getSum(yOthersFracs) > 0) chart2.addSeries(OTHERS, xs, yOthersFracs);
    chart2.saveAsPng(outputFilename + "legTimeModalSplit2.png", 800, 600);
    sw.close();
  }