/** * Parses the command line arguments. Performs the experiment using * {@link #perform()} if the arguments allow it. * @param out The print stream to write the feedback from the cli system to. * @param args The arguments to parse. * @return {@link Optional} containing {@link ExperimentResults} if the * experiment was performed, {@link Optional#absent()} otherwise. */ public Optional<ExperimentResults> perform(PrintStream out, String... args) { LOGGER.trace("perform {}", Arrays.toString(args)); final Optional<String> error = ExperimentCli.safeExecute(this, args); if (error.isPresent()) { out.println(error.get()); return Optional.absent(); } return Optional.of(perform()); }
/** * Parses the command line arguments. Performs the experiment using * {@link #perform()} if the arguments allow it. * @param out The print stream to write the feedback from the cli system to. * @param args The arguments to parse. * @return {@link Optional} containing {@link ExperimentResults} if the * experiment was performed, {@link Optional#absent()} otherwise. */ public Optional<ExperimentResults> perform(PrintStream out, String... args) { LOGGER.trace("perform {}", Arrays.toString(args)); final Optional<String> error = ExperimentCli.safeExecute(this, args); if (error.isPresent()) { out.println(error.get()); return Optional.absent(); } return Optional.of(perform()); }
/** * Checks determinism of two subsequent identical JPPF experiments. */ @Test public void determinismJppfVsJppf() { final List<Integer> ints = asList(1, 2, 5, 10); final List<ExperimentResults> allResults = newArrayList(); final Experiment.Builder experimentBuilder = Experiment.builder() .computeDistributed() .addScenario(scenario) .withRandomSeed(123) .repeat(10) .addConfiguration(ExperimentTestUtil.testConfig("A")); for (final int i : ints) { allResults.add( experimentBuilder.numBatches(i) .perform()); } assertEquals(4, allResults.size()); for (int i = 0; i < allResults.size() - 1; i++) { assertEquals(allResults.get(i), allResults.get(i + 1)); } }
.withRandomSeed(123); final ExperimentResults er = builder.perform(); final List<SimulationResult> results = new ArrayList<>(er.getResults());
.usePostProcessor(PostProcessors .statisticsPostProcessor(Gendreau06ObjectiveFunction.instance())) .perform();
static StatisticsDTO simulate(Scenario scenario) { final ExperimentResults results = Experiment.builder() .addScenario(scenario) .addConfiguration(Central.solverConfiguration( StochasticSuppliers.constant(TestSolvers.lazyInsertion()))) .withThreads(1) .usePostProcessor(PostProcessors.statisticsPostProcessor(OBJ_FUNC)) .showGui(View.builder() .withAutoPlay() // .withAutoClose() .withSpeedUp(4) // .withFullScreen() .withTitleAppendix("AAMAS 2016 Experiment") .with(RoadUserRenderer.builder() .withToStringLabel()) .with(PDPModelRenderer.builder()) .with(RouteRenderer.builder()) .with(PlaneRoadModelRenderer.builder()) .with(TimeLinePanel.builder()) .withResolution(1280, 1024)) .showGui(false) .perform(); final SimulationResult res = results.getResults().iterator().next(); final StatisticsDTO stats = (StatisticsDTO) res.getResultObject(); return stats; }
/** * Tests whether the SolverConfigurator works. */ @Test public void testConfigurator() { final Gendreau06Scenario scenario = Gendreau06Parser.parse( new File(ScenarioPaths.GENDREAU)); final StochasticSupplier<Solver> s = new StochasticSupplier<Solver>() { @Override public Solver get(long seed) { return SolverValidator.wrap(new MultiVehicleSolverAdapter( ArraysSolverValidator.wrap(new RandomMVArraysSolver( new MersenneTwister(seed))), SI.MILLI(SI.SECOND))); } }; final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .addConfiguration(Central.solverConfiguration(s)) .withRandomSeed(123); final ExperimentResults res1 = builder.perform(); final ExperimentResults res2 = builder.perform(); assertEquals(res1.getResults(), res2.getResults()); }
/** * Checks determinism of a local experiment and a JPPF experiment, both with * identical settings. Using a Gendreau scenario. */ @SuppressWarnings("unchecked") @Test public void determinismLocalVsJppf() { final Experiment.Builder experimentBuilder = Experiment.builder() .computeDistributed() .addScenario(scenario) .withRandomSeed(123) .repeat(1) .usePostProcessor(ExperimentTestUtil.testPostProcessor()) .addConfiguration(ExperimentTestUtil.testConfig("A")); final ExperimentResults results3 = experimentBuilder.perform(); experimentBuilder.computeLocal(); final ExperimentResults results4 = experimentBuilder.perform(); assertEquals(results3, results4); assertThat(results3.getResults().asList().get(0).getResultObject()) .isInstanceOf(ImmutableList.class); assertThat( (List<Point>) results3.getResults().asList().get(0).getResultObject()) .hasSize(10); }
/** * Test correct handling of failure during simulation. */ @Test public void testDefaultPostProcessorFailure() { final Scenario scenario = ScenarioTestUtil.createRandomScenario(123L, StatsTracker.builder(), FailureModel.builder()); final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .addConfiguration(ExperimentTestUtil.testConfig("test")) .withThreads(1) .repeat(3) .withRandomSeed(123); boolean fail = false; try { builder.perform(); } catch (final AbortExperimentException e) { assertThat(e.getCause().getMessage()).contains("FailureModel"); fail = true; } assertThat(fail).isTrue(); }
@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()); }
/** * Tests default processor. */ @Test public void testDefaultPostProcessor() { final Scenario scenario = ScenarioTestUtil.createRandomScenario(123L, StatsTracker.builder()); final Experiment.Builder builder = Experiment .builder() .addScenario(scenario) .addConfiguration(ExperimentTestUtil.testConfig("test")) .withRandomSeed(123); final ExperimentResults er = builder.perform(); assertThat(er.getResults().asList().get(0).getResultObject()) .isInstanceOf(String.class); assertThat(er.getResults().asList().get(0).getResultObject()) .isEqualTo("simulation duration: 10801000"); }
@Test public void testRetryPostProcessor() { final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .computeDistributed() .addConfiguration(ExperimentTestUtil.testConfig("test")) .usePostProcessor(ExperimentTestUtil.retryOncePostProcessor()) .repeat(3) .withRandomSeed(123); final ExperimentResults er = builder.perform(); for (int i = 0; i < er.getResults().size(); i++) { assertThat(er.getResults().asList().get(0).getResultObject()) .isEqualTo("SUCCESS"); } }
/** * Test of {@link RandomSolver} on a scenario using the {@link Solver} * interface. */ @Test public void testRandomSolver() { Experiment.builder() .addScenario(scenario) .addConfiguration( Central.solverConfiguration(SolverValidator.wrap(RandomSolver .supplier()))) .repeat(3) .perform(); } }
/** * Tests a post processor that returns objects that does not implement * {@link Serializable}. */ @Test(expected = IllegalArgumentException.class) public void testFaultyPostProcessor() { Experiment.builder() .computeDistributed() .addScenario(scenario) .withRandomSeed(123) .repeat(1) .usePostProcessor(new TestFaultyPostProcessor()) .addConfiguration(ExperimentTestUtil.testConfig("A")) .perform(); }
/** * Test of {@link RandomMVArraysSolver} using the * {@link com.github.rinde.rinsim.central.arrays.MultiVehicleArraysSolver} * interface. */ @Test public void test() { Experiment.builder() .addScenario(scenario) .addConfiguration( Central.solverConfiguration(RandomMVArraysSolver.solverSupplier())) .repeat(!offline && allowDiversion ? 2 : 1) .perform(); }
@Test public void composite() { final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .computeDistributed() .setCompositeTaskSize(2) .addConfiguration(ExperimentTestUtil.testConfig("test")) .usePostProcessor(ExperimentTestUtil.testPostProcessor()) .repeat(3) .withRandomSeed(123); final ExperimentResults er = builder.perform(); assertThat(er.getResults()).hasSize(3); }
@Test public void testRetryPostProcessor() { final Scenario scenario = ScenarioTestUtil.createRandomScenario(123L, StatsTracker.builder()); final Experiment.Builder builder = Experiment.builder() .addScenario(scenario) .addConfiguration(ExperimentTestUtil.testConfig("test")) .withThreads(1) .usePostProcessor(ExperimentTestUtil.retryOncePostProcessor()) .repeat(3) .withRandomSeed(123); builder.perform(); }
/** * Tests a dry run of an experiment. */ @Test public void dryRun() { builder.perform(System.out, "-dr", "v"); }
/** * Tests help. */ @Test public void testHelp() { testSuccess("-h"); builder.perform(System.out, "-h"); }