Ejemplo n.º 1
0
  public static void writeGraphic(
      String fileName,
      double[][] matrix,
      String title,
      String xLabel,
      String yLabel,
      String[] seriesLabels,
      double[] xValues) {
    XYLineChart chart = new XYLineChart(title, xLabel, yLabel);

    int numberOfXValues = matrix.length;
    int numberOfFunctions = matrix[0].length;

    for (int i = 0; i < numberOfFunctions; i++) {
      double[] series = new double[numberOfXValues];
      for (int j = 0; j < numberOfXValues; j++) {
        series[j] = matrix[j][i];
      }
      chart.addSeries(seriesLabels[i], xValues, series);
    }

    // chart.addMatsimLogo();
    chart.saveAsPng(fileName, 800, 600);

    // if (GlobalRegistry.doPrintGraficDataToConsole) {
    // printGraphicDataToConsole(fileName, matrix, title, xLabel, yLabel,
    // seriesLabels, xValues);
    // }
  }
Ejemplo n.º 2
0
 private void addSeriesToPlot(
     int index, XYLineChart xyLineChart, double[] iterations, int series) {
   double[] values = new double[index + 1];
   System.arraycopy(this.history[series], 0, values, 0, index + 1);
   xyLineChart.addSeries(INDEX.values()[series].enName, iterations, values);
 }
