Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
*
*/
package rinde.sim.core;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.measure.Measure;
import javax.measure.quantity.Duration;
import javax.measure.unit.Unit;
import org.apache.commons.math3.random.RandomGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rinde.sim.core.model.Model;
import rinde.sim.core.model.ModelManager;
import rinde.sim.core.model.ModelProvider;
import rinde.sim.event.Event;
import rinde.sim.event.EventAPI;
import rinde.sim.event.EventDispatcher;
/**
* Simulator is the core class of a simulation. It is responsible for managing
* time which it does by periodically providing {@link TimeLapse} instances to
* registered {@link TickListener}s. Further it provides methods to start and
* stop simulations. The simulator also acts as a facade through which
* {@link Model}s and objects can be added to the simulator, more info about
* models can be found in {@link ModelManager}.
*
* The configuration phase of the simulator looks as follows:
*
*
register models using {@link #register(Model)}
*
call {@link #configure()}
*
register objects using {@link #register(Object)}
*
start simulation by calling {@link #start()}
*
* Note that objects can not be registered before calling
* {@link #configure()} and {@link Model}s can not be registered after
* configuring.
*
* @author Rinde van Lon ([email protected])
* @author Bartosz Michalik - simulator API
* changes
*/
public class Simulator implements SimulatorAPI {
/**
* The logger of the simulator.
*/
protected static final Logger LOGGER = LoggerFactory
.getLogger(Simulator.class);
/**
* Enum that describes the possible types of events that the simulator can
* dispatch.
*/
public enum SimulatorEventType {
/**
* Indicates that the simulator has stopped.
*/
STOPPED,
/**
* Indicates that the simulator has started.
*/
STARTED,
/**
* Indicates that the simulator has been configured.
*/
CONFIGURED
}
/**
* Contains the set of registered {@link TickListener}s.
*/
protected volatile Set tickListeners;
/**
* Reference to dispatcher of simulator events, can be used by subclasses to
* issue additional events.
*/
protected final EventDispatcher dispatcher;
/**
* @see #isPlaying
*/
protected volatile boolean isPlaying;
/**
* @see #getCurrentTime()
*/
protected long time;
/**
* Model manager instance.
*/
protected final ModelManager modelManager;
private boolean configured;
private Set