Little Simulator

An idea from BoyThisStuffMakesMeFeelStupid ...

All programs are simulators of sorts. However, the degree to which a program must model the world is really brought home in a discrete event simulator. Everyone should write a few of these sometime in their career. Here is the pseudocode for one.

  variable time is initially 0.
  variable events is sorted list initially just startEvent.
  while events remain
	remove nearest event from events list.
	set time to its time.
	call its handler.
  variable model is as required.
  startEvent handler.
	adjust model as appropriate.
	add future event(s) to events list.

The model for an elevator simulator would have data structures for people, floors and elevators. A random number generator would probably be used to select destination floors for random visits. The output could be simply the list of events that took place, or it could be an animation from one or more points of view.

For a SpikeSolution we will need the following:

 Elevator1 can initialize to Floor1
 Person1 starts on Floor1
 Person1 requests elevator (pushes button)
 Elevator1 opens
 Person1 enters Elevator1 (exits Floor1)
 Elevator1 travels to Floor2
 Elevator1 opens
 Person1 exits Elevator1 (enters Floor2)

Is there anything else?

Does LittleSimulatorInJava satisfy the SpikeSolution? Please ignore the lack of UnitTests. -- EricHerman

What I'm wanting to know is, where is the event list and the events? -- JohnClonts ( see top of page)

The SpikeSolution in LittleSimulator does not call for an event list

We need a second test, using a second person. Now the event list must be implemented.

 Person1 starts on Floor1
 Person2 starts on Floor2
 Person1 to request elevator in 9 seconds
 Person2 to request elevator in 6 seconds
 Remove nearest event which is request elevator for Person2 in 6 seconds.

how can LittleSimulatorInJava be refactored to satisfy the requirements of the new test?

Event lists and object models are one approach to simulation. A CocoaWorld offers an interesting alternative. Cocoa is an internet programming language from Apple research. It's Java for kids. It is like the GameOfLife on steroids.

View edit of June 30, 2000 or FindPage with title or text search