Ejemplo n.º 3
0
  @Override
  public void notifyIterationEnds(final IterationEndsEvent event) {
    if (this.pConfig.getWriteStatsInterval() > 0) {

      PStatsOverviewDataContainer pStats = new PStatsOverviewDataContainer();

      pStats.addData(PStatsOverviewDataContainer.FIELDS.iteration.ordinal(), event.getIteration());

      pStats.addData(PStatsOverviewDataContainer.FIELDS.nOperators.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nPax.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nVehicle.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal(), 0.0);
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal(), 0.0);
      pStats.addData(PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal(), 0.0);
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal(), 0.0);

      for (Operator operator : this.pBox.getOperators()) {
        List<PPlan> plans = operator.getAllPlans();

        double operatorRoutes = 0.0;
        double operatorPax = 0.0;
        double operatorVeh = 0.0;
        double operatorScore = 0.0;

        for (PPlan plan : plans) {
          operatorRoutes++;
          operatorPax += plan.getTripsServed();
          operatorVeh += plan.getNVehicles();
          operatorScore += plan.getScore();
        }

        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.nOperators.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperators.ordinal()) + 1.0);
        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal()) + operatorRoutes);
        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.nPax.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nPax.ordinal()) + operatorPax);
        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.nVehicle.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicle.ordinal()) + operatorVeh);

        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal())
                + operator.getBudget());
        pStats.addData(
            PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal(),
            pStats.getData(PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal())
                + operatorScore);

        // statistics for each operator in business
        if (operator.getOperatorState().equals(OperatorState.INBUSINESS)) {
          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal(),
              pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal())
                  + 1.0);
          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal(),
              pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal())
                  + operatorRoutes);
          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal(),
              pStats.getData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal())
                  + operatorPax);
          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal(),
              pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal())
                  + operatorVeh);

          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal(),
              pStats.getData(
                      PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal())
                  + operator.getBudget());
          pStats.addData(
              PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal(),
              pStats.getData(
                      PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal())
                  + operatorScore);
        }
      }

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.shareOfInBusinessOperators.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperators.ordinal())
              * 100.0);
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.shareOfInBusinessRoutes.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal())
              * 100.0);
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.shareOfPaxServedByInBusiness.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nPax.ordinal())
              * 100.0);
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.shareOfVehOfInBusiness.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicle.ordinal())
              * 100.0);

      this.statsContainer.handleNewEntry(
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal()));
      this.statsApproxContainer.handleNewEntry(
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal()),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal()));

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperators.ordinal()));
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal(),
          pStats.getData(
                  PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal()));

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal(),
          pStats.getData(PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal()));
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal(),
          pStats.getData(
                  PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal())
              / pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal()));

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedMeanOperatorsInBusiness.ordinal(),
          statsApproxContainer.getArithmeticMeanOperators());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedSDOperatorsInBusiness.ordinal(),
          statsApproxContainer.getStdDevOperators());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedMeanRouteOfInBusiness.ordinal(),
          statsApproxContainer.getArithmeticMeanRoutes());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedSDRouteOfInBusiness.ordinal(),
          statsApproxContainer.getStdDevRoutes());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedMeanPaxServedByInBusiness.ordinal(),
          statsApproxContainer.getArithmeticMeanPax());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedSDPaxServedByInBusiness.ordinal(),
          statsApproxContainer.getStdDevPax());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedMeanVehicleOfInBusiness.ordinal(),
          statsApproxContainer.getArithmeticMeanVeh());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.estimatedSDVehicleOfInBusiness.ordinal(),
          statsApproxContainer.getStdDevVeh());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactMeanOperatorsInBusiness.ordinal(),
          statsContainer.getArithmeticMeanOperators());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactSDOperatorsInBusiness.ordinal(),
          statsContainer.getStdDevOperators());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactMeanRouteOfInBusiness.ordinal(),
          statsContainer.getArithmeticMeanRoutes());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactSDRouteOfInBusiness.ordinal(),
          statsContainer.getStdDevRoutes());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactMeanPaxServedByInBusiness.ordinal(),
          statsContainer.getArithmeticMeanPax());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactSDPaxServedByInBusiness.ordinal(),
          statsContainer.getStdDevPax());

      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactMeanVehicleOfInBusiness.ordinal(),
          statsContainer.getArithmeticMeanVeh());
      pStats.addData(
          PStatsOverviewDataContainer.FIELDS.exactSDVehicleOfInBusiness.ordinal(),
          statsContainer.getStdDevVeh());

      try {
        StringBuffer strB = new StringBuffer();
        for (FIELDS field : PStatsOverviewDataContainer.FIELDS.values()) {
          String value;

          if (Double.isNaN(pStats.getData(field.ordinal()))) {
            value = Double.toString(pStats.getData(field.ordinal()));
          } else {
            value = field.getDecimalFormat().format(pStats.getData(field.ordinal()));
          }

          strB.append(value).append(PStatsOverviewDataContainer.DELIMITER);
        }
        strB.append("\n");
        this.pStatsWriter.write(strB.toString());
        this.pStatsWriter.flush();
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (this.history != null) {
        int index = event.getIteration() - this.minIteration;

        this.history[INDEX.INDEX_NOPERATORS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperators.ordinal());
        this.history[INDEX.INDEX_NOPERATORSPOS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nOperatorsInBusiness.ordinal());
        this.history[INDEX.INDEX_NROUTES.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutes.ordinal());
        this.history[INDEX.INDEX_NROUTESPOS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nRoutesOfInBusiness.ordinal());
        this.history[INDEX.INDEX_NPAX.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nPax.ordinal());
        this.history[INDEX.INDEX_NPAXPOS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nPaxServedByInBusiness.ordinal());
        this.history[INDEX.INDEX_NVEH.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicle.ordinal());
        this.history[INDEX.INDEX_NVEHPOS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.nVehicleOfInBusiness.ordinal());
        this.history[INDEX.INDEX_NBUDGET.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.avgBudgetPerOperator.ordinal());
        this.history[INDEX.INDEX_NBUDGETPOS.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.avgBudgetPerInBusinessOperator.ordinal());
        this.history[INDEX.INDEX_NSCORE.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.avgCashflowPerRoute.ordinal());
        this.history[INDEX.INDEX_NSCOREPOS.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.avgCashflowPerRouteOfInBusiness.ordinal());

        this.history[INDEX.INDEX_SHAREPOSOPERATORS.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.shareOfInBusinessOperators.ordinal());
        this.history[INDEX.INDEX_SHAREPOSROUTES.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.shareOfInBusinessRoutes.ordinal());
        this.history[INDEX.INDEX_SHAREPOSPAX.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.shareOfPaxServedByInBusiness.ordinal());
        this.history[INDEX.INDEX_SHAREPOSVEH.ordinal()][index] =
            pStats.getData(PStatsOverviewDataContainer.FIELDS.shareOfVehOfInBusiness.ordinal());

        this.history[INDEX.INDEX_MEANPOSOPERATORS.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.estimatedMeanOperatorsInBusiness.ordinal());
        this.history[INDEX.INDEX_MEANPOSROUTES.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.estimatedMeanRouteOfInBusiness.ordinal());
        this.history[INDEX.INDEX_MEANPOSPAX.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.estimatedMeanPaxServedByInBusiness.ordinal());
        this.history[INDEX.INDEX_MEANPOSVEH.ordinal()][index] =
            pStats.getData(
                PStatsOverviewDataContainer.FIELDS.estimatedMeanVehicleOfInBusiness.ordinal());

        this.history[INDEX.INDEX_SIGMAUPPERPOSOPERATORS.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanOperatorsInBusiness.ordinal())
                + pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDOperatorsInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMAUPPERPOSROUTES.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanRouteOfInBusiness.ordinal())
                + pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDRouteOfInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMAUPPERPOSPAX.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanPaxServedByInBusiness.ordinal())
                + pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDPaxServedByInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMAUPPERPOSVEH.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanVehicleOfInBusiness.ordinal())
                + pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDVehicleOfInBusiness.ordinal());

        this.history[INDEX.INDEX_SIGMALOWERPOSOPERATORS.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanOperatorsInBusiness.ordinal())
                - pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDOperatorsInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMALOWERPOSROUTES.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanRouteOfInBusiness.ordinal())
                - pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDRouteOfInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMALOWERPOSPAX.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanPaxServedByInBusiness.ordinal())
                - pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDPaxServedByInBusiness.ordinal());
        this.history[INDEX.INDEX_SIGMALOWERPOSVEH.ordinal()][index] =
            pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedMeanVehicleOfInBusiness.ordinal())
                - pStats.getData(
                    PStatsOverviewDataContainer.FIELDS.estimatedSDVehicleOfInBusiness.ordinal());

        if ((event.getIteration() % this.pConfig.getWriteStatsInterval() == 0)) {
          if (event.getIteration() != this.minIteration) {
            // create chart when data of more than one iteration is available.

            XYLineChart size =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "operators/routes/fleet size");
            XYLineChart scores =
                new XYLineChart("Paratransit Statistics", "iteration", "score/budget");
            XYLineChart passengers = new XYLineChart("Paratransit Statistics", "iteration", "pax");
            XYLineChart shares =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "shares of operators in business");
            XYLineChart relaxOperator =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "average and deviation of operators");
            XYLineChart relaxRoutes =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "average and deviation of routes");
            XYLineChart relaxPax =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "average and deviation of passengers");
            XYLineChart relaxVeh =
                new XYLineChart(
                    "Paratransit Statistics", "iteration", "average and deviation of vehicles");

            double[] iterations = new double[index + 1];
            for (int i = 0; i <= index; i++) {
              iterations[i] = i + this.minIteration;
            }

            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NOPERATORS.ordinal());
            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NOPERATORSPOS.ordinal());
            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NROUTES.ordinal());
            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NROUTESPOS.ordinal());
            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NVEH.ordinal());
            addSeriesToPlot(index, size, iterations, INDEX.INDEX_NVEHPOS.ordinal());

            addSeriesToPlot(index, scores, iterations, INDEX.INDEX_NBUDGET.ordinal());
            addSeriesToPlot(index, scores, iterations, INDEX.INDEX_NBUDGETPOS.ordinal());
            addSeriesToPlot(index, scores, iterations, INDEX.INDEX_NSCORE.ordinal());
            addSeriesToPlot(index, scores, iterations, INDEX.INDEX_NSCOREPOS.ordinal());

            addSeriesToPlot(index, passengers, iterations, INDEX.INDEX_NPAX.ordinal());
            addSeriesToPlot(index, passengers, iterations, INDEX.INDEX_NPAXPOS.ordinal());

            addSeriesToPlot(index, shares, iterations, INDEX.INDEX_SHAREPOSOPERATORS.ordinal());
            addSeriesToPlot(index, shares, iterations, INDEX.INDEX_SHAREPOSROUTES.ordinal());
            addSeriesToPlot(index, shares, iterations, INDEX.INDEX_SHAREPOSPAX.ordinal());
            addSeriesToPlot(index, shares, iterations, INDEX.INDEX_SHAREPOSVEH.ordinal());

            addSeriesToPlot(
                index, relaxOperator, iterations, INDEX.INDEX_MEANPOSOPERATORS.ordinal());
            addSeriesToPlot(
                index, relaxOperator, iterations, INDEX.INDEX_SIGMAUPPERPOSOPERATORS.ordinal());
            addSeriesToPlot(
                index, relaxOperator, iterations, INDEX.INDEX_SIGMALOWERPOSOPERATORS.ordinal());

            addSeriesToPlot(index, relaxRoutes, iterations, INDEX.INDEX_MEANPOSROUTES.ordinal());
            addSeriesToPlot(
                index, relaxRoutes, iterations, INDEX.INDEX_SIGMAUPPERPOSROUTES.ordinal());
            addSeriesToPlot(
                index, relaxRoutes, iterations, INDEX.INDEX_SIGMALOWERPOSROUTES.ordinal());

            addSeriesToPlot(index, relaxPax, iterations, INDEX.INDEX_MEANPOSPAX.ordinal());
            addSeriesToPlot(index, relaxPax, iterations, INDEX.INDEX_SIGMAUPPERPOSPAX.ordinal());
            addSeriesToPlot(index, relaxPax, iterations, INDEX.INDEX_SIGMALOWERPOSPAX.ordinal());

            addSeriesToPlot(index, relaxVeh, iterations, INDEX.INDEX_MEANPOSVEH.ordinal());
            addSeriesToPlot(index, relaxVeh, iterations, INDEX.INDEX_SIGMAUPPERPOSVEH.ordinal());
            addSeriesToPlot(index, relaxVeh, iterations, INDEX.INDEX_SIGMALOWERPOSVEH.ordinal());

            size.addMatsimLogo();
            scores.addMatsimLogo();
            passengers.addMatsimLogo();
            shares.addMatsimLogo();
            relaxOperator.addMatsimLogo();
            relaxRoutes.addMatsimLogo();
            relaxPax.addMatsimLogo();
            relaxVeh.addMatsimLogo();

            size.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_size.png"),
                800,
                600);
            scores.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_score.png"),
                800,
                600);
            passengers.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_pax.png"), 800, 600);
            shares.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_shares.png"),
                800,
                600);
            relaxOperator.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_relaxOperators.png"),
                800,
                600);
            relaxRoutes.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_relaxRoutes.png"),
                800,
                600);
            relaxPax.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_relaxPax.png"),
                800,
                600);
            relaxVeh.saveAsPng(
                event.getServices().getControlerIO().getOutputFilename("pStats_relaxVeh.png"),
                800,
                600);
          }
        }
        if (index == (this.history[0].length - 1)) {
          // we cannot store more information, so disable the graph feature.
          this.history = null;
        }
      }
    }
  }
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();
  }
  @Override
  public void notifyIterationEnds(IterationEndsEvent event) {

    // Store and write out some aggregated numbers for analysis purposes.

    this.iteration2totalDelay.put(event.getIteration(), this.delayComputation.getTotalDelay());
    this.iteration2totalTollPayments.put(
        event.getIteration(), this.intervalBasedTolling.getTotalTollPayments());
    this.iteration2totalTravelTime.put(
        event.getIteration(), this.delayComputation.getTotalTravelTime());

    double monetizedUserBenefits = 0.;
    for (Person person : this.congestionInfo.getScenario().getPopulation().getPersons().values()) {
      monetizedUserBenefits =
          monetizedUserBenefits
              + person.getSelectedPlan().getScore()
                  / this.congestionInfo
                      .getScenario()
                      .getConfig()
                      .planCalcScore()
                      .getMarginalUtilityOfMoney();
    }
    this.iteration2userBenefits.put(event.getIteration(), monetizedUserBenefits);

    CongestionInfoWriter.writeIterationStats(
        this.iteration2totalDelay,
        this.iteration2totalTollPayments,
        this.iteration2totalTravelTime,
        this.iteration2userBenefits,
        this.congestionInfo.getScenario().getConfig().controler().getOutputDirectory());

    XYLineChart chart1 = new XYLineChart("Total travel time and total delay", "Iteration", "Hours");
    double[] iterations1 = new double[event.getIteration() + 1];
    double[] values1a = new double[event.getIteration() + 1];
    double[] values1b = new double[event.getIteration() + 1];
    for (int i = this.congestionInfo.getScenario().getConfig().controler().getFirstIteration();
        i <= event.getIteration();
        i++) {
      iterations1[i] = i;
      values1a[i] = this.iteration2totalDelay.get(i) / 3600.;
      values1b[i] = this.iteration2totalTravelTime.get(i) / 3600.;
    }
    chart1.addSeries("Total delay", iterations1, values1a);
    chart1.addSeries("Total travel time", iterations1, values1b);
    chart1.saveAsPng(
        this.congestionInfo.getScenario().getConfig().controler().getOutputDirectory()
            + "travelTime_delay.png",
        800,
        600);

    XYLineChart chart2 =
        new XYLineChart(
            "System welfare, user benefits and toll revenues", "Iteration", "Monetary units");
    double[] iterations2 = new double[event.getIteration() + 1];
    double[] values2a = new double[event.getIteration() + 1];
    double[] values2b = new double[event.getIteration() + 1];
    double[] values2c = new double[event.getIteration() + 1];

    for (int i = this.congestionInfo.getScenario().getConfig().controler().getFirstIteration();
        i <= event.getIteration();
        i++) {
      iterations2[i] = i;
      values2a[i] = this.iteration2userBenefits.get(i) + this.iteration2totalTollPayments.get(i);
      values2b[i] = this.iteration2userBenefits.get(i);
      values2c[i] = this.iteration2totalTollPayments.get(i);
    }
    chart2.addSeries("System welfare", iterations2, values2a);
    chart2.addSeries("User benefits", iterations2, values2b);
    chart2.addSeries("Toll revenues", iterations2, values2c);
    chart2.saveAsPng(
        this.congestionInfo.getScenario().getConfig().controler().getOutputDirectory()
            + "systemWelfare_userBenefits_tollRevenues.png",
        800,
        600);
  }