@Override public ImmutableSet<ModelBuilder<?, ?>> getChildren() { return ImmutableSet.<ModelBuilder<?, ?>>of( RtSolverModel.builder().withThreadGrouping( getOptions().contains(Options.THREAD_GROUPING))); }
/** * Sets the threadpool size. In 'single mode' the default threadpool size is * determined by {@link #DEFAULT_NUM_THREADS_IN_SINGLE_MODE}. In 'multi * mode' the threadpool size is determined by * {@link Runtime#availableProcessors()}. * @param threads The number of threads, must be positive. * @return This, as per the builder pattern. */ @CheckReturnValue public Builder withThreadPoolSize(int threads) { checkArgument(threads > 0); return create(getMode(), threads, getThreadGrouping()); }
/** * Sets the thread grouping property. If thread grouping is enabled all * threads spawned by this model will be locked to the same CPU, if it is * disabled each thread will be locked to unique CPU (on a best effort * basis). * @param grouping Indicates whether grouping should be enabled. Default * value is <code>false</code>. * @return This, as per the builder pattern. */ @CheckReturnValue public Builder withThreadGrouping(boolean grouping) { return create(getMode(), getThreadPoolSize(), grouping); }
/** * Sets up a fake dependency provider and a working model instance. */ @Before public void setUp() { clock = spy((RealtimeClockController) TimeModel.builder() .withRealTime() .build(FakeDependencyProvider.empty())); doNothing().when(clock).switchToRealTime(); doNothing().when(clock).switchToSimulatedTime(); final RoadModelSnapshot planeSnapshot = RoadModelSnapshotTestUtil.createPlaneRoadModelSnapshot(new Point(0, 0), new Point(10, 10), SI.KILOMETER); final PDPRoadModel rm = mock(PDPRoadModel.class); when(rm.getSpeedUnit()).thenReturn(NonSI.KILOMETERS_PER_HOUR); when(rm.getDistanceUnit()).thenReturn(SI.KILOMETER); when(rm.getSnapshot()).thenReturn(planeSnapshot); dependencyProvider = FakeDependencyProvider.builder() .add(clock, RealtimeClockController.class) .add(rm, PDPRoadModel.class) .add(DefaultPDPModel.builder()) .build(); model = RtSolverModel.builder().build(dependencyProvider); ((TimeModel) clock).register(model); assertThat(model.mode).isEqualTo(Mode.UNKNOWN); TestUtil.testEnum(Mode.class); TestUtil.testEnum(RtSimSolver.EventType.class); }
/** * Sets up simple problem with two agents and two parcels. */ @Before public void setUp() { final List<TimedEvent> events = asList( AddParcelEvent.create( Parcel.builder(new Point(0, 0), new Point(3, 3)) .orderAnnounceTime(200) .pickupTimeWindow(TimeWindow.create(1000, 2000)) .buildDTO()), AddParcelEvent.create( Parcel.builder(new Point(0, 0), new Point(3, 3)) .orderAnnounceTime(999) .pickupTimeWindow(TimeWindow.create(60000, 80000)) .serviceDuration(180000L) .buildDTO()), TimeOutEvent.create(3000)); sim = RealtimeTestHelper.init(Handler.INSTANCE, events) .addModel(RtSolverModel.builder() .withThreadPoolSize(3) .withThreadGrouping(false)) .build(); }
@Before public void setUp() { sim = Simulator.builder() .addModel(TimeModel.builder() .withRealTime() .withTickLength(100L) .withTimeUnit(SI.MILLI(SI.SECOND))) .addModel(PDPRoadModel.builder(RoadModelBuilders.plane())) .addModel(DefaultPDPModel.builder()) .addModel(RtSolverModel.builder() .withSingleMode() .withThreadGrouping(useThreadGrouping)) .build(); model = sim.getModelProvider().getModel(RtSolverModel.class); rtClock = sim.getModelProvider().getModel(TimeModel.class) .get(RealtimeClockController.class); sim.register(new Depot(new Point(5, 5))); sim.register(new RouteFollowingVehicle(VehicleDTO.builder().build(), true)); }
/** * Tests that the builder options are set correctly. */ @Test public void testBuilder() { final RtSolverModel m = RtSolverModel.builder() .withMultiMode() .build(dependencyProvider); assertThat(m.mode).isEqualTo(Mode.MULTI_MODE); final RtSolverModel m2 = RtSolverModel.builder() .withSingleMode() .build(dependencyProvider); assertThat(m2.mode).isEqualTo(Mode.SINGLE_MODE); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RtSolverModel.Builder) { RtSolverModel.Builder that = (RtSolverModel.Builder) o; return (this.mode.equals(that.getMode())) && (this.threadPoolSize == that.getThreadPoolSize()) && (this.threadGrouping == that.getThreadGrouping()); } return false; }
/** * Constructs a {@link Builder} instance for {@link RtSolverModel}. * @return A new instance. */ @CheckReturnValue public static Builder builder() { return Builder.create(Mode.UNKNOWN, 0, false); }
@Override public RtSolverModel build(DependencyProvider dependencyProvider) { final RealtimeClockController c = dependencyProvider .get(RealtimeClockController.class); final PDPRoadModel rm = dependencyProvider.get(PDPRoadModel.class); final PDPModel pm = dependencyProvider.get(PDPModel.class); return new RtSolverModel(c, rm, pm, getMode(), getThreadPoolSize(), getThreadGrouping()); }
/** * The initial mode of the produced {@link RtSolverModel} will be 'single'. * See {@link RtSolverModel} for more information. * @return This, as per the builder pattern. */ @CheckReturnValue public Builder withSingleMode() { return create(Mode.SINGLE_MODE, getThreadPoolSize(), getThreadGrouping()); }
Builder() { setDependencies(RealtimeClockController.class, PDPRoadModel.class, PDPModel.class); setProvidingTypes(RtSimSolverBuilder.class, RtSolverModelAPI.class); }
/** * The initial mode of the produced {@link RtSolverModel} will be 'multi'. * See {@link RtSolverModel} for more information. * @return This, as per the builder pattern. */ @CheckReturnValue public Builder withMultiMode() { return create(Mode.MULTI_MODE, getThreadPoolSize(), getThreadGrouping()); }