You are on page 1of 146

1.

Systems concepts

1.1 SYSTEM APPROACH TO PROBLEM SOLVING

Systems approach is widely used in problem solving in the field of science and technology
and Business problems can also be analyzed and solved using this approach.

The approach stands on the assumption that breaking down of a complex concept into simple
easy to understand units helps in better understanding of the complexity

1.1.1 System

A system is an orderly grouping of interdependent components linked together according to a


plan to achieve a specific objective.

A system is defined as an aggregation or assemblage of objects joined in some regular


interaction or interdependence toward the accomplishment of some purpose.

Example : Production System

In the above system there are certain distinct objects, each of which possesses properties of
interest. There are also certain interactions occurring in the system that cause changes in the
system.

The study of system concepts has three basic implications:

1. A system must be designed to achieve a predetermined objective.

2. Interrelationships and interdependence must exist among the components.

3. The objectives of the organization as a whole have a higher priority than the objectives of
its subsystems. The following steps are required for this.

1
Defining the Problem

This is the step when the problem has to be defined. Sometimes one may confuse the
symptoms or the exhibition of a behavior to be a problem but actually it may only be a
symptom of a larger malaise.

One must appreciate that this in the initial stage of problem solving and if the problem itself
is not correctly diagnosed then the solution will obviously be wrong.

Systems approach is therefore used to understand the problem in granular detail to establish
requirement and objectives in-depth.

By using the systems approach the problem will be analyzed in its totality with inherent
elements and their interrelationships and therefore this detailed analysis will bring out the
actual problem and separate out the symptom from it.

Developing Alternative Solutions

In this stage alternative solutions are generated.

This requires creativity and innovation.

The outline of solutions is generated rather than the actual solutions.

Selecting a Solution

The solution that suits the requirement and objectives in the most comprehensive manner is
selected as the 'best' solution.

This is done after evaluating all the possible solutions and then comparing the possible set of
solutions to find the most suitable solution

Designing the Solution

Once the most appropriate solution is chosen, it is then made into a design document to give
it the shape of an actionable solution.

At this stage the details of the solution are worked out to create the blueprint for the solution.
Several design diagrams are used to prepare the design document.

Implementing the Solution

The solution that has been designed is implemented as per the specifications -laid down in the
design document.

During implementation care is taken to ensure that there are no deviations from the design.

2
Reviewing the Solution

This is the final step in the problem solving process where the review of the impact of the
solution is noted.

This is a stage for finding out if the desired result has been achieved that was set out.

A Systems Approach Example

Let us assume that A is the coach of the Ethiopian football team. Let us also assume that the
objective that A has been entrusted with is to secure a win over the touring Spain football
team. The coach uses a systems approach to attain this objective. He starts by
gathering information about his own team.

Through systems approach he views his own team as a system whose environment would
include the other team in the competition, umpires, regulators, crowd and media.

His system, i.e., team itself maybe conceptualized as having two subsystems, i.e., players and
supporting staff for players.

Each subsystem would have its own set of components/entities like the player subsystem
will have goalkeeper, defense, midfield and striker., etc. The supporting staff subsystem
would include coach, keeping coach, physiotherapist, psychologist, etc. All these entities
would indeed have a bearing on the actual outcome of the game. The coach adopts a systems
approach to determine the playing strategy that he will adopt to ensure that the Ethiopian side
wins. He analyses the issue in a stepwise manner as given below:

Step 1: Defining the problem-In this stage the coach tries to understand the past performance
of his team and that of the other team in the competition. His objective is to defeat the
competing team. He realizes that the problem he faces is that of losing the game. This is his
main problem.

Step 2: Collecting data-The coach employs his supporting staff to gather data on the skills
and physical condition of the players in the competing team by analyzing past performance
data, viewing television footage of previous games, making psychological profiles of each
player. The support staff analyses the data and comes up with the following observations:

Both teams use an aggressive strategy during the play. The competing Spain team uses the
striking players to spearhead this attack. The game is being played in Addis Ababa and the
local crowd support is estimated to be of some value. Also the crowd has come to watch the
Ethiopian team win. A loss here would cost the team in terms of morale.

3
The umpires are neutral and are not intimidated by large crowd support but are lenient
towards sledging.

Step 3: Identifying alternatives-Based on the collected data the coach generates the following
alternate strategies:

Play upon the minds of the striking players of the competitors by highlighting their personal
differences using sledging alone.

Employ defensive tactics during first half of the play when the strikers are most aggressive
and not using sledging.

Step 4: Evaluating alternatives-After having generated different alternatives, the coach has to
select only one. The first alternative may lead to loss of concentration on the part of strikers
and result in breakthroughs.

Step 5: Selecting the best alternative-The coach selects the second alternative as it provides
him with the opportunity of neutralizing the aggressive playing strategy of the strikers as well
as increases the chances of getting goals

Step 6: Implementing and monitoring-The coach communicates his strategy to his players
and support staff, instructs support staff to organize mock sessions and tactics to be employed
to make the strategy a success. The players and support staff performance is monitored by the
coach on a regular basis to ensure that the strategy is employed perfectly.

1.1.2 Simplifying a System

The easiest way to simplify a system for better understanding is to follow a two-stage
approach.

Partitioning the System into Black Boxes

This is the first stage of the simplification process, in this stage the system is partitioned into
black boxes. Black boxes need limited knowledge to be constructed. To construct a black box
one needs to know the input that goes into it, the output that comes out of it and its function.
The knowledge of how the functionality is achieved is not required for constructing a black
box. Black box partitioning helps in the comprehension of the system, as the entire system
gets broken down into granular functionalities of a set of black boxes.

4
Organizing the Black Boxes into Hierarchies

This is the second stage of the simplification process, in this stage the black boxes
constructed in the earlier phase are organized into hierarchies so that the relationships among
the black boxes is easily established. Once, a hierarchy of the black boxes is established, the
system becomes easier to understand as the internal working of the system becomes clearer.

1.2 Characteristics of Systems

1. Organization:

It implies structure and order. It is the arrangement of components that helps to achieve
objectives.

2. Interaction:

It refers to the manner in which each component functions with other components of the
system.

3. Interdependence:

It means that parts of the organization or computer system depend on one another. They are
coordinated and linked together according to a plan. One subsystem depends on the output of
another subsystem for proper functioning.

4. Integration:

It refers to the holism of systems. It is concerned with how a system is tied together.

5. Central Objective:

A system should have a central objective. Objectives may be real or stated. Although a stated
objective may be the real objective, it is not uncommon for an organization to state one
objective and operate to achieve another. The important point is that users must know the
central objective of a computer application early in the analysis for a successful design and
conversion.

1.3 State of the System

• State of a system: Collection of variables and their values necessary to describe the
system at that time
– Might depend on desired objectives, output performance measures

5
– Bank model: Could include number of busy tellers, time of arrival of each
customer, etc.
State of a system: It is the minimal collection of information with which the system future
behavior can be predicted. For the Jet aircraft, the state of the system can be determined by
Speed, Direction of travel, weather conditions, number of passengers, and amount of
remaining fuel.

An Activity: It is the process or Event which changes the system state.

1.4 System Boundaries and environment

Systems of any practical relevance are open as they interact with the environment. Therefore,
to understand the system it has to be differentiated from the environment, i.e., the boundary
of the system has to be clearly defined along with its interaction with the environment from
within this boundary.

To model a system, it is necessary to understand the concept of a system and the system
constraints. We define a system as a group of objects that are joined together in some
interaction or interdependence toward the accomplishment of some purpose. An example is a
production system manufacturing automobiles. The machines, component parts, and workers
operate jointly along an assembly line to produce a high-quality vehicle.
A system is often affected by changes occurring outside the system. Such changes are said to
occur in the system environment. In modelling systems, it is necessary to decide on the
boundary between the system and its environment. This decision may depend on the purpose
of the study.

The external components which interact with the system and produce necessary changes are
said to constitute the system environment. In modeling systems, it is necessary to decide on
the boundary between the system and its environment. This decision may depend on the
purpose of the study.

6
Ex: In a factory system, the factors controlling arrival of orders may be considered to be
outside

the factory but yet a part of the system environment. When, we consider the demand and
supply

of goods, there is certainly a relationship between the factory output and arrival of orders.
This

relationship is considered as an activity of the system.

Endogenous System

The term endogenous is used to describe activities and events occurring within a system.

Ex: Drawing cash in a bank.

Exogenous System

The term exogenous is used to describe activities and events in the environment that affect
the system. Ex: Arrival of customers.

Closed System

A system for which there is no exogenous activity and event is said to be a closed. Ex: Water
in an insulated flask.

Open system

A system for which there is exogenous activity and event is said to be a open. Ex: Bank
system.

One of the challenging aspects of systems is knowing where the boundary lies that separates
the system from its environment.

7
For example, The Open University has its headquarters in Milton Keynes. This campus is
certainly part of the system, as are its two hundred thousand students and staff located across
the UK and worldwide.

The Open University specializes in distance education, and does much of its teaching using
the internet. Is the internet part of the Open University system? All of it?

Or is the internet part of the environment?

Assuming that a system of interest has a purpose, the following definitions will be used on
this course:

The entities inside the system are all those necessary for it to fulfill its purpose and that can
be controlled by the system owners or managers

The entities in the environment are all those things that affect the system but cannot be
controlled by the system owners or managers

Anything not in the system and not in the environment has no effect on the system‘s
behavior.

By this definition, the internet is not part of the Open University but is part of its
environment.

1.5 Modeling and Simulation

• Simulation: Imitate the operations of a facility or process, usually via computer

Computer simulation is a powerful methodology for design and analysis and complex
systems. The overall approach in computer simulation is to represent the dynamic
characteristics of a real world system in a computer model.

Brief Explanation

The behavior of a system as it evolves over time is studied by developing a simulation


model. This model takes the form of a set of assumptions concerning the operation of the
system. The assumptions are expressed in
 Mathematical relationships
 Logical relationships
 Symbolic relationships Between the entities of the system.

8
Measures of performance

The model solved by mathematical methods such as differential calculus, probability


theory, algebraic methods has the solution usually consists of one or more numerical
parameters which are called measures of performance.

Steps in a Simulation study

1. Problem formulation
Every study begins with a statement of the problem, provided by policy makers. Analyst
ensures its clearly understood. If it is developed by analyst policy makers should
understand and agree with it.
2. Setting of objectives and overall project plan
The objectives indicate the questions to be answered by simulation. At this point a
determination should be made concerning whether simulation is the appropriate
methodology. Assuming it is appropriate, the overall project plan should include
 A statement of the alternative systems
 A method for evaluating the effectiveness of these alternatives
 Plans for the study in terms of the number of people involved
 Cost of the study
 The number of days required to accomplish each phase of the work with the
anticipated results.
3. Model conceptualization
The construction of a model of a system is probably as much art as science. The art of
modeling is enhanced by an ability
 To abstract the essential features of a problem
 To select and modify basic assumptions that characterize the system
 To enrich and elaborate the model until a useful approximation results
Thus, it is best to start with a simple model and build toward greater complexity. Model
conceptualization enhance the quality of the resulting model and increase the confidence
of the model user in the application of the model.
4. Data collection
There is a constant interplay between the construction of model and the collection of
needed input data. Done in the early stages. Objective kind of data are to be collected.

9
5. Model translation
Real-world systems result in models that require a great deal of information storage and
computation. It can be programmed by using simulation languages or special purpose
simulation software. Simulation languages are powerful and flexible. Simulation software
models development time can be reduced.
6. Verified
It pertains to he computer program and checking the performance. If the input parameters
and logical structure and correctly represented, verification is completed.
7. Validated
It is the determination that a model is an accurate representation of the real system.
Achieved through calibration of the model, an iterative process of comparing the model
to actual system behavior and the discrepancies between the two.
8. Experimental Design
The alternatives that are to be simulated must be determined. Which alternatives to
simulate may be a function of runs. For each system design, decisions need to be made
concerning
 Length of the initialization period
 Length of simulation runs
 Number of replication to be made of each run
9. Production runs and analysis
They are used to estimate measures of performance for the system designs that are being
simulated.
10.More runs
Based on the analysis of runs that have been completed. The analyst determines if
additional runs are needed and what design those additional experiments should follow.
11.Documentation and reporting
Two types of documentation.
 Program documentation
 Process documentation
Program documentation
Can be used again by the same or different analysts to understand how the program
operates. Further modification will be easier. Model users can change the input
parameters for better performance.

10
Process documentation
Gives the history of a simulation project. The result of all analysis should be reported
clearly and concisely in a final report. This enable to review the final formulation and
alternatives, results of the experiments and the recommended solution to the problem.
The final report provides a vehicle of certification.
12. Implementation
Success depends on the previous steps. If the model user has been thoroughly involved
and understands the nature of the model and its outputs, likelihood of a vigorous
implementation is enhanced. The simulation model building can be broken into 4 phases.
I Phase
 Consists of steps 1 and 2
 It is period of discovery/orientation
 The analyst may have to restart the process if it is not fine-tuned
 Recalibrations and clarifications may occur in this phase or another phase.
II Phase
 Consists of steps 3,4,5,6 and 7
 A continuing interplay is required among the steps
 Exclusion of model user results in implications during implementation
III Phase
 Consists of steps 8,9 and 10
 Conceives a thorough plan for experimenting
 Discrete-event stochastic is a statistical experiment
 The output variables are estimates that contain random error and therefore proper
statistical analysis is required.
IV Phase
 Consists of steps 11 and 12
 Successful implementation depends on the involvement of user and every steps
successful completion.

11
Figure 1.1: simulation model

When Simulation is the Appropriate Tool

 Simulation enables the study of and experimentation with the internal interactions
of a complex system, or of a subsystem within a complex system.
 Informational, organizational and environmental changes can be simulated and the
effect of those alternations on the model‘s behavior can be observer.

12
 The knowledge gained in designing a simulation model can be of great value
toward suggesting improvement in the system under investigation.
 By changing simulation inputs and observing the resulting outputs, valuable
insight may be obtained into which variables are most important and how
variables interact.
 Simulation can be used as a pedagogical device to reinforce analytic solution
methodologies.
 Simulation can be used to experiment with new designs or policies prior to
implementation, so as to prepare for what may happen.
 Simulation can be used to verify analytic solutions.
 By simulating different capabilities for a machine, requirements can be
determined.
 Simulation models designed for training, allow learning without the cost and
disruption of on-the-job learning.
 Animation shows a system in simulated operation so that the plan can be
visualized.
 The modern system(factory, water fabrication plant, service organization, etc) is
so complex that the interactions can be treated only through simulation.

When Simulation is Not Appropriate

 Simulation should be used when the problem cannot be solved using common
sense.
 Simulation should not be used if the problem can be solved analytically.
 Simulation should not be used, if it is easier to perform direct experiments.
 Simulation should not be used, if the costs exceeds savings.
 Simulation should not be performed, if the resources or time are not available.
 If no data is available, not even estimate simulation is not advised.
 If there is not enough time or the person are not available, simulation is not
appropriate.
 If managers have unreasonable expectation say, too much soon – or the power of
simulation is over estimated, simulation may not be appropriate.
 If system behavior is too complex or cannot be defined, simulation is not
appropriate.

13
Advantages of Simulation

 Simulation can also be used to study systems in the design stage.


 Simulation models are run rather than solver.
 New policies, operating procedures, decision rules, information flow, etc can be
explored without disrupting the ongoing operations of the real system.
 New hardware designs, physical layouts, transportation systems can be tested
without committing resources for their acquisition.
 Hypotheses about how or why certain phenomena occur can be tested for
feasibility.
 Time can be compressed or expanded allowing for a speedup or slowdown of the
phenomena under investigation.
 Insight can be obtained about the interaction of variables.
 Insight can be obtained about the importance of variables to the performance of
the system.
 Bottleneck analysis can be performed indication where work- inprocess,
information materials and so on are being excessively delayed.
 A simulation study can help in understanding how the system operates rather than
how individuals think the system operates.
 ―what-if‖ questions can be answered. Useful in the design of new systems.

Disadvantages of simulation

 Model building requires special training.


 Simulation results may be difficult to interpret.
 Simulation modeling and analysis can be time consuming and expensive.
 Simulation is used in some cases when an analytical solution is possible or even
preferable.

Applications of Simulation

 Manufacturing Applications
1. Analysis of electronics assembly operations
2. Design and evaluation of a selective assembly station for high precision scroll
compressor shells.

14
3. Comparison of dispatching rules for semiconductor manufacturing using large
facility models.
4. Evaluation of cluster tool throughput for thin-film head production.
5. Determining optimal lot size for a semiconductor backend factory.
6. Optimization of cycle time and utilization in semiconductor test manufacturing.
7. Analysis of storage and retrieval strategies in a warehouse.
8. Investigation of dynamics in a service oriented supply chain.
9. Model for an Army chemical munitions disposal facility.
 Semiconductor Manufacturing
1. Comparison of dispatching rules using large-facility models.
2. The corrupting influence of variability.
3. A new lot-release rule for wafer fabs.
4. Assessment of potential gains in productivity due to proactive retied
management.
5. Comparison of a 200 mm and 300 mm X-ray lithography cell.
6. Capacity planning with time constraints between operations.
7. 300 mm logistic system risk reduction.
 Construction Engineering
1. Construction of a dam embankment.
2. Trench less renewal of underground urban infrastructures.
3. Activity scheduling in a dynamic, multiproject setting.
4. Investigation of the structural steel erection process.
5. Special purpose template for utility tunnel construction.
 Military Applications
1. Modeling leadership effects and recruit type in a Army recruiting station.
2. Design and test of an intelligent controller for autonomous underwater vehicles.
3. Modeling military requirements for non war fighting operations.
4. Multi trajectory performance for varying scenario sizes.
5. Using adaptive agents in U.S. Air Force retention.
 Logistics, Transportation and Distribution Applications
1. Evaluating the potential benefits of a rail-traffic planning algorithm.
2. Evaluating strategies to improve railroad performance.
3. Parametric Modeling in rail-capacity planning.

15
4. Analysis of passenger flows in an airport terminal.
5. Proactive flight-schedule evaluation.
6. Logistic issues in autonomous food production systems for extended duration
space exploration.
7. Sizing industrial rail-car fleets.
8. Production distribution in newspaper industry.
9. Design of a toll plaza
10.Choosing between rental-car locations.
11.Quick response replenishment.
 Business Process Simulation
1. Impact of connection bank redesign on airport gate assignment.
2. Product development program planning.
3. Reconciliation of business and system modeling.
4. Personal forecasting and strategic workforce planning.
 Human Systems
1. Modeling human performance in complex systems.
2. Studying the human element in out traffic control.

1.5.1 Need of studying models

• Model: Mathematical representation of the system


– Models are a fundamental tool of science, engineering, business, etc.
– Abstraction of reality
– Models always have limits of credibility
• A model construct a conceptual framework that describes a system
• The behavior of a system that evolves over time is studied by developing a simulation
model.
• A model can be used to investigate a wide verity of ―what if‖ questions about real-
world system.
• - Potential changes to the system can be simulated and predicate their impact on the
system.
• Find adequate parameters before implementation. So simulation can be used as -
Analysis tool for predicating the effect of changes
• Design tool to predicate the performance of new system

• It is better to do simulation before Implementation.

16
1.5.2 Type of Models

Physical : (Scale models, prototype plants,…)

Mathematical : (Analytical models, simulation)

Classification of simulation models

• Static vs. dynamic


• Deterministic vs. stochastic
• Continuous vs. discrete

Static vs. dynamic

A static simulation is one that is not based on time. It often involves drawing random samples
to generate a statistical outcome, so it is sometimes called Monte Carlo simulation.
Dynamic simulation includes the passage of time. It looks at state changes as they occur over
time. A clock mechanism moves forward in time and state variables are updated as time
advances. Dynamic simulation is well suited for analyzing manufacturing and service
systems since they operate over time.
Deterministic vs. stochastic
Simulations in which one or more input variables are random are referred to as stochastic or
probabilistic simulations. A stochastic simulation produces output that is itself random and
therefore gives only one data point of how the system might behave.
Simulations having no input components that are random are said to be deterministic.
Deterministic simulation models are built the same way as stochastic models except that they
contain no randomness. In a deterministic simulation, all future states are determined once
the input data and initial state have been defined.

Figure 1.2: Deterministic vs. stochastic Model

17
A discrete-event simulation is one in which state changes occur at discrete points in time as
triggered by events. State changes in a model occur when some event happens. State
variables in a discrete-event simulation are referred to as discrete change state variables. A
restaurant simulation is an example of a discrete-event simulation because all of the state
variables in the model, such as the number of customers in the restaurant, are discrete-change
state variables
In continuous simulation, state variables change continuously with respect to time and are
therefore referred to as continuous-change state variables. An example of a continuous-
change state variable is the level of oil in an oil tanker that is being either loaded or unloaded

Figure 1.3: Continuous vs. Discrete Model

Most operational models are dynamic, stochastic, and discrete – will be called discrete-event
simulation models

1.6 Principles and Nature of Computer Modeling and Simulation

• To study system, often make assumptions/approximations, both logical and


mathematical, about how it works. These assumptions form a model of the system
• If model structure is simple enough, could use mathematical methods to get exact
information on questions of interest — analytical solution

 New policies, operating procedures, information flows and so on can be explored


without disrupting ongoing operation of the real system.

18
 New hardware designs, physical layouts, transportation systems and … can be
tested without committing resources for their acquisition.
 Time can be compressed or expanded to allow for a speedup or slow-down of the
phenomenon (clock is self-control).
 Insight can be obtained about interaction of variables and important variables to
the performance.
 Bottleneck analysis can be performed to discover where work in process, the
system is delayed.
 A simulation study can help in understanding how the system operates.
 ―What if‖ questions can be answered.
 It permits controlled experimentation.
 It permits sensitivity analysis by manipulation of input variables.
 It causes no disturbance of the real system.
 It constitutes an effective training tool.

1.6.1 When to Use Simulation

a) If the experimentation on the real-world system is not feasible or not possible:

 Too expensive
 Too risky (atomic problems),
 Too complex,
 Not existing system,

b) Simulation is the best (may be the only) technique available under conditions of
uncertainty due to stochastic (random) variables, or nonlinearity. Mathematical treatment
of such systems is frequently not possible.

• Simulation enable the study of internal interaction of a subsystem with complex


system. Informational, organizational and environmental changes can be
simulated and find their effects.

• A simulation model helps us to gain knowledge about improvement of system.

• Finding important input parameters with changing simulation inputs.

• Simulation can be used with new design and policies before implementation.

19
• Simulating different capabilities for a machine can help determine the
requirement. Simulation models designed for training make learning possible
without the cost disruption

• A plan can be visualized with animated simulation

• The modern system (factory, wafer fabrication plant, service organization) is too
complex that its internal interaction can be treated only by simulation

1.6.2 Limitations of Simulation

 Model building requires special training.


 Simulation results can be difficult to interpret.
 Simulation modeling and analysis can be time consuming.
 Stochastic simulations produce only estimates
 Simulation models can be expensive to develop
 Simulations usually produce large volumes of output – need to summarize,
statistically analyze appropriately

20
2. Simulation Concepts
2.1 Concepts of Continuous /Discrete System Simulations
Continuous Systems
Systems in which the changes are predominantly smooth are called continuous system. Ex:
Head of a water behind a dam.

Figure 2.1: Continuous Systems Model

 State variables change continuously as a function of time


 Example: Airplane flight: State variables like position, velocity change
continuously
Discrete Systems
Systems in which the changes are predominantly discontinuous are called discrete systems.
Ex: Bank – the number of customers changes only when a customer arrives or when the
service provided a customer is completed.State variables change instantly at separated points
in time
Example: Bank model: State changes occur only when a customer arrives or departs

Figure 2.2: discrete-event simulation model

