|
Coensys, Inc. |
|
| Discrete Event Simulation (DES) Using AnyLogic 6Anylogic supports Discrete Event Simulation. Anylogic comes with a fairly robust library of discrete event elements that can be used to rapidly develop a discrete event models by dragging and dropping these library elements. The following graphic shows some of the typical library elements used in a model:
These elements can be used to rapidly develop a model using a Flowchart or a Layout, or a Network-based modeling approach. This approach can be used to model processes, sequences of activities, and utilization of resources.
Anylogic enables drag and drop modeling and naturally interoperates with all other AnyLogic modeling constructs. Models are scalable and extensible. All blocks are AnyLogic active objects made of standard components (ports, statecharts, timers). Anylogic supports sophisticated web based animation capabilities:
Discrete Event Simulation with Anylogic 6
The world around us appears
to be "continuous": the greater majority of processes we observe
consist of continuous changes. However, when we analyze those processes, in many
cases it makes sense to abstract from their continuous nature and consider
only some "important moments", "events" in the system
lifetime. The modeling paradigm that suggests to approximate the real-world
processes with such events is called Discrete Event Modeling. (The term Discrete
Event is also used in the narrower sense to denote "process-centric"
modeling where the system is described as a process flowchart.) Discrete
Event modeling is fully supported by AnyLogic as well as System Dynamics and Agent Based Modeling. Here are some examples of
events: a customer arrives at a shop, a truck finishes unloading, a conveyor
stops, a new product is launched, the inventory level reaches a certain
threshold, etc. In discrete event modeling the movement of e.g. a train
from point A to point B would be modeled with two events: departure and arrival,
and the actual movement will become a time delay (interval) between them. (This
does not mean however that you cannot animate the train as moving, in fact in
AnyLogic you can produce visually continuous animations for logically discrete models). Event in AnyLogic model
(which as you know is an abstraction) takes zero time to execute, is atomic
(will not interfere with any other event execution), may change the model when
it is executed, in particular may schedule other events. If AnyLogic engine is
executing a purely discrete model, the time is essentially a sequence of events,
and the engine just jumps from one event to another. If several events are
scheduled to occur at the same time (are simultaneous), they are serialized,
i.e. executed one after another in some internal (not guaranteed) order. If the
order is important for you, you should take care of it when developing the model
so that the simulation results do not depend on the engine implementation. At the low level (at the
level of AnyLogic modeling primitives) events may be scheduled by two types of
objects: Events and Statecharts. There is
however, a library of higher-level objects that help you to create discrete
event patterns frequently used in process-centric modeling (queuing, resource
usage, entity generation, etc.) - it is called Enterprise Library. Events and Dynamic Events
The simplest way to generate
events in AnyLogic is to use model elements of the same name – events. There
are two types of events: event
and dynamic event. Both of them
are responsible for scheduling some user-defined actions in the model. They are
commonly used to model delays and timeouts. The difference between the
event and the dynamic event is that the dynamic event deletes itself after its
action is executed, whereas an event survives and can be restarted. However,
there can be multiple instances of the same dynamic event scheduled concurrently
in the model.
Static
and dynamic events Events
To schedule some action
using AnyLogic event, you should add the event on the active object diagram, and
then configure it by specifying, when it should occur and what action should be
performed on its occurrence. Adding an Event
1.
Choose the Event
2.
Click in the
graphical editor where you want to place the event. Scheduling an Event
To schedule the event
occurrence, you should define the event trigger. There are three event trigger
types: ·
Timeout ·
Rate Timeout
triggered event
The event will occur exactly
in the defined timeout time after it was started. Optionally, the event may be
made cyclic and set to occur at startup.
1.
Choose Timeout
from the Trigger Type drop-down list. 2.
Specify the
timeout in the Timeout edit box below. It might be an expression that is
evaluated to obtain the timeout. 3.
Specify the
timeout event mode. From the Mode drop-down list, choose, whether this
event should be o
Occurs once
– event will occur only once exactly in the specified Occurrence time.
You can define the ocurrence time as a calendar date or as a number of model
time units to be passed from the model start. Please note that here you define
the absolute time and in the case the event will be created after the
specified time, it will never occur. o
Cyclic –
event will occur cyclically. You define the First occurrence time and the
Recurrence time for an event. The first ocurrence time can be defined
either as a calendar date, or as a number of model time units to be passed
from the model start. Please
note that you define absolute times. If event will be created after
the specified first occurrence time, the model will schedule the first
occurrence time in the past and then will successively increment it with Recurrence
time. The first time that will exceed the current model time will be used as
the actual first occurrence time. The next occurrence times will be counted as
it should be by adding the defined Recurrence time. If
you want to use relative times (i.e. count the first occurrence time from
the moment this event will be created), use time()
function in the First occurrence time property. time() will
refer to the moment this event was created at. o
User control
– the event will work in manual mode. It will occur if and only of user calls
the event’s restart method passing the timeout as the argument, for instance mytimer.restart(15).
If the timeout is fixed, you can define it once in the Timeout
property and simply call mytimer.restart()
without specifying the timeout as a method parameter. Condition
triggered event
You may define a Boolean
condition as the trigger for the event. In this case the event will occur when
the defined condition will become true.
1.
Choose On
Condition from the Trigger Type drop-down list. 2.
Specify the
Boolean condition in the Condition edit box below. If the active object has
continuously changing variables, the numeric engine constantly monitors the
condition. In purely discrete models the condition is tested when something
changes in the active obejct, i.e. when onChange() is called. Rate
triggered event
A rate is a form of
updateable exponential timeout. If you define a rate triggered event, the event
will occur periodically with time intervals distributed exponentially with the
parameter rate, i.e. if the rate is 5, the event will occur on average 5 times
per time unit.
1.
Choose Rate
from the Trigger Type drop-down list. 2.
Specify the rate
in the Rate edit box below. If the rate changes
dynamically, the event occurrence gets re-scheduled; such changes may only be
noticed by the event if onChange()
is called for the active object. Specifying an Event Action
Event’s action is
specified in the Action property of the event. There you can write Java
code to be executed on the event occurrence. Or may be more convenient is
defining this code as a function and just placing this function call in the Action
field. Manual Controlling an Event
A static event can expire
any number of times. To schedule a static event, you call its method restart(),
specifying the timeout value as a parameter. When the event occurs, it
calls the method action(). By calling the method reset(),
you deactivate the event until the next call to restart(). Dynamic Event
Dynamic events are used to
schedule any number of concurrent and independent events. For example, a
communication channel which is able to transmit an arbitrary number of messages
concurrently can be modeled with the help of dynamic events that are
created for each message. Another example is a server with infinite capacity. Defining a Dynamic Event
1.
Choose the Dynamic
Event
2.
Click in the
graphical editor where you want to place the dynamic event. Configuring a Dynamic Event
Event action
The event’s action is
specified in the Action property of the event. There you can write Java
code to be executed on the event occurrence. Or may be more convenient is
defining this code as a function and just placing this function call in the Action
field. Dynamic event parameters
You may define some optional
parameters. Dynamic event parameters can be accessed as member variables of the
dynamic event object. Every parameter should be
declared in form: ·
Name - the
name of the parameter ·
Type - the
type of the parameter ·
Default Value
- the optional default value of the parameter. When creating an instance of the
dynamic event class, you may specify actual parameter values or leave the
default ones. Since the order of
parameters in the table is significant, AnyLogic enables changing the parameter
order just moving them up or down using the buttons
To remove parameter, select
the parameter row in the table and click the Remove button. Specifying an Event Action
Event’s action is
specified in the Action property of the event. There you can write Java
code to be executed on the event occurrence. Or may be more convenient is
defining this code as a function and just placing this function call in the Action
field. Scheduling Dynamic Events
To create new dynamic event
instance, use the method that is generated automatically by AnyLogic for every
dynamic event declared on the active object diagram. void
create_<dynamic_event_name>( double timeout, <1st_Parameter_Type>
param1, <2nd_Parameter_Type> param2, …) You pass the timeout to the
function as the first parameter, then you specify the parameter values in the
order they were defined in the Parameters table for the dynamic event. Time counting begins at the
moment of creating the instance of a dynamic event. When the event timeout
expires, AnyLogic executes the event’s action and then deletes this instance
of dynamic event. If the method reset()
of the dynamic event is called before expiry, this instance of event is deleted
and its action is never performed.
|