Object-Oriented, Discrete Event Simulation
Midterm Exam, Due 10:am Nov. 15, 1995
Please do individually without consultation or help from other persons.
1. A generator has two input ports, "in1" and "in2". When it receives a value on "in1" it immediates switches to an inter-arrival-time given by that value. Receiving a value on "in2", it switches to the new inter-arrival-time but only after the current period has been completed. The initial state has sigma = 0 and inter-arrival-time = 10.
a) Present the generator as a box with state variables and input, output ports shown. Write DEVS-C++ code or pseudo for the generator.
b) Draw a timing diagram (input, state, and output trajectories) to show the behavior when an input of 5 is injected at time = 13 on port "in1". Draw another timing diagram for the same input pattern on port "in2".
c) Add input ports "stop" and "start" to the generator. When a "stop" input is received, the generator stores the time remaining to the next output and passivates. When a "start" input is received, the
generator starts up and puts out an output after a time equal to the stored time remaining to next output. Show the appropriate code/pseudo code and demonstrate in a timing diagram.
2. Consider an atomic model for a baseball pitcher-catcher system as follows
The model continually cycles through phases pitcher-has-ball, ball-on-way-to-plate, ball-crossing-plate, catcher-has-ball, pitcher-has-ball, etc. The model stays in phases pitcher-has-ball and catcher-has-ball for 1 unit time. The model stays in phases ball-on-way-to-plate and ball-crossing-plate for a time inversely proportional to the speed of the ball, which the pitcher determines in phase pitcher-has-ball. Let this choice be represented by a random variable choose-speed.. The pitcher also determines the height of the ball using a random variable, choose-height. The model has an input port "bat" which takes on a value representing the height of the batter's bat. When an external event is received on this port, if the model is in phase ball-crossing-plate and the height of the bat is equal to the height of the ball, then an output event on port "hit" is produced by the model 2 units of time later, after which the pitcher-catcher cycle starts up again.
There are two more output ports, "strike" and "ball" which report whether each pitch is a strike or ball. A "strike" occurs when the batter swings at a pitch and misses, or does not swing but the ball is within a certain interval of height at the plate; a "ball" is called when the batter does not swing but the ball is not within the given interval.
a) Present the model as a box with state variables and input, output ports shown. Write DEVS-C++ code or pseudocode to implement the model. Explain what this code is doing. by illustrating with time charts showing the different behavior cases.
b) Refine the model so that it puts out a value on port "hit" which can take on one of the values {foul_left, home_run, foul_right} depending on whether the batter's swing (input on port "bat") is too early, just right, or too late, respectively, relative to the travel time of the ball across home plate. Explain as in a).
3. A digraph-model D has components A and B. Component A is an atomic model which has no external transition function and whose internal transition function is:
deltint(){
count++;
hold_in("active", 5);
}
Component B is an atomic model with no external transition function and with internal transition function
deltint(){
if( a->get_count() > 10)
a->reset_count();
else hold_in("active",1);
}
Note that component B has direct access to read a state variable of A and also to write (change) it. This is not a modular interaction.
a) What are the disadvantages of non-modular specifications such this?
b) Show how to modify these models so that the same behavior is obtained except that all interaction occurs through input and output ports. Rewrite atomic-models A and B suitably and couple them using a system entity structure which transforms into the proper form of D.
4. A farmer owns a flock of sheep which are supposed to remain in the barn all night. Every so often however, each lamb leaves the barn for a brief period but you can assume that only one lamb is outside at any time. A pack of wolves lies waiting close to the barn for this to happen. The wolf with the highest rank (they are initially ranked) starts towards the wayward lamb but it takes some time to reach it, and the wolf makes noise in the process. The noise wakes the farmer and he runs out to shoot the wolf. Sometimes the farmer kills the wolf before it can kill the lamb, other times the wolf gets away and returns to the pack full-bellied.
We are interested in the number of sheep and wolves killed over a 12 hour night. The experiment stops whenever there are no sheep or wolves left. The experimental frame module consists of an acceptor and transducer for this objective.
The following SES is pruned to use block models for the multiple entities.
EF-F | EF-F-DEC | ------------------------------------ | F EF | | EF-DEC | F-DEC | | ---------------- | | | | | | | | | ACC TRANSD -----------|------- | | | FARMER LAMBS WOLFS ||| ||| LAMB WOLFLAMBS has an output port 'lamb-out
WOLFS has output ports 'noise, 'catch-lamb and 'got-me
FARMER has an output port 'shoot-wolf
ACC has an output port 'stop
TRANSD has an output port' result
a) Write a pseudo-code description (including a diagram showing ports and state variables) of TRANSD, the transducer that keeps track only of the number of lambs and wolves killed.
b) Also write a pseudo-code description of ACC, the acceptor that keeps track of time remaining till morning and of the number of lambs and wolves left (and issues the appropriate stop condition).
c) Write a pseudo-code description (including a diagram showing ports and state variables) of
the WOLF.
d) Fill in the SES diagram above showing the couplings attached to each
aspect; also include any internal couplings required in the block models.