The Meta Algorithm

The simulator manages a collection of objects which represent the structures, input hydrology and control policies within a managed river basin. Since there are many different kinds of objects involved, if this is to work, each object must be able to respond in a predictable way to a standard set of messages. Note that this does not mean that each object does the same thing. Rather, it means that each object will do its individual part to further the state of the simulation when it gets the proper message.

This style of simulation is known as "event driven". Each object maintains a consistent internal state (for water handling objects, such as reservoirs, that means that inflow, outflow, storage and losses are such that mass is conserved).

The meta algorithm consists of the following steps:

  • Prepare for Simulation. This message is sent once during each simulation run before the time loop starts. During this step each object initializes its internal variables, sets any counters to zero, etc. In other words, it gets its internal state ready to begin the business of simulation.

  • Begin Time Step. As indicated by the name, this message is issued at the start of each time step of the simulation and gets the object ready to do its job during the upcoming simulation step. If the object's state is being read from a time series, it is during this step that that value is read.

  • Dispatch. This message may be issued more than once during each time step if necessary. It is during this step that the actual work of the simulation is done by each object. The dispatch message triggers four internal methods:

    • Initialize. This resets any internal variables of does any precalculations that may be needed before the main work is done.

    • Task. This does the primary work that the object will contribute to the overall simulation. It may be either simple or complex as need be.

    • Propagate. Here the object informs any other objects, as necessary, of what it did .

    • Clean Up. As indicated, here the object resets any variables as necessary so that it will be in the proper state to be dispatched once again if need be.

  • Finish Time Step. This is analogous to the clean up step above except that it is done only once per time step. Typically, during this step result values are written so that they will be available for report generation or saving as a part of a scenario record.

In event driven simulation, the control structure is a simple queue. During the begin time step phase, each object is polled and makes a determination whether it needs perform some calculation. If so, it places itself on the queue. The central controller simply removes the top object from the queue and issues it a dispatch message. During the propagate stage of the dispatch step, the active object may send a message to some other object which causes the receiver to place itself on the queue. A time step's calculations continue until the queue is empty.

Perhaps a simple example will help make this clearer. Consider a simple system with two reservoirs in series. During begin time step, reservoir A receives some inflow. The inflow means that the storage and perhaps the release will have to be adjusted, so reservoir A places itself on the queue. When A receives a dispatch message, it calculates its new storage and perhaps determines that its operating policy requires that it release some water downstream to reservoir B. Reservoir A calculates the magnitude of that release and sends that value to reservoir B during its propagate step. Upon receiving this information, reservoir B places itself on the queue.

In our little example, if reservoir B has no policy objection to the amount of water released by A, the time step is finished once B has completed its dispatch step. If B must meet a downstream demand and has a policy that such demand must be satisfied from upstream storage, it will adjust the inflow provided by A and send the new value to A during its propagation phase. In that case, A would place itself back on the queue and the time step would continue for at least one more dispatch step.

The initial simulation order is from upstream down. As upstream reservoirs are dispatched, they have the ability to query downstream and ascertain whether there is any demand on their water. In the absence of competitive constraints, the network settles in a single pass. If there are constraints that need to be balanced, only those reservoirs that have such constraints are involved in the iteration.

Contents
Index

Copyright Jon Behrens & Associates, Inc. 1994 - 2000
All rights reserved.