Original Post
Hello peeps!
I''ve recently started out with C++ and I''d like to do something nice with my newly found class-skills.
I''ve seen a few examples on the net (mostly java) about Event-driven simulation, but it seems that I haven''t understood all of it yet, so I thought I asked you guys
What I''ve seen, a common event-driven simulation would be to simulate a store or a bank of somekind, with customers, cashiers and queues.
What I know is that all the Events are stored in a list of some kind (preferrably a linked-list), and as the times goes on, the Events are handeled and they usually cause more Events to be placed into the list.
If we take that bank thing as an example, we''d have Cashiers, Customers and a Queue. So these could be the Classes needed for the simulation with the addition of an abstract Event-class with different subtypes for the different Classes.
The Event-Classes would, in my opinion only have the method Action() aswell as a reference to the owner. Also internal variables that tell what Action is to be taken need to be added.
The Queue Class.
addToQueue() // Creates and adds a few Customers to the Queue
// and adds a new Event into the Eventlist
// telling when it''s time to add more customers
getFirst() // removes and returns the first Customer
The Cashier Class.
status() // returns CLOSED, OCCUPIED or FREE
handleCust() // starts handling the customer and creates an
// Event that tells when it can take
// the next customer
releaseCust() // releases the current customer and takes a
// new one
Does this look right at all?
What happens if the Queue becomes empty?
AddToQueue() checking if any of the cashiers are available? Okay, but that''d mean that the Queue-class would need a linked list containing all of the cashiers and loop them through to check if any of them are available.
And most importantly, do I have the right idea here, I mean not every interaction between the objects seem to go via Events. Maybe this is the way it''s supposed to be? Help me, teach me!
I''m not looking for any source-code, unless it''s very abstract. I just need to understand the fundamentals of Event-driven simulations to get me going.
Thanks