@Override public String toString() { return new StringBuilder() .append("SimArgs{problemClass=") .append(getScenario().getProblemClass().toString()) .append(",instancedId=") .append(getScenario().getProblemInstanceId()) .append(",masConfig=") .append(getMasConfig().getName()) .append(",randomSeed=") .append(getRandomSeed()) .append(",repetition=") .append(getRepetition()) .append(",postProcessor=") .append(getPostProcessor()) .append("}") .toString(); }
@Override public String toString() { return new StringBuilder() .append("SimArgs{problemClass=") .append(getScenario().getProblemClass().toString()) .append(",instancedId=") .append(getScenario().getProblemInstanceId()) .append(",masConfig=") .append(getMasConfig().getName()) .append(",randomSeed=") .append(getRandomSeed()) .append(",repetition=") .append(getRepetition()) .append(",postProcessor=") .append(getPostProcessor()) .append("}") .toString(); }
@Nullable @Override public Long apply(@Nullable SimArgs input) { return verifyNotNull(input).getRandomSeed(); } }
sr.getSimArgs().getRandomSeed() + " " + sr.getResultObject());
sr.getSimArgs().getRandomSeed() + " " + sr.getResultObject());
static Object perform(SimArgs args) { final Simulator sim = Experiment.init(args.getScenario(), args.getMasConfig(), args.getRandomSeed(), args.isShowGui(), args.getUiCreator()); try { sim.start(); final Object resultObject = args.getPostProcessor().collectResults(sim, args); checkNotNull(resultObject, "PostProcessor may not return null."); return resultObject; } catch (final Exception e) { final FailureStrategy strategy = args.getPostProcessor().handleFailure(e, sim, args); checkNotNull(strategy, "An exception (%s) occured in the simulation but the PostProcessor %s " + "failed to handle the failure.", e.toString(), args.getPostProcessor()); if (strategy == FailureStrategy.INCLUDE) { return args.getPostProcessor().collectResults(sim, args); } else if (strategy == FailureStrategy.ABORT_EXPERIMENT_RUN) { throw new AbortExperimentException("Failed: " + args, e); } return strategy; } }
static Object perform(SimArgs args) { final Simulator sim = Experiment.init(args.getScenario(), args.getMasConfig(), args.getRandomSeed(), args.isShowGui(), args.getUiCreator()); try { sim.start(); final Object resultObject = args.getPostProcessor().collectResults(sim, args); checkNotNull(resultObject, "PostProcessor may not return null."); return resultObject; } catch (final Exception e) { final FailureStrategy strategy = args.getPostProcessor().handleFailure(e, sim, args); checkNotNull(strategy, "An exception (%s) occured in the simulation but the PostProcessor %s " + "failed to handle the failure.", e.toString(), args.getPostProcessor()); if (strategy == FailureStrategy.INCLUDE) { return args.getPostProcessor().collectResults(sim, args); } else if (strategy == FailureStrategy.ABORT_EXPERIMENT_RUN) { throw new AbortExperimentException("Failed: " + args, e); } return strategy; } }
static void constructTasks( Set<SimArgs> inputs, List<SimulationTask> tasks, IdMap<MASConfiguration> configMap, IdMap<ScenarioProvider> scenarioMap, IdMap<PostProcessor<?>> ppMap, Map<String, Scenario> scenariosMap) { for (final SimArgs args : inputs) { final String configId = configMap.storeAndGenerateId( args.getMasConfig()); final String scenId = scenarioMap.storeAndGenerateId( new ScenarioProvider(ScenarioIO.write(args.getScenario()), args.getScenario().getClass())); scenariosMap.put(scenId, args.getScenario()); final String postProcId = ppMap.storeAndGenerateId(args.getPostProcessor()); tasks.add(new SimulationTask(args.getRandomSeed(), args.getRepetition(), scenId, configId, postProcId)); } }
@Test public void testCustomPostProcessor() { TestUtil.testEnum(Experiment.Computers.class); final Scenario scenario = ScenarioTestUtil.createRandomScenario(123L, StatsTracker.builder()); final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .addConfiguration(ExperimentTestUtil.testConfig("test")) .usePostProcessor(ExperimentTestUtil.testPostProcessor()) .addResultListener(new CommandLineProgress(System.out)) .withRandomSeed(123); final ExperimentResults er = builder.perform(); assertEquals(123, er.getMasterSeed()); assertEquals(123, er.getResults().asList().get(0).getSimArgs().getRandomSeed()); @SuppressWarnings("unchecked") final List<Point> positions = (List<Point>) er.getResults().asList().get(0).getResultObject(); assertEquals(10, positions.size()); }
static void constructTasks( Set<SimArgs> inputs, List<SimulationTask> tasks, IdMap<MASConfiguration> configMap, IdMap<ScenarioProvider> scenarioMap, IdMap<PostProcessor<?>> ppMap, Map<String, Scenario> scenariosMap) { for (final SimArgs args : inputs) { final String configId = configMap.storeAndGenerateId( args.getMasConfig()); final String scenId = scenarioMap.storeAndGenerateId( new ScenarioProvider(ScenarioIO.write(args.getScenario()), args.getScenario().getClass())); scenariosMap.put(scenId, args.getScenario()); final String postProcId = ppMap.storeAndGenerateId(args.getPostProcessor()); tasks.add(new SimulationTask(args.getRandomSeed(), args.getRepetition(), scenId, configId, postProcId)); } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Experiment.SimArgs) { Experiment.SimArgs that = (Experiment.SimArgs) o; return (this.scenario.equals(that.getScenario())) && (this.masConfig.equals(that.getMasConfig())) && (this.randomSeed == that.getRandomSeed()) && (this.repetition == that.getRepetition()) && (this.showGui == that.isShowGui()) && (this.postProcessor.equals(that.getPostProcessor())) && (this.uiCreator.equals(that.getUiCreator())); } return false; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Experiment.SimArgs) { Experiment.SimArgs that = (Experiment.SimArgs) o; return (this.scenario.equals(that.getScenario())) && (this.masConfig.equals(that.getMasConfig())) && (this.randomSeed == that.getRandomSeed()) && (this.repetition == that.getRepetition()) && (this.showGui == that.isShowGui()) && (this.postProcessor.equals(that.getPostProcessor())) && (this.uiCreator.equals(that.getUiCreator())); } return false; }
/** * @return A very compact string representation. */ public String toShortString() { return new StringBuilder(getScenario().getProblemClass().getId()) .append(DASH) .append(getScenario().getProblemInstanceId()) .append(DASH) .append(getMasConfig().getName()) .append("-s") .append(getRandomSeed()) .append(DASH) .append("r") .append(getRepetition()) .toString(); }
/** * @return A very compact string representation. */ public String toShortString() { return new StringBuilder(getScenario().getProblemClass().getId()) .append(DASH) .append(getScenario().getProblemInstanceId()) .append(DASH) .append(getMasConfig().getName()) .append("-s") .append(getRandomSeed()) .append(DASH) .append("r") .append(getRepetition()) .toString(); }
static void assertSeedEquality(List<SimulationResult> results) { checkArgument(!results.isEmpty()); final long seed = results.get(0).getSimArgs().getRandomSeed(); for (final SimulationResult sr : results) { assertThat(sr.getSimArgs().getRandomSeed()).isEqualTo(seed); } }
@Nullable @Override public Long apply(@Nullable SimArgs input) { return verifyNotNull(input).getRandomSeed(); } }