21
A discrete-event simulation is one in which state changes occur at discrete points in time as
triggered by events. Typical simulation events might include
• The arrival of an entity to a workstation.
• The failure of a resource.
• The completion of an activity.
• The end of a shift.
State changes in a model occur when some event happens. The state of the model becomes
the collective state of all the elements in the model at a particular point in time. State
variables in a discrete-event simulation are referred to as discrete change state variables.
A restaurant simulation is an example of a discrete-event simulation because all of the state
variables in the model, such as the number of customers in the restaurant, are discrete-change
state variables.
Most manufacturing and service systems are typically modeled using discrete event
simulation. In continuous simulation, state variables change continuously with respect to time
and are therefore referred to as continuous-change state variables. An example of a
continuous-change state variable is the level of oil in an oil tanker that is being either loaded
or unloaded, or the temperature of a building that is controlled by a heating and cooling
system.

Figure 2.3: continuous and discrete simulation


2.1.1 Differential Equations
Sometimes a continuous-change state variable can be modeled using difference equations. In
such instances, the time is decomposed into periods of length t. An algebraic expression is

22
then used to calculate the value of the state variable at the end of period k + 1 based on the
value of the state variable at the end of period k .
For example, the following difference equation might be used to express the rate of change in
the state variable V as a function of the current value of V, a rate of change ( r ), and the
length of the time period (t):

Batch processing in which fluids are pumped into and out of tanks can often be modeled
using difference equations.
Combined Continuous and Discrete Simulation
Many simulation software products provide both discrete-event and continuous simulation
capabilities. This enables systems that have both discrete-event and continuous characteristics
to be modeled, resulting in a hybrid simulation.
Most processing systems that have continuous-change state variables also have discrete-
change state variables. For example, a truck or tanker arrives at a fill station (a discrete event)
and begins filling a tank (a continuous process).
Basic interactions occur between discrete- and continuous-change variables:
1. A continuous variable value may suddenly increase or decrease as the result of a discrete
event (like the replenishment of inventory in an inventory model).
2. The initiation of a discrete event may occur as the result of reaching a threshold value in a
continuous variable (like reaching a reorder point in an inventory model).
3. The change rate of a continuous variable may be altered as the result of a discrete event (a
change in inventory usage rate as the result of a sudden change in demand).
2.1.2 System State Variables
The system state variables are a set of data, required to define the internal process within the
system at a given point of time.

 In a discrete-event model, the system state variables remain constant over intervals
of time and the values change at defined points called event times.

 In continuous-event model, the system state variables are defined by differential


equation results whose value changes continuously over time.

Following are some of the system state variables −

23
 Entities & Attributes − An entity represents an object whose value can be static or
dynamic, depending upon the process with other entities. Attributes are the local
values used by the entity.
 Resources − A resource is an entity that provides service to one or more dynamic
entities at a time. The dynamic entity can request one or more units of a resource; if
accepted then the entity can use the resource and release when completed. If rejected,
the entity can join a queue.
 Lists − Lists are used to represent the queues used by the entities and resources.
There are various possibilities of queues such as LIFO, FIFO, etc. depending upon
the process.
 Delay − It is an indefinite duration that is caused by some combination of system
conditions.

Example: Single-server queue

o State variables

 Status of server (idle, busy) – needed to decide what to do with an


arrival

 Current length of the queue – to know where to store an arrival that


must wait in line

 Time of arrival of each customer now in queue – needed to compute


time in queue when service starts

o Events

 Arrival of a new customer

 Service completion (and departure) of a customer

 Maybe – end-simulation event (a ―fake‖ event) – whether this is an


event depends on how simulation terminates (a modeling decision)

2.2 Numerical Integration VS Continuous Simulation


Definition
Numerical integration, also known as numerical quadrature, is the process of using
sample points (discrete points) to approximate the value of an integral.

24
 Numerical integration encompasses a broad range of techniques that replace algebraic
integration with simulation.
 There are two main reasons to do numerical integration: analytical integration may be
impossible or infeasible, or may wish to integrate tabulated data rather than known
functions.
 Numerical integration is the approximate computation of an integral using numerical
techniques. The numerical computation of an integral is sometimes called quadrature,
the word "quadrature" to mean numerical computation of a univariate integral, and
"cubature" to mean numerical computation of a multiple integral.
 The most straightforward numerical integration technique uses the Newton-Cotes
formulas (also called quadrature formulas), which approximate a function tabulated at
a sequence of regularly spaced intervals.
 If the endpoints are tabulated then the Boole's rule or trapezoidal rule can yield
accurate results for many fewer function evaluations.
 If the functions are known analytically instead of being tabulated at equally spaced
intervals, the best numerical method of integration is called Gaussian quadrature.
2.2.1 Numerical Computation Technique for Continuous Models
To illustrate the general numerical technique of simulation based on a continuous model,
consider the following example. A builder observes that the rate at which he can sell houses
depends directly upon the number of families who do not yet have a house. As the number of
people without houses diminishes, the rate at which he sells house drops. Let Hbe the
potential number of households, andybe the number of families with houses. The situation is
represented in Fig. 1. Sale of houses and air conditioners

Figure 2.4: Sale of houses and air conditioners

25
The horizontal line at H is the total market for houses. The curve for y indicates how
the number of houses sold increases with time. The slope of the curve (i.e., the rate at which
y increases) decreases as H-y gets less. This reflects the slowdown of sales as the market
becomes saturated. Mathematically, the trend can be expressed by the equation

y. = k1 (H-y), y=0 at t=0

Consider now a manufacturer of central air conditioners designed for houses. His rate
of sales depends upon the number of houses build. (For simplicity, it is assumed that all
houses will install an air conditioner.) As with house sales, the rate of sales diminishes as the
unfilled market diminishes.
Let s be the number of installed air conditioners. Then the unfilled market is the
difference between the number of houses and the number of installed air conditioners. The
sales trend may be expressed mathematically by the equation

x. = k2 (y-x), x=0 at t=0

The change of s with time is also illustrated in Fig. 2. The two equation constitute a mode of
the growth of air conditioner sales. Because of its simplicity, it is in fact possible to solve the
method analytically. However, it quickly becomes insoluble if it is expanded to become more
representative of actual marketing conditions. The market limit, for example, may not be
stable. It could grow with population growth or fluctuate with economic conditions. The
coefficients that determine the rates of growth could be influences by the amount of money
spent on advertising, and there could be competitive influences, such as mobile homes or
apartment housing. These influences could also depend upon the population growth or
prevailing economic condition, and so further complicate the model.

The simple model, however, will serve to illustrate the general methods applied in
suppose that the computation is made at uniform intervals of time and that the calculation has
already progressed to the time ti when the two variables of the problem have the values yi and
s i . Figure 2.5 shows the next step in the calculation.

26
Figure 2.5: calculations for air-conditioners sales model

The calculation steps forward an interval ∆t to ti+1 = ti + ∆t. The rates of sales are
assumed to be constant over the interval. The rates can be interpreted as the amount of
change per unit time. That is,

Since yi and xi are known, it is a simple matter to get the values of y and x at time t i+1 .
However, it will be noticed that the equation for ∆yi must be solved first to get the value of yi
needed in the equation for xi . In preparation for the solution of a continuous system model,
therefore, there must be a careful sorting of the equations to establish a workable order.

Repetition of the calculation using the new values of y and x produces the output at
the end of the next interval. As illustrated in Fig.2, the calculation is equivalent to calculation
the slope at each point and projecting a short straight line at that slope. The simulation output

27
is a series of such line segments, approximating the continuous curve that represents the true
output of the model.

The method described is a very simple way of integrating differential equations


numerically, but it is not a very accurate method, unless small steps are used, compared with
the rate at which the variables change. There are other much more accurate, and often more
efficient, ways of integrating numerically which do not rely simply upon the last-known
value of the variables. Rather, they use several previous values to predict the rate at which the
variables are changing. (Special methods are used to supply initial values to start the
process.) In addition, the computation interval is often adjusted in size to match the rate at
which the variables are changing.

There are many programming systems available that incorporate continuous system
simulation languages. They usually include a number of computational methods for the user‘s
selection.
Table 2.1:NCT for Discrete Models

Do Document Start Work Finish Cumulative Break Pending


No. Time(Tw) Time(Tc) Flag(Y/N)
Time(Ts) Time(Tf) Jobs(N)

1 0 45 45 45 N 57

2 45 16 61 61 Y 56

3 66 5 71 5 N 55

4 71 29 100 34 N 54

5 100 33 133 67 Y 53

6 138 25 163 25 N 52

7 163 21 184 46 N 51

NOTE :-Tf = Ts + Tw, Tc= Tc + Tw

28
Consider the above example, a clerk begins his days of works with a file of document
to be processed. The time taken to process them varies. He works through the file beginning
each document, as soon as he finishes the previous one except that he takes that 5min break if
at that time, he finishes a document is an hour or more, since he begins work or he left a
break. We assume that the time to process the documents are given. We will keep a count of
no. of documents left for processing. This count will be initially set to the no. of document at
the beginning of the day and we assume that no. of document arrive during the day. The
count will be decremented for each completed job and the work will stop when count goes to
zero.

The first column numbers the documents, the second column gives the time the clerk
begins to work for a document denoted by (Ts), the third column give the time required to
work on the document called as the work time(Tw), the fourth column gives the time at
which the document is finished processing in time (Tf), the fifth column contains the
cumulative time since work started on since the last break measured at the time each job is
completed (Tc), the sixth column contains the break flag, this take the value ‗Y‘ ,if the clerk
should take a break after the ith document and the value ‗N‘ if he should not. The clerk works
until there are no more documents to be processed. On the time he finishes the document
goes beyond some prescribed time limit representing the end of the working period. The
computation proceeds row by row and from left to right.

2.2.2 Progress of simulation study

An initial state is to describe the problem to be solved in a concise manner so that


there is a clear statement of what question are being asked and what measurements need to be
taken in order to answer those question. Based on this problem definition a model must be
defined. A possible solution is to explore to pass the model that can be solved analytically.
The result will help to guide the simulation technique. When it is decided to simulate, we
must plan the study by deciding upon the major parameters to be varied, the no. of cases to be
conducted and order in which runs are to be made.

29
Figure 2.6: Progress of simulation study

Given that, the simulation is to be on a digital computer and its program must be
written. The next stage is, executing a series of runs according to the study plan. The main
value of the early runs in a simulation study is to get insight in to general behaviour of the
system and to know which parameters are important for the system. This may lead to
reassessment of the model then results are verified and if found reasonable, simulation stops.

Given that, the simulation is to be on a digital computer and its program must be
written. The next stage is, executing a series of runs according to the study plan. The main
value of the early runs in a simulation study is to get insight in to general behaviour of the

30
system and to know which parameters are important for the system. This may lead to
reassessment of the model then results are verified and if found reasonable, simulation stops.

Figure2.7: Re-assessment of the model

31
An initial state to describe the problem to be solved in a concise manner so that there is a
clear statement of what questions to be asked and what measurements needed to be taken answer
these questions. Based on these problem definition a problem must be defines. A possible part
explore the cost of a model that can be solved analytically the results in guiding the simulation
study. When it is decided to simulate we must plan the study by deciding upon the measure
parameter to be varied the number of cases to be conducted and the order in which runs at to be
made. Given that the simulation is to be on a digital computer a program must be written. The
next stage is executing runs to be study plans. The main value of the early runs in a simulation
study is to get inside into the general behaviour of the system and to know which Parameters are
important for the system. This may lead to re-assessment of the model, when results are verified
and it found reasonable the simulation will be stopped.
2.3 Analog vs. Digital Simulation
2.3.1 Analog Simulation
 Simulating the behavior of circuits before actually building it, can greatly improve design
efficiency by making insights into behavior of electronic circuit design.
 The goal of analog simulation is to calculate a circuit‘s voltage and current.
 The representation of physical systems and phenomenon by variables such as translation,
rotation, resistance, and voltage.
 Analog Simulation is a way of emulating the output of digital audio through an analog
system. This way, audio's "real-life" output can be simulated.
 This can be very useful in finding the real output values of an electronic device or circuit.
The analog simulation circuit will be the difference amplifier from the difference amplifier
lab. Before the lab prepare a table of the measured and calculated DC node voltages, the sum
and difference gains, CMRR, and the amplifier high and low roll-off frequencies. You should
have almost all this information in your laboratory notebook. The simulated circuit should
have the same component values used in the lab circuit. The results of the simulation should
then be entered as a separate column in your table.
1. Simulate the difference amplifier circuit using the circuit you built for the Difference
Amplifier lab. The component values should be identical to those used in the lab. We use
the Electronics Workbench application.
2. The first step is to make a schematic diagram.

32
3. Perform a DC analysis. Check the results agains the expected values.
4. Perform a Transient analysis for 5 cycles and compute the difference and common
mode gains. Use the same frequency as you used in the lab. Use the Analysis Graphs
window to print out the desired waveforms.
5. Perform a frequency analysis and determine the low and high rolloff frequencies. Print
out the Bode plot using the Analysis Graphs window.
6. Present the results as a three column table: theory, measurement, and simulation for the
requested quantities. Most people did not measure the frequency dependence in lab, but
you should be able to calculate the roll-off frequencies.
7. The final results will include the table, a copy of the circuit diagram, waveforms, and
your explanations as to why the simulation might be giving different results from theory
and measurement .
2.3.2 Digital Simulation

 The representation of a system in a form acceptable to a digital computer as opposed to


an analog computer.
 It is a method of investigating real phenomena, processes, devices, or systems that is
based on the study of mathematical models with the aid of digital computers.
 The program executed by the computer is also a kind of model of the subject of the
investigation. Special problem-oriented simulation languages are used in digital
simulation. Example: CSMP, SIMSCRIPT, GPSS, SIMULA etc.,

33
Table 2.2: Comparison of Analog and Digital Simulation

2.4 Hybrid Simulation

The definition of hybrid simulation is ―the process of model development and simulation that
uses more than one simulation method in order to enrich the model.‖

A hybrid simulation model is a simulation model that is formed from at least two different
simulation modeling methods, e.g. discrete-event simulation (DES), system dynamics (SD) and
Continuous Simulation.

Benefits of Hybrid simulation

 One of the key benefits of combining different simulation methods is the potential to
combine the benefits and virtues of each method

34
 Hybrid simulation model can capture both the continuous and discrete elements present
in the real world system that is being modeled
 Hybrid simulation is useful when there is a need to achieve a complete representation of
the real world problem (after the model conceptualization process) that is not possible
with only one simulation method.
 Hybrid model will provide more accuracy in the problem representation and solution.
 Hybrid models may integrate more stakeholders into the implementation of model
solutions since hybrid models can address multi- level issues.

2.5 Markov Chains

A Markov chain is "a stochastic model describing a sequence of possible events in which the
probability of each event depends only on the state attained in the previous event."

A process satisfies the Markov property then predictions can be made for the future of the
process based solely on its present state.

• Markov Property: The state of the system at time t+1 depends only on the state of the
system at time t

Pr  X t 1
 x t 1 | X t
 xt 

X1 X X X X

Markov Process

Example 1:
Coke vs. Pepsi Example

• Given that a person‘s last cola purchase was Coke, there is a 90% chance that his next
cola purchase will also be Coke.

• If a person‘s last cola purchase was Pepsi, there is an 80% chance that his next cola
purchase will also be Pepsi.

35
Transition matrix:

0.9 0.1
 0 .9 0 .1  0.8
P   
 0 .2 0 .8 
coke peps
i
Example 2:
0.2
Suppose that an orange juice
company controls 20% of the Orange juice market. Suppose they hire a market research
company to predict the effects on an aggressive advertisement campaign. Suppose they calculate.

Someone using brand A will stay with Brand A with 90 % Probability

Someone NOT using brand A will switch to brand A with 70 % probability

Question: If the probabilities in P remain valid over a long time what happens to the company‘s
market share?

Solution:

Assume users Buy OJ once in a week

A = uses Brand A; A‘ = uses other brand

Transition Diagram

0.9 0.1
0.3

A A’

0.7 36
Transition Probability Matrix
 0 .9 0 .1
P   
 0 .7 0 .3 

Initial State Distribution Matrix


S0 = [.2 .8]
Probability uses brand A after 1 week

 0 .9 0 .1 
S0 . P = [.2 .8]  
 0 .7 0 .3 

= [(.2)(.9) + (.8)(.7) , (.2)(.1)(.8)(.3)]


= [(.18 + .56) = .74; (.2 + .24) = .26];
S1 = [.74 .26]
= [.74 .26] = S1 = First Sate Matrix
The Market share of product A after one Week will be 0.74
 0 .9 0 .1 
S2 = [.74 .26]  
 0 .7 0 .3 

[(.74)(.9) + (.26)(.7) ; (.74)(.1) + (.26)(.3)]


S2 = [.848 .152]
The Market share of product A after two Weeks will be increased to 0.848
 0 .9 0 .1 
S3 = [.848 .152]  
 0 .7 0 .3 

[(.848)(.9) + (.152)(.7) , (.848)(.1) + (.152)(.3)]


S3 = [.8696 .1304]
The Market share of product A increases every Week

2.6 Generation of Random Numbers

Random numbers are a necessary basic ingredient in the simulation of almost all discrete
systems. Most computer languages have a subroutine, object, or function that will generate a
random number. Similarly simulation languages generate random numbers that are used to
generate event limes and other random variables.

37
Properties of Random Numbers
A sequence of random numbers, R1; R2; _ _ _, must have two important statistical properties
 Uniformity
 Independence.
Uniformity states the random numbers are equally probable in any interval of the uniform
distribution x-axis.
Independence states that the current value of a random variable has no relation with the previous
values. Combining these two properties, we say that each random number Ri, is an independent
sample drawn from a continuous uniform distribution between 0 and 1.That is, the pdf is given as

Important considerations in RN Generations:


 Fast
 Portable to different computers
 Replicable
 The ideal properties of uniformity and independence.

38
2.7 Generation of Pseudo-Random Numbers
Pseudo means false, so false random numbers are being generated. The goal of any generation
scheme, is to produce a sequence of numbers between zero and 1 which simulates, or initates, the
ideal properties of uniform distribution and independence as closely as possible. When
generating pseudo-random numbers, certain problems or errors can occur. These errors, or
departures from ideal randomness, are all related to the properties stated previously.
Some examples include the following
1. The generated numbers may not be uniformly distributed.
2. The generated numbers may be discrete -valued instead continuous valued
3. The mean of the generated numbers may be too high or too low.
4. The variance of the generated numbers may be too high or low
5. There may be dependence. The following are examples:
(a) Autocorrelation between numbers.
(b) Numbers successively higher or lower than adjacent numbers.
(c) Several numbers above the mean followed by several numbers below the mean.
Usually, random numbers are generated by a digital computer as part of the simulation.
Numerous methods can be used to generate the values. In selecting among these methods, or
routines, there are a number of important considerations.
1. The routine should be fast. . The total cost can be managed by selecting a computationally
efficient method of random-number generation.
2. The routine should be portable to different computers, and ideally to different programming
languages .This is desirable so that the simulation program produces the same results wherever it
is executed.
3. The routine should have a sufficiently long cycle. The cycle length, or period, represents the
length of the random-number sequence before previous numbers begin to repeat themselves in an
earlier order. Thus, if 10,000 events are to be generated, the period should be many times that
long, A special case cycling is degenerating. A routine degenerates when the same random
numbers appear repeatedly. Such an occurrence is certainly unacceptable. This can happen
rapidly with some methods.
4. The random numbers should be replicable. Given the starting point (or conditions), it should
be possible to generate the same set of random numbers, completely independent of the system

39
that is being simulated. This is helpful for debugging purpose and is a means of facilitating
comparisons between systems.
5. Most important, and as indicated previously, the generated random numbers should closely
approximate the ideal statistical properties of uniformity and independences
2.7.1 Linear Congruential Method
The linear congruential method, initially proposed by Lehmer [1951], produces a sequence of
integers, X\, X2,... between zero and m — 1 according to the following recursive relationship:

Xi+1 = (aXi + c) mod m, i = 0,1,2…


Where,
a: constant multiplier
c: increment
m: modulus
The initial value X0 is called the seed.

when c  0 then the form is called the Mixed Congruential method:

Xi+1 = (aXi + c) mod m, i = 0,1,2…

when c = 0 then the form is called the Multiplicative Congruential method:

Xi+1 = aXi mod m, i = 0,1,2…


The random integers are being generated [0,m-1], and to convert the integers to random
numbers:

The selection of the values for a, c, m and X0 drastically affects the statistical properties and the
cycle length

40
Example 1:

X0 = 27

X1 = (17*27 + 43) mod 100


= (459 + 43) mod 100
= 502 mod 100 ;( when 500 is divided by 100 the remainder is 2)
=2
R1 = 2/100 = 0.02

X2 = (17*2 + 43 ) mod 100


= (34 + 43) mod 100
= 77 mod 100 = 77
R2 = 77/100 = 0.77

X3 = (17*77+ 43) mod 100 = 1352 mod 100 = 52


= (1309 + 43) mod 100
= 1352 mod 100 = 52
R3 = 52 ⁄100=0. 52
……

First, notice that the numbers generated from Equation (7.2) can only assume values from the set
I = {0,1 /m, 2/m,..., (m — l)/m), since each Xi is an integer in the set {0,1,2,..., m — 1}.
Thus, each Ri is discrete on I, instead of continuous on the interval [0, 1], This approximation
appears to be of little consequence, provided that the modulus m is a very large integer. (Values
such as m = 231 — 1 and m = 248 are in common use in generators appearing in many
simulation languages.) By maximum density is meant that the values assumed by Ri = 1, 2,...,
leave no large
gaps on [0,1]
Second, to help achieve maximum density, and to avoid cycling (i.e., recurrence of the same
sequence of generated numbers) in practical applications, the generator should have the largest
possible period. Maximal period can be achieved by the proper choice of a, c, m, and X0 .

41
• For m a power of 2, say m =2b and c _ 0, the longest possible period is P = m = 2b, which is
achieved provided that c is relatively prime to m (that is, the greatest common factor of c and m i
s l ), and =a = l+4k, where k is an integer.
• For m a power of 2, say m =2b and c = 0, the longest possible period is P = m⁄4 = 2b-2, which
is achieved provided that the seed X0 is odd and the multiplier ,a, is given by a=3+8K , for some
K=0,1,..
• For m a prime number and c=0, the longest possible period is P=m-1, which is achieved
provided that the multiplier , a, has the property that the smallest integer k such that a k- 1is
divisible by m is k= m-1.
EXAMPLE 2
Let m = 102 = 100, a = 19, c = 0, and X0 = 63, and generate a sequence c random integers using
Equation (7.1).
X0 = 63
X1 = (19)(63) mod 100 = 1197 mod 100 = 97
X2 = (19) (97) mod 100 = 1843 mod 100 = 43
X3 = (19) (43) mod 100 = 817 mod 100 = 17
.
.
.
.
When m is a power of 10, say m = 10b , the modulo operation is accomplished by saving
the b rightmost (decimal) digits.
2.7.2 Combined Linear Congruential Generators
As computing power has increased, the complexity of the systems that we are able to simulate
has also increased. One fruitful approach is to combine two or more multiplicative congruen-tial
generators in such a way that the combined generator has good statistical properties and a longer
period. The following result from L'Ecuyer [1988] suggests how this can be done:
If Wi, 1 , Wi , 2. . . , W i,k are any independent, discrete-valued random variables (not
necessarily identically distributed), but one of them, say Wi, 1, is uniformly distributed on the
integers 0 to mi — 2, then is uniformly distributed on the integers 0 to mi — 2.

42
To see how this result can be used to form combined generators, let Xi,1, X i,2,..., X i,k be the i
th output from k different multiplicative congru-ential generators, where the j th generator has
prime modulus mj, and the multiplier aj is chosen so that the period is mj — 1. Then the j'th
generator is producing integers Xi,j that are approximately uniformly distributed on 1 to mj - 1,
and Wi,j = X i,j — 1 is approximately uniformly distributed on 0 to mj - 2. L'Ecuyer [1988]
therefore suggests combined generators of the form

2.7.3 Tests for Random Numbers


The desirable properties of random numbers — uniformity and independence To insure that
these desirable properties are achieved, a number of tests can be performed. The first entry in the
list below concerns testing for uniformity. The second through fifth entries concern testing for
independence. The five types of tests are:
 Frequency tests
 Runs test
 Autocorrelation test
 Gap test
 Poker test

