Tabnine Logo
ScenarioController
Code IndexAdd Tabnine to your IDE (free)

How to use
ScenarioController
in
com.github.rinde.rinsim.scenario

Best Java code snippets using com.github.rinde.rinsim.scenario.ScenarioController (Showing top 20 results out of 315)

origin: com.github.rinde/rinsim-scenario

 covered, m.entrySet(), required, s.getProblemClass(),
 s.getProblemInstanceId());
return new ScenarioController(sim, clockController, s,
 ImmutableMap.copyOf(m), getNumberOfTicks());
origin: com.github.rinde/rinsim-scenario

/**
 * Dispatch all setup events (the ones that define initial settings). For
 * example, a vehicle that is added during setup (at time < 0) will receive
 * its first tick at time 0. If the vehicle is added at the beginning of the
 * simulation (time 0) the first tick it will receive will be the second
 * (globally) tick.
 */
protected void dispatchSetupEvents() {
 TimedEvent e = null;
 while ((e = scenarioQueue.peek()) != null && e.getTime() < 0) {
  scenarioQueue.poll();
  dispatch(e);
 }
}
origin: rinde/RinSim

@Override
public void tick(TimeLapse timeLapse) {
 if (endOfScenario) {
  return;
 }
 if (ticks == 0) {
  stopClock(timeLapse);
 }
 if (LOGGER.isDebugEnabled() && ticks >= 0) {
  LOGGER.debug("ticks to end: " + ticks);
 }
 if (ticks > 0) {
  ticks--;
 }
 dispatchEvents(timeLapse);
 if (ticks == 0 && status == EventType.SCENARIO_FINISHED) {
  stopClock(timeLapse);
  endOfScenario = true;
 }
}
origin: rinde/RinSim

/**
 * Tests that a not handled event results in a {@link IllegalStateException}.
 */
