4. Models and Objects
CS:2820 Object Oriented Software Development Notes, Spring 2021
A model is an abstraction of some aspect of reality. So, for example, we can describe a flood control reservoir such as the Coralville reservoir by a set of variables and functions:
The model connects these variables and functions to describe the behavior of the reservoir:
This model is an oversimplification. It ignores groundwater, it ignores bank erosion, it ignores evaporation. All real models are oversimplifications.
The U.S. Army Corps of Engineers in Rock Island spends quite a bit of effort on such models, they are essential to management of the many dams and flood control reservoirs that they operate. They use stream gauging stations, rainfall data and weather forecasts, plus the predictions for upstream reservoirs in order to get inflow data, and then they use this to test different gate setting strategies in order to minimize flood damage and maximize navigation on the Mississippi River.
We will focus on that kind of model; it is what is called a continuous model because the system being modeled is a continuous system. That is, variables and functions have real values, and the functions are all continuous functions. Continuous systems are best described by differential equations. Take a numerical analysis course if you want to learn more about that kind of modeling. Here, we will focus on discrete event models.
For a second continuous example, consider a model of a satellite in near Earth orbit. This is a problem in orbital dynamics. For short-term dynamics, we can ignore the effects of the Moon, the Sun and other planets, and we can ignore the rotation of the Earth, treating both the Earth and Moon as point masses. The variables that interest us are:
Some constants matter:
All of the above are 3 dimensional vectors, with x y and z components. The basic rules are the rules of physics:
Given an initial position and velocity, this model predicts the future behavior of the satellite. Smaller values of Δt and higher precision arithmetic lead to more precise predictions. Numerical analysis can be used to derive far more accurate models from this framework.
Our modern ideas of object-oriented programming originated in a Norwegian research group that was heavily ivolved in discrete event models and discrete event simulation. Here are some examples of systems that illustrate this kind of model:
Consider modelling a highway network. A model of a highway network will typically have:
In an object-oriented model, we can consider each of the above to be the name of a class, and each attribute of the objects in a class can be considered to be a field of that class. Some of these classes are more complex than others. Intersections have subclasses depending on the control algorithm. Vehicles may have subclasses that depend on the type (taxis and dump trucks have very different behavior).
The events that interest us constitute another class. The following events matter in this highway network:
The primary attribute of every event is the time at which it occurs. In a discrete event model, each event occurs at a specific instant of time. Any process that takes time is considered to occur as a sequence of events spanning that time, where each event in that sequence marks a points where the state of the model must be checked to determine when the next event in that sequence occurs.
Of course, if your model is being used in a context where there is a graphic display of the progress of the model, each vehicle, road and intersection will need to have display coordinates associated with it, but simulation visualization only matters after the underlying model is completed, and here, our focus is on the model.
As a second example consider digital logic. Here, the major classes were:
Of course, if your goal is to manipulate digital logic circuits on a display screen, each gate and wire must know where it is on the display.
Events, in a digital logic circuit, represent changes in the value of the output of a gate or the output of a wire. As in the traffic example, these output state changes are considered to be instantaneous, and for boolean logic we use only two values, true and false. (Not all logic is boolean; in the 1960's, the Russians built a run 50 ternary mainframe computers with the three values true, unknown and false.)
It turns out that the model just presented is just a bit too simplistic: To realistically simulate digital logic circuits containing feedback loops, you need the time delay of gates to have a small random component. Without this, as it turns out, metastable states of the feedback loops do not behave realistically. While you have no need to know this about logic circuitry, the refinement of a model to incorporate such details is very typical of real-world modelling.
A third example, neural networks, model the behavior of neurons in the brains of animals, including people. Note that the term neural network has another meaning, referring to classification algorithms inspired by biological neural networks. Here, we are talking about models of actual nervous systems, not artificial intelligence algorithms. The components that matter in such a model are:
This is vastly oversimplified, but it is still a useful approximation for how neural networks work. This model does not cover learning, which is believed to involve modification to the synapses, and it does not cover exhaustion of the neurotransmitters when a synapse fires too frequently. Again, adding such detail is typical of how models are refined.
A model of an epidemic ignores many details of human behavior, viewing people only as being subject to infection. The goal of the model is to study the spread of infection through the community, so the model needs to track people's contact patterns. The basic components that matter in such a model are:
This model can be made arbitrarily complex, giving it more and more detail, but the goal is to ask, if one person in the community becomes infected, how does the infection spread through the community, how many are bedridden at any time (a measure of Hospital demand), and how many die as a function of time.
Once the basic model works, you can do things like examine the impact of policy changes such as closing schools when the infection rate crosses some threshold. With a slightly more complex model, subdividing workplaces between essential and non-essential, you can examine the impact of closing some categoryof non-essential businesses.