43
1. Frequency test Uses the Kolmogorov-Smirnov or the chi- square test to compare the
distribution of the set of numbers generated to a uniform distribution.
2. Runs test. Tests the runs up and down or the runs above, and below the mean by comparing
the actual values to expected values. The statistic for comparison is the chi-square.
3.Autocorrelation test Tests the correlation between numbers and compares the sample
correlation to the expected correlation of zero.
4. Gap test. Counts the number of digits that appear between repetitions of particular digit and
then uses the Kolmogorov-Smirnov test to compare with the expected size of gaps.
5 Poker test . Treats numbers grouped together as a poker hand. Then the hands obtained are
compared to what is expected using the chi-square test.
In testing for uniformity, the hypotheses are as follows:
 H0 : Ri ~ U/[0,1]
 H1 : Ri ~U/[0,l]
The null hypothesis, H0 reads that the numbers are distributed uniformly on the interval [0,1].
Failure to reject the null hypothesis means that no evidence of nonuniformity has been detected
on the basis of this test. This does not imply that further testing of the generator for uniformity is
unnecessary.
In testing for independence, the hypotheses are as follows:
H0 :Ri ~ independently
H1 :Ri~independently
This null hypothesis H0 reads that the numbers are independent. Failure to reject the null
hypothesis means that no evidence of dependence has been detected on the basis of this test.
This does not imply that further testing of the generator for independence is unnecessary. For
each test, a level of significance a must be stated. The level a is the probability of rejecting the
null hypothesis given that the null hypothesis is true, or
a = P (reject H0 |H0 true)
The decision maker sets the value of & for any test. Frequently, a is set to 0.01 or 0.05.
If several tests are conducted on the same set of numbers, the probability of rejecting the null
hypothesis on at least one test, by chance alone [i.e., making a Type I (a) error], increases. Say
that a= 0.05 and that five different tests are conducted on a sequence of numbers. The probability
of rejecting the null hypothesis on at least one test, by chance alone, may be as large as 0.25.

44
1. Frequency Tests
A basic test that should always be performed to validate a new generator is the test of uniformity.
Two different methods of testing are available. They are the Kolmogorov-Smirnov and the chi-
square test. Both of these tests measure the degree of agreement between the distribution of a
sample of generated random numbers and the theoretical uniform distribution. Both tests are
based on the null hypothesis of no significant difference between the sample distribution and the
theoretical distribution.
1. The Kolmogorov-Smirnov test. This test compares the continuous cdf, F(X), of the uniform
distribution to the empirical cdf, SN(x), of the sample of N observations. By definition,
F(x) = x, 0 <= x <= 1
If the sample from the random-number generator is R1 R2, ,• • •, RN, then the empirical cdf, SN (X),
is defined by
SN (X) = number of R1 R2, ,• • •, Rn which are <= x / N
As N becomes larger, SN (X) should become a better approximation to F(X) , provided that the
null hypothesis is true.
The Kolmogorov-Smirnov test is based on the largest absolute deviation between F(x) and
SN (X) over the range of the random variable. That is.it is based on the statistic
D = max | F(x) - SN(x)|
For testing against a uniform cdf, the test procedure follows these steps:
Step 1. Rank the data from smallest to largest. Let R(i) denote the i th smallest observation, so
that
R (1) <= R (2) <= • • • <= R (N)
Step 2. Compute

D+ = max { i/N - R (i) }

1 <=i<=N

D- = max { i/N - R (i) }

1 <=i<=N

Step3. Compute D = max(D+, D-).


Step 4. Determine the critical value, Da, from Table A.8 for the specified significance level a and
the given sample size N.

45
Step 5. If the sample statistic D is greater than the critical value, Da, the null hypothesis that the
data are a sample from a uniform distribution is rejected.
If D <= Da, conclude that no difference has been detected between the true distribution of { R1 R2,
,• • •, Rn } and the uniform distribution.
2.Runs Tests
1. Runs up and runs down. Consider a generator that provided a set of 40 numbers in the
following sequence:
0.08 0.09 0.23 0.29 0.42 0.55 0.58 0.72 0.89 0.91
0.11 0.16 0.18 0.31 0.41 0.53 0.71 0.73 0.74 0.84
0.02 0.09 0.30 0.32 0.45 0.47 0.69 0.74 0.91 0.95
0.12 0.13 0.29 0.36 0.38 0.54 0.68 0.86 0.88 0.91
Both the Kolmogorov-Smirnov test and the chi-square test would indicate that the numbers are
uniformly distributed. However, a glance at the ordering shows that the numbers are successively
larger in blocks of 10 values. If these numbers are rearranged as follows, there is far less reason
to doubt their independence
0.41 0.68 0.89 0.84 0.74 0.91 0.55 0.71 0.36 0.30
0.09 0.72 0.86 0.08 0.54 0.02 0.11 0.29 0.16 0.18
0.88 0.91 0.95 0.69 0.09 0.38 0.23 0.32 0.91 0.53
0.31 0.42 0.73 0.12 0.74 0.45 0.13 0.47 0.58 0.29
The runs test examines the arrangement of numbers in a sequence to test the hypothesis of
independence. Before defining a run, a look at a sequence of coin tosses will help with some
terminology.
Consider the following sequence generated by tossing a coin 10 times:
HTTHH TTTHT
There are three mutually exclusive outcomes, or events, with respect to the sequence. Two of the
possibilities are rather obvious. That is, the toss can result in a head or a tail. The third possibility
is "no event." The first head is preceded by no event and the last tail is succeeded by no event.
Every sequence begins and ends with no event.
A run is defined as a succession of similar events preceded and followed by a different event.
The length of the run is the number of events that occur in the run. In the coin-flipping example
above there are six runs. The first run is of length one, the second and third of length two, the
fourth of length three. and the fifth and sixth of length one.

46
There are two possible concerns in a runs test for a sequence of number The number of runs is
the first concern and the length of runs is a second concern. The types of runs counted in the first
case might be runs up and runs down. An up run is a sequence of numbers each of which is
succeeded by a larger number. Similarly, a down run is a sequence of numbers each of which is
succeeded by a smaller number. To illustrate the concept, consider the following sequence of 15
numbers:
-0.87 +0.15 +0.23 + 0.45 -0.69 -0.32 -0.30 +0.19 -.24 +0.18 +0.65 +0.82 -0.93 +0.22 0.81
The numbers are given a " + " or a " — " depending on whether they are followed by a larger
number or a smaller number. Since there are 15 numbers, and they are all different, there will be
14 +'s and — 's. The last number is followed by "no event" and hence will get neither a + nor a
— . The sequence of 14 +s and — 's is as follows: - + + + - - - + - + + - +
Each succession of + 's and — 's forms a run. There are eight runs. The first run is of length one.
the second and third are of length three, and so on. Further, there are four runs up and four runs
down. There can be too few runs or too many runs. Consider the following sequence of numbers:
0.08 0.18 0.23 0.36 0.42 0.55 0.63 0.72 0.89 0.91
This sequence has one run, a run up. It is unlikely that a valid random-number generator would
produce such a sequence. Next, consider the following sequence
0,08 0.93 0.15 0.96 0.26 0.84 0.28 0.79 0.36 0.57
This sequence has nine runs, five up and four down. It is unlikely that a sequence of l0 numbers
would have this many runs. What is more likely is that the number of runs will be somewhere
between the two extremes. These two extremes can be formalized as follows: if N is the number
of numbers in a sequence, the maximum number of runs is N — I and the minimum number of
runs is one.
If a is the total number of runs in a truly random sequence, the mean and variance of a are given
by μa = 2N – 1 / 3
And σ a2 = 16N – 29 / 90
For N > 20, the distribution of a is reasonably approximated by a normal distribution, N( μa , σ a2 )

This approximation can be used to test the independence of numbers from a generator. In that
case the standardized normal test statistic is developed by subtracting the mean from the
observed number of runs, a , and dividing by the standard deviation. That is, the test statistic is
Z0 = a - μa / σa
Substituting Equation for μa and the square root of Equation for σa yields
47
Z0 = a - [( 2N - 1)/3] / sqrt((16N – 29) / 90 )
where Zo ~ N(0 1). Failure to reject the hypothesis of independence occur when — za / 2 <=
Zo <= za / 2 where a is the level of significance.
Runs above and below the mean. The test for runs up and runs down is not completely
adequate to assess the independence of a group of numbers.
Consider the following 40 numbers:
0.63 0.72 0.79 0.81 0.52 0.94 0.8.1 0.93 0.87 0.67
0.54 0.83 0.89 0.55 0.88 0.77 0.74 0.95 0.82 0.86
0.43 0.32 0.36 0.18 0.08 0.19 0.18 0.27 0.36 0.34
0.31 0.45 0.49 0.43 0.46 0.35 0.25 0.39 0.47 0.41
The sequence of runs up and runs down is as follows:
+++-+-+---++-+--+-+--+--+-++--++-+--++-
This sequence is exactly the same as that in Example 7.8. Thus, the numbers would pass the
runs-up and runs-down test. However, it can be observed that the first 20 numbers are all above
the mean [(0.99 + O.OO)/2 = 0.495] and the last 20 numbers are all below the mean.
Such an occurrence is highly unlikely. The previous runs analysis can be used to test for this
condition, if the definition of a run is changed. Runs will be described as being above the mean
or below the mean. A " + " sign will be used to denote an observation above the mean, and a "-"
sign will denote an observation below the mean.
For example, consider the following sequence of 20 two-digit random numbers;
0.40 0.84 0.75 0.18 0.13 0.92 0.57 0.77 0.30 0.71
0.42 0.05 0.78 0.74 0.68 0.03 0.18 0.51 0.10 0.37
The pluses and minuses are as follows :
-++--+++-+--+++--+--
In this case, there is a run of length one below the mean followed by a run of length two above
the mean, and so on. In all. there are 11 runs, five of which are above the mean and six of which
are below the mean. Let n1 and n2 be the number of individual observations above and below the
mean and let b be the total number of runs. Notice that the maximum number of runs is N = n1 +
n2 and the minimum number of runs is one.
Given n1 and n2 . the mean — with a continuity correction suggested by Swed and Eisenhart
[1943] —and the variance of b for a truly independent sequence are given by
μb =2 n1 n2 / N +1/2 and σb2 =2n1 n2 (2n1 n2 -N) / N 2 (N – 1)
48
For either n1 or n2 greater than 20, b is approximately normally distributed. The test statistic can
be formed by subtracting the mean from the number of runs and dividing by the standard
deviation, or Z0 = (b-(2n1 n2 /N)-1/2) / [2n1 n2 (2n1 n2 -N/N 2 (N-1)] 1/2
Failure to reject the hypothesis of independence occurs when —za/2 <= Z0 < =za/2-, where a is
the level of significance.
EXAMPLE
Determine whether there is an excessive number of runs above or below the mean for the
sequence of numbers given in Example 7.8. The assignment of + 's and — 's results in the
following:
-+++++++---++-+-------++
----++--+-+--++-
The values of n1 ,n2 , and b are as follows:
n1 = 18
n2 = 22
N = n1 +n2 = 40
b = 17
Equations (7.6) and (7.7) are used to determine μb and σb
2 as follows:
μb = 2(18)(22)/40 + 1/2 = 20.3
σb2 = 2(18)(22)[(2)(18)(22)-40] /(40)2 (40-1)=9.54
Since n2 is greater than 20, the normal approximation is acceptable, resulting in a Z0 value of
Z0 = 17-20.3/√9.54 = -1.07
Since Z0.025 = 1.96 the hypothesis of independence cannot be rejected on the basis of this test
Runs test: length of runs. Yet another concern is the length of runs. As an example of what
might occur, consider the following sequence of numbers
0.16, 0.27, 0.58, 0.63, 0.45, 0.21, 0.72, 0.87, 0.27, 0.15, 0.92, 0.85,...
Assume that this sequence continues in a like fashion: two numbers below the mean followed by
two numbers above the mean. A test of runs above and below the mean would detect no
departure from independence. However, it is to be expected that runs other than of length two
should occur.

49
Let Y, be the number of runs of length i in a sequence of N numbers. For an independent
sequence, the expected value of Yj for runs up and down is given by
E(Yi) = 2/(i+3)! [ N(i2 +3i+1)-(i3 +3i2 -i-4) ] ,i <= N - 2
E(Yi) =2/N! i = N – 1
For runs above and below the mean, the expected value of y, is approximately given by
E(Yi) = N w i / E(I ), N>20
where w i the approximate probability that a run has length i, is given by
w i =( n1 /N)I (n2 /N) + (n1 /N)(n2 /N)I N>20
and where E(I ) , the approximate expected length of a run, is given by
E(I )= n1 / n2 + n2 / n1 N>20
The approximate expected total number of runs (of all lengths) in a sequence of length N,
E(A), is given by
E(A)=N/ E(I) N>20
The appropriate test is the chi-square test with Oi, being the observed number of runs of length
i. Then the test statistic is
X02 =Σi=1L [ Oi - E(Yi)2 ] / E(Yi)
where L = N - 1 for runs up and down and L = N for runs above and below the mean. If the null
hypothesis of independence is true, then X02 is approximately chi-square distributed with L — 1
degrees of freedom.
3. Tests for Autocorrelation
The tests for autocorrelation are concerned with the dependence between numbers in a sequence.
As an example, consider the following sequence of numbers:
0.12 0.01 0.23 0.28 0.89 0.31 0.64 0.28 0.83 0.93
0.99 0.15 0.33 0.35 0.91 0.41 0.60 0.27 0.75 0.88
0.68 0.49 0.05 0.43 0.95 0.58 0.19 0.36 0.69 0.87
From a visual inspection, these numbers appear random, and they would probably pass all the
tests presented to this point. However, an examination of the 5th, 10th, 15th (every five numbers
beginning with the fifth), and so on. indicates a very large number in that position. Now, 30
numbers is a rather small sample size to reject a random-number generator, but the notion is that
numbers in the sequence might be related. In this particular section, a method for determining
whether such a relationship exists is described. The relationship would not have to be all high

50
numbers. It is possible to have all low numbers in the locations being examined, or the numbers
may alternately shift from very high to very low.
The test to be described below requires the computation of the autocorrelation between every m
numbers (m is also known as the lag) starting with the ith number. Thus, the autocorrelation p,m
between the following numbers would be of interest: /?,-, Rj+m, Ri+2m,, Ri+(M+\)m- The value
M is the largest integer such that / + (M + l)m < N, where N is the total number of values in the
sequence. (Thus, a subsequence of length M + 2 is being tested.)
Since a nonzero autocorrelation implies a lack of independence, the following two tailed test is
appropriate:

H0 : ρim= 0

Hi: ρim ≠ 0

For large values of M, the distribution of the estimator of ρim denoted ρ^im is approximately

normal if the values Ri, Ri+m, Ri+2m ,…….Ri+(M+1)m are un-correlated. Then the test statistic can be
formed as follows:

Z0 = ρ^im / σ ρ^im

which is distributed normally with a mean of zero and a variance of 1, under the assumption of
independence, for large M.

The formula for ρ^im in a slightly different form, and the standard deviation of the estimator, σ

ρ^im are given by Schmidt and Taylor [1970] as follows:

ρ^im = 1/ M +1[ ΣM
k=0 Ri +km Ri+(k+1)m ] - 0.25
and σ ρ^im = √ (13M + 7) / 12(M +1)
After computing Z0 , do not reject the null hypothesis of independence if - za/2 <= Z0 <=za/2,
where a is the level of significance

If ρim > 0, the subsequence is said to exhibit positive autocorrelation. In this case, successive

values at lag m have a higher probability than expected of being close in value (i.e., high random
numbers in the subsequence followed by high, and low followed by low). On the other hand, if

ρim < 0, the subsequence is exhibiting negative autocorrelation, which means that low random

51
numbers tend to be followed by high ones, and vice versa. The desired property of independence,
which implies zero autocorrelation, means that there is no discernible relationship of the nature
discussed here between successive, random numbers at lag m.
4. Gap test
The gap test is used to deter.nine the significance of the interval between the recurrences of the
same digit. A gap of length x occurs between the recurrences of some specified digit. The
following example illustrates the length of gaps associated with the digit 3:
4, 1, 3, 5, 1, 7. 2. 8. 2. 0, 7. 9. 1. 3. 5, 2, 7, 9. 4. 1. 6. 3
3, 9. 6, 3, 4. 8, 2. 3, 1, 9, 4. 4, 6. 8. 4, 1, 3. 8. 9. 5. 5. 7
3, 9, 5, 9. 8, 5. 3. 2, 2, 3, 7. 4, 7. 0. 3. 6. 3, 5, 9. 9. 5. 5
5, 0, 4. 6. 8. 0, 4. 7. 0, 3. 3, 0, 9, 5. 7, 9. 5. 1. 6. 6. 3. 8
8, 8, 9, 2, 9. 1. 8. 5, 4. 4. 5, 0, 2. 3, 9, 7. 1. 2. 0. 3, 6. 3
To facilitate the analysis, the digit 3 has been underlined. There are eighteen 3's in the list. Thus,
only 17 gaps can occur. The first gap is of length 10. the second gap is of length 7, and so on.
The frequency of the gaps is of interest. The probability of the first gap is determined as follows:
10 of these terms
P(gapof l0) = P(no3)---P(no3)P(3) = (0.9)10 (0.1) (7.12)
since the probability that any digit is not a 3 is 0.9, and the probability that any digit is a 3 is 0.1.
In general,
P( t followed by exactly x non-r digits) = (0.9)x (0.1), X = 0.1.2..
The theoretical frequency distribution for randomly ordered digits is given by
P(gap <=x) = F(x) = 0.1 Σ xn=0 (0.9)n = 1 - 0.9 x+1
The procedure for the test follows the steps below. When applying the test to random numbers,
class intervals such as [0, 0.1), [0.1,0.2),. . . play the role of random digits.
Step 1. Specify the cdf for the theoretical frequency distribution given in the Equation based on
the selected class interval width.
Step2.Arrange the observed sample of gaps in a cumulative distribution with these same classes.
Step 3. Find D, the maximum deviation between F(x) and SN(X) as in Equation.
Step 4. Determine the critical value, Da, from Table A.8 for the specified value of a and
the sample size N.
Step 5. If the calculated value of D is greater than the tabulated value of Da, the null hypothesis
of independence is rejected.
52
5. Poker Test
The poker test for independence is based on the frequency with which certain digits are repeated
in a series of numbers. The following example shows an unusual amount of repetition:
0.255, 0.577, 0.331, 0.414, 0.828, 0.909, 0.303,0.001, ...
In each case, a pair of like digits appears in the number that was generated. In three-digit
numbers there are only three possibilities, as follows:
1. The individual numbers can all be different.
2. The individual numbers can all be the same.
3. There can be one pair of like digits.
The probability associated with each of these possibilities is given by the following P(three
different digits) = P(second different from the first) x P(third different from the first and second)
= (0.9)(0.8) = 0.72
P(three like digits) = P(second digit same as the first) x P (third digit same as the first) =
(0.1)(0.1) = 0.01
P(exactly one pair) = 1 - 0.72 - 0.01 = 0.27 Alternatively, the last result can be obtained as
follows:
P(exactly one pair) = (32 ) (0.1)(0.9) = 0.27
2.8 Monte Carlo Computations VS. Stochastic Simulation

Statistical simulation technique that provides approximate solution to problems expressed


mathematically. It utilize the sequence of random number to perform the simulation.

Simulation can also be defined as a technique of performing sampling experiments on the model
of the system. This is called stochastic simulation and is a part of simulation techniques. Because
sampling from a particular probability distribution involves the use of random numbers,
stochastic simulation is sometimes called Monte Carlo Simulation. Historically, Monte Carlo
method is considered to be a technique, using random numbers.

It is important to know what random numbers are. Let us take a simple example of tossing a
coin. If coin is unbiased, probability of coming head is 0.5. If we generate two numbers say, 0
and 1, so that occurrence of both is equally likely. Let us assume that number 1 depicts head and
0, tail. These numbers are called uniform random numbers.

53
This techniques can be used in different domain

 Complex Integral Computation


 Economics Specially in Risk Management
 Extensively used in financial institutions to compute European prices,
 To evaluate sensitivities of portfolios to various parameters and to compute risk
measurements

Example 1:

The automobile company manufactures around 150 scooters the daily production varies from 146 to 154.

Production per day: 146 147 148 149 150 151 152 153 154

Probability: 0.04 0.09 0.12 0.14 0.11 0.10 0.20 0.12 0.08

The finished scooters are transported in a truck that accommodating 150 scooters, Simulate Average
number of scooters waiting in the factory and Average number of empty space in the truck by using the
following 15 random variables 80,81,76,75,64,43,18,26,10,12,65,68,69,61,57.

Solution:

Two simulation tables can be constructed:

First simulation table :

Production Per Probability Cumulative Random Numbers


Day probability Range
146 0.04 0.04 1– 4
147 0.09 0.13 5 – 13
148 0.12 0.25 14 – 25
149 0.14 0.39 26 – 39
150 0.11 0.50 40 – 50
151 0.10 0.60 51 – 60
152 0.20 0.80 61 – 80
153 0.12 0.92 81 – 92

54
154 0.08 1 93 – 00
With the help of Random Numbers Range we can construct the second simulation table:

S.No Random Production per day(as per No.of scooters No. of empty
1 80
Numbers 152
the given random numbers) 2waiting -space in the truck
2 81 153 3 -
3 76 152 2 -
4 75 152 2 -
5 64 152 2 -
6 43 150 - -
7 18 148 - 2
8 26 149 - 1
9 10 147 - 3
10 12 147 - 3
11 65 152 2 -
12 68 152 2 -
13 69 152 2 -
14 61 152 2 -
15 57 151 1 -
20 9

Average number of scooters waiting in the factory = 20/15

Average number of empty space in the truck = 9/15

55
3. Simulation of Queuing System

3.1 Simulation of Pure Pursuit Problem


Pure Pursuit- When target is not aware of pursuer. In this case, the course of the target is
known.
Pure Pursuit Problem example
A fighter aircraft sights an enemy bomber and flies directly toward it, in order to catch up and
destroy it. We have to determine the attack the attack course of the fighter and how long does the
fighter take to catch up with the bomber.
If the target flies along a straight line, the problem can be solved directly with analytic
techniques. But if the path of the bomber is curved, the problem can not be solved directly. We
can solve such problems using simulation.
We are given following conditions:
1. Both target and pursuer are flying in the same 2 dimensional plane.

2. The fighter's speed is constant that is VF.


3. The target's path is known.

4. Minimum distance required by the fighter to fire a missile at bomber is 10 units.

5. If the target is not caught within given time t∘ (here t∘ = 12), the target escapes.

6. Initial coordinates of the pursuer (fighter) are known.


We will choose our coordinate system such that, initially target will be lying on the X axis and
pursuer will be lying on Y axis as shown in the figure below.

56
The fighter looks at the target at instant t, aligns its velocity vector with line of sight (i.e. points
itself towards the target). It continues to fly in that direction for one unit of time (up to t+1). At
(t+1) it looks at the target again and realigns itself.

The distance between the 2 (dist[t]) at a given instant of time can be calculated by using distance
formula.

dist[t] = √( (yb[t]-yf[t])² + (xb[t]-yf[t])² )

The angle θ of the line from fighter to target at a given time t is given by

Sin θ = (yb[t]-yf[t]) /dist[t]

Cos θ = (xb[t]-xf[t]) /dist[t]

Using these values, next position of fighter at time (t+1) is

xf[t+1]= xf[t] + VF Sin θ

yf[t+1]= yf[t] + VF Cos θ

3.2 Simulation of Chemical Reactor

The chemical and allied industries are of greatest importance for the modern society but their
paradigm is changing due to the harsh economic conditions, limited feedstock and high demand
of their products. Much emphasis and efforts were devoted to design inherently safer and
economic conceptual design, process imagination, process intensification, revamps, energy
optimization, and sustainability. The creative efforts/innovations were evaluated against
substantial economic advantages and overall sustainability impact. From last two decade, a major
shift has begun for above tasks in chemical industry, since there is a need of software tools to
help optimization, integration, intensification, sustainability, etc., for design and operation in
chemical process industry. Approaches to address and solve problem may differs for the same
task, platform (software/ language) may be different, problems and objectives can be different
too, but todays industry is centered on modeling and simulation. This editorial focuses and
reviews how modeling and simulation plays role in modern process industry and available tools.

57
The chemical and allied industries are of greatest importance for the modern society but their
paradigm is changing due to the harsh economic conditions, limited feedstock and high demand
of their products. Much emphasis and efforts were devoted to design inherently safer and
economic conceptual design, process imagination, process intensification, revamps, energy
optimization, and sustainability. The creative efforts/innovations were evaluated against
substantial economic advantages and overall sustainability impact. From last two decade, a major
shift has begun for above tasks in chemical industry, since there is a need of software tools to
help optimization, integration, intensification, sustainability, etc., for design and operation in
chemical process industry. Approaches to address and solve problem may differs for the same
task, platform (software/ language) may be different, problems and objectives can be different
too, but todays industry is centered on modeling and simulation. This editorial focuses and
reviews how modeling and simulation plays role in modern process industry and available tools.

Since designing stage at conceptual process design (CPD) or Process Design Package (PDP), the
job of a chemical engineer is challenging as he has to integrate a large number of constraints, and
to deal often with contradictory aspects; e.g., selection of the suitable chemistry, selection of
appropriate reactor design, safety, economics, energy consumption, environment, operation and
installation compatibilities, etc., The design of complex processes implies the availability of
adequate science, modeling and simulation using powerful computer-based tools. A systematic
approach can provide the guidance‘s in identifying bottlenecks, feasible scenarios, several
alternative possibilities, optimum solution, economics, etc., leading to decision. With respect to
problems and mode of information required, different types of mathematical models, different
numerical analysis and solution strategies are needed. In general, algebraic systems for steady
state models, ordinary differential algebraic equations for dynamic models and partial differential
algebraic equations for distributed models are involved.

Chemical reactors and process modeling includes kinetics, reactor performance equation, mass
and energy balance of unit process and/or operations, interpret process flow sheets to simulated
flow sheet, simulate individual unit operations, locate malfunctions, and solve to predict the
performance. The model is a replacement of the real system of sufficient fidelity for
performing optimization tests those cannot be performed safely in shortest possible time in real
systems. The systems formalism is generally seen in every problem that can be tackled using

58
generic view by posing set of known variables and leaving others to be estimated. However, the
preliminary considerations around problem statement and necessity to decision-making are
common elements despite the modeling life cycle. In the area of mathematical modeling there is
minor progress, while describing the dynamics of engineering systems has great importance and
number of ways. Now a days much emphasis are given to below topics:

• Equation oriented reactor and process modeling

• Computer-aided product and process flow sheet simulation

• Optimization technology for reactor, process and materials design

• Shortcut modeling approaches

• Revamping options of commercial simulation and optimization

• Environmental process modeling

The model verification is generally a debugging activity; checking the model implementation,
equations, code, etc., against the conceptual description of system. It gives confidence whether
the model is well structured as per need and accurate representation of the conceptualization and
save lot of time during implementation/ validation. In order to avoid significant rework it is
always recommendable to review the modeling methodology, assumptions and their
justifications, sequential coding, suitable data for modeling and validation, etc., Before using the
model or simulation for prediction model needs to be validated and it provide confidence that,
the model is a reasonable representation of the actual system. At this stage, someone may need to
fine-tune it with actual data, kinetic parameters, heat capacities, etc., In case of dynamic
modeling, the actual data organization approaches initially via statistical parameter estimation
and providing initialization for validation.

Chemical process modeling and simulation software‘s has been widely used by chemical
engineers to design, test, optimize, and integrate reactors and/or process revamps. M. W. Kellogg
Inc. (United States) in 1958 launched the first chemical process simulation program ‗Flexible
Flow sheeting‘. Today‘s chemical engineering is focused on, a) Increase productivity and

