Example #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) {
   List<NetworkChangeEvent> allchangeevents = new ArrayList<NetworkChangeEvent>();
   Iterator<GenericP0ControlHandler> hiter = handlers.iterator();
   while (hiter.hasNext()) {
     GenericP0ControlHandler handler = hiter.next();
     handler.setIteration(
         event.getIteration()); // To run without P0 call with 0, and comment out initialisation of
     // events in initialise function
     allchangeevents.addAll(handler.getChangeEvents());
     handler.initialise();
   }
   final List<NetworkChangeEvent> events = allchangeevents;
   NetworkUtils.setNetworkChangeEvents(network, events);
   allchangeevents.removeAll(allchangeevents);
 }
  @Override
  public void notifyIterationStarts(IterationStartsEvent event) {
    iteration = event.getIteration();

    logger.info("creating new emission internalization handler...");
    emissionInternalizationHandler =
        new EmissionResponsibilityInternalizationHandler(controler, emissionCostModule);
    logger.info("adding emission internalization module to emission events stream...");
    emissionModule.getEmissionEventsManager().addHandler(emissionInternalizationHandler);

    if (iteration == firstIt || iteration == lastIt) {
      emissionEventOutputFile =
          controler.getControlerIO().getIterationFilename(iteration, "emission.events.xml.gz");
      logger.info("creating new emission events writer...");
      emissionEventWriter = new EventWriterXML(emissionEventOutputFile);
      logger.info("adding emission events writer to emission events stream...");
      emissionModule.getEmissionEventsManager().addHandler(emissionEventWriter);
    }
  }
    @Override
    public void notifyIterationStarts(IterationStartsEvent event) {
      if (event.getIteration() == 0) {
        Controler controler = event.getControler();

        // initialize the social costs calculator
        SocialCostCalculatorV2 scc =
            new SocialCostCalculatorV2(
                controler.getScenario().getNetwork(),
                controler.getEvents(),
                controler.getLinkTravelTimes(),
                controler,
                blendFactor);

        controler.addControlerListener(scc);
        controler.getEvents().addHandler(scc);

        // initialize the social costs disutility calculator
        final SocialCostTravelDisutilityFactory factory =
            new SocialCostTravelDisutilityFactory(scc);
        controler.addOverridingModule(
            new AbstractModule() {
              @Override
              public void install() {
                bindCarTravelDisutilityFactory().toInstance(factory);
              }
            });

        // create a plot containing the mean travel times
        Set<String> transportModes = new HashSet<String>();
        transportModes.add(TransportMode.car);
        transportModes.add(TransportMode.pt);
        transportModes.add(TransportMode.walk);
        MeanTravelTimeCalculator mttc =
            new MeanTravelTimeCalculator(controler.getScenario(), transportModes);
        controler.addControlerListener(mttc);
        controler.getEvents().addHandler(mttc);
      }
    }
Example #5
0
 @Override
 public void notifyIterationStarts(IterationStartsEvent event) {
   int countsInterval = this.config.ptCounts().getPtCountsInterval();
   if (event.getIteration() % countsInterval == 0) {
     this.recordPtCounts = true;
     this.events.addHandler(this.ptLinkCountsEventHandler);
     this.ptLinkCountsEventHandler.reset(event.getIteration());
     this.events.addHandler(this.ptStationCountsEventHandler);
     this.ptStationCountsEventHandler.reset(event.getIteration());
   }
   countsInterval = this.config.counts().getWriteCountsInterval();
   if (event.getIteration() % countsInterval == 0) {
     this.recordStreetCounts = true;
     this.events.addHandler(this.streetLinkDailyCountsEventHandler);
     this.streetLinkDailyCountsEventHandler.reset(event.getIteration());
     this.events.addHandler(this.streetLinkHourlyCountsEventHandler);
     this.streetLinkHourlyCountsEventHandler.reset(event.getIteration());
   }
 }
 @Override
 public void notifyIterationStarts(IterationStartsEvent event) {
   this.iteration = event.getIteration();
 }
  @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();
        }
      }
    }
  }