@Test
public void testEventNotHandled() {
 final ScenarioController.Builder b = ScenarioController.builder(scenario)
  .withNumberOfTicks(3);
 boolean fail = false;
 try {
  b.build(dependencyProvider);
 } catch (final IllegalStateException e) {
  assertThat(e.getMessage()).containsMatch("No handler found for event");
  fail = true;
 }
 assertThat(fail).isTrue();
}
origin: rinde/RinSim

 .setTimeUnit(SI.SECOND)
 .addModel(
  ScenarioController.builder(scenario)
   .withEventHandler(EventA.class, (NopHandler<EventA>) handler)
   .withEventHandler(EventB.class, (NopHandler<EventB>) handler)
sc.getEventAPI().addListener(leh);
assertThat(sc.isScenarioFinished()).isFalse();
sim.start();
 .inOrder();
assertThat(sc.isScenarioFinished()).isTrue();
sim.stop();
final long before = sc.clock.getCurrentTime();
final TimeLapse emptyTime = TimeLapseFactory.create(0, 1);
emptyTime.consumeAll();
sc.tick(emptyTime);
origin: rinde/RinSim

 .setTimeUnit(SI.SECOND)
 .addModel(
  ScenarioController.builder(scenario)
   .withNumberOfTicks(-1)
   .withEventHandler(EventA.class, (NopHandler<EventA>) handler)
controller.getEventAPI().addListener(new Listener() {
 @Override
 public void handleEvent(Event e) {
sim.start();
assertThat(handler.getEvents()).hasSize(scenario.getEvents().size());
assertThat(controller.isScenarioFinished()).isTrue();
origin: rinde/RinSim

 .setTimeUnit(SI.SECOND)
 .addModel(
  ScenarioController.builder(scenario)
   .withEventHandler(EventA.class, aHandler)
   .withEventHandler(EventB.class, bHandler)
controller.getEventAPI().addListener(leh);
origin: com.github.rinde/rinsim-pdptw

StatsTracker(ScenarioController scenContr, Clock c, RoadModel rm,
  PDPModel pm) {
 clock = c;
 roadModel = rm;
 eventDispatcher = new EventDispatcher(StatsProvider.EventTypes.values());
 theListener = new TheListener();
 scenContr.getEventAPI().addListener(theListener, SCENARIO_STARTED,
  SCENARIO_FINISHED, SCENARIO_EVENT);
 roadModel.getEventAPI().addListener(theListener, MOVE);
 clock.getEventAPI().addListener(theListener, STARTED, STOPPED);
 pm.getEventAPI()
  .addListener(theListener, START_PICKUP, END_PICKUP, START_DELIVERY,
   END_DELIVERY, NEW_PARCEL, NEW_VEHICLE);
}
origin: com.github.rinde/rinsim-scenario

 @Override
 public void handleEvent(Event e) {
  if (clock.getCurrentTime() == 0) {
   dispatchSetupEvents();
  }
  if (sc.endOfScenario) {
   clock.stop();
  }
 }
}, Clock.ClockEventType.STARTED);
origin: rinde/RinSim

/**
 * Tests that handling an interface is rejected.
 */
@Test
public void testHandleInterface() {
 boolean fail = false;
 try {
  ScenarioController.builder(scenario)
   .withEventHandler(TimedEvent.class, new NopHandler<>()).toString();
 } catch (final IllegalArgumentException e) {
  fail = true;
  assertThat(e.getMessage()).containsMatch("Must handle a concrete class");
 }
 assertThat(fail).isTrue();
}
origin: rinde/RinSim

 .setTimeUnit(SI.SECOND)
 .addModel(
  ScenarioController.builder(s)
   .withNumberOfTicks(1)
   .withEventHandler(EventA.class, (NopHandler<EventA>) handler)
final ScenarioController sc = sim.getModelProvider().getModel(
 ScenarioController.class);
sc.getEventAPI().addListener(leh);
sim.start();
origin: rinde/RinSim

StatsTracker(ScenarioController scenContr, Clock c, RoadModel rm,
  PDPModel pm) {
 clock = c;
 roadModel = rm;
 eventDispatcher = new EventDispatcher(StatsProvider.EventTypes.values());
 theListener = new TheListener();
 scenContr.getEventAPI().addListener(theListener, SCENARIO_STARTED,
  SCENARIO_FINISHED, SCENARIO_EVENT);
 roadModel.getEventAPI().addListener(theListener, MOVE);
 clock.getEventAPI().addListener(theListener, STARTED, STOPPED);
 pm.getEventAPI()
  .addListener(theListener, START_PICKUP, END_PICKUP, START_DELIVERY,
   END_DELIVERY, NEW_PARCEL, NEW_VEHICLE);
}
origin: rinde/RinSim

 @Override
 public void handleEvent(Event e) {
  if (clock.getCurrentTime() == 0) {
   dispatchSetupEvents();
  }
  if (sc.endOfScenario) {
   clock.stop();
  }
 }
}, Clock.ClockEventType.STARTED);
origin: rinde/RinSim

ScenarioController.builder(
 scenario)
 .withIgnoreRedundantHandlers(true)
origin: com.github.rinde/rinsim-scenario

@Override
public void tick(TimeLapse timeLapse) {
 if (endOfScenario) {
  return;
 }
 if (ticks == 0) {
  stopClock(timeLapse);
 }
 if (LOGGER.isDebugEnabled() && ticks >= 0) {
  LOGGER.debug("ticks to end: " + ticks);
 }
 if (ticks > 0) {
  ticks--;
 }
 dispatchEvents(timeLapse);
 if (ticks == 0 && status == EventType.SCENARIO_FINISHED) {
  stopClock(timeLapse);
  endOfScenario = true;
 }
}
origin: rinde/RinSim

/**
 * Dispatch all setup events (the ones that define initial settings). For
 * example, a vehicle that is added during setup (at time &lt; 0) will receive
 * its first tick at time 0. If the vehicle is added at the beginning of the
 * simulation (time 0) the first tick it will receive will be the second
 * (globally) tick.
 */
protected void dispatchSetupEvents() {
 TimedEvent e = null;
 while ((e = scenarioQueue.peek()) != null && e.getTime() < 0) {
  scenarioQueue.poll();
  dispatch(e);
 }
}
origin: rinde/RinSim

 covered, m.entrySet(), required, s.getProblemClass(),
 s.getProblemInstanceId());
return new ScenarioController(sim, clockController, s,
 ImmutableMap.copyOf(m), getNumberOfTicks());
origin: com.github.rinde/rinsim-experiment

ScenarioController.builder(
 scenario)
 .withIgnoreRedundantHandlers(true)
origin: rinde/RinSim

private void dispatchEvents(TimeLapse timeLapse) {
 TimedEvent e = null;
 while ((e = scenarioQueue.peek()) != null
  && e.getTime() <= timeLapse.getTime()) {
  scenarioQueue.poll();
  if (status == null) {
   LOGGER.info("scenario started at virtual time:" + timeLapse.getTime());
   status = EventType.SCENARIO_STARTED;
   disp.dispatchEvent(new Event(status, this));
  }
  dispatch(e);
 }
 if ((e = scenarioQueue.peek()) != null
  && e.getTime() <= timeLapse.getTime() + timeLapse.getTickLength()
  && clock instanceof RealtimeClockController) {
  LOGGER.trace("Found an event in next tick, switch to RT");
  ((RealtimeClockController) clock).switchToRealTime();
 }
 if (e == null && status != EventType.SCENARIO_FINISHED) {
  status = EventType.SCENARIO_FINISHED;
  disp.dispatchEvent(new Event(status, this));
 }
}
origin: com.github.rinde/rinsim-example

.addModel(
 ScenarioController
  .builder(scenario)
  .withEventHandler(AddParcelEvent.class,
   AddParcelEvent.defaultHandler())
com.github.rinde.rinsim.scenarioScenarioController

Javadoc

A scenario controller represents a single simulation run using a Scenario. The scenario controller makes sure that all events in the scenario are dispatched at their respective time and it checks whether they are handled.

Most used methods

  • builder
    Creates a Builder for ScenarioController.
  • getEventAPI
    Provides access to the Event API, allows adding and removing Listeners that are notified when Scenar
  • <init>
  • dispatch
  • dispatchEvents
  • dispatchSetupEvents
    Dispatch all setup events (the ones that define initial settings). For example, a vehicle that is ad
  • isScenarioFinished
  • stopClock
  • tick

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • startActivity (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now