/** * Constructs a {@link Builder} for creating a real-time central model. The * real-time central model is a model that takes control of all vehicles in a * simulation and uses a {@link RealtimeSolver} to compute routes for all * vehicles. * @param solverSupplier A {@link StochasticSupplier} that creates the * {@link RealtimeSolver} that will be used for controlling all * vehicles. * @return A new {@link Builder} instance. */ public static Builder builder( StochasticSupplier<? extends RealtimeSolver> solverSupplier) { return Builder.create(solverSupplier, ImmutableSet.<Options>of()); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RtCentral.Builder) { RtCentral.Builder that = (RtCentral.Builder) o; return (this.solverSupplier.equals(that.getSolverSupplier())) && (this.options.equals(that.getOptions())); } return false; }
ImmutableList.<Parcel>of()); })).withSleepOnChange(true)) .build();
RtCentral.builder( StochasticSuppliers.constant(new TestRtSolver(150))) .withSleepOnChange(true)) .build();
/** * If set to <code>true</code> the model will wait half a tick (wall clock * time) after it has started a new computation. By sleeping half a tick the * solver has time to do some computations already, and, if it is fast * enough if may already be finished. When it is already finished computing, * the new schedule will be applied immediately. If set to * <code>false</code> the model will not wait, this means that a new * schedule will be applied at the earliest the tick after it started the * computation. By default sleep on change is set to <code>false</code>. * @param flag If set to <code>true</code> sleep on change is enabled, * otherwise it is disabled. * @return A new builder instance with the flag. */ public Builder withSleepOnChange(boolean flag) { return change(Options.SLEEP_ON_CHANGE, flag); }
@Override public RtCentralModel build( DependencyProvider dependencyProvider) { final RandomProvider rnd = dependencyProvider.get(RandomProvider.class); final RealtimeSolver solver = getSolverSupplier() .get(rnd.masterInstance().nextLong()); final RtSimSolver s = dependencyProvider.get(RtSimSolverBuilder.class) .build(solver); final RealtimeClockController clock = dependencyProvider .get(RealtimeClockController.class); final PDPRoadModel rm = dependencyProvider.get(PDPRoadModel.class); final PDPModel pm = dependencyProvider.get(PDPModel.class); return new RtCentral.RtCentralModel(clock, s, rm, pm, getOptions()); }
public Builder withThreadGrouping(boolean flag) { return change(Options.THREAD_GROUPING, flag); }
public Builder withContinuousUpdates(boolean flag) { return change(Options.CONTINUOUS_UPDATES, flag); }
public static MASConfiguration solverConfigurationAdapt( StochasticSupplier<? extends Solver> solverSupplier, String nameSuffix, boolean threadGrouping) { return configBuilder(solverSupplier, nameSuffix) .addModel(builder(AdapterSupplier.create(solverSupplier)) .withThreadGrouping(threadGrouping)) .build(); }
@Override public ImmutableSet<ModelBuilder<?, ?>> getChildren() { return ImmutableSet.<ModelBuilder<?, ?>>of( RtSolverModel.builder().withThreadGrouping( getOptions().contains(Options.THREAD_GROUPING))); }
Builder() { setDependencies( RandomProvider.class, RtSimSolverBuilder.class, RealtimeClockController.class, PDPRoadModel.class, PDPModel.class); }
Builder change(Options option, boolean toAdd) { final Set<Options> opts = new LinkedHashSet<>(getOptions()); if (toAdd) { opts.add(option); } else { opts.remove(option); } return create(getSolverSupplier(), opts); }