parallel and distributed simulation object-oriented simulation
Post on 21-Dec-2015
243 views
TRANSCRIPT
Parallel and Distributed Simulation
Object-Oriented Simulation
Outline
• Process-Oriented Simulation (quick review)• Generalized Simulation Architecture (review)• Object-oriented simulation
– Object-oriented vs. Object-based– Is-A and Has-A class hierarchies– Object Interactions
• Additional simulation concepts– Indirect event exchange via group communication– Event retraction
Event vs. Process Oriented Views
State variables
Integer: InTheAir;Integer: OnTheGround;Boolean: RunwayFree;
Event oriented view
Entities modeled by event handlers
Arrival Event
{
…
}
Landed Event
{
…
}
Departure Event
{
…
}
State variables
Integer: InTheAir;Integer: OnTheGround;Boolean: RunwayFree;
Process oriented view
Entities modeled by processes
Aircraft 1
{
ArriveLandDepart
}
Aircraft 2
{
ArriveLandDepart
}
Aircraft n
{
ArriveLandDepart
}
Simulation PrimitivesPrimitives needed to advance simulation time• AdvanceTime(T): advance T units of simulation time
– Also called “hold”– E.g.: AdvanceTime(R) to model using runway R units of
simulation time
• WaitUntil(p): simulation time advances until predicate p becomes true– Predicate based on simulation variables that can be modified by
other simulation processes– E.g.: WaitUntil(RunwayFree) to wait until runway becomes
available for landing
• Other combinations– WaitUntil(p,T): Wait up to T units of simulation time for predicate p
to become true– Not used in the air traffic example
Execution Example
OnTheGround
Simulation Time
StateVariables
RunwayFree
InTheAir
0 1 2 3 4 5 6 7 8 9 10 11
true
0
0
R=3G=4
false
1 2 1
1
0
2
true
1 0
Flight 11 InTheAir := InTheAir+1;
2 WaitUntil (RunwayFree);
3 RunwayFree := FALSE;
4 AdvanceTime(R);
5 RunwayFree := TRUE;
6 InTheAir := InTheAir-1;
7 OnTheGround:=OnTheGround+1;
8 AdvanceTime(G);
9 OnTheGround:=OnTheGround-1;
Flight 21 InTheAir := InTheAir+1;
2 WaitUntil (RunwayFree);
3 RunwayFree := FALSE;
4 AdvanceTime(R);
5 RunwayFree := TRUE;
6 InTheAir := InTheAir-1;
7 OnTheGround:=OnTheGround+1;
8 AdvanceTime(G);
9 OnTheGround:=OnTheGround-1;
Process-oriented Simulation• Is usually built over event oriented simulation
mechanisms (event list, event processing loop)• typically simplifies model development and modification• requires threading (e.g., co-routine) mechanism• Incurs additional complexity and computation overhead to
suspend and resume simulation processes
Overall Simulation Architecture
Network
SMP 1 SMP m
Processor 1 Processor n
Simulator 1 Simulator n
LP 1 LP p
Object 1 Object i
State variables
Process1
Processs
EventHandlers Methods
LP = Logical ProcessSMP=Symmetric Multi-Processor
Simulation Application• state variables• code modeling system behavior• I/O and user interface software
Simulation Executive• event list management• managing advances in simulation time
calls toscheduleevents
calls to eventhandlers
Discrete Event Simulation System
model of the physical system
independent
of the simulation
application
Object Oriented Simulation• Models defined in terms of objects and interactions.• Object-orientation includes:
– Encapsulation• Attributes of an object are entirely contained within the object
scope• E.g. Fuel attribute & land() method of an Aircraft object
– Inheritance• Attributes of an object are copied into inheriting class• E.g. Fuel attribute & land() method of an Aircraft object are
copied into a Boeing object that inherits from Aircraft
– Polymorphism• Method bodies can be changed in inheriting class• The correct, class-specific method gets invoked at runtime• E.g. The land() method of an Aircraft object is changed in Boeing class to model Boeing-specific landing behavior
Object-Oriented Vs. Object-Based
• Object-oriented includes:– Encapsulation– Inheritance– Polymorphism
• Object-based includes:– Encapsulation– Limited inheritance– No polymorphism
Simulation Class Hierarchies
• Objects organized in class hierarchies• Both the simulator as well as the application can be
object-oriented• Simulator and application share the hierarchies
– Event hierarchy– Process hierarchy– Is-A and Has-A hierarchies
Event: Is-A HierarchyEvent
InternalEvent
ROEvent
TSOEvent
AppEvent
RO = Receive-orderedTSO = Timestamp-ordered
AppEvent
… TimerEvent
RetractEvent
… Add/DelEvent
App = ApplicationAdd/Del = Add or Delete a ProcessResume = Resume a suspended process
ResumeEvent
Commonly used in real-time simulations
Focus on this in rest of the class
Logical Process: Is-A HierarchyLogical Process
Event-OrientedProcess
ThreadedProcess
…
Event-oriented Process: Object with simple event handlerPeriodic Process: Object with a simple, periodically repeating actionThreaded Process: Object with full process-oriented behavior using a stack
PeriodicProcess
… …
Simulator: Has-A HierarchySimulator
Process ListGroup
List
LogicalProcesses
Process List: Set of currently active logical processesLogical Processes: Mixture of event-oriented, periodic and process-oriented processesPending Event List: Priority queue of unprocessed eventsTSO Events: Timestamp-ordered eventsGroup List: Table of “event interest” groupsSubscribed Groups: Event interest groups some processes are subscribed toPublishing Groups: Event interest groups some processes publish to
PendingEvent List
TSOEvents
SubscribedGroups
PublishingGroups
Clock
Object Interactions
Object interaction modeled with– Direct method invocation– Direct event exchange– Indirect event exchange
Object Interaction – Method InvocationInteraction via the usual method invocation:• One object invokes another object’s method by
reference, synchronously• Simulation time remains constant during method
execution• The source object’s method could be an event
handler or a process• Typically, the destination object’s method is not a
processObject A:Method(){ … B.Method() …}
Object B:Method(){ … …}
Object Interaction – Direct EventsInteraction via direct event exchange:• One object invokes another object’s method by
sending it an event• Simulation time can advance before interaction• The source specifies the destination object by
reference/identifier• Either of source and destination methods could be an
event handler or a process
Object A:Method(){ … Send(E) …}
Object B:Method(){ … …}
Event Eat time T
Object Interaction – Indirect EventsInteraction via indirect event exchange:• One object invokes another object’s method by
“posting” an event to an “interest group”• Simulation executive routes the event to a set of zero
or more objects
Object A:Method(){ … Send(G,E) …}
Object C:Method(){ … …}
Event Eat time T
Object B:Method(){ … …}
Group G
Interest Group Communication• Events exchanged via a “group” intermediary• Analogous to Internet newsgroups (bulletin boards)• Objects send events to a specific group instead of
to a specific object• Simulator executive forwards event to “interested”
objects• Example: State updates in Virtual Environments
– Interaction among geographically distributed entities– Entities periodically send their position updates– Updates are sent to groups corresponding to
geographical grid regions– Only entities subscribed to those regions receive the
update events
Interest Group CommunicationPrimitives:
– Create(G)• Analogous to creation of a newsgroup G
– Subscribe(G)• Analogous to subscribing to a newsgroup G
– Publish(G)• Analogous to obtaining permission to post to newsgroup G
– Update(G,E)• Analogous to posting a message E to newsgroup G
– Reflect(G,E)• Analogous to receiving/reading a message E on newsgroup G
Group Communication Advantages
• Loose coupling among objects– Leads to easier model development and maintenance– Aids in easy extensibility
• Simulation executive can perform filtering– Leads to better performance due to reduced
communication, compared to broadcast
Event Retraction• Retract previously scheduled events
– “Cancel”
• Air traffic example– Airport closing because of bad weather– Schedule a “closing” event at an airport with a time
stamp indicating when the airport closes
• Event retraction mechanism– “Un-schedule” departure event– Reschedule departure events based on re-opening
time of airport
• Or ignore the invalid departure events without event retraction mechanism
• What about arrival events?
Summary
• Object-oriented simulation– Object-oriented vs. Object-Based– Is-A and Has-A class hierarchies– Object Interactions
• Additional simulation concepts– Indirect event exchange via group communication– Event retraction