@Inject TerminateAtFixedIterationNumber(ControlerConfigGroup controlerConfigGroup) { this.lastIteration = controlerConfigGroup.getLastIteration(); }
private void dumpOutputEvents() { try { File toFile = new File( controlerIO.getOutputFilename(Controler.OUTPUT_PREFIX + Controler.FILENAME_EVENTS_XML)); File fromFile = new File(controlerIO.getIterationFilename(controlerConfigGroup.getLastIteration(), Controler.FILENAME_EVENTS_XML)); try { Files.copy(fromFile.toPath(), toFile.toPath(),StandardCopyOption.REPLACE_EXISTING,StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { throw new UncheckedIOException(e); } } catch ( Exception ee ) { Logger.getLogger(this.getClass()).error("writing output events did not work; probably parameters were such that no events were " + "generated in the final iteration" ); } }
@Override public void notifyShutdown(ShutdownEvent event) { // call shutdown for all remaining gexf for (SimpleGexfPStat gexf : this.lineId2GexfPStat.values()) { gexf.notifyShutdown(event.getServices().getConfig().controler().getLastIteration()); } log.info("terminated the last " + this.lineId2GexfPStat.values().size() + " gexf handlers..."); } }
private void dumpExperiencedPlans() { if ( config.planCalcScore().isWriteExperiencedPlans() ) { try { File toFile = new File( controlerIO.getOutputFilename(Controler.OUTPUT_PREFIX + Controler.FILENAME_EXPERIENCED_PLANS)); File fromFile = new File(controlerIO.getIterationFilename(controlerConfigGroup.getLastIteration(), Controler.FILENAME_EXPERIENCED_PLANS)); try { Files.copy(fromFile.toPath(), toFile.toPath(),StandardCopyOption.REPLACE_EXISTING,StandardCopyOption.COPY_ATTRIBUTES); } catch (IOException e) { throw new UncheckedIOException(e); } } catch ( Exception ee ) { Logger.getLogger(this.getClass()).error("writing output experienced plans did not work; probably parameters were such that they " + "were not generated in the final iteration", ee); } } }
@Inject EventsHandlingImpl( final EventsManager eventsManager, final ControlerConfigGroup config, final OutputDirectoryHierarchy controlerIO) { this.eventsManager = eventsManager; this.writeEventsInterval = config.getWriteEventsInterval(); this.lastIteration = config.getLastIteration() ; this.eventsFileFormats = config.getEventsFileFormats(); this.controlerIO = controlerIO; this.writeMoreUntilIteration = config.getWriteEventsUntilIteration() ; }
@Override protected boolean continueIterations(int iteration) { return iteration <= config.controler().getLastIteration(); } }
public SlaveScoreStats(Config config) { firstIter = config.controler().getFirstIteration(); int size = config.controler().getLastIteration() - firstIter+1; this.history = new double[4][size]; }
TravelDistanceStats(ControlerConfigGroup controlerConfigGroup, GlobalConfigGroup globalConfigGroup, String filename, boolean createPNG) { this.controlerConfigGroup = controlerConfigGroup; this.globalConfigGroup = globalConfigGroup; this.fileName = filename; if (createPNG) { int iterations = controlerConfigGroup.getLastIteration() - controlerConfigGroup.getFirstIteration(); if (iterations > 5000) { iterations = 5000; // limit the history size } this.history = new double[iterations+1]; } if (filename.toLowerCase(Locale.ROOT).endsWith(".txt")) { this.out = IOUtils.getBufferedWriter(filename); } else { this.out = IOUtils.getBufferedWriter(filename + ".txt"); } try { this.out.write("ITERATION\tavg. EXECUTED\tavg. WORST\tavg. AVG\tavg. BEST\n"); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Inject NewScoreAssignerImpl(PlanCalcScoreConfigGroup planCalcScoreConfigGroup, ControlerConfigGroup controlerConfigGroup) { if (planCalcScoreConfigGroup.getFractionOfIterationsToStartScoreMSA()!=null ) { final int diff = controlerConfigGroup.getLastIteration() - controlerConfigGroup.getFirstIteration(); this.scoreMSAstartsAtIteration = (int) (diff * planCalcScoreConfigGroup.getFractionOfIterationsToStartScoreMSA() + controlerConfigGroup.getFirstIteration()); } learningRate = planCalcScoreConfigGroup.getLearningRate(); }
@Override public void notifyIterationEnds(IterationEndsEvent event) { if (event.getIteration() != scenario.getConfig().controler().getLastIteration()) return; try { delegate.writeSimulationResultsToTabSeparated(scenario.getConfig().controler().getOutputDirectory(),"output_"); } catch (IOException e) { log.error("Writing of traveldiaries failed."); e.printStackTrace(); } } }
private boolean determineIfQSimIter(int iteration) { if (iteration == scenario.getConfig().controler().getLastIteration() || iteration == scenario.getConfig().controler().getFirstIteration() ) { isQSimIteration = true; return isQSimIteration; } if (isQSimIteration && psimIterationCount == 0) { isQSimIteration = false; psimIterationCount++; return isQSimIteration; } if (psimIterationCount >= iterationsPerCycle - 1) { isQSimIteration = true; qsimIters.add(iteration); psimIterationCount = 0; return isQSimIteration; } if (isQSimIteration) { qsimIters.add(iteration); } else { psimIterationCount++; } return isQSimIteration; }
int maxIter = controler.getConfig().controler().getLastIteration(); int iterations = maxIter - this.minIteration; this.tripsHistory = new double[this.sortedModes.size() + 1][iterations + 1];
@Override public void notifyIterationStarts(IterationStartsEvent event) { if (event.getIteration() != scenario.getConfig().controler().getLastIteration()) return; delegate = new EventsToTravelDiaries(scenario); eventsManager.addHandler(delegate); }
@Override public void notifyStartup(final StartupEvent event) { if (fileName.toLowerCase(Locale.ROOT).endsWith(".txt")) { this.out = IOUtils.getBufferedWriter(fileName); } else { this.out = IOUtils.getBufferedWriter(fileName + ".txt"); } try { this.out.write("ITERATION\tavg. EXECUTED\tavg. WORST\tavg. AVG\tavg. BEST\n"); } catch (IOException e) { throw new UncheckedIOException(e); } this.minIteration = event.getServices().getConfig().controler().getFirstIteration(); int maxIter = event.getServices().getConfig().controler().getLastIteration(); int iterations = maxIter - this.minIteration; if (iterations > 5000) iterations = 5000; // limit the history size this.history = new double[4][iterations+1]; }
@Override public PlanAlgorithm getPlanAlgoInstance() { final CompositeStageActivityTypes blackList = new CompositeStageActivityTypes(); blackList.addActivityTypes( tripRouterFactory.get().getStageActivityTypes() ); blackList.addActivityTypes( JointActingTypes.JOINT_STAGE_ACTS ); final int iteration = getReplanningContext().getIteration(); final int firstIteration = config.controler().getFirstIteration(); final double nIters = config.controler().getLastIteration() - firstIteration; final double minTemp = 1; final double startMin = (2 / 3.) * nIters; final double progress = (iteration - firstIteration) / startMin; final double temp = minTemp + Math.max(1 - progress , 0) * (maxTemp - minTemp); log.debug( "temperature in iteration "+iteration+": "+temp ); final BlackListedTimeAllocationMutator algo = new BlackListedTimeAllocationMutator( blackList, config.timeAllocationMutator().getMutationRange() * temp, MatsimRandom.getLocalInstance() ); return algo; } }));
@Override public void notifyStartup(final StartupEvent event) { MatsimServices controler = event.getServices(); if(this.pConfig.getWriteStatsInterval() > 0){ log.info("enabled"); this.pStatsWriter = IOUtils.getBufferedWriter(controler.getControlerIO().getOutputFilename("pStats.txt")); try { this.pStatsWriter.write(PStatsOverviewDataContainer.getHeaderLine()); this.pStatsWriter.newLine(); } catch (IOException e) { throw new UncheckedIOException(e); } } else { this.pStatsWriter = null; } this.minIteration = controler.getConfig().controler().getFirstIteration(); int maxIter = controler.getConfig().controler().getLastIteration(); int iterations = maxIter - this.minIteration; if (iterations > 10000) iterations = 10000; // limit the history size this.history = new double[29][iterations+1]; this.statsContainer = new RecursiveStatsContainer(); this.statsApproxContainer = new RecursiveStatsApproxContainer(0.1, 10); }
setMaxPlansPerAgent(strategyConfigGroup.getMaxAgentPlanMemorySize()); int globalInnovationDisableAfter = (int) ((controlerConfigGroup.getLastIteration() - controlerConfigGroup.getFirstIteration())
private void initializeSlave(SlaveHandler slaveHandler, int i, boolean initialRoutingOnSlaves) throws IOException { slaveHandler.sendNumber(i); slaveHandler.sendNumber(slaveIterationsPerMasterIteration); slaveHandler.sendNumber(slaveNumberOfPlans); slaveHandler.sendDouble(slaveMutationRate); slaveHandler.sendNumber(config.controler().getLastIteration() * slaveIterationsPerMasterIteration); slaveHandler.sendBoolean(initialRoutingOnSlaves); slaveHandler.sendBoolean(QuickReplanning); slaveHandler.sendBoolean(fullTransitPerformanceTransmission); slaveHandler.sendBoolean(TrackGenome); slaveHandler.sendBoolean(intelligentRouters); slaveHandler.sendBoolean(false); //for diversity generation; slaveHandler.readMemoryStats(); slaveHandler.readNumberOfThreadsOnSlave(); }
public static void main(String[] args) throws IOException { Config config = ConfigUtils.loadConfig(configFile, new NoiseConfigGroup()); Scenario scenario = ScenarioUtils.loadScenario(config); Controler controler = new Controler(scenario); controler.addOverridingModule(new NoiseModule(scenario)); controler.getConfig().controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); controler.run(); // optionally process the output data String workingDirectory = controler.getConfig().controler().getOutputDirectory() + "/ITERS/it." + controler.getConfig().controler().getLastIteration() + "/immissions/"; String receiverPointsFile = controler.getConfig().controler().getOutputDirectory() + "/receiverPoints/receiverPoints.csv"; NoiseConfigGroup noiseParameters = ConfigUtils.addOrGetModule(config, NoiseConfigGroup.class ) ; ProcessNoiseImmissions processNoiseImmissions = new ProcessNoiseImmissions(workingDirectory, receiverPointsFile, noiseParameters.getReceiverPointGap()); processNoiseImmissions.run(); }
@Override public void notifyAfterMobsim(AfterMobsimEvent event) { if (event.getIteration() % this.congestionInfo.getDecongestionConfigGroup().getWriteOutputIteration() == 0. || event.getIteration() % this.congestionInfo.getDecongestionConfigGroup().getUpdatePriceInterval() == 0.) { computeDelays(event); } if (event.getIteration() == this.congestionInfo.getScenario().getConfig().controler().getFirstIteration()) { // skip first iteration } else if (event.getIteration() % this.congestionInfo.getDecongestionConfigGroup().getUpdatePriceInterval() == 0.) { int totalNumberOfIterations = this.congestionInfo.getScenario().getConfig().controler().getLastIteration() - this.congestionInfo.getScenario().getConfig().controler().getFirstIteration(); int iterationCounter = event.getIteration() - this.congestionInfo.getScenario().getConfig().controler().getFirstIteration(); if (iterationCounter < this.congestionInfo.getDecongestionConfigGroup().getFractionOfIterationsToEndPriceAdjustment() * totalNumberOfIterations && iterationCounter > this.congestionInfo.getDecongestionConfigGroup().getFractionOfIterationsToStartPriceAdjustment() * totalNumberOfIterations) { if (tollComputation != null) { log.info("+++ Iteration " + event.getIteration() + ". Update tolls per link and time bin."); tollComputation.updateTolls(); } } } if (event.getIteration() % this.congestionInfo.getDecongestionConfigGroup().getWriteOutputIteration() == 0.) { CongestionInfoWriter.writeDelays(congestionInfo, event.getIteration(), this.outputDirectory + "ITERS/it." + event.getIteration() + "/", this.congestionInfo.getScenario().getConfig().controler().getRunId()); CongestionInfoWriter.writeTolls(congestionInfo, event.getIteration(), this.outputDirectory + "ITERS/it." + event.getIteration() + "/", this.congestionInfo.getScenario().getConfig().controler().getRunId()); } }