/** * Copies properties of the specified scenario into this builder. * @param scenario The scenario to copy the properties from. * @return This, as per the builder pattern. */ protected T copyProperties(Scenario scenario) { timeWindow = scenario.getTimeWindow(); stopCondition = scenario.getStopCondition(); return self(); }
static Builder create(Scenario scen) { final int ticks = scen.getTimeWindow().end() == Long.MAX_VALUE ? -1 : (int) (scen.getTimeWindow().end() - scen.getTimeWindow().begin()); return create( scen, ImmutableMap.<Class<? extends TimedEvent>, TimedEventHandler<?>>of(), ticks, StopModelBuilder.create(scen.getStopCondition()), false); }
static Builder create(Scenario scen) { final int ticks = scen.getTimeWindow().end() == Long.MAX_VALUE ? -1 : (int) (scen.getTimeWindow().end() - scen.getTimeWindow().begin()); return create( scen, ImmutableMap.<Class<? extends TimedEvent>, TimedEventHandler<?>>of(), ticks, StopModelBuilder.create(scen.getStopCondition()), false); }
/** * Copies properties of the specified scenario into this builder. * @param scenario The scenario to copy the properties from. * @return This, as per the builder pattern. */ protected T copyProperties(Scenario scenario) { timeWindow = scenario.getTimeWindow(); stopCondition = scenario.getStopCondition(); return self(); }
/** * Measures the degree of dynamism of the specified scenario. * @param s The scenario to measure. * @return A double in range [0,1]. */ public static double measureDynamism(Scenario s) { return measureDynamism(s, s.getTimeWindow().end()); }
@Override public String collectResults(Simulator sim, SimArgs args) { // Read state of simulator, check how many vehicles exist in road model: final Set<Vehicle> vehicles = sim.getModelProvider() .getModel(RoadModel.class).getObjectsOfType(Vehicle.class); // Construct a result string based on the simulator state, of course, in // actual code the result should not be a string but a value object // containing the values of interest. final StringBuilder sb = new StringBuilder(); if (vehicles.isEmpty()) { sb.append("No vehicles were added"); } else { sb.append(vehicles.size()).append(" vehicles were added"); } if (sim.getCurrentTime() >= args.getScenario().getTimeWindow().end()) { sb.append(", simulation has completed."); } else { sb.append(", simulation was stopped prematurely."); } return sb.toString(); }
@Override public String collectResults(Simulator sim, SimArgs args) { // Read state of simulator, check how many vehicles exist in road model: final Set<Vehicle> vehicles = sim.getModelProvider() .getModel(RoadModel.class).getObjectsOfType(Vehicle.class); // Construct a result string based on the simulator state, of course, in // actual code the result should not be a string but a value object // containing the values of interest. final StringBuilder sb = new StringBuilder(); if (vehicles.isEmpty()) { sb.append("No vehicles were added"); } else { sb.append(vehicles.size()).append(" vehicles were added"); } if (sim.getCurrentTime() >= args.getScenario().getTimeWindow().end()) { sb.append(", simulation has completed."); } else { sb.append(", simulation was stopped prematurely."); } return sb.toString(); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Scenario) { Scenario that = (Scenario) o; return (this.events.equals(that.getEvents())) && (this.modelBuilders.equals(that.getModelBuilders())) && (this.timeWindow.equals(that.getTimeWindow())) && (this.stopCondition.equals(that.getStopCondition())) && (this.problemClass.equals(that.getProblemClass())) && (this.problemInstanceId.equals(that.getProblemInstanceId())); } return false; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Scenario) { Scenario that = (Scenario) o; return (this.events.equals(that.getEvents())) && (this.modelBuilders.equals(that.getModelBuilders())) && (this.timeWindow.equals(that.getTimeWindow())) && (this.stopCondition.equals(that.getStopCondition())) && (this.problemClass.equals(that.getProblemClass())) && (this.problemInstanceId.equals(that.getProblemInstanceId())); } return false; }
/** * Test the default settings of a scenario. */ @Test public void testDefaults() { final Scenario.Builder builder = Scenario .builder(Scenario.DEFAULT_PROBLEM_CLASS); assertThat(builder.getTimeWindow()) .isEqualTo(TimeWindow.create(0, 8 * 60 * 60 * 1000)); assertThat(builder.getStopCondition()) .isEqualTo(StopConditions.alwaysFalse()); final Scenario scenario = builder.build(); assertTrue(scenario.getModelBuilders().isEmpty()); assertSame(Scenario.DEFAULT_PROBLEM_CLASS, scenario.getProblemClass()); assertEquals("", scenario.getProblemInstanceId()); assertThat(scenario.getStopCondition()).isEqualTo( StopConditions.alwaysFalse()); assertEquals(TimeWindow.create(0, 8 * 60 * 60 * 1000), scenario.getTimeWindow()); }
assertEquals(TimeWindow.create(0L, 7L), scenario.getTimeWindow());