[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
This Airport Simulation problem is from one of my favorite books "Data Structures in Pascal" by Ellis Horowitz and Sartai Sahni. Here's an abbreviated description:
Simulate an airport landing and takeoff pattern. The airport has 3 runways,
two primarily for landing and one mainly for takeoffs. There are two
arrival holding pattern queues for each of runways 1 & 2 and three departure
queues, one for each runway. The queues are to be kept as close to the same size as possible.
Background & Techniques
I wrote this program this week thinking that it would make a good simple introduction to discrete event simulators. I turned to be not so typical - discrete event simulators usually have a "future events" queue with timestamps that drive the simulation. This problem has a fixed time stamp increment with a random number of events occurring for each step. But it's an interesting exercise anyway.
This problem is from the referenced book at the end of the chapter on linked lists. Queues are particular kind of lists where new items are always added to the tail end of the list and retrievals are (normally) from the front of the list.
List processing these days with Delphi , is simplified since several list processing components are included. I created objects TQObj and TRunwayObj derived from TListBox in order to combine display capabilities with the other data fields. The Items property of TListbox is a TStrings list object .
I suppose that TQobj and TRunwayObj should be installed as visual components, but I dislike cluttering up Delphi with components that will probably never be used in another program. I solved the problem of getting display properties for a non-component by visually designing with Listbox components to represent the queues and runways on the form. These are passed to the Create constructors for queues and runways, copying the visual properties (parent, location, size, font, and color) and then freeing the listboxes.
I also defined a TPlane object to contain information about arrival time, id#, and fuel remaining. Items (TStrings) has an Objects array that holds the plane objects while they are wait to land or takeoff. The displayed strings in TQObj are the plane Id numbers. For the runways, processing statistics for that runway are updated for display at each time step.
The queues and runways are placed in arrays for ease of coding. Most of the action is in the TimeStep procedure, if you understand it, the rest is mainly bookkeeping to accumulate and display statistics. A second unit contains a memo object witht the complete problem description.
The program contains about 450 lines of code, just over my limit for Intermediate, so we'll call it an advanced.
Running/Exploring the Program
Suggestions for Further Explorations
Copyright © 2000-2017, Gary Darby All rights reserved.