Package jasima.core.simulation
Class Simulation
- java.lang.Object
-
- jasima.core.simulation.Simulation
-
- All Implemented Interfaces:
ProcessActivator,SimOperations,Notifier<Simulation,Simulation.SimLifecycleEvent>,ValueStore
public class Simulation extends Object implements ValueStore, SimOperations, ProcessActivator, Notifier<Simulation,Simulation.SimLifecycleEvent>
Base class for a discrete event simulation. This class mainly maintains the event queue and manages simulation time. Additionally it offers a centralized place to initialize random number streams and to create status and debug messages.The typical life cycle of a simulation would be to create it, and subsequently set any parameters. Afterwards
init()has to be called before the actual simulation can be performed inrun(). After completing a simulation thedone()-method should be called to perform clean-up, collecting simulation results, etc. As a final step usuallyproduceResults(Map)is called to allow the simulation and all simulation components to report simulation results.- Author:
- Torsten Hildebrandt
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSimulation.ErrorHandlerstatic classSimulation.ProduceResultsMessageMessage send when allSimComponents are requested to produce results.static classSimulation.SimExecStatestatic interfaceSimulation.SimLifecycleEventstatic classSimulation.SimulationFailedstatic classSimulation.StdSimLifecycleEvents-
Nested classes/interfaces inherited from interface jasima.core.simulation.util.SimOperations
SimOperations.SimEventType
-
-
Field Summary
Fields Modifier and Type Field Description static StringQUEUE_IMPL_KEYstatic Class<? extends EventQueue>queueImplstatic StringSIM_TIME-
Fields inherited from interface jasima.core.simulation.util.ProcessActivator
log
-
-
Constructor Summary
Constructors Constructor Description Simulation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends SimEntity>
TactivateEntity(T e)Activates the given entity but does not add it to the components tree.voidaddPrintListener(Consumer<SimPrintMessage> listener)voidaddResult(String name, Object value)Adds a certain result to the simulation's result Map.voidafterRun()Override this method to perform some action after running the simulation, but beforedone()is called.voidbeforeRun()Override this method to perform initializations afterinit(), but before running the simulation.Clockclock()Returns a JavaClockobject using the simulation time and its time zone.booleancontinueSim()protected EventQueuecreateEventQueue()Factory method to create a new event queue.SimEventcurrentEvent()Returns theSimEventobject that is currently processed.intcurrentPrio()Returns the priority of the currently processed event.SimProcess<?>currentProcess()Returns the currently activeSimProcess.protected booleandefaultErrorHandler(Exception e)voiddone()Performs clean-up etc., after a simulation'srun()method finished.voidend()After calling end() the simulation is terminated (after handling the current event).StringformattedMessage(Enum<?> key, Object... params)SimComponentgetComponentByHierarchicalName(String hierarchicalName)Convenience method to get a component by its name given a fully qualified name such as "container1.sub1.myMachine".Simulation.ErrorHandlergetErrorHandler()intgetInitialEventPriority()doublegetInitialSimTime()LocalegetLocale()Returns the currently setLocale, i.e., language and region.SimProcessUtil.SimActiongetMainProcessActions()StringgetName()MsgCategorygetPrintLevel()RandomFactorygetRndStreamFactory()SimComponentRootgetRootComponent()SimulationgetSim()InstantgetSimTimeStartInstant()Returns theInstantcorresponding to the initial simulation time.longgetSimTimeToMillisFactor()Returns the factor used to convert the (double-valued) simulation time to milli-seconds sincegetSimTimeStartInstant().doublegetSimulationLength()doublegetStatsResetTime()Returns the statistics reset time.ZoneIdgetZoneId()voidinit()Performs all initializations required for a successful simulationrun().protected voidinitComponentTree(SimComponent parent, SimComponent child)Recursively initialize components before run by setting simulation and parent node.RandominitRndGen(String streamName)Creates an instance of Java'sRandomclass initialized with a seed derived from the parameterstreamName.<T extends DblSequence>
TinitRndGen(T s, String streamName)Initializes the random number generator associated with theDblSequences.booleanisEndRequested()Returns true, ifSimOperations.end()was called and the simulation run ends after processing the current event.booleanisTraceEnabled()Returns true is trace messages should be produced.Stringmessage(Enum<?> key)Stringmessage(String keyName)NotifierImpl<Simulation,Simulation.SimLifecycleEvent>notifierImpl()longnumAppEvents()Returns the number of normal, i.e., application events currently contained in the event queue.longnumEvents()Returns the total number of events (both application and utility events) currently contained in the event queue.longnumEventsProcessed()Returns the number of events processed by the main simulation loop.intnumPrintListener()intnumRunnableProcesses()ObservableValue<Simulation.SimExecState>observableState()Returns the current simulation execution state.static Map<String,Object>of(SimComponent... components)static Map<String,Object>of(SimProcessUtil.SimAction a)static Map<String,Object>of(SimProcessUtil.SimRunnable r)static Map<String,Object>of(String name, SimComponent... components)static Map<String,Object>of(String name, SimProcessUtil.SimAction a)static Map<String,Object>of(String name, SimProcessUtil.SimRunnable r)voidpause()After callingpause()the simulation is paused.Map<String,Object>performRun()Convenience method callinginit(),beforeRun(),run(),afterRun(),done()and returning the results produced byproduceResults(Map)in a newHashMap.Future<Map<String,Object>>performRunAsync()Trigger asynchronous execution of the simulation in the default thread pool.Future<Map<String,Object>>performRunAsync(ExecutorService pool)Call theperformRun()method in an asynchronous way.protected voidprint(SimPrintMessage e)Prints a certainSimPrintMessageby passing it to the registered print listeners.voidprint(MsgCategory category, Object... params)Triggers a print event of the given category.voidprint(MsgCategory category, String message)Triggers a print event of the given category.voidprint(String message)Triggers a print event for the given message of category "INFO".voidprintFmt(MsgCategory category, String messageFormatString, Object... params)Triggers a print event of the given category with the message produced by a Java format String.voidprintFmt(String messageFormatString, Object... params)Same asprintFmt(MsgCategory, String, Object...), but defaulting to categoryINFO.List<Consumer<SimPrintMessage>>printListener()voidproduceResults(Map<String,Object> res)Populates the given HashMap with results produced in the simulation run.booleanremovePrintListener(Consumer<SimPrintMessage> listener)protected voidresetStats()This method is called once afterbeforeRun()and immediately before the main simulation loop starts.voidrun()Runs the main simulation loop.protected voidrunEventHandler(SimEvent evt)Runs the handle-method ofevt(seeSimEvent.handle().voidrunInSimThread(SimProcessUtil.SimAction a)voidrunInSimThread(Runnable r)List<SimProcess<?>>runnableProcesses()SimEventschedule(SimEvent event)Schedules a new event.List<SimEvent>scheduledEvents()Returns an ordered list of all events currently in the event queue.voidschedulePeriodically(double firstInvocation, double interval, int prio, Runnable method)Periodically calls a certain method until the simulation terminates.voidschedulePeriodically(double firstInvocation, double interval, int prio, BooleanSupplier method)Periodically calls a certain method.voidscheduleProcess(double firstInvocation, int prio, DoubleSupplier method)Calls a certain method at the times returned by the method itself.voidscheduleProcess(int prio, DoubleSupplier method)Calls a certain method at the times returned by the method itself.voidsetErrorHandler(Simulation.ErrorHandler errorHandler)voidsetInitialEventPriority(int initialEventPriority)Sets the initial priority value (default=0, i.e.,SimEvent.EVENT_PRIO_NORMAL).voidsetInitialSimTime(double initialSimTime)Sets the initial value of the simulation clock.voidsetLocale(Locale locale)Sets the currentLocale.voidsetMainProcessActions(SimProcessUtil.SimAction mainProcessActions)voidsetMainProcessActions(SimProcessUtil.SimRunnable r)voidsetName(String name)Sets a name for this simulation.voidsetPrintLevel(MsgCategory printLevel)Sets the maximum print message category to be forwared to the print listeners.voidsetRndStreamFactory(RandomFactory rndStreamFactory)Sets the random factory to use to create random number streams for stochastic simulations.voidsetSimTimeStartInstant(Instant simTimeStartInstant)Sets theInstantcorresponding to the a simulation time of 0.voidsetSimTimeToMillisFactor(long simTimeToMillisFactor)Sets the factor used to convert the (double-valued) simulation time to milli-seconds sincegetSimTimeStartInstant().voidsetSimTimeToMillisFactor(TemporalUnit u)Specifies the time unit of the (double-valued) simulation time.voidsetSimulationLength(double simulationLength)Sets the maximum simulation time.voidsetStatsResetTime(double statsResetTime)Sets the time when to perform a statistics reset.voidsetZoneId(ZoneId zone)Sets the current time zone (used bysimTimeToLocalDateTime().doublesimTime()Returns the current simulation time.DurationsimTimeToDuration(double simTime)Converts the given simulation time span to a JavaDuration.InstantsimTimeToInstant(double simTime)Converts the given simulation time to a JavaInstant(UTC time stamp).LocalDateTimesimTimeToLocalDateTime()Converts the current simulation time to a JavaLocalDateTime.LocalDateTimesimTimeToLocalDateTime(double simTime)Converts a simulation time to a JavaLocalDateTime.LocalDateTimesimTimeToLocalDateTime(Instant instant)Converts the givenInstantto a local date/time at this simulation's zone id (getZoneId().Simulation.SimExecStatestate()Returns the current simulation execution state.doubletoSimTime(long numUnits, TemporalUnit u)Converts a given number ofTemporalUnits to the corresponding simulation time, likedouble time = sim.toSimTime(5, ChronoUnit.MINUTE).doubletoSimTime(Duration d)Converts a given JavaDuration(i.e., a time span) to the corresponding (relative) simulation time.doubletoSimTime(Instant instant)Converts a given JavaInstant(absolute UTC time stamp) to the simulation time it corresponds to.voidtrace(Object... params)Produces a trace message (if there are any print listeners such asTraceFileProducerare registered that do something with such messages).voidunpause()After callingunpause()a paused simulation is continued.booleanunschedule(SimEvent event)Removes the given event object from the event queue.ValueStorevalueStoreImpl()Returns the implementation to use for adding ValueStore functionality.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jasima.core.util.observer.Notifier
addListener, addListener, addListener, fire, fire, getListener, numListener, removeCurrentListener, removeListener
-
Methods inherited from interface jasima.core.simulation.util.ProcessActivator
activate, activate, activate, activate, activateCallable, activateCallable, activateCallable, activateCallable
-
Methods inherited from interface jasima.core.simulation.util.SimOperations
addComponent, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleAt, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, scheduleIn, simTimeAbs
-
Methods inherited from interface jasima.core.util.ValueStore
valueStoreContains, valueStoreGet, valueStoreGet, valueStoreGetAllKeys, valueStoreGetNumKeys, valueStorePut, valueStoreRemove, valueStoreUpdate
-
-
-
-
Field Detail
-
SIM_TIME
public static final String SIM_TIME
- See Also:
- Constant Field Values
-
QUEUE_IMPL_KEY
public static final String QUEUE_IMPL_KEY
- See Also:
- Constant Field Values
-
queueImpl
public static final Class<? extends EventQueue> queueImpl
-
-
Method Detail
-
notifierImpl
public NotifierImpl<Simulation,Simulation.SimLifecycleEvent> notifierImpl()
- Specified by:
notifierImplin interfaceNotifier<Simulation,Simulation.SimLifecycleEvent>
-
of
public static Map<String,Object> of(SimProcessUtil.SimRunnable r)
-
of
public static Map<String,Object> of(String name, SimProcessUtil.SimRunnable r)
-
of
public static Map<String,Object> of(SimComponent... components)
-
of
public static Map<String,Object> of(String name, SimComponent... components)
-
of
public static Map<String,Object> of(SimProcessUtil.SimAction a)
-
of
public static Map<String,Object> of(String name, SimProcessUtil.SimAction a)
-
addPrintListener
public void addPrintListener(Consumer<SimPrintMessage> listener)
-
removePrintListener
public boolean removePrintListener(Consumer<SimPrintMessage> listener)
-
numPrintListener
public int numPrintListener()
-
printListener
public List<Consumer<SimPrintMessage>> printListener()
-
init
public void init()
Performs all initializations required for a successful simulationrun().
-
initComponentTree
protected void initComponentTree(SimComponent parent, SimComponent child)
Recursively initialize components before run by setting simulation and parent node.- Parameters:
parent-child-
-
run
public void run()
Runs the main simulation loop. This means:- taking an event from the event queue,
- advancing simulation time, and
- triggering event processing.
end()was called.- See Also:
SimEvent.isAppEvent()
-
runEventHandler
protected void runEventHandler(SimEvent evt)
Runs the handle-method ofevt(seeSimEvent.handle(). This method exists to allow executing custom code before and after each event by sub-classingSimulation.- Parameters:
evt- The event to execute
-
defaultErrorHandler
protected boolean defaultErrorHandler(Exception e)
-
beforeRun
public void beforeRun()
-
resetStats
protected void resetStats()
This method is called once afterbeforeRun()and immediately before the main simulation loop starts. It is called a second time if the simulation has a a value for statsResetTime() set.It should contain code to initialize statistics variables.
-
afterRun
public void afterRun()
-
done
public void done()
Performs clean-up etc., after a simulation'srun()method finished.
-
performRun
public Map<String,Object> performRun()
Convenience method callinginit(),beforeRun(),run(),afterRun(),done()and returning the results produced byproduceResults(Map)in a newHashMap.- Returns:
- The results produced by the simulation and its components.
-
performRunAsync
public Future<Map<String,Object>> performRunAsync(ExecutorService pool)
Call theperformRun()method in an asynchronous way.- Parameters:
pool- TheExecutorServiceto use.- Returns:
- A
Futureto obtain the simulation results. - See Also:
performRun(),performRunAsync()
-
performRunAsync
public Future<Map<String,Object>> performRunAsync()
Trigger asynchronous execution of the simulation in the default thread pool.- Returns:
- A
Futureto obtain the simulation results. - See Also:
performRun(),performRunAsync(ExecutorService)
-
unschedule
public boolean unschedule(SimEvent event)
Removes the given event object from the event queue.- Parameters:
event- the event to remove- Returns:
trueif the operation was present in the event queue and could be successfully removed,falseotherwise
-
schedule
public SimEvent schedule(SimEvent event)
Schedules a new event.- Specified by:
schedulein interfaceSimOperations- Parameters:
event- Some future event to be executed by the main event loop.- See Also:
schedule(SimEvent)
-
schedulePeriodically
public void schedulePeriodically(double firstInvocation, double interval, int prio, BooleanSupplier method)Periodically calls a certain method. While this method returns true, a next invocation after the given time interval is scheduled.- Specified by:
schedulePeriodicallyin interfaceSimOperations- See Also:
schedulePeriodically(double, double, int, BooleanSupplier)
-
schedulePeriodically
public void schedulePeriodically(double firstInvocation, double interval, int prio, Runnable method)Periodically calls a certain method until the simulation terminates.- Specified by:
schedulePeriodicallyin interfaceSimOperations- See Also:
schedulePeriodically(double, double, int, Runnable)
-
scheduleProcess
public void scheduleProcess(int prio, DoubleSupplier method)Calls a certain method at the times returned by the method itself. The first invocation is performed at the current time (asynchronously, i.e.,scheduleProcess()returns beforemethodis called for the first time). Subsequent calls are scheduled at the absolute times returned by the previous method invocation. No more invocations are scheduled ifmethodreturned NaN or a negative value.- Specified by:
scheduleProcessin interfaceSimOperations- See Also:
scheduleProcess(int, DoubleSupplier)
-
scheduleProcess
public void scheduleProcess(double firstInvocation, int prio, DoubleSupplier method)Calls a certain method at the times returned by the method itself. The first invocation is performed atfirstInvocation. Subsequent calls are scheduled at the absolute times returned by the previous method invocation. No more invocations are scheduled ifmethodreturned NaN or a negative value.- Specified by:
scheduleProcessin interfaceSimOperations- See Also:
scheduleProcess(double, int, DoubleSupplier)
-
end
public void end()
After calling end() the simulation is terminated (after handling the current event). This method might also be called from an external thread.- Specified by:
endin interfaceSimOperations
-
isEndRequested
public boolean isEndRequested()
Returns true, ifSimOperations.end()was called and the simulation run ends after processing the current event.- Specified by:
isEndRequestedin interfaceSimOperations
-
pause
public void pause()
-
unpause
public void unpause()
After callingunpause()a paused simulation is continued. Internally each pause request increases a counter that has to be followed by an unpause request. Simulation only resumes if the pause counter reaches zero.This method might also be called from an external thread.
-
simTime
public double simTime()
Returns the current simulation time.- Specified by:
simTimein interfaceSimOperations- See Also:
simTime()
-
simTimeToLocalDateTime
public LocalDateTime simTimeToLocalDateTime()
Converts the current simulation time to a JavaLocalDateTime. This converts the current simulation time to anInstantfirst (seeSimOperations.simTimeAbs()) and then converts it to the local time for this simulation's zone id (getZoneId().- See Also:
simTimeToInstant(double)
-
simTimeToLocalDateTime
public LocalDateTime simTimeToLocalDateTime(double simTime)
Converts a simulation time to a JavaLocalDateTime. The simulation time is converted to anInstantfirst (seeSimOperations.simTimeAbs()) and then converted to the local time for this simulation's zone id (seegetZoneId().- See Also:
simTimeToInstant(double)
-
simTimeToLocalDateTime
public LocalDateTime simTimeToLocalDateTime(Instant instant)
Converts the givenInstantto a local date/time at this simulation's zone id (getZoneId().- See Also:
simTimeToInstant(double)
-
simTimeToInstant
public Instant simTimeToInstant(double simTime)
Converts the given simulation time to a JavaInstant(UTC time stamp). Conversion multiplies the time with the factorgetSimTimeToMillisFactor()and rounds the results to the closest integer to get the number of milliseconds since a simTime of 0. This amount of milliseconds is then added togetSimTimeStartInstant()to get an absolute Java time stamp.- Specified by:
simTimeToInstantin interfaceSimOperations- See Also:
setSimTimeStartInstant(Instant),setSimTimeToMillisFactor(long)
-
simTimeToDuration
public Duration simTimeToDuration(double simTime)
Converts the given simulation time span to a JavaDuration.
-
toSimTime
public double toSimTime(Instant instant)
Converts a given JavaInstant(absolute UTC time stamp) to the simulation time it corresponds to.- Specified by:
toSimTimein interfaceSimOperations- Parameters:
instant- The instant to be converted to simulation time.- Returns:
- The instant converted to simulation time.
- See Also:
toSimTime(Instant)
-
toSimTime
public double toSimTime(Duration d)
Converts a given JavaDuration(i.e., a time span) to the corresponding (relative) simulation time.- Specified by:
toSimTimein interfaceSimOperations- Parameters:
d- The duration to be converted to simulation time.- Returns:
- The amount of simulation time.
- See Also:
toSimTime(Duration)
-
toSimTime
public double toSimTime(long numUnits, TemporalUnit u)Converts a given number ofTemporalUnits to the corresponding simulation time, likedouble time = sim.toSimTime(5, ChronoUnit.MINUTE). Internally this creates a temporaryDurationobject and then callstoSimTime(Duration).- Specified by:
toSimTimein interfaceSimOperations- Parameters:
numUnits- the amount of time unitsu- the temporal unit to use; will usually be on fromChronoUnit- Returns:
- The amount of simulation time.
- See Also:
toSimTime(long, TemporalUnit)
-
currentPrio
public int currentPrio()
Returns the priority of the currently processed event.- Specified by:
currentPrioin interfaceSimOperations- See Also:
currentPrio()
-
currentEvent
public SimEvent currentEvent()
Returns theSimEventobject that is currently processed.
-
currentProcess
@Nullable public SimProcess<?> currentProcess()
Returns the currently activeSimProcess.
-
state
public Simulation.SimExecState state()
Returns the current simulation execution state.
-
observableState
public ObservableValue<Simulation.SimExecState> observableState()
Returns the current simulation execution state.
-
numEventsProcessed
public long numEventsProcessed()
Returns the number of events processed by the main simulation loop.
-
numAppEvents
public long numAppEvents()
Returns the number of normal, i.e., application events currently contained in the event queue.
-
numEvents
public long numEvents()
Returns the total number of events (both application and utility events) currently contained in the event queue.
-
scheduledEvents
public List<SimEvent> scheduledEvents()
Returns an ordered list of all events currently in the event queue. Use with care, this is an expensive operation. The list does not include the current
-
produceResults
public void produceResults(Map<String,Object> res)
Populates the given HashMap with results produced in the simulation run.
-
addResult
public void addResult(String name, Object value)
Adds a certain result to the simulation's result Map.- Specified by:
addResultin interfaceSimOperations- Parameters:
name- Name of the result.value- Result value.- See Also:
addResult(String, Object)
-
activateEntity
public <T extends SimEntity> T activateEntity(T e)
Activates the given entity but does not add it to the components tree. Therefore they will not be notified of any future simulation lifecycle events such asproduceResults. It is therefore intended for temporarySimEntitys only.- Specified by:
activateEntityin interfaceSimOperations- See Also:
activateEntity(SimEntity)
-
getComponentByHierarchicalName
public SimComponent getComponentByHierarchicalName(String hierarchicalName)
Convenience method to get a component by its name given a fully qualified name such as "container1.sub1.myMachine".
-
print
public void print(String message)
Triggers a print event for the given message of category "INFO".- Parameters:
message- The message to print.- See Also:
print(MsgCategory, String)
-
print
public void print(MsgCategory category, String message)
Triggers a print event of the given category. If an appropriate listener is installed, this should produce an output ofmessage.- Parameters:
message- The message to print.
-
print
public void print(MsgCategory category, Object... params)
Triggers a print event of the given category. If an appropriate listener is installed, this should produce an output ofmessage.
-
print
protected void print(SimPrintMessage e)
Prints a certainSimPrintMessageby passing it to the registered print listeners.
-
trace
public void trace(Object... params)
Produces a trace message (if there are any print listeners such asTraceFileProducerare registered that do something with such messages). A trace message consists of the simulation time and all parameters converted to Strings (separated by tabs).- Specified by:
tracein interfaceSimOperations- Parameters:
params- The components of the trace message.- See Also:
trace(Object...)
-
isTraceEnabled
public boolean isTraceEnabled()
Description copied from interface:SimOperationsReturns true is trace messages should be produced.- Specified by:
isTraceEnabledin interfaceSimOperations- Returns:
- Whether or not trace messages are to be produced.
- See Also:
isTraceEnabled()
-
getPrintLevel
public MsgCategory getPrintLevel()
- Returns:
- The current maximum print message category.
-
setPrintLevel
public void setPrintLevel(MsgCategory printLevel)
Sets the maximum print message category to be forwared to the print listeners. If this is set to e.g. INFO, then only messages of the categories ERROR, WARN and INFO are forwared to- Parameters:
printLevel-
-
printFmt
public void printFmt(MsgCategory category, String messageFormatString, Object... params)
Triggers a print event of the given category with the message produced by a Java format String. If an appropriate listener is installed, this produces a message defined by the format stringmessageFormatString(used with the arguments given inparams).
-
printFmt
public void printFmt(String messageFormatString, Object... params)
Same asprintFmt(MsgCategory, String, Object...), but defaulting to categoryINFO.
-
createEventQueue
protected EventQueue createEventQueue()
Factory method to create a new event queue.- Returns:
- The event queue to use in this simulation.
-
setSimulationLength
public void setSimulationLength(double simulationLength)
Sets the maximum simulation time. A value of 0.0 means no such limit.
-
getSimulationLength
public double getSimulationLength()
- Returns:
- The maximum simulation time; a value of 0.0 means no such limit.
-
getRndStreamFactory
public RandomFactory getRndStreamFactory()
- Returns:
- The RandomFactory used to create random number streams.
-
setRndStreamFactory
public void setRndStreamFactory(RandomFactory rndStreamFactory)
Sets the random factory to use to create random number streams for stochastic simulations.
-
initRndGen
public <T extends DblSequence> T initRndGen(T s, String streamName)
Initializes the random number generator associated with theDblSequences. This just delegates to theRandomFactoryof this simulation.- Specified by:
initRndGenin interfaceSimOperations- See Also:
initRndGen(DblSequence, String)
-
initRndGen
public Random initRndGen(String streamName)
Creates an instance of Java'sRandomclass initialized with a seed derived from the parameterstreamName. This just delegates to the methodRandomFactory.createInstance(String)of this simulation.- Specified by:
initRndGenin interfaceSimOperations- See Also:
initRndGen(String)
-
getName
public String getName()
- Returns:
- The name of this simulation.
-
setName
public void setName(String name)
Sets a name for this simulation.
-
getRootComponent
public SimComponentRoot getRootComponent()
- Specified by:
getRootComponentin interfaceSimOperations- Returns:
- The root component of all
SimComponents contained in the simulation.
-
getInitialSimTime
public double getInitialSimTime()
-
setInitialSimTime
public void setInitialSimTime(double initialSimTime)
Sets the initial value of the simulation clock.
-
getInitialEventPriority
public int getInitialEventPriority()
-
setInitialEventPriority
public void setInitialEventPriority(int initialEventPriority)
Sets the initial priority value (default=0, i.e.,SimEvent.EVENT_PRIO_NORMAL).
-
getSimTimeStartInstant
public Instant getSimTimeStartInstant()
Returns theInstantcorresponding to the initial simulation time.
-
setSimTimeStartInstant
public void setSimTimeStartInstant(Instant simTimeStartInstant)
Sets theInstantcorresponding to the a simulation time of 0. The default setting is to use the beginning of the current year.The Instant will be truncated to milliseconds, so any nano-second part will be cleared.
- See Also:
simTimeToInstant(double)
-
getSimTimeToMillisFactor
public long getSimTimeToMillisFactor()
Returns the factor used to convert the (double-valued) simulation time to milli-seconds sincegetSimTimeStartInstant().- See Also:
setSimTimeToMillisFactor(long)
-
getStatsResetTime
public double getStatsResetTime()
Returns the statistics reset time.
-
setStatsResetTime
public void setStatsResetTime(double statsResetTime)
Sets the time when to perform a statistics reset. The value set here will only have an effect before the simulation is started.- Parameters:
statsResetTime- The new statistics reset time.
-
getLocale
public Locale getLocale()
Returns the currently setLocale, i.e., language and region.
-
setLocale
public void setLocale(Locale locale)
Sets the currentLocale.
-
getZoneId
public ZoneId getZoneId()
-
setZoneId
public void setZoneId(ZoneId zone)
Sets the current time zone (used bysimTimeToLocalDateTime().
-
getErrorHandler
public Simulation.ErrorHandler getErrorHandler()
-
setErrorHandler
public void setErrorHandler(Simulation.ErrorHandler errorHandler)
-
setSimTimeToMillisFactor
public void setSimTimeToMillisFactor(long simTimeToMillisFactor)
Sets the factor used to convert the (double-valued) simulation time to milli-seconds sincegetSimTimeStartInstant(). The default value is 60*1000=60000, assuming simulation time to be in minutes.- See Also:
simTimeToInstant(double)
-
setSimTimeToMillisFactor
public void setSimTimeToMillisFactor(TemporalUnit u)
Specifies the time unit of the (double-valued) simulation time. The default value is ChronoUnit.MINUTES.
-
continueSim
public boolean continueSim()
-
runInSimThread
public void runInSimThread(Runnable r)
-
runInSimThread
public void runInSimThread(SimProcessUtil.SimAction a)
-
valueStoreImpl
public ValueStore valueStoreImpl()
Description copied from interface:ValueStoreReturns the implementation to use for adding ValueStore functionality.- Specified by:
valueStoreImplin interfaceValueStore
-
getSim
public Simulation getSim()
- Specified by:
getSimin interfaceProcessActivator- Specified by:
getSimin interfaceSimOperations
-
numRunnableProcesses
public int numRunnableProcesses()
-
runnableProcesses
public List<SimProcess<?>> runnableProcesses()
-
getMainProcessActions
public SimProcessUtil.SimAction getMainProcessActions()
-
setMainProcessActions
public void setMainProcessActions(SimProcessUtil.SimRunnable r)
-
setMainProcessActions
public void setMainProcessActions(SimProcessUtil.SimAction mainProcessActions)
-
-