Download presentation
Presentation is loading. Please wait.
Published byJames Sherman Modified over 9 years ago
1
Object Oriented Simulation with OOSimL Conditional Waiting
2
Feb. 2015 Conditional Waiting One or more processes wait for a condition to become true. Waiting processes are suspended and automatically placed in a queue. A suspended process will be reactivated when another process changes the condition.
3
Conditional Waiting The processes involved use the synchronization mechanism implemented in a synchronization conditional object This synchronization object suspends and later reactivates the interacting processes. The synchronization object evaluates the specified condition on behalf of a process Feb. 2015
4
Evaluating the Condition If the condition is not true, the process is suspended by the synchronization object and placed in the condition queue. Suspended processes are held in the condition queue that belongs to the synchronization object. Another process, which changes the parameters of the condition, will signal the synchronization object and it reactivates any waiting processes. Feb. 2015
5
Synchronization Object The mechanism that controls conditional waiting synchronization is implemented in class Condq An object of class Condq is a passive object and includes an internal queue to hold waiting processes An object of class Condq is needed for each condition.
6
Feb. 2015 UML Diagram With Conditional Wait
7
Feb. 2015 Two Processes and Conditional Waiting
8
Feb. 2015 Declaring and Creating an Object of Class Condq To use a conditional object of class Condq, the object reference must be declared and the object created with title and the optional number of priorities to use. The default number of priorities is 250. define cond_cust of class Condq... create cond_cust of class Condq using "Customer Cond”, priorities
9
Feb. 2015 Waituntil Statement A Process tests a condition by executing the waituntil statement, and if the condition is not true, is suspended and placed in the condition queue waituntil in
10
Example of ‘waituntil’ define mcond of type boolean... set mcond = false while mcond not equal true do // evaluate boolean expression set mcond = (att1 > 3 ) and (att2 <= att1) waituntil mcond in cond_cust endwhile // now acquire resources // hold for a specified time interval // release resources Feb. 2015
11
Signal Statement A process that changes the condition, execute the signal statement to reactivate waiting process at the head of the queue A reactivated process will re-evaluate the condition signal to
12
Feb. 2015 Length of Conditional Queue The assign length statement, gets the number of processes waiting in the conditional queue of the specified Condq object, and assigns it to the specified integer variable. define cond_num of type integer... assign length of cond_cust to cond_num
13
Feb. 2015 Conditional Port System Ships arrive periodically at a port to unload their cargo To dock, ships require the following resources: a pier and two tugboats To leave, ships require one tugboat Ships can only dock if the tide is high The tide changes every 13 hours, and lasts for 4 hours.
14
Feb. 2015 Processes and Resources in the Port System There are four types of processes Ships, with several instances Arrivals, one instance Tide, with only one instance Cport, the top class The resource types are: Tugboats Piers
15
Feb. 2015 Conditions in the Port System The condition for ships to dock is: a pier and two tugboats available the tide is not low. The tide remains low for 4 time units. The cycle continuously repeats.
16
Feb. 2015 Ships Behavior 1. First acquire a pier, if there any available 2. Evaluate the condition for tide not low and enough tugs available 3. Wait suspended if condition is not true 4. Continue 5. Acquire the necessary tugs for docking 6. Unload, which takes a finite time interval 7. Acquire 1 tugboat for undocking and departure.
17
Feb. 2015 Timings for the Simulation Inter-arrival time of ships follows an exponential distribution with mean of 26.0 minutes. Docking time is constant: 32.5 minutes. Unloading follows a normal distribution: mean time is 74.0 minutes with a standard deviation of 8.0 minutes. Undocking time interval is constant: 25.0 time units.
18
Feb. 2015 Tide Behavior and Condition Changes The tide is modeled as a process When the tide changes state, the evaluation of the condition also changes When the tide changes to high, this process invokes the signal method of the conditional object, so ships can re-evaluate the condition
19
Main Body of Tide while clktime < simperiod do set lowtide = true hold self for 4.0 set lowtide = false signal to cond_obj hold self for 9.0 endwhile Feb. 2015
20
Condition Changes When a ship process releases resources, this event may also cause a change of the condition. The ship process executes the signal statement.
21
Feb. 2015 Implementation The Conditional Port model is archived in file cport.jar The classes of this model are stored in files: Cport.osl, Arrivals.osl, Ship.osl, and Tide.osl.
22
Feb. 2015 Partial Output of a Simulation Run End Simulation of Port System with Conditions date: 10/13/2014 time: 7:16 Total number of ships that arrived: 27 Average wait period: 123.5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.