59
selectivity through intensification of intelligent operations; b) multi scale approach to processes
control; c) micro-tailoring with controlled structure; c) unique equipment design; d) process
intensification; e) multiscale modeling and simulation to mimic real-system from molecular scale
to the production scale. Many modeling tools are available for Process modeling and simulation,
e.g., integrated Aspen Process Modelling (AspenPlus a process simulator, Aspen Custom
Modeler, Aspen Dynamics, etc.), HYSYS, computer aided system (ICAS), gPROMS (process
and reactor simulator), DynSim Dynamics, ChemCad, Design II, Pr-Sim, MATLAB, UniSim,
computational fluid dynamics (CFD), respectively. These systems allow the conceptualization of
the reactor or process by defining systems of balance volumes in the governing equations to
describe the phenomena occurring within the system. Multiscale modeling poses many
challenges and only few modeling platforms can handle such systems to enable integration
frameworks. There is diversity in approaches and tools used for modeling, somehow for their
marketing justification, as most of the models are represented by a set of mathematical equations
solved by similar numerical methods. The selection of numerical method depends on various
factors, e.g., nature of the modeling equations being solved, desired accuracy, and computing
speed/time. The summary of commonly used process modeling and simulation tools are as
below:

Aspen Process Modeling is a general-purpose process simulation tool, integrated with properties
databank to make accurate and reliable calculation of thermo physical properties, from
AspenTech (USA) having number of modules for building large-scale flowsheets, economic
analysis, reactor modeling, implement several operating procedure, perform detailed design
studies, optimizing operation of individual equipment or complete process, etc., Where
AspenPlus is commonly used for process flowsheet design, process and energy optimization, unit
operations and reactor simulation, heat exchanger design software. AspenDynamics has set of
unit operations and control model library and user-oriented modeling capabilities for building
dynamic simulations. AspenDynamics is mostly used for safety and controllability studies, sizing
relief valves, optimizing transition, start-up, and shutdown policies, etc., It helps an engineer to
estimate the relative costs of proposed designs and making decisions. Aspen Custom
Modular (ACM) provides environment for building custom-based equation oriented modeling,

60
and commonly used for reactor and other sophisticated equipment‘s modelling those, were not
available in aspen library or available but not upto the desired sophistication level [6,7].

HYSYS was originally a product of Hyprotech (Canada) which was acquired by AspenTech in
2002. HYSYS is well-known in refinery and petrochemical process for its capabilities to
perform, e.g., process safety analysis, preliminary cost estimation, control, equipment sizing and
design, refinery flowsheeting, operational optimization of process bottlenecks, start-up
procedures, and performing dynamic studies, etc., The built-in advanced sequential quadratic
program (SQP) algorithm enables offline and online optimization of design and operation. Both
Aspen Process Modular and AspenHYSYS are fully supported CAPEOPEN compliant models.

gPROMS: A product of Process Systems Enterprise Ltd. (UK) which is characterized by the
equation-based model building of any complex process and custom based equipment modelling.
The tool is useful in novel technology developments, new process or equipment design having
capabilities of experimental design, parameter estimation, statistical analysis, dynamic modeling,
operators training, process control, safety analysis and advanced
optimization. gPROMS language is a text-based powerful language, required proper description
of chemical system similar to ACM, having number of solver options and has state-of-the-art
model library.

Process Intensification designates the emerging techniques or equipment that can achieve
significant improvement in productivity, savings in capital expenditure, energy efficiency and
environmental friendliness of processes. Such as novel reactors, intensive mixing, heat transfer
and mass-transfer devices, equipment size and cost reduction, safe operation, integration of
reaction and separation steps in multifunctional reactors (examples: reactive distillation,
membrane reactors, fuel cells), hybrid separations (example membrane distillation), alternative
energy sources, and new operation modes (example periodic operations), etc. This enhances
creativity and increases the number of attractive process alternatives. Creativity is a major issue
in process design. In today‘s innovation of chemical process industries means to achieve highly
efficient, economically competitive and sustainable design; and it can only be achieved using
robust modelling and simulation tools. In the end, an integrated conceptual design (process
design) may reveal a simpler flowsheet with lower energy consumption and equipment costs, and

61
further consists of an optimal combination of technical, economic, environmental and social
aspects.

3.3 Simulation of Water Reservoir System Operations

Reservoir storage is necessary to regulate highly variable water flows for more constant uses
such as municipal and industrial water supply, irrigation, hydroelectric power generation, and
navigation. Typically, the water drawn from a reservoir is used at a much slower (and constant)
rate than the rate and consistency of the water flowing into the reservoir (see Figure 1). Reservoir
modeling has typically been employed to help size reservoir storage capacities, establishing
operating policies, evaluating operating plans, administering water allocations, developing
management strategies, and real-time operations.

Figure 3.1: Inflow and Outflow Hydrograph

The basic requirement for adequate representation of a reservoir is employment of the continuity
equation, or conservation of volume over a period of time. This is a function that interacts
dynamically with the current state of the reservoir. The foundational equation for conservation of
volume is:

62
The term ―Reservoir System Operations‖ refers to the practice of maintaining and managing a
reservoir for multiple purposes, under dynamic conditions. The word ―system‖ is used because
of the complexity inherent in the operations of a typical reservoir or network of reservoirs. The
state of the reservoir system is constantly in flux, requiring dynamic methods of simulation to
evaluate and model them. The term ―Reservoir System Operations Model‖ refers to a computer
program used for simulating and optimizing changes in storage, water deliveries, and flood
control for one or multiple reservoirs.
Often times, the objective of the reservoir operation is to balance the control of flood storage and
maintain reliable water supply. Operational procedures are different for flood events than what
are employed under water scarce conditions and therefore, the model must be adapted for these
changing conditions.To better manage potential changes to reservoir operations given
uncertainties or changes in circumstances, it is helpful to develop a calibrated simulation model
of the reservoir. Some key topics related to reservoir system operations modeling are presented
in this paper.
3.3.1 Single pool operations
The main purpose of a reservoir is to control a determined amount of water during some period
of time. The amounts that are controlled depend on the properties of the reservoir system, which
include components such as the dam, spillway, inflow facility, and outlet works. Figure 2 depicts
a simple example of a basic reservoir system. Inflow to a reservoir is typically uncontrolled if the
reservoir is on the river. Some dams are built off-stream and water is delivered to the reservoir in
a controlled manner. Usually, the controls on inflows to the reservoir are a function of the water
level in the reservoir.

Figure 3.2: Simple Reservoir Diagram

63
As the reservoir begins to approach an upper limit, the flow into the reservoir is turned off if the
inflows are able to be controlled. For reservoirs that are located on a stream, the inflows cannot
be controlled so the reservoir must operate a flood control system that usually includes an outlet
works and an uncontrolled spillway. When the outlet works are not able to discharge enough
water to lower the reservoir level, then the water will rise above the spillway and water will
discharge over the spillway at a flow rate that is dependent on the height of water above the
spillway.
Often times the reservoir system operations need to be simulated in a computer model. Typically,
a reservoir model must include the major parts of the reservoir system in order to evaluate the
reservoir system operations. The fundamental aspect of reservoir modeling is the routing of
water. This is done in various ways, depending on the situation and modeling requirements. All
routing methods are based on the continuity of volume.

3.3.2 Operation of multiple pools

Typically, reservoirs are operated based on policies that involve multiple pools that are defined
to be used for different purposes. An example of a typical multi-pool reservoir is shown in
Figure 3, where the reservoir is divided into surcharge, flood control, conservation, and dead
pool zones. Often times, the conservation pool is referred to as the multi-use zone because water
needs to be conserved in this pool for multiple and often conflicting uses.
The flood control zone is to remain empty except during the times following a flood event
upstream of the reservoir. Flood control zones often include a surcharge zone, which is the
uncontrolled storage volume above a spillway elevation. Usually, it is not in the interest of
reservoir operators to spill water over the spillway because it is uncontrolled and poses a risk to
the channel downstream. The flood zone is typically drained in a controlled manner through use
of an outlet works with an operated gate or valve.

64
Figure 3.3: Reservoir Pools

The conservation pool is used to store water temporarily for downstream uses such as power
generation, recreation, navigation, irrigation, municipal and industrial water supply, and instream
flows for habitat. This pool is only drawn down if a request is made in behalf of one of these
uses. Often times the top of the conservation pool varies seasonally as shown in the simple
example in Figure 4. Typically, the top of the conservation pool rises during the part of year that
additional storage is needed to supply water for beneficial use later on. A rise in the conservation
pool poses greater risk on the operations of the reservoir because it requires that the flood pool
zone is decreased, which gives the reservoir less opportunity to evacuate flood flows before the
reservoir level enters the surcharge stage.

Figure 3.4: Seasonal Variations in Conservation Pool

65
Often times, the top of the conservation pool acts as a guide, target, or rule curve for operators.
The reservoir is operated in order to try and keep the reservoir level as close as possible to the
top of the conservation pool. Obviously, it is critical that the seasonally varying conservation
pool limit is first optimized using appropriate methods prior to actual use in the field.
Interaction with groundwate r in bank storage
Since the permeability of the bottom of a reservoir tends to decrease over time due to
sedimentation, seepage from the reservoir into the surrounding groundwater aquifer is usually
ignored. This said, it is possible for groundwater seepage to be a significant factor in overall
reservoir losses for some sites and an appropriate method of seepage simulation should be
considered. Some reservoirs are intentionally sited in locations were permeability is high as a
way to inject water into the ground. This is referred to as aquifer storage recovery and it is
becoming more popular as many groundwater aquifers are being mined of their water supply due
to increased groundwater pumping.
One of the simplest ways to estimate seepage to groundwater is to develop a function related to
reservoir depth. This usually requires the assumption that seepage flows are always a net loss
from the reservoir, which is likely case for most sites. However, there are times when you might
need to consider bi-directional flux due to seepage outflows and inflows, depending on the
elevation of the reservoir pool compared to the surrounding groundwater levels.
3.3.3 Water Supply Allocation
Before discussing allocations of water to multiple users from a reservoir or reservoir system, it is
necessary to first introduce the term ―firm yield‖. This is an important concept used in reservoir
system operations. Firm yield is the amount of water that can be continuously delivered from a
reservoir with 100% reliability over a historical period-of-record or hypothetical repetition of
hydrology. Reliability is usually defined as the ratio of total water supplied by the reservoir (n) to
the total amount of water requested (V). The equation looks something like this:

66
There are other reservoir yields (i.e. secondary yield, etc) that can also be provided for beneficial
use but are not 100% reliable. Often times, water from a reservoir is allocated based on various
levels of reliability, with the highest priority water demand being given the 100% reliable yield.
This is how multiple water users are allocated their supplies: Each successive priority is given an
incrementally less reliable reservoir yield.
Another important aspect of water supply allocation is the implementation of a permit system
and adjudication of water rights. Usually, priorities are assigned to the various permit/water right
holders as a way to simulate the allocation of water supplied to the user. Due to the complexity, a
numerical methods formula such as linear programming (LP) might be necessary to solve for the
overall firm yield given multiple users with varying priorities. The LP algorithm might also be
useful for solving a priority based water allocation for a reservoir and water demand network. A
good reference for this type of programming for reservoir operations is the book entitled,
―Modeing and Analysis of Reservoir System Operations‖ by Ralph A. Wurbs, 1996 Prentice
Hall PTR.
Network flow programming might also be appropriate as this is an efficient form of LP which
can be used to represent a network of nodes and links similar to a reservoir/water demand
network. This type of algorithm has been used many times for complex models that require
prioritization of water supplies to multiple and conflicting water demands. Other methods
include dynamic programming (DP), various non-linear programming techniques, and univariate
gradient search.
3.3.4 Multiple reservoirs in series
When evaluating the operations of multiple reservoirs in series, special considerations need to be
made. The decision of which reservoir to release water from will affect overall operations of the
system. Typically, it is best practice to minimize spills from the upstream reservoirs so that
capacity in the downstream reservoirs is preserved and will be able to catch uncontrolled spills
from the upper reservoirs and thus protect the downstream river channel. It is also helpful to
maximize conservation pool water in the upper reservoirs so that the most users will benefit at
any given time. It is easy to release water from an upstream reservoir to a downstream reservoir
but not the other way around. Figure 5 shows a simple example reservoir network with two
reservoirs in series (Reservoir A and Reservoir B).

67
Figure 3.5: Simple Reservoir Network Example

The objective for reservoirs in parallel should be to balance storage depletions between the two
(see Reservoir B and Reservoir C). Under such a reservoir system setup, you might end up with
control points to operate Reservoir A located at diversions 1-4 and the other two reservoirs. As
discussed in the previous section, more complex systems like this may require an LP or
optimization solver approach.

3.4 Simulation of Queuing System

Introduction

Queues (waiting lines) are a part of everyday life. We all wait in queues to buy a movie ticket,
make a bank deposit, pay for groceries, mail a package, and obtain food in a cafeteria, vehicles
waiting at petrol pumps or to pass a road bottle neck etc. A queue, in fact doesn‟t contain
discrete units only, liquids entering in a sudden large volume into a tank having only a small
outlet pipe can be said to be queuing in the tank. Customers wait when the number of customers
requiring service exceeds the number of service facilities. An amazing number of waiting time
situations exists as when computer programs are waiting to be processed at computer center.

The queuing theory is the probabilistic study of waiting lines. Although it does not solve all type
of waiting line problems, yet it provides useful and vital information by forecasting or predicting

68
to various characteristics and parameters of the particular waiting lines under study. Since the
prediction about the waiting times, the number of waiting at any times, the time for which the
servers remain busy, delay etc. heavily depends on the basic concept of stochastic processes,
hence, queuing theory can be taken as an application of stochastic processes. Queuing theory is
generally considered a branch of Operational Research because the results are often used when
making decisions about the resources needed to provide services. Thus we can say queuing
theory is a stochastic process in Operations Research. The queues and queuing systems have
been the subject of considerable research since the appearance of the first telephone systems.

Economical aspects of queuing theory

Waiting for service is usually an unpleasant experience, which creates unhappiness among
customers who may switch to competitive service offerings. Having to wait is not just a petty
personal annoyance. Waiting time represents the loss of valuable resources and this loss
translates into psychological as well as economical costs of waiting. The longer, customers wait
the more dissatisfied they are to be. The amount of time that a nation‟s populaces waste by
waiting in queues is a major factor in both, the quality of life and the efficiency of the nation‟s
economy. Taking machines wait to be repaired may result in loss of production. Airlines waiting
to take off or land may disrupt later travel schedule. Delaying service jobs beyond their due date
may result in a lot of future business causing manufacturing jobs to wait to be performed may
disrupt subsequent production. Queuing problems in industry are more serious than those
experienced in our daily life. Excessive waiting time in production will mean longer
manufacturing cycle, that is longer deliveries and high investment in work in progress.

Virtually, all queuing situations have economic interpretation for their implication. In general
there are two opposing economic aspects to queues.

(a) It can cost money for an item to be idle in queue. An employee has to be paid while queuing
at the tool store, valuable production is lost while machine stand out of order, tax receipts are
delayed while document remain in the inspectors tray. And, of course, the smaller the service
facility, longer the queues and higher the cost.

(b) On the other hand, larger the service facility quicker it will disperse queue and therefore,
more often the system will stand idle and hence it costs money to increase the service facility.

69
Queuing theory based on probability concept gives an indication of the capability of a given
system and of the possible changes in its performance with modification to the system. With the
help of queuing theory the executive can at most make an informed guess of what could be the
balance between the customer‘s waiting time and in preventing waiting time. He first takes into
consideration several alternatives, evaluates through queuing models, their effects on the system
and makes his choice. The criteria for evaluation will be the efficiency of the system like the
average length of the queue, expected waiting time of a customer and the average time spent by
the customer in the system

The Queuing theory studies waiting line system by formulating the appropriate mathematical
models of the particular system under study. These models and their operation are then used to
derive the necessary performance measurements of the queuing system as a whole. These
measurements provide the vital information which will be later utilized in designing an effective
waiting line system. An appropriate balance or tradeoff between the various costs and the
waiting for the required service are, of course, the optimum line in a waiting-line system. The
total cost of service and customer waiting time is the essence of our study of queuing systems.

The optimum balance may be arrived at either by:

(a) Introducing more facilities at extra cost, or

70
(b) Changing the pattern of the arrival of customers for service, or Rescheduling arrival of
customers

(c) Changing pattern of servicing, or effecting method improvements to reduce service time.

(d) To relate waiting delays queue lengths and other measure of performance to the given
properties of the input stream and the service procedures.

(e) To search out space cost along with customer waiting and idle service cost to obtain the
optimal system design.

(f) Ultimate objectives are to determine the increase in investment of service for a corresponding
decrease in customer‘s delay.

(g) To develop the queue model in order to predict fluctuating demands and to enable one to
provide adequate service for the customers with tolerable waiting.

(h) To search such queue models with control and delayed vacation so that the vacation period of
servers can be utilized.

(i) To minimize the total operations cost of the system in feedback queue model under
parametric constraints.

Thus the main reason for the study of queues is to enable us, through our queue models, to
predict what will happen if certain changes are made. (e.g. in the pattern of arrivals, reducing the
mean length of service time, increasing the number of server or increasing the amount of room to
accommodate waiting customers). Typical measures of congestion that we would like to be able
to predict are the average number of customers waiting, the average length of time that they will
wait, and the proportion of time that the service facility is busy.

3.4.1 Rudime nts of Queuing Theory

Simulation is often used in the analysis of queuing models. Queuing models provide the analyst
with a powerful tool for designing and evaluating the performance of queuing systems.

71
Key elements of queuing systems

Customer: refers to anything that arrives at a facility and requires service, e.g., people,
machines, trucks, emails.

Server: refers to any resource that provides the requested service, e.g., repairpersons, retrieval
machines, runways at airport.

The basic Elements of a queue system is as follows:

1. The Input or arrival-pattern of customers (λ-mean arrival rate).

2. The Output or service-pattern of customers (µ-mean departure rate).

3. The number of service channels.

4. The capacity of the system.

5. Queue discipline (FIFO, LIFO, and SIRO etc.)

72
a) The Input or Arrival-Pattern of Customers
The input pattern means the manner in which the arrivals occur. It is specified by the inter arrival
time between any two consecutive arrivals.
The interarrival time is the amount of time between the arrival of one customer and the arrival of
the next customer.
It is calculated for each customer after the first and is often averaged to get the mean interarrival
time, represented by lambda.
b) The Output or Pattern of Service
It represents the manner in which the service is rendered. It is specified by the time taken to
complete a service. The time may be constant (deterministic) or it may be stochastic. If it is
stochastic, the pattern specification involves the distribution of service time of a unit.
c) The Number of Servers
A system may have a single server or a number of parallel servers. An arrival who finds more
than one free server may choose at random any one of them for receiving service. If he finds the
entire server busy, he joins a queue common to all the servers. for example, in a bank or at a
ticket counter.
There may also be situations where there is a separate queue in front of each service facility, as
in the case of a supermarket.

d) The Capacity of The System


A system may have an infinite capacity – that is, the queue in front of the server(s) may grow to
any length. Against this there may be limitation of space, so that when the space is filled to
capacity, an arrival will not be able to join the system and will be lost to the system. The system
is called a delay system or a loss system, according to whether the capacity is finite or infinite. If
finite, it will have to be specified by the number of places available for the queue as well as for
the one(s) being served, if any.
e) Queue Discipline

Most queues are based on a first come first serve (FIFO) system. This is not always so,
sometimes certain queue components have priorities (e.g. ambulances at traffic lights),
sometimes a LIFO system work (as when a tax inspector always takes the top document first
from his in tray)

73
Transient and Steady- State Behavior

A time-dependent solution of the stochastic behavior of queue process Pn(t), n≥0 is called
transient state. It is often difficult to obtain such solutions. Or even when found, these may be
too complicated to handle. For many practical situations, however, one needs the equilibrium
behavior-that is, the behavior when the system reaches an equilibrium state after being in
operation for a sufficiently long time. In other words, one is often interested in the limiting
behavior of Pn(t) as t→∞. Denote Pn = , n= 0, 1, 2…… (t) p lim n t

Whenever the limit exists, the system is said to reach a steady (equilibrium) state, and Pn is
called the steady-state probability or the long-run proportion of time that the system contains
exactly n customers. In steady state, the operating queue characteristics are independent of time.

3.4.2 Types of Uncertainty


