@Override
 public void notifyIterationEnds(IterationEndsEvent event) {
   if (this.recordPtCounts) {
     this.ptLinkCountsEventHandler.write(
         this.controlerIO.getIterationFilename(event.getIteration(), "ptLinkCounts.csv"));
     this.events.removeHandler(this.ptLinkCountsEventHandler);
     this.ptStationCountsEventHandler.write(
         this.controlerIO.getIterationFilename(event.getIteration(), "ptStationCounts.csv"));
     this.events.removeHandler(this.ptStationCountsEventHandler);
   }
   this.recordPtCounts = false;
   if (this.recordStreetCounts) {
     this.streetLinkDailyCountsEventHandler.write(
         this.controlerIO.getIterationFilename(event.getIteration(), "streetDailyCounts.csv"));
     this.events.removeHandler(this.streetLinkDailyCountsEventHandler);
     this.streetLinkHourlyCountsEventHandler.write(
         this.controlerIO.getIterationFilename(event.getIteration(), "streetHourlyCounts.csv"));
     this.events.removeHandler(this.streetLinkHourlyCountsEventHandler);
   }
   this.recordStreetCounts = false;
 }
Exemple #2
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;
        }
      }
    }
  }
  @Override
  public void notifyIterationEnds(IterationEndsEvent event) {
    // TODO send output to file
    int iteration = event.getIteration();
    final BufferedWriter outLink =
        IOUtils.getBufferedWriter(
            this.controler.getControlerIO().getIterationFilename(iteration, "prices.txt"));
    HashMap<Id<PC2Parking>, double[]> rentableDur =
        this.arrivalDepartureParkingHandler.getRentableDurPerHour();

    try {
      for (PC2Parking parking : getParkingInfrastructure().getAllParkings().values()) {
        if (parking instanceof OptimizableParking) {
          OptimizableParking par = (OptimizableParking) parking;

          double oldPrice = par.getCostPerHour();

          outLink.write(
              par.getId()
                  + ";"
                  + Double.toString(oldPrice)
                  + ";"
                  + par.getCoordinate().getX()
                  + ";"
                  + par.getCoordinate().getY()
                  + ";"
                  + par.getMaximumParkingCapacity());
          if (!(rentableDur.get(par.getId()) == null)) {

            double[] durations = rentableDur.get(par.getId());
            for (int i = 0; i < 24; i++) {
              outLink.write(";" + durations[i] / (60 * 60 * par.getMaximumParkingCapacity()));
            }

          } else {
            for (int i = 0; i < 24; i++) outLink.write(";0.0");
          }

          if (par.getGroupName().equals("streetParking")) {
            boolean hight = par.isHighTariff();
            for (int i = 0; i < 24; i++) {
              if (hight) outLink.write(";" + par.getCostPerHour(i) * 2);
              else outLink.write(";" + par.getCostPerHour(i));
            }

          } else {
            for (int i = 0; i < 24; i++) outLink.write(";" + par.getCostPerHour(i));
          }

          outLink.newLine();
        }
      }
      outLink.flush();
      outLink.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // ==================== Setting new prices for rentable parking dependig on the usage
    for (PC2Parking parking : getParkingInfrastructure().getAllParkings().values()) {
      double occup = 0;
      if (parking instanceof OptimizableParking) {
        OptimizableParking par = (OptimizableParking) parking;

        if (!(rentableDur.get(par.getId()) == null)) {

          double[] durations = rentableDur.get(par.getId());
          for (int i = 0; i < 24; i++) {

            occup = durations[i] / (60 * 60 * par.getMaximumParkingCapacity());
            if (occup > 1.0) System.out.println();

            double oldPrice = par.getCostPerHour(i);
            if (occup > 0.85) {
              // If occupancy was > 0.85, increase price by 0.25, else decrease price by 0.25
              if (oldPrice < 200) {
                par.setCostPerHour(oldPrice + 0.25, i);
              }
            } else {
              if (oldPrice >= 0.25) {
                par.setCostPerHour(oldPrice - 0.25, i);
              } else par.setCostPerHour(0.0, i);
            }
          }
        }
        // rentable space was not used at all (is not in list) => also decrease price by 0.25
        else {
          for (int i = 0; i < 24; i++) {
            double oldPrice = par.getCostPerHour(i);

            if (oldPrice >= 0.25) {
              par.setCostPerHour(oldPrice - 0.25, i);
            } else par.setCostPerHour(0.0, i);
          }
        }
      }
    }

    parkingGroupOccupanciesZH.savePlot(
        event
            .getServices()
            .getControlerIO()
            .getIterationFilename(event.getIteration(), "parkingGroupOccupancy.png"));
    averageWalkDistanceStatsZH.printStatistics();

    eventsManager.finishProcessing();
    eventsWriter.reset(0);
  }
  @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);
  }
  @Override
  public void notifyIterationEnds(IterationEndsEvent event) {
    Retailer r;
    int modelIter = 0;
    String modelIterParam = this.controler.getConfig().findParam("Retailers", "modelIteration");
    if (modelIterParam == null) {
      log.warn(
          "The iteration in which the model should be run has not been set, the model run will be performed at the last iteration");
      modelIter = this.controler.getConfig().controler().getLastIteration();
    } else {
      modelIter = Integer.parseInt(modelIterParam);
    }

    int analysisFrequency = 0;
    String AnalysisFrequencyParam =
        this.controler.getConfig().findParam("Retailers", "analysisFrequency");
    if (AnalysisFrequencyParam == null) {
      log.warn(
          "The frequency with which the analysis should be run has not been set, the analysis will be only performed when the model will run and at the last iteration");
      analysisFrequency = this.controler.getConfig().controler().getLastIteration();
    } else {
      analysisFrequency = Integer.parseInt(AnalysisFrequencyParam);
    }

    if (event.getIteration() == modelIter) {
      this.lrr = new LinksRetailerReaderV2(this.controler, this.retailers);
      this.lrr.init();
      final PersonAlgorithm router =
          new PlanRouter(event.getControler().getTripRouterProvider().get());
      for (Iterator<Retailer> localIterator = this.retailers.getRetailers().values().iterator();
          localIterator.hasNext(); ) {
        r = localIterator.next();
        this.rsw.write(r, event.getIteration(), this.cfc);
        r.runStrategy(this.lrr.getFreeLinks());
        this.lrr.updateFreeLinks();
        Map persons = this.controler.getScenario().getPopulation().getPersons();
        new ReRoutePersons()
            .run(
                r.getMovedFacilities(),
                this.controler.getScenario().getNetwork(),
                persons,
                router,
                this.controler.getScenario().getActivityFacilities());
      }
    }
    if ((event.getIteration() != 0)
        && (event.getIteration() % analysisFrequency == 0)
        && (event.getIteration() != modelIter)
        && (event.getIteration() != this.controler.getConfig().controler().getLastIteration())) {
      log.info("Test1");
      for (Iterator<Retailer> localIterator = this.retailers.getRetailers().values().iterator();
          localIterator.hasNext(); ) {
        r = localIterator.next();

        this.rsw.write(r, event.getIteration(), this.cfc);
      }
    }

    if (event.getIteration() != this.controler.getConfig().controler().getLastIteration()) return;
    for (Iterator<Retailer> localIterator = this.retailers.getRetailers().values().iterator();
        localIterator.hasNext(); ) {
      r = localIterator.next();

      this.rsw.write(r, event.getIteration(), this.cfc);
      log.info("Test2");
    }

    this.rsw.close();
  }