Exemplo n.º 1
0
  @Override
  public void notifyIterationStarts(IterationStartsEvent event) {
    int evCount = 0;
    int cvCount = 0;
    int newKeysAdded = 0;
    int existingKeyUsed = 0;
    int numberOfPlansRemovedFromHM = 0;
    HashSet<Plan> allCurrentPlans = new HashSet<Plan>();
    for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) {

      if (person.getId().toString().equalsIgnoreCase("111106347")) {
        System.out.println();
      }

      if (hasCarLeg(person.getSelectedPlan())) {
        if (!hasElectricVehicle.containsKey(person.getSelectedPlan())) {
          hasElectricVehicle.put(person.getSelectedPlan(), MatsimRandom.getRandom().nextBoolean());
          newKeysAdded++;
        } else {
          existingKeyUsed++;
        }

        if (hasElectricVehicle.get(person.getSelectedPlan())) {
          evCount++;
          personHasElectricVehicle.put(person.getId(), true);
        } else {
          cvCount++;
          personHasElectricVehicle.put(person.getId(), false);
        }

        for (Plan plan : person.getPlans()) {
          allCurrentPlans.add(plan);
        }
      }
    }

    LinkedList<Plan> removePlans = new LinkedList<Plan>();
    for (Plan plan : hasElectricVehicle.keySet()) {
      if (!allCurrentPlans.contains(plan)) {
        removePlans.add(plan);
      }
    }

    for (Plan plan1 : removePlans) {
      hasElectricVehicle.remove(plan1);
      numberOfPlansRemovedFromHM++;
    }

    log.info("iteration: " + event.getIteration());

    log.info("numberOfPlansRemovedFromHM: " + numberOfPlansRemovedFromHM);
    log.info("evCount: " + evCount);
    log.info("cvCount: " + cvCount);
    log.info("hasElectricVehicle.size(): " + hasElectricVehicle.size());
    log.info("newKeysAdded: " + newKeysAdded);
    log.info("existingKeyUsed: " + existingKeyUsed);
    log.info("");
  }
  @Override
  public void notifyIterationStarts(IterationStartsEvent event) {

    /*for (ParkingArrivalEvent rA: rentableArrival) {
    	for (ParkingDepartureEvent rD: rentableDeparture) {
    		double rentedTime = 0;
    		if (rA.getParkingId(rA.getAttributes()).equals(rD.getParkingId(rD.getAttributes())) && rD.getTime() > rA.getTime()){
    			rentedTime = rD.getTime()-rA.getTime();
    			double tempTime =0;
    			if(rentableDur.containsKey(rA.getParkingId(rA.getAttributes()))){
    				tempTime = rentableDur.get(rA.getParkingId(rA.getAttributes()));
    				rentableDur.put(rA.getParkingId(rA.getAttributes()), rentedTime+tempTime);
    			} else {
    				rentableDur.put(rA.getParkingId(rA.getAttributes()), rentedTime);
    			}
    			break;
    		}
    	}
    }*/
    // Save rentable parking information
    /*HashMap<String, ArrayList<String>> rentableInfo = new HashMap<String, ArrayList<String>>();
    for (PC2Parking parking : getParkingInfrastructure().getAllParkings().values()) {
    	if (parking instanceof OptimizableParking){
    		OptimizableParking par = (OptimizableParking) parking;
    		ArrayList<String> info = new ArrayList<String>();

    		double occup = Double.NaN;
    		double rentedTime = Double.NaN;
    		double pricePerHour=par.getCostPerHour();
    		if (!(rentableDur.get(par.getId()) == null)){
    			rentedTime = rentableDur.get(par.getId());
    			occup = rentableDur.get(par.getId())/(24 * 60 * 60);
    		}
    		info.add(parking.getId().toString());
    		info.add(Double.toString(rentedTime));
    		info.add(Double.toString(occup));
    		info.add(Double.toString(pricePerHour));
    		info.add(Double.toString(parking.getCoordinate().getX()));
    		info.add(Double.toString(parking.getCoordinate().getY()));
    		rentableInfo.put(parking.getId().toString(), info);
    	}
    }*/

    // String outputFolder = event.getControler().getControlerIO().getIterationPath(iter);
    // CsvFileWriter.writeCsvFile(outputFolder+"/rentableParkingInfo.csv", rentableInfo);

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

    eventsManager = EventsUtils.createEventsManager();
    eventsWriter =
        new EventWriterXML(
            event
                .getServices()
                .getControlerIO()
                .getIterationFilename(event.getIteration(), "parkingEvents.xml.gz"));
    eventsManager.addHandler(eventsWriter);
    parkingGroupOccupanciesZH = new ParkingGroupOccupanciesZH(this.controler);
    eventsManager.addHandler(parkingGroupOccupanciesZH);
    averageWalkDistanceStatsZH =
        new AverageWalkDistanceStatsZH(getParkingInfrastructureManager().getAllParkings());
    eventsManager.addHandler(averageWalkDistanceStatsZH);

    arrivalDepartureParkingHandler = new ArrivalDepartureParkingHandler();
    eventsManager.addHandler(arrivalDepartureParkingHandler);

    eventsManager.resetHandlers(0);
    eventsWriter.init(
        event
            .getServices()
            .getControlerIO()
            .getIterationFilename(event.getIteration(), "parkingEvents.xml.gz"));

    getParkingInfrastructure().setEventsManager(eventsManager);
  }
  @Override
  public void notifyIterationStarts(IterationStartsEvent event) {

    if (event.getIteration()
        == this.congestionInfo.getScenario().getConfig().controler().getFirstIteration()) {

      this.nextDisableInnovativeStrategiesIteration =
          (int)
              (congestionInfo
                      .getScenario()
                      .getConfig()
                      .strategy()
                      .getFractionOfIterationsToDisableInnovation()
                  * congestionInfo.getDecongestionConfigGroup().getUPDATE_PRICE_INTERVAL());
      log.info(
          "next disable innovative strategies iteration: "
              + this.nextDisableInnovativeStrategiesIteration);

      if (this.nextDisableInnovativeStrategiesIteration != 0) {
        this.nextEnableInnovativeStrategiesIteration =
            (int) (congestionInfo.getDecongestionConfigGroup().getUPDATE_PRICE_INTERVAL() + 1);
      }
      log.info(
          "next enable innovative strategies iteration: "
              + this.nextEnableInnovativeStrategiesIteration);

    } else {

      if (event.getIteration() == this.nextDisableInnovativeStrategiesIteration) {
        // set weight to zero
        log.warn("Strategy weight adjustment (set to zero) in iteration " + event.getIteration());

        for (GenericPlanStrategy<Plan, Person> strategy :
            event.getServices().getStrategyManager().getStrategies(null)) {

          String strategyName = strategy.toString();
          if (isInnovativeStrategy(strategyName)) {
            log.info("Setting weight for " + strategyName + " to zero.");
            event.getServices().getStrategyManager().changeWeightOfStrategy(strategy, null, 0.0);
          }
        }

        this.nextDisableInnovativeStrategiesIteration +=
            congestionInfo.getDecongestionConfigGroup().getUPDATE_PRICE_INTERVAL();
        log.info(
            "next disable innovative strategies iteration: "
                + this.nextDisableInnovativeStrategiesIteration);

      } else if (event.getIteration() == this.nextEnableInnovativeStrategiesIteration) {
        // set weight back to original value

        if (event.getIteration()
            >= congestionInfo
                    .getScenario()
                    .getConfig()
                    .strategy()
                    .getFractionOfIterationsToDisableInnovation()
                * (congestionInfo.getScenario().getConfig().controler().getLastIteration()
                    - congestionInfo.getScenario().getConfig().controler().getFirstIteration())) {

          log.info(
              "Strategies are switched off by global settings. Do not set back the strategy parameters to original values...");

        } else {

          log.info(
              "Strategy weight adjustment (set back to original value) in iteration "
                  + event.getIteration());

          for (GenericPlanStrategy<Plan, Person> strategy :
              event.getServices().getStrategyManager().getStrategies(null)) {

            String strategyName = strategy.toString();
            if (isInnovativeStrategy(strategyName)) {

              double originalValue = -1.0;
              for (StrategySettings setting :
                  event.getServices().getConfig().strategy().getStrategySettings()) {
                log.info("setting: " + setting.getStrategyName());
                log.info("strategyName: " + strategyName);

                if (strategyName.contains(setting.getStrategyName())) {
                  originalValue = setting.getWeight();
                }
              }

              if (originalValue == -1.0) {
                throw new RuntimeException("Aborting...");
              }

              log.warn(
                  "Setting weight for "
                      + strategyName
                      + " back to original value: "
                      + originalValue);
              event
                  .getServices()
                  .getStrategyManager()
                  .changeWeightOfStrategy(strategy, null, originalValue);
            }
          }
          this.nextEnableInnovativeStrategiesIteration +=
              congestionInfo.getDecongestionConfigGroup().getUPDATE_PRICE_INTERVAL();
        }
      }
    }
  }