static String toJson(FabriRechtScenario scenario) { return ScenarioIO.write(scenario); }
/** * Write the scenario to disk in JSON format. * @param scenario The scenario to write. * @param writer The writer to use. * @throws IOException When writing fails. */ public static void toJson(FabriRechtScenario scenario, Writer writer) throws IOException { final String s = ScenarioIO.write(scenario); writer.append(s); writer.close(); }
/** * Writes the specified {@link Scenario} to disk in the JSON format. * @param s The scenario. * @param to The file to write to. * @throws IOException In case anything went wrong during writing the * scenario. */ public static void write(Scenario s, Path to) throws IOException { Files.write(to, Splitter.on(System.lineSeparator()).split(write(s)), Charsets.UTF_8); }
/** * Writes the specified {@link Scenario} to disk in the JSON format. * @param s The scenario. * @param to The file to write to. * @throws IOException In case anything went wrong during writing the * scenario. */ public static void write(Scenario s, Path to) throws IOException { Files.write(to, Splitter.on(System.lineSeparator()).split(write(s)), Charsets.UTF_8); }
/** * Tests whether the specified scenario can be correctly written to disk, it * compares the equality of the specified object with a parsed object and it * compares the equality of the serialized string. * @param input The scenario to test with IO. */ public static void assertScenarioIO(Scenario input) { final String serialized = ScenarioIO.write(input); final Scenario parsed = ScenarioIO.read(serialized); final String serializedAgain = ScenarioIO.write(parsed); System.out.println(serialized); assertThat(input).isEqualTo(parsed); assertThat(serialized).isEqualTo(serializedAgain); }
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)); } }
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)); } }
/** * Tests {@link ScenarioIO#readerAdapter(com.google.common.base.Function)}. * @throws IOException When IO fails. */ @Test public void testReaderAdapter() throws IOException { final Scenario s = Scenario.builder() .addModel(TimeModel.builder().withTickLength(7L)) .build(); final Path tmpDir = Files.createTempDirectory("rinsim-scenario-io-test"); final Path file = Paths.get(tmpDir.toString(), "test.scen"); ScenarioIO.write(s, file); final Scenario out = ScenarioIO.reader().apply(file); final Scenario convertedOut = verifyNotNull(ScenarioIO.readerAdapter(ScenarioConverters.toRealtime()) .apply(file)); assertThat(s).isEqualTo(out); assertThat(s).isNotEqualTo(convertedOut); assertThat(convertedOut.getModelBuilders()) .contains(TimeModel.builder() .withRealTime() .withStartInClockMode(ClockMode.SIMULATED) .withTickLength(7L)); Files.delete(file); Files.delete(tmpDir); }
/** * Tests detection and correct error message. * @throws IOException If something goes wrong with the filesystem. */ @Test public void testGraphRmbDirectIO() throws IOException { final Graph<LengthData> g = new TableGraph<>(); g.addConnection(new Point(0, 0), new Point(1, 0)); g.addConnection(new Point(1, 1), new Point(1, 0)); final Scenario s = Scenario.builder() .addModel(TimeModel.builder().withTickLength(7L)) .addModel(RoadModelBuilders.staticGraph(Suppliers.ofInstance(g))) .build(); boolean fail = false; try { ScenarioIO.write(s); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()) .isEqualTo("A graph cannot be serialized embedded in a scenario."); } assertThat(fail).isTrue(); } }
.build(); final String serialized = ScenarioIO.write(s); assertThat(serialized).isEqualTo(ser);
final String generatedJson = ScenarioIO.write(s);
scenario); final String output = ScenarioIO.write(scenario); final Scenario converted = ScenarioIO.read(output);