Event-Driven Simulation in Java

Creation USS Code 39 in Java Event-Driven Simulation
Event-Driven Simulation
Drawing ANSI/AIM Code 39 In Java
Using Barcode creation for Java Control to generate, create Code 3 of 9 image in Java applications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Barcode Generator In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.
/ / Run the simulation until stopping time occurs / / Print output as in Figure 144
Reading Bar Code In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
void ModemSim::runSim( int stoppingTime I static Event e; int howlong; while( !eventSetempty( )
Encoding Code 39 Full ASCII In C#.NET
Using Barcode generation for .NET Control to generate, create Code 39 image in VS .NET applications.
) );
ANSI/AIM Code 39 Printer In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications.
e = eventSettop( ) ; eventSetpop( if( etime > stoppingTime ) break; if( ewhat == Event::HANG-UP
Code 39 Full ASCII Drawer In .NET
Using Barcode generation for .NET Control to generate, create Code 3/9 image in .NET framework applications.
l i HANG-UP
ANSI/AIM Code 39 Creation In Visual Basic .NET
Using Barcode creator for VS .NET Control to generate, create Code39 image in .NET applications.
freeModems++; cout << "User << ewho < < " hangs up at time " < < etime << endl;
Print Code-128 In Java
Using Barcode drawer for Java Control to generate, create USS Code 128 image in Java applications.
else
EAN13 Generation In Java
Using Barcode encoder for Java Control to generate, create UPC - 13 image in Java applications.
/ / DIAL-IN
Encoding Data Matrix 2d Barcode In Java
Using Barcode maker for Java Control to generate, create ECC200 image in Java applications.
cout << "User " << ewho << " dials in at time << etime << "; if( freeModems > 0 ) ! freeModems--; howLong = rpoisson( avgCallLen ) ; cout << "and connects for " << howLong << minutes" < < endl; etirne + = howlong; ewhat = Event::HANG-UP; eventset push( e ) ; 1 else cout << "but gets busy signal" < < endl;
UPC A Generation In Java
Using Barcode maker for Java Control to generate, create UPCA image in Java applications.
nextcall( freqOfCalls 1 ; 1
Encoding Barcode In Java
Using Barcode generation for Java Control to generate, create bar code image in Java applications.
The basic simulation routine
Intelligent Mail Encoder In Java
Using Barcode generation for Java Control to generate, create 4-State Customer Barcode image in Java applications.
1 The first DIAL-IN request is inserted 2 After DIAL-IN is removed, the request is connected, thereby resulting in a HANG-UP and a replacement DIAL-IN request 3 A HANG-UP request is processed 4 A DIAL-IN request is processed resulting in a connect Thus both a HANG-UP event and a DIAL-IN event are added (three times)
EAN-13 Supplement 5 Creation In Visual Studio .NET
Using Barcode generation for .NET framework Control to generate, create European Article Number 13 image in VS .NET applications.
User 0, Len 1
Draw Code128 In C#
Using Barcode encoder for VS .NET Control to generate, create Code 128B image in .NET applications.
User 1, Len 5
Scanning ANSI/AIM Code 39 In .NET Framework
Using Barcode reader for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
User 1, Len 5
Decoding EAN13 In VS .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET framework applications.
User 2 Len 4
Data Matrix 2d Barcode Generator In .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in .NET framework applications.
User I Len 5
Data Matrix ECC200 Creation In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
User 2, Len 4
Read Barcode In .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
User 3 Len 1 L
User 4, Len
User I , Len 5
User 2, Len 4
User 3, Len 11
User 1, Len 5
User 2 Len 4
(1 6
User 1, Len 5 User 2, Len 4 User I , Len 5 User 2, Len 4
v m) l
1 4 u s e r 3,
1 4 u s e r 3,
en I I
User 6, Len
User 3 Len 1 1
User 7, Len 8
User 2, Len 4
User 3, Len 1 1
User 7, Len 8
Figure 1410 The priority queue for modem bank simulation after each step
Event-Driven Simulation
5 A DIAL-IN request fails; a replacement DIAL-IN is generated
(three times) 6 A HANG-UP request is processed (twice) 7 A DIAL-IN request succeeds, and HANG-UP and DIAL-IN are added Again, if Event were an abstract base class, we would expect a procedure doEvent to be defined through the Event hierarchy; then we would not need long chains of if /else statements However to access the priority queue, which is in the simulation class, we would need Event to store a pointer to the simulation ModemSim class as a data member We would insert it at construction time A minimal main routine is shown for completeness in Figure 141 1 However, using a Poisson distribution to model connect time is not appropriate A better choice would be to use a negative exponential distribution (but the reasons for doing so are beyond the scope of this text) Additionally, assuming a fixed time between dial-in attempts is also inaccurate Again, a negative exponential distribution would be a better model If we change the simulation to use these distributions, the clock would be represented as a double In Exercise 1414 you are asked to implement these changes
Thesimulation usesa poor model Negative exponential distributions would more accurately model the time between dial-in attempts and total connect time
1 / / Simple main to test ModemSim class 2 int main( ) 3 { 4 int numModems; 5 int totalTime; 6 double avgConnectTime; 7 int dialInFrequency; 8 9 cout << "Enter: number of modems, length of simulation, " 10 < < " average connect time, how often calls occur: " ; 11 12 cin >> numModems >> totalTime >> 13 avgConnectTime >> dialInFrequency; 14 15 ModemSim s( numModems, avgConnectTime, dialInFrequency ) ; 16 srunSim( totalTime ) ; 17 return 0; 18 19 1
Figure 1411 A simple main to test the simulation
Summary
Simulation is an important area of computer science and involves many more complexities than we could discuss here A simulation is only as good as the model of randomness, so a solid background in probability, statistics, and queueing theory is required in order for the modeler to know what types of probability distributions are reasonable to assume Simulation is an important application area for object-oriented techniques
Objects of the Game
discrete time-driven simulation A simulation in which each unit of time is processed consecutively It is inappropriate if the interval between successive events is large (p 477) event-driven simulation A simulation in which the current time is advanced to the next event (p 477) Josephus problem A game in which a hot potato is repeatedly passed; when passing terminates, the player holding the potato is eliminated; the game then continues, and the last remaining player wins (P 47 1) simulation An important use of computers, in which the computer is used to emulate the operation of a real system and gather statistics (P 47 1) tick The quantum unit of time in a simulation (p 477)