SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.simevents.Event Class Referenceabstract

This abstract class provides event scheduling tools. More...

Inheritance diagram for umontreal.ssj.simevents.Event:
tutorial.BankEv.Arrival tutorial.BankEv.Departure tutorial.CallCenter.Arrival tutorial.CallCenter.CallCompletion tutorial.CallCenter.NextPeriod tutorial.CallEv.Arrival tutorial.CallEv.CallCompletion tutorial.CallEv.NextPeriod tutorial.PreyPred.EndOfSim tutorial.PreyPred.PrintPoint tutorial.QueueEv.Arrival tutorial.QueueEv.Departure tutorial.QueueEv.EndOfSim

Public Member Functions

 Event ()
 Constructs a new event instance, which can be placed afterwards into the event list of the default simulator by calling one of the schedule... variants.
 Event (Simulator sim)
 Construct a new event instance associated with the given simulator.
void schedule (double delay)
 Schedules this event to happen in delay time units, i.e., at time sim.time() + delay, by inserting it in the event list.
void scheduleNext ()
 Schedules this event as the first event in the event list, to be executed at the current time (as the next event).
void scheduleBefore (Event other)
 Schedules this event to happen just before, and at the same time, as the event other.
void scheduleAfter (Event other)
 Schedules this event to happen just after, and at the same time, as the event other.
void reschedule (double delay)
 Cancels this event and reschedules it to happen in delay time units.
boolean cancel ()
 Cancels this event before it occurs.
final boolean cancel (String type)
 Finds the first occurence of an event of class "type" in the event list, and cancels it.
final Simulator simulator ()
 Returns the simulator linked to this event.
final void setSimulator (Simulator sim)
 Sets the simulator associated with this event to sim.
final double time ()
 Returns the (planned) time of occurence of this event.
final void setTime (double time)
 Sets the (planned) time of occurence of this event to time.
final double priority ()
 Returns the priority of this event.
final void setPriority (double priority)
 Sets the priority of this event to inPriority.
int compareTo (Event e)
 Compares this object with the specified object e for order.
abstract void actions ()
 This is the method that is executed when this event occurs.

Detailed Description

This abstract class provides event scheduling tools.

Each type of event should be defined as a subclass of the class Event, and should provide an implementation of the method actions which is executed when an event of this type occurs. The instances of these subclasses are the actual events.

Each event is linked to a simulator represented by an instance of

Simulator before it can be scheduled and processed. A default simulator, given by Simulator.getDefaultSimulator, is used if no simulator is linked explicitly with an event. When an event is constructed, it is not scheduled. It must be scheduled separately by calling one of the scheduling methods schedule, scheduleNext, scheduleBefore, etc. An event can also be cancelled before it occurs.

A scheduled event has an associated time at which it will happen and a priority, which can be queried using the methods time and priority, respectively. By default, events occur in ascending order of time, and have priority 1. Events with the same time occur in ascending order of priority. For example, if events e1 and e2 occur at the same time with priority 2 and 1 respectively, then e2 will occur before e1. Events with the same time and priority occur in the order they were scheduled.

Definition at line 53 of file Event.java.

Constructor & Destructor Documentation

◆ Event() [1/2]

umontreal.ssj.simevents.Event.Event ( )

Constructs a new event instance, which can be placed afterwards into the event list of the default simulator by calling one of the schedule... variants.

For example, if Bang is an Event subclass, the statement "<tt>new Bang().scheduleNext();</tt>" creates a new Bang event and places it at the beginning of the event list.

