Download Restrained re-engineering

Transcript
Multiple simulations
Once the object-oriented model has been fully applied to HC-Sim, the rigid entity
previously referred to as "the simulator" is no more. In the One simulator, several
simulations section we stated that a simulation is simply an instance of a simulator, which
is a natural consequence of an object-oriented design. This fact is also depicted in Figure
49. For each Simulation instance we instantiate, instances of the associated component
classes are created as well. This new trait allows for all kinds of usage of the program that
was previously not possible or seemed difficult to implement. Below we will examine
how this trait could be applied to our imposed requirements of sequential and parallel
simulations. We also evaluate the gain, the effort, and to what extent this was feasible
with the original design.
Sequential simulations
Imagine a scenario where a user wishes to run 100 simulations, each with a slightly
different simulation setup. The old way to do this would be to configure HC-Sim, run the
program, wait for it to finish and save the result. Then one would change the configuration
and do the whole thing over, and over again. Should this type of usage become more than
a one-time event, then the program should make this easier and quicker by at least
providing a partial automization of the process, since the user most likely would become
tired and bored of doing the same thing several times.
Achieving sequentiality
The nature of sequentiality makes the process rather intuitive. For each simulation
configuration that the user provides, a Simulation instance is created and placed in a
queue. When the user has finished adding simulations, he tells HC-Sim to start running
them. The program then successively dequeues the first simulation, runs it and adds it to a
list of finished simulations for later data processing. This is repeated until the simulation
queue is empty. Alternatively, the simulation output could simply be saved directly and
the finished instance discarded. The process is described in Figure 50.
Queued simulations
Sim4
Sim5
Sim6
Running simulations
Finished simulations
Sim3
Sim1
Sim2
Output
Figure 50. Running queued sequential simulations in HC-Sim.
Evaluation
The process of queuing and sequentially executing simulations could just as well be
accomplished by reading simulation configurations from a file representation, which
would be perfectly feasible with the current version of HC-Sim. Unless there is some
specific purpose of keeping finished simulation objects in memory, sequential simulations
alone would not even be reason enough to make a classful design of HC-Sim.
Parallel simulations
If we imagine a situation where a visual comparison of different simulations is required,
then there are several ways in which this could be achieved. The simulations could either
be run in advance, and their output saved so that the data could be interpreted later, or the
simulations could run in parallel, allowing the user to view the simulation turnout as it is
being produced.
80