In general there are two types of uncertainties
(i) Probabilistic uncertainty: - Mostly whenever an event occurs, the uncertainty about its
outcome is attributed to ―randomness‖ or stochastic. The best to approach this question
might be to describe the status in terms of probability distribution.

Following processes are based on Probabilistic uncertainty.

Stochastic Process

A stochastic process is defined to be the process which develops in time according to some
probabilistic law. The state space of a stochastic process is a list of possible outcomes at any
point in time. We can say a stochastic process has a state space and a time structure.

A stochastic process {X(t), t T} is a collection of random variables, that is, for each t T, X(t) is a
random variable. The random variables X(t) denotes the state of the system at a time t. If t
assumes discrete values, then the process {X(t), t = 0,1,2 … ……} is called a discrete
parametric stochastic process. If t assumes continuous values then the process {X(t),t ≥0} is
called a continuous parametric stochastic process. The set of possible values of X(t) is called
state space and the set of possible values of t, denoted by T, is called parametric space or the
index set. More clearly, a stochastic process is a family of random variables which provides
description of the evolution of some physical phenomenon through time. Queuing systems

74
provide many examples of stochastic processes. For example X(t) might be the number of
customers that arrive before a service counter by time t, then {X(t), t≥0} is of type continuous
time and discrete state space. Again it might be the queuing time of nth arrival, then {Wn; n= 0,
1, 2……..} is of type discrete time and continuous state space.

Generally, the stochastic processes encountered in the analysis of a specified complex system
can be identified any one of the following:-

(a) Markov Process

A stochastic (or random) system is called a Markov process if the occurrence of a future state
depends on the immediately preceding state and only on it.

A Markov process whose state space S is discrete is called a Markov chain. A Markov chain is
called a discrete parameter Markov chain or a continuous parameter Markov chain according as
the parametric space is discrete or continuous. Mathematically, A stochastic process

{Xn ; n ≥ 0} is called a Markov chain, if for every xi S,

Pr{Xn=xn/Xn-1=xn-1,………X0=x0}= Pr{Xn=xn/Xn-1=xn-1} (1.1)

provided L.H.S. is defined. This equation indicates a kind of dependence between random
variables Xn; intuitively, it implies that given the present state of the system, the future is
independent of the past.

The probability of moving from one state to another or remaining in the same state during a
single time period is called the transition probability. The transition probability Pr{Xr+n= k/ Xr
=j} from state j to state k in n steps (from state j in steps r to state k in step r+n) is called n step
transition probability. We denote Pjk(n) = Pr {Xr+n = k/Xr = j} so that

Pjk(1) = pjk

Define pjk(0) = jk

A single server queue system can also be considered to be in two states idle or busy according
to whether server is idle or busy. The idle and busy states alternate and together constitute a

75
cycle of an alternating renewal process. A busy period starts as soon as a customer arrives
before an idle server and ends at the instant when server becomes free.

The case of the alternating renewal process can be generalized to cyclical movement of more
than two states. A Markov renewal process becomes a Markov process when the transition
times are independent exponential and are independent of the next state visited. It becomes a
Markov chain when the transition times are all identically equal to 1. It reduces to a renewal
process if there is only one state and then only transition times become relevant. Let {X(t)} be a
Markov process with discrete state space & let the transition occurs at any instant of time ti ,
i=0, 1, 2……….. Then the sequence {Xn=X(tn+1)} forms a Markov chain and the time interval
(tn+1-tn)=Δtn between transition have independent exponential distribution , the parameter
which may depends upon Xn. Suppose that the transitions {Xn} of the process X(t) constitute a
Markov chain but the transition intervals (tn+1-tn) may have any probability distributions with
parameters which may depends not only on Xn but also on Xn+1. The process {Xn, tn} as well
as {Xn, tn+1-tn} is called a Markov renewal process and the process {X(t)} is known as semi
Markov process. More clearly semi Markov process is a stochastic process in which changes of
state occurs according to Markov chain and in which the time interval between two successive
transitions is a random variable whose distribution may depends upon the state from which the
transition take place as well as on the state to which the next transition take place.

e.g. The problem of occupational mobility, where transition between occupation as well as
intervals between transitions is taken into account may be treated as a semi Markov process.
Semi-Markov processes are used in the study of certain queuing systems.

(b) Poisson Process

The Poisson process is a stochastic process with infinite number of states. It is applied to a
system when the changes are independent of time. An infinite sequence of independent events
occurring at an instant of time form a Poisson process, if the following conditions satisfied:

(i)The total number of events in anytime interval X does not depend on the event which has
occurred before the beginning of the period i.e. the number of arrivals in non-overlapping
interval are statistically independent and the process has independent and identically distributed
increments.

76
(ii) Two or more units cannot arrive or serviced at the same time i.e. the probability of the
occurrence of more than one event in the interval t and t +t is of the order O(t) which is
negligible.

The Poisson process is a continuous parameter Markov chain and is widely used in queuing
theory. It is well known that these conditions lead to the Poisson distribution. An important
relationship exists between the Poisson and exponential distributions.
(ii) Fuzzy Uncertainty
Let us suppose there is a research project or paper which is to be accepted by the authority or
the editor. It is sent to the experts for the independent advice or comments about the acceptance.
Each expert is asked to grade the project or the research paper to grade the product at some
point in the scale of 0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0, where grade 0 means that the
project is completely unacceptable and there is no uncertainty in the mind of the expert about it
and grade 1 means that the project is completely acceptable and again there is no uncertainty in
the mind of the expert about it. Grade 0.1 means that the project is almost unacceptable but
there are some good features in the project which creates some uncertainty in the mind of the
expert. Similarly grade 0.9 means the project is almost acceptable but there are some
undesirable features which creates some uncertainty in the mind of the expert about its
acceptability.

Now when the authority or the editor receives the experts opinions, his concern about grade 0
and 1 gave him a clear indication but grade 0.1 and 0.9 creates a certain degree of uncertainty in
his mind which is the same in both cases.

Similarly grades 0.2 and 0.8 and 0.3 and 0.7, 0.4 and 0.6 represents the same degree of
uncertainty form the authority or the editor. We call this type of uncertainty a fuzzy uncertainty
as distinguished from probabilistic uncertainty. It is true that the fuzzy uncertainty is maximum
when the expert gives the grade 0.5 as the authority is complete uncertain whether the project is
accepted or rejected.

3.4.3 Characteristics of Queuing Network

1. Arrivals from the outside to node i follow a Poisson process with mean rate λ1.

77
2. Service (holding) times at each channel at node i are independent and exponentially
distributed with parameter (a node‟s service rate may allowed to depend on its queue length).

3. The probability that a customer who has completed service at node i will go next to node j
(routing probability) is rij (independent of the state of the system), where i = 1, 2,
3…………….k, j = 0, 1, 2, 3……0..ki and ri0 indicates the probability that a customer will
leave the system from node i. These properties are called Jackson Networks .

3.5 Simulation of Single Server

For example, queuing requirements of a restaurant will depend upon factors like:

 How do customers arrive in the restaurant? Are customer arrivals more during lunch and dinner
time (a regular restaurant)? Or is the customer traffic more uniformly distributed?
 How much time do customers spend in the restaurant? Do customers typically leave the restaurant
in a fixed amount of time? Does the customer service time vary with the type of customer?
 How many tables does the restaurant have for servicing customers?

Simulation Example:

Calculate the statistical output for the single server queuing system whose IAT and ST for 10
arrivals are given below.
IAT - 8 6 1 8 3 8 7 2 3

ST 4 1 4 3 2 4 5 4 5 3

78
Customer IAT AT ST Time TC TSE TC ITS
Service Waits Spent
(ST + (AT-
Begins in Q in
TSB) TSE)
System
Comp(AT (TSB-
& TSE) AT) (TSE-
AT)

1 - 0 4 0 0 4 4 0

2 8 8 1 8 0 9 1 4

3 6 14 4 14 0 18 4 5

4 1 15 3 18 3 21 6 0

5 8 23 2 23 0 25 2 2

6 3 26 4 26 0 30 4 1

7 8 34 5 34 0 39 5 4

8 7 41 4 41 0 45 4 2

9 2 43 5 45 2 50 7 0

10 3 46 3 50 4 53 7 0

Total 46 35 9 44 18

Output Statistics:

1. Avg. waiting time (W) = 9 /10 = 0.9

2. Probability that a customer has to wait in queue P(wait) = 3/10 = 0.3

3. Average service time (S) = 35/10 =3.5

79
4. Average time between arrivals( λ ) = 46/(10-1) = 5.11

5. Avg. waiting time of those who wait(Wwaited) = 9/3 =3

6. Average time of customer spend in a system (t) = 44/10 =4.4

7. Probability of Idle Server P(idle) = 18/53 = 0.34

8. % server utilization = (18/44)* 100 = 40.90%

Formulas:

1. Avg. waiting time(W) = waiting time in queue / no. of customers


2. Probability that a customer has to wait in queue P(wait) = No.of customers
who wait / no. of customers
3. Average service time (S) = service time / number of customers
4. Average time between arrivals (λ ) = time between arrivals (IAT) / Number
of arrivals – 1
5. Avg. waiting time of those who wait(Wwaited) = waiting time in queue / no.
of customers that wait
6. Average time of customer spend in a system (t) = total time customer spends
in the system/ Number of customers
7. Probability of Idle Server P(idle) = Idle time of server / service time ends
8. % server utilization = Total Idle time / total busy time* 100
3.6 Two Server Queuing System

In a M|M|C queue, there are c parallel servers, each serving customers, (c > 1). All arriving
customers after entering the service system join a single queue. If all c servers are already busy
in serving customers, the next customer will wait in the queue. The customer will be served by
any of the c servers as soon as any server will be free from serving previous customer.

80
Service Rate (µ) = Number of customers served per unit time

Arrival Rate (λ) = Mean number of customers arriving per unit time

Capacity Utilization when there is multiple servers = λ / Cµ

Example - This example illustrates the simulation procedure when there is more than one service
channel. Consider a drive-in restaurant where carhops take orders and bring food to the car. Cars
arrive in the manner shown in table 1. There are two carhops-Able and Baker. Able is better able
to do the job and works a bit faster than Baker. The distribution of their service times are shown
in tables 2 and 3.

Table 1: Interarrival time distribution of cars

81
Table 2 and 3 : Service distribution of carhops

A simplifying rule is that since Able has seniority he gets the customer if both carhops are idle.
(The solution would be different if the decision were made at random or by any other rule.)

System Events:

 A customer arrives
 A customer begins service from able
 A customer completes service from Able
 A customer begins service from Baker
 A customer completes service from Baker.

82
Simulation Table

Simulation process

 Time of arrival for customer = Time between arrivals + Time of arrival of previous
customer
Logic of who gets a customer when a customer arrives:

 If the customer finds Able idle! The customer begins service immediately with Able
 If Able is not idle but Baker is ! The customer begins service immediately with Baker
 If both are busy! The customer begins service with the first server to become free
Simulation result analysis

 A longer simulation would yield more reliable results.


 Able was busy 92% of the time
Busy time of Able = Service Time / Total time = 25/27=0.92 = 92%
 Baker was busy 48% of the time
Busy time of Baker = Service Time / Total time = 13/ 27 = 0.48 = 48%

 Two of the 10 arrivals (about 20%) had to wait


 Average waiting time for all customers = (Total time in queue) / (number of customers)
83
= 02/10 = 0.2 minutes

 Average waiting time for those who waited = (Total time in queue) / (number of
customers who waited)
= 02 / 02 = 1 minute

Summary

In summary, this system seems well balanced. One server cannot handle all the diners, and three
servers would probably be too many. Adding an additional server would surely reduce the
waiting time to nearly zero. However, the cost of waiting would have to be quite high to justify
an additional server.

3.7 Simulation in Inventory Control and Forecasting

In the beginning of inventory some amount M of goods is in stock. As sales continue, the stock
decreases. Periodic review of length N the stock (inventory) level is checked. At the end of the
first review period, an order quantity Q1 is placed to bring the inventory up to the level M.
Demands are usually known with uncertainty! It is possible that the inventory becomes negative,
meaning the goods is in shortage.

The lead time, this is the time between the issuance of re-order and the arrival of the goods.

Simulation of an (M;N) inventory system

84
Example:

This example follows the pattern of the probabilistic order-level inventory system shown in the
previous figure. Suppose that the maximum inventory level, M, is 11 units and the review period,
N, is 5 days. The problem is to estimate, by simulation, the average ending units in inventory the
number of days when a shortage condition occurs.

Assume that orders are placed at the close of business and are received for inventory at the
beginning as determined by the lead-time. Lead time for first three reorders are 1,3 and 1.

The below table shows the distributions of the number of units demanded per day and the lead-
time.

Simulation Table

85
Simulation result

To make an estimate of the mean units in ending inventory, many cycles would have to be
simulated. For purposes of this example, only three cycles will be shown.

The simulation has been started with the inventory level at 3 units and an order of 8 units
scheduled to arrive in 2 days time.

The order for 8 units is available on the morning of the third day of the first cycle, raising the
inventory level from 1 unit to 9 units.

Demands during the remainder of the first cycle reduced the ending inventory level to 2 units on
the fifth day. Thus, an order for 9 units was placed. The lead time for this order was 1 day. The
order of 9 units was added to inventory on the morning of day 2 of cycle 2.

Notice that the beginning inventory on the second day of the third cycle was zero. An order
for 2 units on that day lead to a shortage condition. The units were backordered on that day and
the next day also. On the morning of day 4 of cycle 3 there was a beginning inventory of 9 units.
The 4 units that were backordered and the 1 unit demanded that day reduced the ending
inventory to 4 units.

Based on three cycles of simulation,

the average ending inventory is 3.1 or (47/15) units.

On 2 of 15 days a shortage condition existed.

86
4. Design of Simulation Experiments

Introduction

 The simulation technique is the experimentation on the model of the system under study.
 Simulation experiment in most of the situations involves the stochastic variables.
 Even if there is one such variable then the whole system is affected and the values of the
parameters being observed are vary from time to time.
4.1 Run length of Static/Dynamic Simulation Experiments

 Simulation run-length is the time duration of the simulation.


 The problem is how long it needs to run the simulation to have statistically independence
of my performance measures and calculate the confidence interval of my means,
excluding the warm-up period.
 The purpose of the warm-up period, run-length and replication is to get rid of biases in
the measurements. Obviously, determining the warm-up plays more important role.
Warm-up-period- A warm up period is the amount of time that the model needs to run to
remove the initialization bias before statistical data collection begins. The length of the period is
dependent upon the type of model being used. Warm up periods for steady state simulation can
sound through experimentation with moving averages and other techniques.

Model Run or Run length - A model run involves operating a simulation for a specifically
period of time with a unique set of random values. The simulation run length is the amount of
time simulated during the model runs.

Independent model replication -An independent model Replication entails operating the same
model for the same period of time with one or more random seed values. Multiple model
replications are essential when analyzing results.

Then, to achieve the same statistical accuracy, you should realize that there is an interaction
between run length and replication. If you have shorter runs, you need more samples and vice
versa.

87
Some practical considerations for run length

 Many models have some cyclical behavior (e.g. reduced working hours during
weekends), so each run is a multiple of such a cycle.
 The run-length should also be limited by the "life cycle" of a production facility (usually
a few months to a few years at best).
 Run at least 5 replications per experiment, preferably more.
 If you settle for less statistical accuracy (for whatever reason), you may not be able to
justify some conclusions on strict statistical grounds.
 If the warm-up time is relatively long, you will probably settle for fewer runs, since then
you spend less time on warm-ups.
 To design a stochastic simulation experiment, it is helpful to have an estimate of the
simulation run lengths required to achieve desired statistical precision.
 Preliminary estimates of required run lengths can be obtained by approximating the
stochastic model of interest by a more elementary Markov model that can be analyzed
analytically.
 Simulation experiments are like exploring trips. We usually have initial goals, but the
interesting discoveries often come from the unexpected.
 We typically do not know in advance precisely how we will proceed and we cannot
predict all the benefits.
 In reality, most simulation experiments are sequences of experiments, with new goals
being based on successive discoveries;
Two steps to choose run length

 First, we must find a suitable approximation for the given stochastic model.
 Second, we must calculate the asymptotic quantities of interest for the approximating
model. Of course, we do not want the preliminary analysis to be harder than doing the
experiment itself. The preliminary analysis better be easy or we wouldn‘t bother with it.
4.1.1 Terminating and Non Terminating Systems

A terminating system is the one that run s for a specified duration of time or until some specified
event/events occur.

88
Each simulation run of a terminating system starts from time zero, under well specified starting
conditions and end at the specified stopping time or as soon as specified event/events occur.

For example the operation a bank while considering the service to the customers it is a
terminating system as it opens daily in the morning with all tellers empty and close at the end of
the day or some fixed time. The queue at the closing time is not carried to the next day.

A non terminating system is a system that runs continuously for a long period of time. For
example flow line production systems, assembly lines, telephone systems, communication
systems and hospitals run continuously even the systems which come to stop after fixed
intervals. As production system running in day shift only but restart after a time gap with the
same state in which it came to halt is a continuous system.

For example in a production system larger the variance of operation times more will be the
variation in the output values. The average values obtained may not be highly reliable. To make
the results reliable it is essential to design the experiment in such a way that the results obtained
are within some specified tolerance limits and at a reasonable level of confidence. So length of
simulation run, initial conditions and number of replications are some of the important aspects of
simulation experiment.

The statistical design of the simulation experiment helps to optimize the length of the simulation
run, number of replications and analyze and evaluate the information obtained in the experiment.

For determining the simulation run the simulation experiment is first conducted for a small run
which is called as pilot experiment. Form this pilot experiment mean and standard deviation of
the parameter being observed is determined.

In stochastic simulation random numbers are used to produce the values of the input variables
and the output data from such simulation experiments exhibit random variability.

Two different streams of random numbers will produce two different sets of data which in all
probability will differ. The purpose of the statistical design of experiment of a simulation is to
estimate the variance or to determine the number of observations required to achieve a desired
precession.

89
4.1.2 Length of simulation run

A simulation run is an uninterrupted recording of a system behavior under a specified


combination of controllable variable.

One of the important question is how long to run a simulation experiment so that we have
reasonable label degree of confident. Suppose the probability density function is stationary and
we take n independent sample

x1,x2,….xn