public Event (double delay) \begin{hide} { this
(Simulator.getDefaultSimulator(), delay); } \end{hide}
public Event (Simulator sim, double delay)\begin{hide} { if (sim ==
null) throw new NullPointerException(); if (delay >= 0.0) { priority =
1; this.sim = sim; eventTime = sim.time() + delay; sim.eventList.add
(this); } else throw new IllegalArgumentException ("Cannot schedule in
the past."); }\end{hide}
Event()
Constructs a new event instance, which can be placed afterwards into the event list of the default si...
Definition Event.java:126
final double priority()
Returns the priority of this event.
Definition Event.java:301
Represents the executive of a discrete-event simulator.
static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated class.
double time()
Returns the current value of the simulation clock.

Constructs a new event and inserts it in the event list of the default simulator. If delay >= 0.0, the event is scheduled to happen in delay units of simutated time. If two or more events are scheduled to happen at the same time, events with the highest priorities (lowest value of the priority field) occur first. If two or more events are schedule to the same time, with the same priority, they are placed in the event list (and executed) in the same order as they have been scheduled.

We recall that such constructors with parameters are not inherited automatically by the subclasses in Java, but they can be invoked using super. For example, one can have

class Bang extends Event { public Bang (double delay) { super (delay);
} public void actions() { \dots }
abstract void actions()
This is the method that is executed when this event occurs.

and then invoke the constructor "<tt>new Bang (10.0)</tt>" to get a Bang in 10 units of time. This is equivalent to "<tt>new Bang().schedule(10.0)</tt>."

Parameters
delaysimulation time that must pass before the event happens

Definition at line 126 of file Event.java.

◆ Event() [2/2]

umontreal.ssj.simevents.Event.Event ( Simulator sim)

Construct a new event instance associated with the given simulator.

Parameters
simInstance of class Simulator associated with the new Event

Definition at line 135 of file Event.java.

Member Function Documentation

◆ actions()

abstract void umontreal.ssj.simevents.Event.actions ( )
abstract

◆ cancel() [1/2]

boolean umontreal.ssj.simevents.Event.cancel ( )

Cancels this event before it occurs.

Returns true if cancellation succeeds (this event was found in the event list), false otherwise.

Returns
true if the event could be cancelled

Definition at line 231 of file Event.java.

◆ cancel() [2/2]

final boolean umontreal.ssj.simevents.Event.cancel ( String type)

Finds the first occurence of an event of class "type" in the event list, and cancels it.

Returns true if cancellation succeeds, false otherwise.

Parameters
typename of an event subclass
Returns
true if an event of this class was found and cancelled

Definition at line 246 of file Event.java.

◆ compareTo()

int umontreal.ssj.simevents.Event.compareTo ( Event e)

Compares this object with the specified object e for order.

Returns \(-1\) or \(+1\) as this event occurs before or after the specified event e, respectively. If the two events occur at the same time, then returns \(-1\), \(0\), or \(+1\) as this event has a smaller, equal, or larger priority than event e.

Definition at line 325 of file Event.java.

◆ priority()

final double umontreal.ssj.simevents.Event.priority ( )

Returns the priority of this event.

Returns
the priority of the event

Definition at line 301 of file Event.java.

◆ reschedule()

void umontreal.ssj.simevents.Event.reschedule ( double delay)

Cancels this event and reschedules it to happen in delay time units.

Parameters
delaysimulation time units that must elapse before the event happens

Definition at line 215 of file Event.java.

◆ schedule()

void umontreal.ssj.simevents.Event.schedule ( double delay)

Schedules this event to happen in delay time units, i.e., at time sim.time() + delay, by inserting it in the event list.

When two or more events are scheduled to happen at the same time and with the same priority, they are placed in the event list (and executed) in the same order as they have been scheduled. Note that the priority of this event should be adjusted using setPriority before it is scheduled.

Parameters
delaysimulation time that must pass before the event happens

Definition at line 153 of file Event.java.

◆ scheduleAfter()

void umontreal.ssj.simevents.Event.scheduleAfter ( Event other)

Schedules this event to happen just after, and at the same time, as the event other.

Parameters
otherevent after which this event will be scheduled

Definition at line 202 of file Event.java.

◆ scheduleBefore()

void umontreal.ssj.simevents.Event.scheduleBefore ( Event other)

Schedules this event to happen just before, and at the same time, as the event other.

For example, if Bing and Bang are Event subclasses, after the statements

Bang bigOne = new Bang().schedule(12.0); new
Bing().scheduleBefore(bigOne);

the event list contains two new events scheduled to happen in 12 units of time: a Bing event, followed by a Bang called bigOne.

Parameters
otherevent before which this event will be scheduled

Definition at line 188 of file Event.java.

◆ scheduleNext()

void umontreal.ssj.simevents.Event.scheduleNext ( )

Schedules this event as the first event in the event list, to be executed at the current time (as the next event).

Definition at line 166 of file Event.java.

◆ setPriority()

final void umontreal.ssj.simevents.Event.setPriority ( double priority)

Sets the priority of this event to inPriority.

This method should never be called after the event was scheduled, otherwise the events would not execute in ascending priority order anymore.

Parameters
prioritynew priority for the event

Definition at line 312 of file Event.java.

◆ setSimulator()

final void umontreal.ssj.simevents.Event.setSimulator ( Simulator sim)

Sets the simulator associated with this event to sim.

This method should not be called while this event is in an event list.

Parameters
simthe Simulator

Definition at line 266 of file Event.java.

◆ setTime()

final void umontreal.ssj.simevents.Event.setTime ( double time)

Sets the (planned) time of occurence of this event to time.

This method should never be called after the event was scheduled, otherwise the events would not execute in ascending time order anymore.

Parameters
timenew time of occurence for the event

Definition at line 290 of file Event.java.

◆ simulator()

final Simulator umontreal.ssj.simevents.Event.simulator ( )

Returns the simulator linked to this event.

Returns
the simulator linked to the event

Definition at line 256 of file Event.java.

◆ time()

final double umontreal.ssj.simevents.Event.time ( )

Returns the (planned) time of occurence of this event.

Returns
the time of occurence of the event

Definition at line 279 of file Event.java.


The documentation for this class was generated from the following file:
  • src/main/java/umontreal/ssj/simevents/Event.java