X=1/nΣ_/[ xi

_DE

The number of required sample is given by:-

N=(yj-α/2) Ϫ2/t2

Where t=tolerence limit

Ϫ2 is variance of population parent

(yj-α/2) is two tailed standard normal static for the probability 1-α

4.2 Variance Reduction Techniques

The simulation run length is estimated to calculate the mean value of the result with specified
variance.

Larger the simulation run closer will be the expected value to exact value. This phenomenon
is called stochastic convergence, and in many applications these are very slow process.

There are a number of statistical techniques to variance reduction without increasing the
number of simulation runs.

Some of the variance reduction techniques also used to increase the precision the results
are

90
 Antithetic sampling
 Correlated sampling
 Importance sampling
 Control variates
 Stratified sampling
 Common random numbers.
4.2.1 Verification and validation of simulation models

 The development of simulation model is incomplete without verification and validation


 The validation is essential to build the credibility and acceptability of the model.
The objectives of the validation

 To obtain the model that can represent the behavior of the real system closely that is used
to substitute the experimenting on the real system
 To increase the accuracy of the output results.
The verification and validation is not a separate part of the design but these are integrated part of
the system it has to be carried out throughout the development of the model.

This requires the interaction between the model development team; people those who have
knowledge on the system and end users of the system.

In simulation model we have three different states of the system, the real system, the conceptual
model and the simulation program that is the computer representation of the model.

The process of verification is to determine that the computer simulation program designed as
they intended thus verification checks the correctness of the translation of conceptual model into
computer program. Verification involves debugging the computer program. Validation checks
how accurately the conceptual model represents the real system.

91
4.2.2 Iterative process of verification and Validation

One of the most important and difficult tasks facing a model developer is the verification and
validation of the simulation model. · It is the job of the model developer to work closely with the
end users throughout the period (development and validation to reduce this skepticism and to
increase the credibility.

The verification and validation process consists of the following components:-

1: Verification is concerned with building the model right. It is utilized in comparison of the
conceptual model to the computer representation that implements that conception. It asks the
questions: Is the model implemented correctly in the computer? Are the input parameters and
logical structure of the model correctly represented?

2: Validation is concerned with building the right model. It is utilized to determine that a model
is an accurate representation of the real system. It is usually achieved through the calibration of
the model.

 The first step in model building consists of observing the real system and the interactions
among its various components and collecting data on its behavior. Operators, technicians,
repair and maintenance personnel, engineers, supervisors, and managers under certain
aspects of the system which may be unfamiliar to others. As model development proceeds,
new questions may arise, and the model developers will return, to this step of learning true
system structure and behavior.
 The second step in model building is the construction of a conceptual model – a collection of
assumptions on the components and the structure of the system, plus hypotheses on the
values of model input parameters, illustrated by the following figure.
 The third step is the translation of the operational model into a computer recognizable form-
the computerized model.

92
Introduction

How do we know that the model we have used, is an accurate representation of the system
being simulated? This is an important question and must be answered satisfactorily before a
simulation study can be made use of. The area of experimentation and results analysis for
simulation models is well developed and a range of rules and guiding methods can be found
in the literature, e.g. are available. Many of the techniques developed are here to ensure that
dangerous mistakes are not made when analyzing and interpreting the results. In fact , without
establishing the validity of the model , if we accept the(erroneous) simulation results the
consequences may be disastrous. Put simply the power of modern simulation software to
93
generate large quantities of data can leave the user with the false sense of security that the
results generated are credible and truly representative of the system under study. Like all
modelling techniques care needs to be exercised. What is a valid model? Since no simulation
model will duplicate the given system in every detail it is not an appropriate question to ask if
a simulator is a ‗true‘ model of a real system. We should only ask if the model is a
‗reasonable‘ approximation of the real system. The acceptable levels of reasonableness and
approximation will vary from system to system and simulation to simulation. There is no
universally acceptable criteria for accepting a simulation model as a valid representation.
There are only guidelines that aid in establishing confidence in the model.
There are a number of phases as shown in Figure 1, for checking a simulation model prior to
experimental analysis:
 Verification - the accuracy of transforming a problem formulation into a model
(specification) deals with building the model right
 Validation - model behaves with satisfactory accuracy consistent with the study
objectives deals with building the right model
The above are essential checks performed prior to analysis of the model and are used to
establish what is known as model credibility. Verification and validation is shown in Figure 2,
as cause - effect and input – output terms.
A simulation run typically starts in the empty and idle state. The run is therefore characterised
by a "run-in" phase followed by a "steady state" phase, see Figure 1. The run-in phase is
generally ignored and is only used for investigating the effects of transient conditions such as
starting up a new factory or performing radical changes within an existing facility.
Equilibrium
Run in

Work In Progress (WIP) Delay


Steady State

Increase

Figure 4.1: The two key phases of a simulation run

94
Typically the steady state phase is of greater interest. At this stage checks must be made to
ensure no long term trends exist, such as continual build up of stock in the factory, that
suggest the model (hence the real system) will be unstable and unworkable.
Generally what is known as multiple replications is performed. This is where the model is run
several times. Each time the random number generators are set to provide different sequences
of random numbers, e.g. in case of manufacturing process the breakdown patterns of
machines are different and the points at which material is scrapped is different. This allows
confidence that the results being compiled represent the average and the range of conditions
that are likely and therefore play down ‗freak‘ or ‗unusual‘ behaviour.
Effect
Cause System

Conceptual Model
Model
Validation

Structural Validation
Behavioural
Validation

Varification

Simulation Model
Output

Input

Figure 4.2: Verification and Validation Activities

4.2.3 Verification and Validation

The validation efforts can be grouped into two parts


1. validation of the abstract model itself
2. validation of its implementation
The first part consists of examining all assumptions, which transform the real world system
into the conceptual model. A great deal of judgment and an intimate knowledge of the real

95
system are involved in this step. The validation of the abstract model is often highly
subjective. Testing the validity of an implementation is a more objective and easier task. It
consists of checking the logic, the flowchart, and the computer program to ensure that the
model has been correctly implemented.
The presentation of an experimental frame, which is shown in Figure 2, enables a rigorous
definition of model validity. Let us first postulate the existence of a unique Base Model. This
model is assumed to accurately represent the behavior of the Real System under all possible
experimental conditions. This model is universally valid as the data D RealSystem obtainable
from the Real System is always equal (symbol ≡ is used for equality) to the data D Base Mode l
obtainable from the model.

DBaseModel ≡ DRealSystem -------------------- (i)

_ A Base Model is distinguished from a Lumped Model by the limited experimental context
within which the latter accurately represents Real System behavior.
A particular experimental frame E may be applicable to a real system or to a model. In the
first case, the data potentially obtainable within the context of E are denoted by

D Re alSystem║E. In the second case, obtainable data are denote by Dmodel ║ E. With this
notation, a model is valid for a real system within Experimental Frame E if

D LumpedModel E ≡ DRealSystem E -------------------- (ii)

The data equality ≡ must be interpreted as equal to a certain degree of accuracy. It shows how
the concept of validity is not absolute, but is related to the experimental context within which
Model and Real System behavior are compared and to the accuracy metric used.
One typically distinguishes between the following types of model validity.
Replicative Validity concerns the ability of the Lumped Model to replicate the input/output
data of the Real System. With the definition of a Base Model, a Lumped Model is
replicatively valid in Experimental Frame E for a Real System if

96
DLumpedModel ║ E ≡ DBaseModel ║E --------------------(iii)

Predictive Validity concerns the ability to identify the state a model should be set into to
allow prediction of the response of the Real System to any (not only the ones used to identify
the model) input segment. A Lumped Model is predicatively valid in Experimental Frame E
for a Real System if it is replicatively valid and
FLumpedModel E FBaseModel ║E --------------------(iv)

where FS is the set of I/O functions of system S within Experimental Frame E. An I/O
function identifies a functional relationship between Input and Output, as opposed to a
general non-functional relation in the case of replicative validity.
Structural Validity concerns the structural relationship between the Real System and the
Lumped Model. A Lumped Model is structurally valid in Experimental Frame E for a Real
System if it is predictively valid and there exists a morphism ∆ from Base Model to Lumped
Model within frame E.

LumpedModel ║ E ∆ BaseModel ║E --------------------(v)


When trying to assess model validity, one must bear in mind that one only observes, at any
time t, D RealSystem (t) , a subset of the potentially observable data DRealSystem . This obviously
does not simplify the model validation enterprise.
Whereas assessing model validity is intrinsically impossible, the verification of a model
implementation can be done rigorously. A simulator implements a lumped model and is thus a
source of obtainable data DSimulator . If it is possible to prove (often by design) a structural
realtionship (morphism) between Lumped model and Simulator, the following will hold
unconditionally

DSimulator ≡ DLumpedModel --------------------(vi)


Before we go deeper into predictive validity, the relationship between different refinements
of both Experimental Frames and models is elaborated. In Figure 3, the derived from
relationship for Experimental Frames and the homomorphism.
Relationship for Models is depicted. If we think of an Experimental Frame as a formal
representation of the context within which the model is a valid representation of the dynamics
of the system, a more restricted Experimental Frame means a more specific behaviour. It is
obvious that such a restricted Experimental Frame will match far more models than a more
97
general Experimental Frame. Few models are elaborate enough to be valid in a very general
input/parameter/performance range. Hence, the large number of applies to (i.e., match) lines
emanating from a restricted Experimental Frame. The homomorphism between models means
that, when modifying/transforming a model (e.g., adding some non-linear term to a model),
the simulation results (i.e., the behaviour) within the same experimental frame must remain
the same.

applies to
general

derived from

restricted homomorphism

more

restricte

Experimental Frames Models


Figure 4.3: Experimental Frame – Model Relationship

Though it is meaningful to keep the above in mind during model development and use, the
highly non-linear nature of many continuous models makes it very difficult to automate the
management of information depicted in Figure 3. Non-linear behaviour makes it almost
impossible, based on a model or experimental frame symbolic representation, to make a
statement about the area in state-space, which will be covered (i.e., behaviour). A pragmatic
approach is to

1. Let an expert indicate what the different relations are. This is based on some insight into
the nonlinear dynamics. Such expert knowledge can be built from a large number of
conducted experiments.
2. Constantly with each experiment validate the expert information.
A crucial question is whether a model has predictive validity, is it capable not only of
98
reproducing data which was used to choose the model and parameters but also of predicting
new behavior? The predictive validity of a model is usually substantiated by comparing new
experimental data sets to those produced by simulation, an activity known as model
validation. Due to its special importance in the communication between model builders and
users, model validation has received considerable attention in the past few decades. The
comparison of the experimental and simulation data are accomplished either subjectively,
such as through graphical comparison, Turing test, or statistically, such as through analysis of
the mean and variance of the residual signal employing the standard F statistics, multivariate
analysis of variance regression analysis, spectral analysis, autoregressive analysis,
autocorrelation function testing, error analysis, and some non-parametric methods.
The above-mentioned methods are designed to determine, through comparison of measured
and simulated data, the validity of a model. As one might intuitively expect, different
modelling errors usually cause the behavior of the model to deviate in different ways from
that of the real system or, in other words, different modelling errors correspond to different
pattern in the error signal, the difference between experimental data and simulated data. These
patterns if extractable, can obviously be used to identify the modelling errors.

4.2.4 Comparing Model Data with Real System Data


After development of suitable model of defined problem and simulation of defined model,
we have to perform the comparison of output data with real system data.

Validating Existing Systems

When the simulated system exists in real life, then the most obvious and the best approach is
to use the real world inputs to the model and compare its outputs with that of the real world
inputs to the model and compare its output with that of the real system. This process of
validation is straightforward enough in principal but may present some difficulties when
carried out. Firstly, it may not always be easy to obtain input and output data from a real life
system without distributing it. Secondly, even if we could get actual input output of an
existing model it would not generally be for very long periods. Since the data are usually
probabilistic. For small lengths of simulation runs the variability of the model output would
be large. Therefore designing test that work with small samples is difficult. What usually is

99
done is to simulate the model several times (replicate) with different sequences of random
numbers and obtain the range of variation amongst these. Then, if the model is valid, the real
output should lie somewhere in the middle of the range of model output. The third problem is
to establish that the model output and the real system outputs are ‗practically‘ from the same
population.

If the outputs to be compared are sample means (e.g., average queue length, waiting time, idle
time), one could use any of a number of statistical tests (called ‘goodness’ of fit tests)
available to measure the discrepancy between the two outputs (i.e., model output and the real
system output). One such test is chi-square test. Others are Kolmogorov- Smirnov test,
Cramer - von Mises test and the Moments test. One could also use hypothesis testing to
determine if there is any significant difference between, say the average of the independent
set of observations.

Validating Fist Time Model


If a model is intended to describe a proposed or hypothethetical system (which does not exist
at present or did not exist in the past) then the task of validation is even more difficult. There
are no historical data available to compare its performance with. Since hypothetical system
are , by their very nature , based upon assumptions it is the validity of these assumptions the
simulation model is dependent on. A number of guidelines for testing validity of such system
have been found useful. These are as
1. Subsystem Validity: A model itself may not have any existing system to compare it
with, but it may consist of known subsystem each of that validity can be tested
separately.
2. Internal validity: One tends to rejects a model if it has a high degree of internal
variability. A stochastic system with high variance due to its internal processes will
obscure changes in the output due to input changes. The test can be performed by
replicating a simulation run with several different random number sequences and then
computing the variance of the outputs. If the variance is too high we reject the model.
3. Sensitivity Analysis: Sensitivity analysis consists of systematically varying the values
of parameters or the input variables one at a time (while keeping all others constant)
over some range of interest and observing the effect upon the model‘s response.

100
Sensitivity analysis will tell to which parameters the system is more sensitive. The
parameters to which the system response is relatively insensitive, we need not pay
very close attention to. The knowledge how far the assumed parameters values could
be from the true one without significantly affecting the response helps building our
confidence in the model.
4. Face Validity: If the model goes against the common sense and logic, it should be
rejected (even if it behaves like the real system). If those with experience and insight
into similar system do not judge the model as reasonable, it has to be rejected.
These and other validation tests do not completely validate a model. While failure to
pass a validation test would results in rejection of a model, passing these tests does not
guarantee that the model is valid. It only builds up our confidence in the model.
Ideally errors of a modeling should be separated from the errors in its implementation
(programming errors, etc.) by first validating the abstract mathematical model before
writing a simulator for it. In practice, however, it is really possible to check the
validity of the mathematical model without examining its computer version. This is
because of the mathematical intractability of a model, which was the reason for
simulating it in the first place.
Although validation is often messy, expensive and time consuming, involves
subjective ness and judgments and is rarely conclusive, it must always be attempted.
However inconclusive, it does provide a check against grosser errors and gives us
confidence to use the simulation results for decision making.

Summary

Verification and validation of defined system is very critical and it provides the testability to
defined system against the real system. Verification is defined as the accuracy of transforming
a problem formulation into a model (specification) deals with building the model right while
Validation is defined as the defined model behaves with satisfactory accuracy consistent with
the study objectives deals with building the right model. Without establishing the validity of
the model, simulation results can be erroneous and their consequences may be disastrous.

101
5. Simulation Languages
Introduction
A computer simulation language is used to describe the operation of a simulation on a
computer. Most languages also have a graphical interface and a simple statistic gathering
capability for the analysis of the results.
Benefits of Simulation Languages
 Save development time
 Built-in facilities for time advancing, event scheduling, random number generation,
statistical data collection, and report generation
 Readable modular code
There are two major types of simulation:
– Discrete-event simulations
– Continuous simulations

• Some modern languages can handle combinations of Discrete and continuous


simulations.

Continuous simulation languages are designed for simulating continuous models and discrete
simulation languages for discrete models – models that change their states abruptly at
discrete points in time. But few languages are suitable for both the discrete as well as
continuous models. e.g. GASP IV (General Activity Simulation Program), GSL–A
(Generalized Simulation Language), SIMSCRIPT etc. These languages are generally for
system models in which some of the variables change continuously and other variables
change discretely, and these continuous and discrete variables interact with each other.
5.1 Continuous Simulation Languages
• In analog computers, for dynamic engineering Problems/systems for which analytical
solution was difficult, differential equations were used to describe the system for
simulation.
• The system was described by means of block diagram which was then simulated on the
analog computer by suitably patching together corresponding blocks available on the
analog computer. But after the invention of digital computers with the greater accuracy,
speed, freedom from scaling etc., special program packages, called Canned Programs,

102
were used on digital computers to make a digital computer appear like an analog
computer.
• These programs are called Digital-Analog Simulators. They allow a continuous system
model to be programmed on a digital computer essentially in the same way as it is solved
on an analog computer.
Some Continuous Simulation Languages
• Advanced Continuous Simulation Language (ACSL):
Supports textual or graphical model specification.
• SimApp:
Simple simulation of dynamic systems and control systems.
• Simgua:
A simulation toolbox and environment that supports Visual Basic.
• VisSim:
A visually programmed block diagram language.
5.1.2 Types of continuous simulation languages
1. Block-structured continuous simulation languages:
Simulation language that makes a digital computer emulate an analog computer is called
a block-structured continuous simulation language.
It requires the user to prepare an analog-computer type block diagram to represent the
system to be simulated and then input this diagram by providing patching instructions
which specify how these blocks are to be connected together.
A typical block oriented language (eg. 1130 CSMP) provides a number of standard
functional blocks (in the form of subroutines).
These include the common simulation elements such as integrators (I), multipliers (X),
summers (+), limiter (L), unit delay (U) In addition to these fixed functional blocks, the
language generally also provides a few elements for which the user can define the
functional relationship.
Examples of block oriented languages are MIDAS, PACTOLUS, 1130 CSMP, etc.

103
Integrator (I) and multiplier (X) blocks
Such blocks in the language may have one, two or three inputs depending on the type of
block, eg. the integrator has three i/ps and multiplier two. The o/p of each block is a single
value function. Each of the elements or the blocks is identified by its type denoted by a
specific symbol in the language (eg. I, X, +, etc) and by its block number-n.
In order to simulate the given continuous system we first represent it by means of a block
diagram and this block is then put into a computer program by means of three types of
statements;
• Configuration statements – are the set of patching instructions which define the
interconnection between the blocks.
• Parameter statements – associate the numerical values with the block elements
to specify the exact functional operations of the blocks.
• Function generation statements – define the input/output of the function
generator elements.
2. Expression-based languages
The block oriented language is severely limited by its small specialized vocabulary and lack
of FORTRAN like statements.
Therefore, no relationship or equation can be expressed directly. But, in the expression-based
language one can write FORTRAN like statements (along with representing the block
diagram). Such a feature eliminates the necessity of drawing a block diagram. Differential,
algebraic and logical equations representing the model of a system being simulated can then
be written directly as statements or expressions in the language.
Example: 10 LET K1=0.05 ; 20 LET k3=0.01
Some examples of expression-based languages are MIMIC, DYNAMO, S/360 CSMP etc.

104
5.2 Discrete System Simulation Languages
discrete simulation languages are designed for simulating discrete models – models that
change their states abruptly at discrete points in time.
These languages are user friendly and provide many facilities such as automatic generation
of streams of random numbers for any desired statistical distribution; automatic data collection;
their statistical analysis and report generation; good diagnostics; automatic handling of queues
etc.
In addition, a good simulation language also provides the model builder with a view of the
world that makes model building easier. It gives a vocabulary for describing dynamic systems
and powerful concepts for expressing the relevant aspects of system behavior. Thus a simulation
language can be of help even at the model building stage. But there are three major problems
in using such languages;
1. The programmer has to learn a new language.
2. Such languages are highly problem oriented.
3. The language may not be available easily.
Every discrete system simulation language must provide the statements for
1. Representing the state of the system at a single point in time (static modeling).
2. Moving a system from state to state (dynamic modeling)
3. Performing random number generation, data analysis, and report generation.
5.2.1 Types
1. Event-oriented languages
2. Activity and process-oriented languages (including flow chart-oriented)
3. Transaction-flow oriented language
1. Event-oriented languages: In this language, each event is represented by an instantaneous
occurrence in simulated time and must be scheduled to occur, when a proper set of conditions
exists. The state of the system changes at the occurrence of an event. These are generally
used to model processes that are characterized by a large number of entities.
eg. SIMSCRIPT, GASP etc.

105
5.3 SIMSCRIPT
• A complete, modern, general purpose programming language
– English like syntax is self documenting
– Data structures make programming easier and faster
– Highly portable language
• A powerful discrete event simulation language
– Models a system as it evolves over time
– Timing routine and event set handled automatically
• Variables
– Integer Let number = 1
– Real, Double Let money = 5.50
– Alpha Let grade = ―A‖
– Pointer ... Address of an entity
• Control Structures
– Assignments
– Branches
– Loops
– Functions
• Entities, Attributes and Sets
– Entity : an item of interest; e.g. a communications packet; an airplane
– Attribute: characteristic of an entity; e.g. source, destination, priority;
 tail number, takeoff weight
– Set: collection of entities
e.g. transmission queue of packets to be processed; a fleet of airplanes.
Activity and Process-oriented language: A key feature of process orientation is that of a
single process routine, composed of a number of segments describing a sequence of
activities. Each segment behaves as an independently controlled program. On receiving the
control, only the statement composing the segment are executed and then control is returned.
Thus the model is defined as a series of occurrences (called processes), and explicit
interaction between the processes is brought about by the process routine. eg. SIMULA,
ASPOL, SOL, SIMUFOR

106
5.4 GPSS
Transaction-flow oriented language
It is a sub-category of process-oriented language, except that the flow of activities
passes through specifically defined blocks. The system model is represented by a flow chart
block diagram consisting of the language blocks. The program creates transactions, executes
them in the blocks and moves them along the flow chart. eg. GPSS (General Purpose Simulation
System).
In GPSS, the system is represented by blocks or sequence of blocks in a flow chart or block
diagram. Each block represent the activities. The lines joining these blocks in the flow chart
indicate the sequence in which the activities can be executed. The block diagram is a network of
interconnected blocks. Each block performs special simulation function. The choice of activities
is shown by more than one line leaving the block and the conditions are stated at the block. Each
block has a number of data fields as indicated by letters A, B, C, D, E etc. An identification
number called the location is given to each block, moving from top to bottom the locations are
assigned automatically. Blocks are also given symbolic name and should be from three to five
non-blank characters of which first three must be letters.
Features of GPSS
1. Easy to learn and use;
2. Good debugging facilities;
3. Simple mathematical calculations can be carried out with the use of variable statements
4. Can generate number of basic random variates;
5. Programs are usually much shorter than in other simulation languages;
Drawbacks of GPSS:
1. Restricted to simple queuing problems;
2. Poor computational facilities;
3. Inflexible input/output;
4. No language extension possible;
5. There are no elementary mathematical functions in GPSS, such as the trigonometric or
logarithmic functions;
6. Machine efficiency is often poor since GPSS is an interpretative system

107
5.5 SIMULA

Introduction

The first Object Oriented Language (OOL) Simula 67 was officially introduced by Ole Johan
Dahl and Kristen Nygaard at the IFIP TC 2 Working Conference on Simulation Languages
in Lysebu near Oslo in May 1967. All modern programming work carried out today is based
on principles of OOP introduced for the first time in the Simula definition.
A computer program is a series of instructions, which contains all the information necessary
for a computer to perform some task. It is similar to a knitting pattern, a recipe or a musical
score. Like all of these it uses special shorthand, known in this case as a programming
language. We will learn the programming in SIMULA 67,in SIMULA 67, 67 stood for 1967,
the year in which this earlier version was first defined .We will call SIMULA 67 as SIMULA
only in our discussion.
5.5.1 Basic Building Block of SIMULA
SIMULA program is made up of sequences of instructions known as blocks, which act
independently to varying degrees, but which are combined to produce the desired overall
effect. The simplest programs contain only one block, known as the program block. All other
blocks follow the same basic rules, so let us have a look at the single block program,
example 1.

Example 1: A simple example


begin

integer Int1;
comment The first SIMULA program written for this book; Int1:=3;
OutInt(Int1,4);
OutImage end
This is not the simplest possible program. We could have written begin end
and had a complete program block. This tells us the first rule about all blocks. A block
always begins with the word begin and ends with the word end. Begin and end are called
"keywords", since they are reserved for special purposes and may not be used for anything
else.

108
SIMULA is not a case sensitive language which mean we can use lower case or upper case or
mix of two to write program. Instructions in the SIMULA are of two types,
DECLARATIONS and STATEMENTS. Every executable statements in SIMULA end with
a semicolon. There are also pieces of the text which are ignored by the SIMULA system and
which simply help any human who reads the program to follow what is happening. These are
called comments.
SIMULA comments begins with the keyword comment, is followed by some text and ends
in a semi-colon.

comment The first SIMULA program written for this book;


comments can also be used in certain places within instructions or combined on the same line
as them. To help everyone understand your programs, you should include comments in them.

Declarations
In example 1, the first instruction after the word begin is a declaration: integer Int1;
Declarations in a block show how much of the computer's memory is going to be needed by
that block. They also show into how many sections it is to be divided , how big each is to be
and to what sort of use each will be put. Each of these sections is given a name, by which the
program will refer to it.
The program block in example 1 has only one declaration. It starts with the "type"
keyword integer, followed by a name or "identifier", Int1.

In example1 it will be used to hold a whole number, which is called an integer in SIMULA.
The identifier Int1 is now the name of the space reserved in this way. We may sometimes
refer to the value held in this space as Int1 also.
If we want to use more locations, we can declare them in the same way, being careful to give
the correct type to each. Thus we might write
begin
integer Int1; real Real1;

etc.
Which gives us a location of type real and called Real1, which we can use in this block.

109
5.5.2 Statements
The other instructions in our example are all statements. They tell the SIMULA system what
it is to do.The first one is an "assignment" statement. It tells the system to place something in
one of the locations declared for use by this block. In this case the value three is to be stored
in the integer location declared as Int1. Since this value is of a type which matches that
declared for the location the statement is legal SIMULA.
The next statement uses something called OutInt, which is a "procedure" and is available in
all SIMULA systems. OutInt will write out the first number in the parentheses - ordinary
brackets - after it. It writes it as a whole number at the end of the line, or "image", which is
currently being created. The second number is used to tell the system how much space to use
on the line, when writing out the first number.
The final statement uses OutImage. Like OutInt, OutImage is a procedure and is available in
all SIMULA systems. Such standard procedures are known as "system procedures". They
are not keywords, since you may declare a different meaning for them within a block if you
wish.
5.5.3 Syntax Rules
The commonest errors reported by a compiler are those, which do not obey the grammar or
"syntax" of the language. Often they are the result of typing errors.
The rule that a program block must start with begin and finish with end is a syntax rule.

Syntax of Declarations
The declarations integer Int1;
and
integer Int1,Count;
both follow the syntax rules for declarations. A declaration has to be a keyword giving the
type, followed by an identifier list. An identifier list is either a single identifier or a series of
identifiers, separated by commas, with the option of as many spaces as desired either side of
the commas.
The syntax rules for SIMULA, like those for most programming languages, are very strict.
You cannot omit the space which indicates the end of the keyword integer, without breaking
the syntax rules for a declaration.

110
Syntax of Identifiers
We have used the word identifier as the technical term for the name given to something in our
programs. So far we have not considered what an identifier must look like.

The identifiers which we have used so far are

Int1 Count OutInt OutImage Real1


Notice that procedure names are identifiers and follow the same rules. Keywords have the
same syntax as identifiers, but they are not available for the programmer to define or redefine.
An identifier is a sequence of letters, numbers and underline characters (the last are known sometimes
as break characters). An identifier must start with a letter.
Some systems set a limit on the number of characters in an identifier. Others allow long
identifiers, but only look at the first so many characters. You should consult the
documentation for any system before using it, especially when moving a program from one
system to another.
Letters are often called "alphabetic characters", numbers "numeric characters" or "digits".
Mixtures of these two types are called "alphanumeric characters".
The following are valid identifiers TOTAL
A1 NEW4SUB6 MAX_SIZE G43

Syntax of Blocks
A block starts with the keyword begin, which, like all keywords, must have at least one space
following it or be the last word on a line.
This keyword is followed by a list of declarations or a list of statements or a list of
declarations followed by a list of statements. Statements and declarations are separated by
semi-colons or keywords. All declarations must come before any statements in a block.
The following are valid blocks

Example 2

begin
integer I;
real Arc;

I := 5;

111
Arc := 3.2;
OutInt(I,3);
OutImage end
In addition we can note that a block can be used in place of a simple statement. In this case it
is called a "sub-block" or a block which is "local" to the program block.
A procedure call is an identifier (the name of the procedure) followed in some cases by a
parameter list which is enclosed in brackets. The parameter list is a list of identifiers,
constants and expressions, separated by commas.
Examples 3: Procedure calls.
OutImage : No parameters. Moves output to next line.
OutImage : One parameter, a text, which is printed on the current line. In this example a text
constant is used as the parameter.
OutInt(643,3): Two parameters, both integers, separated by a comma. Prints out the first
integer on the current line, padding on the left with spaces if this produces fewer figures than
the second integer. Either or both the integer constants given as parameters in the example
could have been replaced with identifiers or expressions.
Assignment statements have an identifier followed by optional spaces, followed by the
assignment "operator", followed by optional spaces, followed by an expression. The
assignment operator is the sequence colon followed by equal-sign, :=. Before giving an
informal description of expressions, it is probably best to consider the examples of
assignment statements given as 2.5.

Example 4: Assignment statements.


Res := 3 Count := Last
Count := Last + 1
Message := "PLEASE TYPE YOUR NAME"
Next := Average*Number + 2
The use of spaces before and after the assignment operator has no effect on the correctness of
the statement. This applies to all "operators" in SIMULA.
5.5.4 Expressions

Several kinds of expressions are shown to the right of the assignment operator in these
examples. The simplest of these is a constant, such as 3 or "PLEASE TYPE YOUR NAME".

112
An expression can also be a single identifier, such as
Count := Last
The remaining examples show identifiers and constants separated by operators. Thus Last + 1
is the identifier Last followed by the addition operator followed by the constant 1.
Average*Number + 2
is the identifier Average followed by the multiplication operator followed by the identifier
Number followed by the addition operator followed by the constant 2. We shall not attempt a
complete definition of expressions, but explain them as we need to use them. These examples
should give a feel of what is meant.
operators
The commonest arithmetic operators are given below.
+ Addition
- Subtraction
* Multiplication
/ Division with non-whole numbers (reals)
// Division with whole numbers (integers)
:= Assignment

Semantics of Declarations
The same identifier cannot be declared twice in a block.

The identifier is used to name a space in the computer's memory which is large enough to
hold a value of the type specified. Whenever the identifier is used subsequently, it refers to
this space and this type of value.

Semantics of procedure calls


A procedure call must have the correct number of parameters. Each parameter must be of the
correct type. The actions of the procedure are performed, using the parameters to provide information
for the procedure if necessary.

113
Semantics of Assignments
The type of the expression to the right of the assignment operator must be "compatible" with the type of
the identifier on the left.
The value of the expression on the right will be stored in the location reserved for the identifier
on the left.

Semantics of Expressions

The types of the quantities in an expression must be compatible. The type associated with the value of an
expression is determined by the types of the quantities in it, except when the division operators are used.
In this case the type is the same as the operator, i.e. integer for "//" and real for "/".
Semantics of Blocks
Any identifier used in a statement in a block must already have been declared. The statements in
the block are performed in the order indicated.

Syntax and Semantics of a Comment

A comment is a special sequence in SIMULA which is treated as a space by the compiler. It contains a
message which explains what is going on around it in human terms. Its syntax is quite simple.
A comment is:
The keyword comment, followed by any sequence of characters ending at the first semi-
colon, ;. Or the character !, followed by any sequence of characters ending at the first
semicolon. Or Any sequence of characters following the keyword end, ending at the first
occurence of the keyword end, else, when or otherwise or a semi-colon or the end of the
program. Comments, partly to help you understand things and partly to get you into the habit
of using them. They will help you see what is going on, but only in the important places.
Be very careful to end your comments properly. If you forget a semi-colon or keyword, as
appropriate, you will lose some of the following program, since it will be treated as part of the
comment. In particular, remember that the end of a line does not end a comment . Comments
have no meaning in the program.

Example 5 : The use of comments.


begin
comment Double space removal program, first version, Rob Pooley, March 1984;
text T; ! Holds the text to be processed;

114
InImage; ! Reads the text into SysIn.Image; inspect SysIn do
! Refer to SysIn not SysOut; begin
T :- Blanks(Image.Length); ! See the next chapter; T:=Image; ! Copies the
characters into T;
end;
if T.GetChar=' ' then ! First character is a space?; begin
if T.GetChar=' ' then ! Second character is also?; T:=T.Sub(2,T.Length-1); !
Remove first character;
end;
comment Now write out the text; OutText(T);
OutImage
end Double space remover
5.5.5 Type Cast Actors
So far we have seen three types: integer, real and text. The only one we have looked at in
any detail is integer. In fact SIMULA contains several other types as keywords or
combinations of keywords. In addition it is possible for you to create combinations of these
simple types and give them names, by using the class mechanism.

Types in Assignments
A type is given in a declaration so that the SIMULA system knows how much space to allow
for the declared quantity. The system checks whenever a new value is stored into this location
that the value is of the same type. If the types are different then the system may do one of two
things.
It may "convert" the quantity being stored to that of the location. This is only possible
between the types integer and real and their short and long variants.
If conversion between the types is not specified in SIMULA, the system will report a
semantic error.
SIMULA will only convert one type to another where this has a clear meaning. In practice
this is only the case for arithmetic values, i.e. types which represent numbers Clearly we must
be very careful how we use types. Even where we are allowed to mix types, we must be
careful that we understand what will happen when a value of one type is converted into a
value of another type.

115
Types of Parameters

Exactly the same rules apply where values are passed as parameters as apply when they are
assigned. In effect the parameter given is assigned to a location with the type specified for that
parameter.

Standard Types
Integer
Values are of type integer if they are whole numbers. They may be positive, negative or zero. On any
particular SIMULA system there will be a largest positive and a smallest negative number, which can be
held in an integer location. In our programs we have used integer constants to represent values being
assigned to our integer locations. An integer constant is a whole number written as a sequence of decimal
digits,
i.e. any digit in the range 0-9. This may be preceded by a minus or, less commonly, a plus
sign. A minus sign indicates a negative value; a plus sign has no effect.

Example 6: integer constants 2


45678231
-432
+ 1245
Spaces after the plus or minus are ignored. Spaces between digits are not allowed. It is also
possible to give integer constants in other number bases.
Real
A real value is a number, which is not necessarily whole. It is held in a form, which allows it
to contain a fractional part. In common speech it is what is known as a 'decimal' number or
decimal fraction, i.e. it is written with a decimal point separating the whole and fractional
parts of the number. A real value is restricted both by a largest/lowest range and by the
number of significant decimal places, which can be held. Most of us are used to writing
decimal numbers (decimal fractions) in what is technically known as "fixed point" notation.
The examples of decimal constants used in examples so far are in this form. It can be
described as two strings of decimal digits (in the range 0-9) separated by a full stop or period.
Like integers they may be preceded by a minus or plus sign.

116
Example 7: Legal fixed point real constants.
5.7
236.0
3246.8096
-45.87

+ 46.876
The use of spaces is not allowed between digits or between a digit and the decimal point.
Mathematicians often use another notation to write decimal values, especially where these are
very large or very small. This way of writing them is known as "floating point" and is also
allowed for writing real constants in SIMULA.

5.5.4 Character
A character holds a value, which represents a single character. SIMULA allows you to use
any of the characters in the "character set" of the computer that you are using plus the
characters defined by the International Standards Organization (ISO) character set
standard. (This is sometimes known as the ASCII character set.). It is important to stress
that a character has a different type from a text.

We normally think of a character as something written on a page. In the computing world this
sort of character is often referred to as a "printing character". It is probably easy enough for us
to accept that a space is also a printing character. It is rather harder to grasp that a character
can produce other effects, such as making the printer start a new line or a new page. These are
non-printing "control characters". Some of these character values produce very complex
effects in certain printers or terminals and no effects or different effects in others. In general
terms the values held in character locations are those, which are sent as instructions to
printers, terminals and other hardware devices. Most of these instructions control the printing
and formatting of written information. The simplest merely instruct the device to print a
visible character. Character constants are normally written as single characters, enclosed in
single quotes. Note carefully that a single character enclosed in double quotes is a text
constant and may not be used as a character. Control characters cannot be written in this way.
They use their internal integer value written as an integer constant and enclosed in
exclamation marks, inside single quotes. This notation can also be used to write printing

117
characters, but is very clumsy.

Example 8: Legal character constants 'A'


'b'
'4'
'%'
' ' '''
'!3!' Control character, enclosed in exclamation marks.
Note that case, i.e. the difference between capital and small letters, is significant in character
constants. Thus 'A' and 'a' are not equivalent. Note also how a single quote is represented as a
character constant.

Boolean
A Boolean quantity can only have two values. These are True and False.
A Boolean can be assigned the value of any conditional expression and can be used wherever
a conditional expression might be used, e.g. in an if statement or a while loop. Boolean
constants can only be represented by the keywords True and False.
Text
A text variable is used to refer to and manipulate sequences of characters. A sequence of
characters is often known as a "string". In the examples using text variables so far we have
often assigned strings as the values to be placed in locations declared as type text. From this it
might seem that a text and a string are the same thing.
Text constants are strings, i.e. sequences of characters, surrounded by double quotes. Each
character in a string can be any of those in the ASCII (ISO) standard set.
A character in a string can also be represented by its internal integer value enclosed in
exclamation marks.
When a string is too long to fit onto a single line of your SIMULA program it can be
continued on the following line by typing a double quote at the end of the first line and again
at the start of the second line. These quote characters are ignored and the value of the constant
is the string on the first line followed by the string on the second line.

118
Example 9: Legal text constants. "The cat sat on the mat" "34.56"

"%"
"This string is typed on two lines, but will be treated as if it "
"was on a single line, without the second and third double quotes." "This string has a
control character !10! embedded"
""""
Note that the last string shown in 9 will contain only one double quote. When you want to
have a text constant, which contains one double quote, you must type two, so that the
compiler knows that it is not the end of the string. Another example showing this is:
"This string contains only one "", but we must type two."
Note also that the single character text constants "%" and "" "" are not the same as the
character constants '%' and '"'. They have different types.

Initial values
An identifier of a certain type, which is not declared as a constant is often referred to as a
"variable" of that type, since, unlike a constant of the same type, its value can be changed by
assigning to it. When we declare such variable, the SIMULA system places an initial value in
the location identified. This value is the same on all SIMULA systems on all computers for all
variables of a given type.
Thus it is quite legal, and meaningful, in SIMULA to write
begin
integer IntVal;
OutInt(IntVal,4);
OutImage
End
since the initial value placed in the location identified by IntVal will be printed. This will be
the value initially given to all integer locations.
The values placed in each type of location are given below.
integer 0
short integer 0
real 0.0

119
long real 0.0
character The ISO NULL character, which is 'invisible'.
Boolean False
text NoText, the empty text, referring to an empty string.
Equivalent to "".

Implicit Conversion of Real and Integer


When a real value is assigned to an integer location or vice versa we have said that the value
will be converted to one with the type of the location. When integers are converted to real, no
problems are involved in understanding what will happen. The values 3 and
3.0 are usually thought of as identical and such a conversion presents no ambiguities.
On the other hand, when real are converted to integers, the result depends on how we deal
with the fractional part of the real value. How do we get rid of the figures to the right of the
decimal point?
If we go back to our earlier examples we might use them to produce example 6.9. Running
this would show the outcome of implicit conversion of real to integer.

Example 10: Implicit conversion and rounding.


begin
integer I1, I2, I3; I1 := 3.2;

I2 := 3.9;
I3 := 3.5;
OutInt(I1,4);
OutInt(I2,4);
OutInt(I3,4);
OutImage end
Clearly more than one outcome is possible. If all reals are rounded up the output will be
44 4
if down
3 3 3
and if to the nearest integer value 3 4 4
or 3 4 3 the last two depending on whether 3.5 is regarded as nearer to 3

120
Constant Declarations
Constant declarations were introduced into SIMULA very late on and are still regarded as
controversial by older SIMULA programmers. They should be used with some restraint if
you want to move your programs to other systems. Older SIMULA systems will not have
constant declarations.
A constant declaration allows an identifier to be assigned a value in its declaration. This
identifier may not then be assigned another value. This can be very useful when using the
same value frequently in a program, especially when the value is easily mistyped or has no
obvious meaning.
real Pi = 3.14159; ! A constant declaration;

5.5.5. Conditional Statements


The ability that makes computers more than calculators or fancy typewriters is the ability to
perform different actions according to some condition or conditions, which it can determine
to be either true or false. Computers can be told, "Check this condition. If it is true then do the
following, otherwise do this other thing". In some cases the other thing is nothing. Put
crudely, computers can make choices. What they cannot do, or, at least, as far as the author is
aware, not yet, is decide which condition to test, or whether the actions which follow are
really sensible. They must be told these things and programming languages have mechanisms
for doing so. In SIMULA, the most important construction for making choices is the
"conditional statement" or, as it is often known, the if statement.
Example 11: Simple use of an if statement.

begin
integer Int1; Int1:=InInt;
if Int1=2 then OutText("YES");
OutImage end
This program will read in a whole number and compare its value against 2. If it is equal to 2
then the program will print YES, otherwise a blank line will be printed. Compile and run it to
make sure. From this example we can see the syntax of an if statement. An if statement starts
with the keyword if, followed by a condition, followed by the keyword then, followed by a
statement. The program checks the condition. If it is true, the statement is executed (or carried

121
out, if you prefer), but if it is false, the statement is skipped. The next statement, if there is
one, is then executed. An if statement may be used wherever a simple statement may be used.

The if-then-else statement


Example 12: Un-combined if statements.
begin
integer Int1; Int1 := InInt;
if Int1=2 then OutText("YES"); if Int1 ne 2 then OutText("NO");
OutImage end
Here we have added a second if statement to our first example, but all that it does is check
the opposite condition to the first. ne is the symbol for "not equal" in SIMULA. This program
will print out YES if the number read in is 2 otherwise it will print out NO.
5.5.6 Compound Statements and Blocks as Statements
As we mentioned in previous section that a block in SIMULA can be used as a statement.
More generally, we can use a sequence of statements enclosed in begin and end wherever we
can use a simple statement. In fact SIMULA uses the term "compound statement" for such a
sequence if it contains only statements and the term block where it contains its own
declarations. We are able to define our own procedures, which we can then use wherever we
like inside the block where we declare them. In fact we can even build a library of our
favorite procedures and use it in all our programs.

Declaring Procedures

It is clearly not enough to declare a procedure in the way we declare an integer. The
declaration
procedure Concatenate
cannot magically tell the SIMULA system what we want Concatenate to do. We must also
supply the actions to match the name. Here is a valid procedure declaration:
procedure PrintName;
OutText("Alice");
The syntax of the simplest procedure declaration is the keyword procedure, followed by the
identifier to be used for the procedure, followed by a semi-colon, followed by a statement.
The statement following the semi-colon is known as the procedure body and specifies what

122
is to be done each time the procedure is invoked or "called" in the subsequent program.
Calling the procedure is done by using its identifier as a statement in the program, exactly as
we call system procedures.
Example 13 shows the use of our procedure, PrintName.

Example 13: Simple procedure use.


begin
procedure PrintName;
OutText("Alice");
Concatenate;
OutImage end

Parameters to Procedures
We have already seen how parameters can be used to pass values to system procedures.
Example 14 shows how to declare two texts as parameters to the Concatenate procedure.

Example 14: Concatenate with parameters.


begin
procedure Concatenate(T1,T2); text T1,T2; begin
text T3;
T3:-Blanks(T1.Length+T2.Length); T3:=T1;

T3.SetPos(T1.Length+1);
while T2.More do T3.PutChar(T2.GetChar); OutText(T3);
OutImage end;
text Text1,Text2;
Text1:-"Fred";
Text2:-"Smith"; Concatenate(Text1,Text2)
end
This passes in our texts, T1 and T2, which are now used as parameters to the procedure. The
identifier given for the procedure in its declaration is followed by a list of all the parameters
to be used, enclosed in parentheses and separated by commas. The declaration text T1,
T2;following the semi-colon and before the begin is known as the type specified and gives the
type of each of the parameters. Where more than one type of parameter is to be used, more

123
than one type declaration must be given. 15 is an example, using one text and one integer
parameter.

Example 15: A procedure with more than one type of parameter.


begin
procedure TextAndInt(T,I); text T; integer I; begin
OutText(T);
OutInt(I);
OutImage end;
TextAndInt("NUMBER",10) end

Parameter Modes
The way of specifying parameters that we have used so far will always work for passing
values into a procedure. If we want to get information out, we may have to add a mode
specifier for some parameters. This sounds confusing, but is easy to follow in practice. Here
is a final version of Concatenate.
Example 16: Using a name parameter to return a result.

begin
procedure Concatenate(T1,T2,T3); name T3; text T1,T2,T3;
begin
T3:-Blanks(T1.Length + T2.Length);

T3:=T1;
T3.SetPos(T1.Length + 1);
while T2.More do T3.PutChar(T2.GetChar); end;
text Text1,Text2,Text3;
Text1:-"Fred";
Text2:-"Smith"; Concatenate(Text1,Text2,Text3); OutText(Text3);
OutImage end
Notice that, as well as specifying that T3 is of type text, we have specified that it is name.
name is not a type but a mode. When a parameter is defined as of name mode, any
assignments to it alter the value of the variable actually passed in the call, rather than a local

124
copy, as would have happened with the other parameters, which are passed by value. In fact
there are three modes; value, reference and name. Where a mode specifier is not given for
a parameter, a mode of value or reference is assumed, depending on its type. Some modes are
illegal for certain types. Table 6.1 is a complete table of the assumed (usually referred to as
default), legal and illegal modes for parameters to procedures.

Type Mode Value Reference


Simple type Default Illegal Legal
text Legal Default Legal
Object reference Illegal Default Legal
Simple type array Legal Default Legal
Reference type array Illegal Default Legal
procedure Illegal Default Legal
type procedure Illegal Default Legal
label Illegal Default Legal
switch Illegal Default Legal
Illegal Default Legal

Table 5.1: Complete table of the modes for parameters to procedures.

A simple type is integer, real, character or Boolean and any long or short variants of them.
Now we can see that name is always legal and reference is the default for all but simple types.
Do not worry about the meaning of those types which are new. We shall consider their use
when we encounter them.

Value Parameters
A value parameter to a procedure acts as if it were a variable of that type declared in the body
of the procedure. The value passed to it when the procedure is called is copied into it as part
of the call statement. Since values declared inside a block cannot be used outside that
block, the value of this mode of parameter is lost on returning from the procedure. When
calling a procedure, any value of the correct type may be passed to a value mode parameter.
Thus constants, expressions and variables are all allowed.

125
To see the effect of passing a parameter by value, consider example 17.

Example 17: Passing parameters by value.

begin
procedure P(Val); integer Val; begin
OutInt(Val);
OutImage;
Val := Val - 1;
OutInt(Val);
OutImage end..of..P;
integer OuterVal;
OuterVal := 4;
P(OuterVal);
OutInt(OuterVal);
OutImage
end

The value in OuterVal, 4, is copied into the parameter Val's location when P is called. Thus
the first number printed will be 4. When 1 is subtracted from Val, OuterVal is not changed.
Thus the second number printed is 3, but the third is 4. When a text is passed by value to a
procedure (N.B. this is not the default) it has the effect of creating reference to a local text
frame with the same length as the text passed, into which the characters from the latter text
are copied. Consider example 6.17.
OutLine is actually quite a useful procedure. Note that in order to pass our text parameter by
value we have to give a mode specification for it, using the keyword value. When the
procedure is called, the parameter T is initialized as if the following statements had been
executed.
T :- Blanks(OuterT.Length); T := OuterT

126
Example 18: Text parameter passed by value.
begin
text OuterT;
procedure OutLine(T); value(T); text(T); begin
OutText(T.Strip);

OutImage end..of..OutLine;
OuterT:-"Here's a line";
OutLine(OuterT)
end

Reference Parameters
When a parameter is passed by reference, the local parameter points at the location holding
the object passed, rather as if the reference assignment operator had been used. No local copy
is made of the contents of the object. For every reference parameter type except text, this
explanation is sufficient and should be reconsidered for its meaning when those types are
encountered. As we have seen, when a text is assigned by reference new copies of Pos,
Length etc. are made, but the same actual text frame is referenced. Pos, Length etc. will have
the same values as those for the original reference, but will not change if the originals do. As
far as the passing of text parameters by reference is concerned the following effects occur:
The characters in the frame referenced by the parameter may be changed by the procedure.
Since this is the same actual location as the frame of the reference, which was copied, the
contents of the frame remain changed when execution of the procedure is complete.
The other attributes have local versions created, with the same values as those current for the
parameter. When those other attributes are changed for the parameter, they remain unchanged
for the original. Thus, any changes to these are lost when execution of the procedure is
complete.
Try rewriting the Concatenate procedure (Example 14) with all the parameters passed by
reference. What would be the effect on running the program using it now? .You should find
that it fails since the Length of Text3 cannot be changed by manipulating T3 inside the
procedure. The only way to get this program to work would be to set the length of Text3
before calling the procedure, as shown in example 19. Note that as reference mode is the
default for all types where it is legal, it is never necessary to give a mode specification for

127
reference parameters. Thus there is no keyword reference to match value and name.

Example 19: Concatenate using only reference mode parameters.


begin
procedure Concatenate(T1, T2, T3); text T1, T2, T3; begin
T3 := T1;
T3.SetPos(T1.Length + 1);
while T2.More do T3.PutChar(T2.GetChar);
end**of**Concatenate**by**reference;

text Text1, Text2, Text3;


Text1 :- "Fred";
Text2 :- " Smith";
Text3 :- Blanks(Text1.Length+Text2.Length); Concatenate(Text1,Text2,Text3);
OutText(Text3);
OutImage end

Name Parameters
Name parameters are very powerful, but complex. It is sometimes possible to make serious
errors using them, through failing to consider all possible outcomes of their use. When a
variable is passed by name, its use within the procedure has the same effect as when that
variable is used outside the procedure. Thus any actions on the parameter inside the procedure
directly affect the variable passed in the call. This is obviously a suitable mode for getting
values back from a procedure, as we have seen. This contrasts with the use of reference mode,
where the contents of what a variable points at are changed, but the variable still points at the
same location. If a reference assignment is made to a name parameter, it is actually made to
the variable passed originally, not a local copy.
Example 6.15 returned the concatenated texts in the name parameter T3. When the procedure
was called, the variable Text3 was passed as this parameter and when the statement following
the call was executed, Text3 contained the combined texts. There is one statement missing
from this Concatenate. It is needed because the Pos, Length and other attributes of Text3 will
be changed by the procedure, when it manipulates T3.
What is this missing line? See if you can work out what it is before reading the polished

128
version below.
Example 20 is the version of Concatenate which we can use in all our programs.

Example 20: Finished version of Concatenate.


begin
procedure Concatenate(T1, T2, T3); name T3; text T1, T2, T3;
begin
T3 :- Blanks(T1.Length + T2.Length); T3 := T1;
T3.SetPos(T1.Length + 1);
while T2.More do T3.PutChar(T2.GetChar);

T3.SetPos(1); ! Did you get this right?; end**of**Concatenate;


text Text1, Text2, Text3; Text1 :- "Fred";
Text2 :- " Smith"; Concatenate(Text1,Text2,Text3); OutText(Text3);
OutImage end
The missing statement must reset the position within T3 to the start of the characters it now
contains, since it is left pointing to their end. Note that, since name mode is never a default for
any type, the mode specifier name must be used in a mode specification for any parameters,
which are to be used in this way. It is worth mentioning that all parameters passed by name
are re-evaluated each time they are used inside the procedure. This is important in some cases
since actions inside the procedure may change the value of an expression passed in this way,
while expressions passed by value or reference are evaluated and their values copied into the
local variables specifying those parameters, once and for all, at the call. Try compiling and
running example 6.20 to see the difference. Note also that while it is legal to pass expressions
by name in this way, an attempt to assign to a name parameter when an arithmetic expression
like those in 6.20 or anything else which is not a valid left hand side has been passed will
cause a runtime error. The general rule is that the exact text of what is passed replaces each
occurrence of the name parameter within the procedure.

Example 21: Expressions by name and by value.


begin
procedure Use_Name(Val1, Val2); name Val2; integer Val1, Val2; begin
OuterVal := 3; OutInt(Val1,4); OutInt(Val2,4);

129
OutImage end..of..Use_Name;
integer OuterVal;
OuterVal := 5;
Use_Name(OuterVal+3,OuterVal+3)

5.5.7 File Handling in SIMULA

You are probably used to the fact that computers keep permanent information in collections
called files. Some systems use other names such as data sets, but they are essentially the same
thing. These files have names by which you can identify them to the computer. Programs can
read from these collections of information and write to them.
SIMULA has objects called Files as well. When you want to read from or write to a file on
your computer, you must use a SIMULA File object to stand for the external file and tell the
computer which external file you want. The exact way that this works may vary slightly from
one computer to another, but the important points are the same.
In fact a SIMULA File can stand for any source of or destination for information. A printer
can also be written to by using a File object to represent it in your programs. A magnetic tape
reader can be used as a source of input in the same way. In fact you have already been using
two File objects without being told that that was what you were doing. These are the standard
input File, SysIn, and the standard output File, SysOut. Whenever you have used InInt,
OutImage and any other input/output instructions you have been using File attributes.

Simple Input
To read information from the computer we normally use a type of File object known as an
InFile. In fact InFile is a sub-class(Concept of Class and Sub Class is declared in subsequent
sections) of the object type or class called File. This means that all the properties of File are
properties of InFile or are redefined in InFile, but that InFile has some extra ones of its own.
In fact all types of File objects are sub-classes of File. InFile is not a direct sub-class of File,
however; there is another level between them, called ImageFile. Put more simply, class File
defines a type of object with a number of attributes used to access sources of and destinations
for information on a computer, such as files, printers, terminals and tape readers. File class
ImageFile is a sub-class of File. It has all the attributes of its parent class File, some of which
it redefines, and in addition some extra attributes used to handle information in certain ways.
130
ImageFile class InFile is a sub-class of ImageFile. It has all the attributes of both File and
ImageFile plus extra ones for reading information using the ways suited to Image File's
attributes. This probably sounds far from simple on first reading, but the idea of thinking of
objects as classes and sub-classes is central to SIMULA and so we use it to describe formally
the relationships of the various sub-types of File.
Example 22 is a program using an In File to provide its information. Notice the familiar
names used for the same purposes, but now prefixed with a File name.
Example 22: Simple input using InFile.
begin
ref (InFile) Inf; text T1;

Inf :- new InFile("MYRECORDS"); Inf.Open(Blanks(80));


Inf.InImage;
T :- Inf.Image;
OutText(T);
OutImage;
OutInt(Inf.InInt);
OutImage;
Inf.Close end
There are a few new concepts in this program. Let us look at them one by one. Firstly, we
have a new type of declaration. It declares Inf to be a ref variable, but has the word InFile in
parentheses between the keyword ref and the identifier Inf. A ref variable is a pointer to an
object of a complex type. The class, which defines that type, is given in parentheses after the
keyword ref. Thus Inf is a location, which can be used to hold a pointer to an object, which is
of type InFile. It is initially pointed at an imaginary object called None, just as text variables
initially reference NoText.
SIMULA allows us to use complex objects, made up of attributes, which are already defined.
These attributes may be of the standard SIMULA types or may reference types defined by the
user, i.e. one user defined type may use others as attributes. The construction in SIMULA
which can be used to declare a complex type is the class. We have already seen predefined
system classes when we looked at File and its sub-classes. Now let us declare a class Lab for
use in our program. Example 23 shows 22 reworked using such a class.

131
Example 23: Simple labels program with classes.
begin
integer NumLabs, I;
procedure OutLine(T); text T; begin
OutText(T);
OutImage end;
text procedure InLine; begin
InImage;
inspect SysIn do InLine:- Copy(Image.Strip) end;
class Lab; begin

text Nam, Street, Town, County, Code; end--of--class--Lab;


ref(Lab) Label1;! Declare a pointer to a Lab object;
Label1:- new Lab;! Create a Lab object and point Label1 at it; comment Remote access
through dot notation;
Label1.Nam:- InLine;
Label1.Street:- InLine;
Label1.Town:-InLine;
Label1.County:- InLine;
Label1.Code:- InLine;
InImage;
NumLabs:= InInt;
comment Now connected access through inspect; inspect Label1 do
begin
for I:=1 step 1 until NumLabs do begin
OutLine(Nam); OutLine(Street); OutLine(Town); OutLine(County); OutLine(Code)
end end
end
Let us look at the new features used here. First there is the class declaration. This provides a
description for a class of objects which all have the same attributes. In this case we define Lab
(label is a SIMULA keyword and may not be used as an identifier). In general, a class
declaration is very like a procedure declaration, with the keyword class instead of procedure.

132
The declaration of Lab specifies the name of the complex type being defined as the identifier
following the keyword class. This identifier is followed by a semi-colon. The attributes of the
class are defined in a statement, known as the class body, which follows. Thus Lab has five
attributes, all of type text. Having defined the attributes of our new type, we can now create
an object, or as many objects as we like, with those attributes. This is done by using an object
generator. An object generator can be used as a statement on its own or as a reference
expression, i.e. on the right hand side of a reference assignment or as a reference parameter.
Examples of all these are shown in 24.

Examples 24: Valid occurrences of object generators.


As a complete statement: new Printer
As the right hand side of a class reference assignment: OutF :- new OutFile As a class
reference parameter: Queue_Up(new Passenger)

A variable is first declared, whose type is ref(Lab). This means that it identifies a location
where a pointer to an object of the type defined by class Lab may be stored. This variable is
used first as the left hand side (destination) of a reference assignment statement. The effect of
this statement is that a new object containing the attributes of Lab is created. Since Label1 is
assigned a pointer to this object (references it), the object's attributes can be accessed through
the variable Label1. As we have seen with objects, which were of types InFile and OutFile,
there are two ways of doing this. Both are shown in example 6.20.
"Remote accessing" of a class object is done by using the identifier of a reference variable,
which currently contains a pointer to the object, Label1 in our example. A ref(Lab) procedure
could also be used, as we have seen with SysIn and SysOut. This reference is followed by a
dot, followed by the name of a visible attribute of the class which defines the type of the
object being accessed. This method of accessing attributes may be used for both text objects
and class objects. This distinction is important, since the type "text" is not defined by a class.
The other way of accessing the attributes of an object is by "connecting" it first. To connect
an object we must use an inspect statement. In the statement, which follows the keyword do,
the use of any identifier which has a declaration in the class defining the type of the connected
object is assumed to refer to this attribute. If no matching declaration is found in this class or
its prefixes, the identifier is assumed to belong outside the object. Thus, within the inspect
statement in example 6.20, the occurences of Nam, Street, Town, County and Code are taken
133
to refer to attributes of the object Label1, since declarations for them are found in class Lab.
5.5.8 Arrays in SIMULA
Many programs need to read, update and write out long series of data items. These items are
the objects, which we wish to manipulate. It is rarely worthwhile to use a computer to process
one or two items. Even our program, which wrote only a few copies of one label, used an
object with a list of data items within it.
The use of files allows us to read lists from outside the program and to store them at its end.
Unfortunately, as our updating programs show, it is not a good idea to create a new file,
external to the program, each time we add, delete or modify an item in a list. We soon end up
with a multitude of out of date files. The use of objects defined by classes allows us to hide a
number of basic items inside larger, more complex items. It does not solve the problem of
how to refer conveniently to a long list of items in succession. The need to declare and use a
separate identifier for each possible line of a letter, for instance, makes long letters unwieldy
to process and those of indefinite length almost impossible. This section is dealing with the
first of three problems by using of lists. It provides simple but elegant mechanisms for solving
most of the problems mentioned above. Let us start with the problem of holding a long list of
items, which are all of the same type.
Example 25 shows the use of an array in a much simplified letter program, where no
addresses are allowed for, only the text and the name of the sender.

First look at the array declaration in class Letter. (The misspelling is deliberate since there is a
system Boolean procedure called Letter, which we might well wish to use in the same
program.

Example 25: Letter program using a text array.


begin
class Leter; begin
text Sender;
text array Line(1:60); integer Len;
procedure ReadLetter; begin
InImage; inspect SysIn do
while Image.Strip ne ".end" do begin
Len := Len + 1;

134
Line(Len) :- Copy(Image.Strip);
InImage end
end++of++ReadLetter;
procedure WriteLetter; begin
integer Current;
for Current := 1 step 1 until Len do begin
OutText(Line(Current));
OutImage end;
OutText(" Yours faithfully,"); OutImage;
OutText(" "); OutText(Sender);
OutImage end++of++WriteLetter;
OutText("Type your letter, ending with '.end' on a line by itself"); OutImage;
ReadLetter;
OutText("Now type your name on a single line"); OutImage;
InImage;

inspect SysIn do Sender :- Copy(Image.Strip) end--of--class--Leter;


new Leter.WriteLetter end**of**program
Simple Array Declarations
The syntax of an array declaration is the type specifier of the items in the list (integer,
ref(Letter) etc.), followed by the keyword array, followed by an identifier, followed by the
"bounds" of the list, enclosed in parentheses. Spaces (or ends of line) are used to separate
keywords and identifiers as usual. They are not required between the identifier and the left
parenthesis, but may be used if you wish. It is legal to omit the type specifier, in which case
the array is assumed to be of type real. The syntax has not included the form of the bounds. In
the commonest case we wish to declare a simple numbered list. The bounds then are two
arithmetic values, which are converted to integers if necessary, separated by a colon. In
example 6.24 the constant integers 1 and 60 are the bounds. This definition is only the
simplest variant, but it covers most uses of arrays for the moment.
The semantics of such a declaration produce information telling the system to reserve space
for a list of items of the specified type. This list is to be numbered consecutively, starting with
the value before the colon and ending with the value after the colon. This also defines the

135
number of elements in the list. This list as a whole is referred to by its identifier. Thus a whole
array can be passed as a parameter to a class or procedure, by giving just the identifier.
Individual items in the list can be referred to by the identifier followed by an arithmetic value
enclosed in parentheses, giving the number of the element to be accessed, within the list. Thus
the declaration in example 6.24 tells the SIMULA system to reserve space for a list of sixty
text variables. These are to be declared to be numbered from one to sixty. The list will be
referred to in the program by the identifier Line.
Note that the value of the first bound does not have to be 1. The bounds can have any values,
even negative ones, as long as the first bound is less than the second or equal to it. The first
bound is usually referred to as the lower bound and the second as the upper.Note also that the
values of the bounds may be given as real values. In this case they are converted to integers in
the same way as for assignments. The values can be arithmetic expressions as well as
constants. The normal rules for evaluating expressions apply.

Using Array Elements


The items in an array list are often called its "elements". Example 6.24 shows how an
individual element of Line can be accessed. This is known as a subscripted variable. The
value within the parentheses is called the subscript or the index. Item number Len of the list is
accessed in ReadLetter. It is referred to as Line(Len). Since Len is increased by one before
each Image is copied to Line(Len) the effect is to copy successive lines of input into
successive elements of the text array Line. The syntax of a simple subscripted variable is an
identifier followed by an arithmetic value enclosed in parentheses. The arithmetic value may
be a constant, a variable or a more complicated expression, including a call on an arithmetic
type procedure. Where necessary the value will be converted to an integer, following the
normal rules. The semantics are also simple. The value of the subscript gives the number used
as an index to the elements of the array. Note that the value of the lower bound is important in
determining which element this refers to. A subscript of six will only refer to the sixth
element if the lower bound was one. If the lower bound was four, indexing by six gives the
third element.
A subscripted variable may be used wherever a simple variable of the same type may be used.
The value of the subscript, converted to an integer if necessary, must lie between the values of
the lower and upper bounds, inclusive. If it is out of this range a runtime error will be

136
reported.

Dynamic Array
Clearly the use of arrays allows large amounts of data to be held in locations declared within
our programs, without the continual need to access files and without declaring long lists of
identifiers. The use of loops, especially for loops, allows us to handle arrays in concise and
clear ways. One problem with the use of arrays is that we must tell the system in their
declarations how many elements they contain and what their bounds are. Often this may not
be known until runtime. This means that example 6.24 can only cope with letters of up to
sixty lines. If someone wanted to use the program for a longer letter, they would have to alter
the source and recompile it. Although the array is not always the best solution when there is
no way of knowing in advance how long the list will be, it can be made more generally useful
by specifying the bounds in other ways. We have defined the bounds as any expressions
giving arithmetic values. This includes constants, as used in 6.24, but also variables and
expressions involving operators and type procedures. The only restriction is that any variables
used must already have their values fixed before entering the block in which the array is
declared. This means that the bounds can changed each time a block is entered.
The SIMULA system allocates the space used by each block only when that block is entered.
Thus it does not need to know how big an array is until then. If a variable used in the bounds
of an array has been declared in an outer block, this variable can have its value set in that
outer block before the array's space is allocated in the inner block. The variable must not be
declared in the same block as the array, since the system may allocate the block's arrays
before its other variables and, anyway, these variables could only have their initial zero
values, since no statements may come in front of declarations in a block. As a consequence,
the only block which cannot use variables in array bounds is the program block. This is the
outermost block and must use constants in all its array bounds. All sub-blocks, procedures
and classes used in a program are free to use variables in array bounds so long as these are
declared in an enclosing block or, for classes and procedures, are parameters. Remotely
accessed variables may also be used.

The simple examples in 26 and 27 show how "dynamic bounds", as this mechanism is known,
may be used for sub-blocks, procedures and classes respectively. These trivial examples

137
demonstrate a very powerful facility. One important point to note is that when the parameters
of a procedure or class are used in bounds for arrays declared in that procedure or class body,
they are treated as outside that body. This is the only case where any distinction is made
between parameters and other locally declared variables inside the procedure or class body. It
is very important that this be allowed.

Example 26: Dynamic array bounds in a sub-block.


begin
integer I1,I2; ! Declared at the outermost block level; I1 := 2; ! Sets a non-zero value in
I1;
I2 := 3; ! Sets a non-zero value in I2; begin

comment Start a sub-block which can only be entered after I1 and I2 have had their
values set;
integer array A1(I1:I2); ! Declare with I1 and I2 as bounds; A1(2) := 6;
end--of--sub-block;
comment Array no longer accessible; end

Example 27: Dynamic array bounds in a procedure.


begin
procedure Bounder(Lowest); integer Lowest; begin
comment Parameters may be used as bounds inside a procedure body;
character array C1(Lowest:4*Lowest); ! Use an expression containing
Lowest as upper bound; C1(Lowest*2+1) := '&'; ! Use an
expression in the subscript too; OutChar(C1(5)); ! Null unless Lowest is 2;
OutImage
end--of--procedure--Bounder;
Bounder(2); ! Should print &; end**of**program

5.5.9 Sub-Classes (Inheritance)


One of the important ways we have of making sense of the world is to classify things. We put
them into categories or classes. SIMULA allows us to reflect this very natural way of thinking

138
in the way we write programs. When classifying things we first group them either very
generally, e.g. as animal, vegetable or mineral, or very specifically, e.g. as bees or roses,
depending on circumstances. These approaches correspond to the programming techniques
known as "top down" and "bottom up" design, respectively. In practice, it is fairly easy to
classify things in general terms, but appearances can be deceptive when it comes to detail.
Things, which look alike, may actually have very different origins. Thus the hedgehog and the
spiny anteater look remarkably similar and live very similar lives, yet, genetically, they are
not closely related at all. SIMULA takes the top down approach as the safest, just as natural
science has tended to. It allows us to define a CLASS, as we have seen, to represent a general
type of object. This may then be extended, to reflect the special characteristics of sub-types by
defining sub-classes of the original. These retain some or all of the characteristics of the
parent type, but include characteristics, which are only found in certain objects of this type. It
is important to notice that sub-types in SIMULA extend and refine the range of characteristics
of the parent type. The more general the class of objects described, the fewer characteristics
that are given to it. One example of the use of such sub-types, that we have already seen, is
the Class File and its sub-classes.

class
File

File class ImageFile

ImageFile class Infile

ImageFile
class

ImageFile class OutFile

Outfile class PrintFile

Figure 5.1 : Family tree of class File

139
The syntax of a sub-class declaration is very simple. The keyword class is preceded by the
name of the parent class. Otherwise the declaration is the same as for a simple class. The new
class is said to be "prefixed" by the parent.

The Types of Class Objects


When a class object is generated it possesses all the attributes of the class whose name is
given in the object generator. This includes any visible attributes from classes on its prefix
chain, following the rules given above concerning name clashes. The type of such an object is
the class specified and this is called its qualification. It can also be thought of as being
qualified by the classes on its prefix chain, except that not all the attributes of these may be
visible. A variable which is declared as a ref to a class which is the qualification of an object
or is on the prefix chain of its qualifying class may be used to access that object. The type of
the refIt is only legal to treat an object which is being remotely accessed as if it was qualified
by the class of the referencing variable. Reference variable used controls how much of the
prefix chain may be so accessed.

5.6 Case Study I

5.6.1. A multi-channel queuing system-Active Customer approach


Figure 2 shows the system being simulated. It is an abstraction of for example a bank where
the customers wait in one queue for any of the tellers. The interval between arrivals is
random, uniformly distributed between 1 to 3 minutes. All servers have the same random
service time that is normally distributed with the mean value 8 minutes and the standard
deviation 2 minutes. The simulation should find the average time a customer spends in the
system. Simulation of similar systems in Simula (exactly in the system class Simulation of
Simula) always starts by identification of processes. One process is obviously the generator of
customers - it will repeatedly generate a customer, record its arrival time, and wait a random
delay. To express the dynamics of the system, there are two logical approaches. First (used in
this example) is based on active customers and passive servers. The opposite approach -
active servers, passive customers is shown in the next example. An active customer has life
rules represented by the following steps:
If there is a free server, proceed. Wait in the queue otherwise. Seize a server; generate random
delay that represents the service time. Release the server.

140
If there is a waiting customer (if the queue is not empty), remove it from the queue and
activate it. (The activated customer will start its step 2.)
Update statistics.
Queue

Customers Servers

Figure5.2: Queuing System made of one Queue and more servers


The following program is a simulation model of the above system. Note, that the primary
objective was to show the logic of the model in a program as simple as possible. Real
simulation models of course prompt for all variable parameters and provide more results (like
for example average and maximum queue length, etc). In the following program there are two
processes that exist during the whole experiment: the generator and the main program (block
prefixed by Simulation), that just waits until the experiment is over and then displays the
result. Then there are a varying number of customer processes that exist temporarily. After
updating statistics the customers terminate. Note the use of standard functions to generate
random delays. There are standard functions in Simula for most commonly used distributions.
All are given an integer variable as a seed to be used by the random generator. So all random
values may use separate streams of random numbers or share a common one.
! Active customer approach; Simulation Begin
Real TrialDuration; ! Experiment length [min];
Ref(Head) Queue; ! The queue;
Integer Servers; ! Total number of servers;
Integer BusyServers; ! Numbers of working servers;
Integer TrialSeedG, TrialSeedS; ! Seeds of random generators;
Long Real TotalTime, TimeSpent; ! Variables for statistics;
Integer CustomersOut; ! Number of served customers;
Real MinInt, MaxInt; ! Uniform interval between arrivals;
Real SMean, SStd; ! Normal service duration;
Process Class Generator;
Begin
While true do begin
Activate New Customer(Time); ! Time is the current (arrival) time;

141
Hold(Uniform(MinInt, MaxInt, TrialSeedG)); ! Interval between arrivals:
End While;
End of Generator;
Process Class Customer(Arrival); Real Arrival;
Begin
Ref(Customer) Next;
If not Queue.Empty or (BusyServers >= Servers) then
Wait(Queue); ! Customer has to wait in the Queue;
BusyServers := BusyServers + 1; ! Seize a server;
Hold(Normal(SMean, SStd, TrialSeedS));
BusyServers := BusyServers - 1; ! Release the server;
If not Queue.Empty then begin
Next :- Queue.First;
Next.Out; ! First from Queue served; Activate Next after Current;
End If;
CustomersOut := CustomersOut + 1; ! Statistics;
TotalTime := TotalTime + (Time - Arrival);
End of Customer; ! MAIN program body: ;
TrialSeedG := 7; TrialSeedS := 23; ! Seeds for random variables;
MinInt := 1; MaxInt := 3; ! Min and Max intervals;
SMean := 8; SStd := 2; ! Random normal servers;
OutText("Enter the number of Servers : ");
OutImage;
Servers := InInt; ! Initial numbers;
TrialDuration := 600; ! Other variables initialized to 0;
Queue :- New Head; ! Create an empty queue;
Activate New Generator; ! This starts the experiment;
Hold(TrialDuration); ! Experiment duration;
TimeSpent := TotalTime/CustomersOut;
OutText("Average time spent in the system: ");
OutFix(TimeSpent, 3, 10); OutImage;

142
InImage; End of program;
5.7. Case Study II
5.7.1. A multi-channel queuing system-Active Server approach

The system being simulated is the same, as in the previous example (refer Figure 2). The
difference is the active server that repeatedly serves customers from the queue until the queue
is empty. Then the server passivate . Customers at first activate all idle servers (if any) and
then go into the queue. This is of course not very efficient, but simple. Servers activate
customers after completing the service. In the rest of their lives the customers just update
statistics. The main program creates and activates all servers, but they immediately passivate,
because the queue is empty. Then the main program activates the generator and waits until the
experiment is over.
! Active server approach;
Simulation Begin
Real TrialDuration; ! Experiment length [min];
Ref(Head) Queue; ! The queue;
Integer Servers; ! Total number of servers;
Integer TrialSeedG, TrialSeedS; ! Seeds of random generators;
Long Real TotalTime, TimeSpent; ! Variables for statistics;
Integer CustomersOut; ! Number of served customers;
Real MinInt, MaxInt; ! Uniform interval between arrivals;
Real SMean, SStd; ! Normal service duration;
Ref(Server) Array ServBank(1:10); ! Max. Number of servers is 10;
Integer i; Process Class Generator;
Begin
While true do begin
Activate New Customer(Time); ! Interval between arrivals: ;
Hold(Uniform(MinInt, MaxInt, TrialSeedG));
End While;
End of Generator;
Process Class Server;
Begin

143
Ref(Customer) ServedOne; While true do
If not Queue.Empty then begin ServedOne :- Queue.First;
ServedOne.Out; ! First from Queue served;
Hold(Normal(SMean, SStd, TrialSeedS));
Activate ServedOne after Current
end
Else Passivate;
End of Server;
Process Class Customer(Arrival); Real Arrival;
Begin
For i:=1 step 1 until Servers do If ServBank(i).Idle then
Activate ServBank(i) after Current;

Wait(Queue); ! Service finished: ;


CustomersOut := CustomersOut + 1; ! Statistics;
TotalTime := TotalTime + Time - Arrival;
End of Customer; ! MAIN program body: ;
TrialSeedG := 7; TrialSeedS := 23; ! Seeds for random variables; MinInt := 1;
MaxInt := 3; ! Min and Max intervals;
SMean := 8; SStd := 2; ! Random normal servers; OutText("Enter the
number of Servers : "); OutImage;
Servers := InInt; ! Initial numbers; TrialDuration := 600;
Queue :- New Head;
For i:=1 step 1 until Servers do begin ServBank(i) :- New Server;
Activate ServBank(i) ! Create and activate all servers; End For;
Activate New Generator; ! This starts the experiment;
Hold(TrialDuration); ! Experiment duration;
TimeSpent := TotalTime / CustomersOut;
OutText("Average time spent in the system: ");
OutFix(TimeSpent, 3, 10);
OutImage;
InImage; End of program;

144
5.8 Disadvantage of SIMULA
SIMULA never became a widely spread commonly used language. There are various reasons
to explain this fact. Even though the reasons all depend on each other, the following is an
attempt to group them from various points of view.
 Expensive
 Does not have a modern Interactive development Environment (IDE)
 Too complicated
 Not enough publications
 Limited file access facilities (typed files)
 Missing data types (records, sets)
 No advanced parallelism and real time support
 No GUI support
 Long executable files for short programs
 No multiple inheritance
 No interfaces
 No automatic collection of statistics
 No report generator

Summary
In this unit we have learn different kinds of simulation languages. SIMULA is studied in
detailed .SIMULA is first object oriented programming language , which having all OOPS
features like concepts of encapsulation, data hiding, classes, objects and inheritance together
the features of any high level language i.e. procedures, loops conditional statements etc.
SIMULA‘s syntax and semantics is almost similar to other high level object oriented
programming language i.e. C++ and Java .At the end of unit we have discussed two case
studies which will be helpful to apply the reader‘s knowledge.

145
5.6 Factors in selection of Discrete Simulation Languages
Simulation is a powerful tool for allowing designers imagines new systems and enabling them to
both quantify and observe behavior.
Currently the market offers a variety of simulation software packages. Some are less expensive
than others. Some are generic and can be used in a wide variety of application areas while others
are more specific. Some have powerful features for modeling while others provide only basic
features. Modeling approaches and strategies are different for different packages.
Following are the list of factors that are important for selection of simulation software.
 Establish the commitment to invest in simulation software to solve your problem.
 Clearly state the problem (or class of problems) that you would like to solve.
 Determine the general type of simulation tool required to solve the problem.
 Carry out an initial survey of potential solutions.
 Develop a list of functional requirements.
 Select the subset of tools that appear to best meet the functional requirements.
 Carry out a detailed evaluation of the screened tools and select a tool.

146

You might also like