Upload
phamliem
View
217
Download
0
Embed Size (px)
Citation preview
TH
E
U N I V E RS
IT
Y
OF
ED I N B U
RG
H
Division of Informatics, University of Edinburgh
Equation-Based and Agent-Based Modeling of Supply Networks
by
Wanwimol Thawornchak
Informatics Research Report EDI-INF-RR-0045
Division of Informatics September 2001http://www.informatics.ed.ac.uk/
Equation-Based and
Agent-Based Modeling
of Supply Networks
Wanwimol Thawornchak
MSc in Computer Science Division of Informatics
University of Edinburgh 2001
Abstract
“Supply networks” is an approach to deal with the interconnections of organizations for
the purpose of supplying goods and services required by consumers. Emerging e-
commerce increases its important because a supply network is directly applicable to
business-to-business scenarios. This project aims to investigate the dynamics of supply
networks using two modeling approaches, which have different but complementary
feature and compare and contrast them. The first is equation-based modeling, which is
the traditional modeling for system dynamics and uses a set of equations in order to
represent the system. The second is agent-based modeling, which consists of collections
of programs running in a distributed fashion and exchanging messages.
- i -
Acknowledgements I would like to thank my supervisor, Wamberto W. Vasconcelos, for the special guidance
during the course of the research reported in this dissertation. I deeply appreciate the
many hours of thoughtful discussion and his seemingly endless patience. He was always
willing to help when I had problems and supported the idea behind this project from the
very beginning. I sincerely thank you.
I also would like to thank the Royal Thai Government for granting me a scholarship,
which gives me an opportunity to pursue my education and enhance my knowledge.
Thanks to Jarassri – my friend, who introduces this university to me and gives me much
advice during my studying.
Special thanks to Tanitha – my sister here, and our private Thai community at Richmond
Place for all encouragement and warm support for the time of being an oversea student.
Lastly and most importantly, my family-especially my parents and my sisters -who give
me the unconditional and unbounded support. Their endless love, devotion, frequent
phone calls have encouraged and cheered me up. I thank you for always being with me.
- ii -
Table of Contents
1. Introduction 1
1.1The purpose of the project 1
1.2 Methodology 1
1.3 A dissertation Layout 2
2. Supply Networks 3
2.1 Supply Networks: a Definition 3
2.2 The Network Perspective 5
2.3 Activities within Supply Networks 6
2.3.1 Channel Management 6
2.3.2 Material Management 7
2.3.3 Supply Chain Management 8
2.3.4 Lean Supply 9
2.4 Insight supply networks 10
2.4.1 Structure 10
2.4.2 Strategy 10
2.4.3 Relationships 11
2.4.4 Dynamics of Supply Networks 12
2.5 Summary 12
2.6 Supply Networks in the experiments 13
3. Modeling and simulation 14
3.1 Equation-Based Model 15
3.1.1 System Dynamics 15
3.1.2 Dynamic model 16
3.1.3 SIMILE 18
3.1.4 VenSim Simulation 21
- iii -
3.2 Agent-Based Model 24
3.2.1Simulation of Order Fulfillment in Divergent Assembly Supply Chains25
3.2.2 The DASCh Project 27
4. Experiments and Results 30 4.1 The first experiment 30
4.1.1 An equation-based model for supply networks 30
4.1.2 An agent-based model for supply networks 36
4.1.3 Compare and contrast the experimental results 46
4.2 The second experiment 48
4.2.1 An equation-based model for supply networks 48
4.2.2 An agent-based model for supply networks 51
4.2.3 Compare and contrast the experimental results 53
4.3 The third experiment 55
4.3.1 An equation-based model for supply networks 55
4.3.2 An agent-based model for supply networks 58
4.3.3 Compare and contrast the experimental results 60
5. Conclusions and Future Work 61 5.1 Conclusions 61
5.2 Future Work 64
Appendix A 70
- iv -
List of Figures
Figure 2-1: An “Hourglass” supply network 5
Figure 2-2: Activities within Supply Networks 6
Figure 2-3: Our 3-tier Supply Networks 13
Figure 3-1: Flow diagram along with the corresponding feedback loop 17
Figure 3-2: Model of population dynamics 19
Figure 3-3: Total population size 20
Figure 3-4: Population size of 4-age classes 20
Figure 3-5: System Dynamics (ODE) Model 22
Figure 3-6: Inventory Oscillation in EBM 23
Figure 3-7: SCN Agent Interactions in the Swarm Implementation 26
Figure 3-8: The DASCh Supply Chain 28
Figure 4-1: EBM for Supply Networks : Experiment 1 31
Figure 4-2: Simile Graphs1 : Experiment 1 33
Figure 4-3: Simile Graphs2 : Experiment 1 35
Figure 4-4: Simile Graphs3 : Experiment 1 36
Figure 4-5: ABM Lpad Platform 37
Figure 4-6: Supply Networks for ABM 38
Figure 4-7: A message-passing Diagram 41
Figure 4-8: ABM Graph1 : Experiment 1 43
Figure 4-9: ABM Graph2 : Experiment 1 45
Figure 4-10: Comparison for EBM and ABM graphs : Experiment 1 47
Figure 4-11: EBM for Supply Networks : Experiment 2 49
Figure 4-12: Average price from EBM : Experiment 2 50
Figure 4-13: Average price from ABM : Experiment 2 52
Figure 4-14: Average price of each dealer from ABM : Experiment 2 53
Figure 4-15: Comparison for EBM and ABM graphs : Experiment 2 54
Figure 4-16: EBM for Supply Networks : Experiment 3 56
- v -
Figure 4-17: EBM graph 1 : Experiement3 57
Figure 4-18: EBM graph 2 : Experiment 3 58
Figure 4-19: ABM graph 1 : Experiment 3 59
Figure 4-20: Comparison for EBM and ABM graphs : Experiment 3 60
1
Chapter 1: Introduction
1.1 The purpose of the project
Modeling and simulation is a very active branch of computer science. This approach is
to create a model representing the real system and execute the model to observe its
behaviour experimentally. In our project, we propose two modeling approaches, which
are equation-based modeling (EBM) and agent-based modeling (ABM). EBM
represents the system as a set of equation that relates observables to one another. ABM
represents the system as the internal behaviour of each individual. We exploit two
models in order to study and analyse a supply network scenario, which is said dynamic.
Supply networks are the interconnections of entities for the purpose of supplying goods
and services required by end customers. The idea is to construct the relationships of
organisations between suppliers and consumers and its goal is to communicate
efficiently and consistently across boundaries. The supply network becomes important
because of its direct applicability to business-to-business scenarios, which are
commonplace in e-commerce.
1.2 Methodology
We construct EBM and ABM for our supply network scenario, which is created, based
on basic business principles. The scenario involves consumers, dealers and a producer,
who sell and buy products. For EBM, we use Simile, a graphic simulation and
modeling software developed by the Institute of Ecology and Resource Management,
The University of Edinburgh. For ABM, we use Sicstus Prolog in order to develop
agents that correspond to entities of our supply networks with support tools. The tool,
developed by Wamberto W. Vasconcelos, supports the replication of agents, and the
automatic upload and execution of a number of agents based on distributed simulation.
2
In analysing the result of the experiment, we use graphs from Simile and create new
graphs from collections of the data by using MS Excel and Matlab.
1.3 A dissertation Layout
This paper is composed of 5 chapters. Chapter 1 is the introduction, where an overview
of the project is given.
Chapter 2 is the surveys work on supply networks. We give the definition and literature
review of supply networks. There are also interesting topics related to supply networks
and a briefly explanation of the supply network scenario that will be used in our model.
Chapter 3 is the overview of the modeling and simulation. We give the meaning of
model and simulation and introduce two approaches of modeling, EBM and ABM.
EBM is the conventional model for mathematics and system dynamics discipline. ABM
is a new kind of modeling that there is the motivation for many researches to exploit
with dynamic works such as business area. We also introduce the interesting works
developed by EBM and ABM. There are the works of DASCh project involving using
EBM and ABM for supply networks, the work of Troy J. Strader, Fu-Ren Lin and
Michael J. Shaw using ABM for inventory scenario and the example of EBM in
ecology field from Simile software.
Chapter 4 is our models and simulation. We describe the model that is constructed by
EBM and ABM including a scenario. Three experiments are conducted by using our
models and their results are analysed.
Chapter 5 is the conclusions, which compare and contrast employing EBM and ABM
for business scenario such as supply networks.
3
Chapter 2: Supply Networks
In our experiments with the business scenario, we focus on supply networks, a popular
and interesting approach to today’s business. Computers and Internet influence in
commercial world and has resulted in the emergence of electronic business (e-business)
applications. Such applications have increased in the degree of complexity and
dynamics in customer requirement. This increase in customer awareness causes a high
degree of competition in business. In such environment, “supply networks” is a trend to
be considered as a strategy and operation beyond the boundaries of the individual firm.
Supply networks increase their importance when business moves to e-commerce where
communication and transaction across different companies are in concern. The
challenges related to improving product quality, customer service and efficient
operation cannot be effectively met by isolated change to specific organisational units,
but instead depend critically on the relationships and interdependencies among different
organisations (or organisational units) [cited by Strader et al, 1998]. The strategies focus
on much closer relationships between suppliers and customers. Companies tend to co-
operate with other companies rather than internalise and control activities and resource
through vertical integration [ION Project, 1999].
2.1 Supply Networks: a Definition
“Supply networks” is a relatively new term evolved from the fields of supply chain
management, channel management, logistic and lean supply/enterprise. These areas are
all linked to operation management and strategy [ION Project, 1999]. Many definitions
given imply supply networks as the co-operation of organisations in order to process the
flow of material and information. These processes ranging from the purchasing activity,
through the operation and out to customers by the way of distribution or service
delivery activity are seen as integrated processes. This approach is close to a
conventional supply chain, which is considered a special kind of supply networks.
4
Unlike supply chain, which is a single route through a total network [ION Project,
1999], supply networks include horizontal relationships, which are links between
companies at the same level. In other respects, a supply chain is seen as an immediate
supply network, which has one tier of customers, and suppliers [Slack et al, 1998] but
supply networks take into account the vertical relationships expanding through several
tiers. However, in supply networks, a non-linear relationship gives a more complex,
albeit holistic and strategic, view of the processes.
Grapher defined supply networks as “vertical interfirm co-operation and disaggregation
of large firm” [cited by ION Project, 1999]. This definition implies the degree of
dependency and relationship among organisations, which form networks. Traditional
economics considers vertical integration as the basic pattern of relationship between
suppliers and consumers. However, integrated business face a risk of becoming locked
into appropriate technologies [cited by Harland, 1996] and this causes a loss of
flexibility when they commit to these technologies. Furthermore, unstable market
condition and changeable customers’ requirement induce modern firms to invest in
flexible manufacturing technologies such as multi-purpose machinery and a versatile
workforce able to adapt to changing conditions [ION Project, 1999].
ION Project defined supply networks as “A number of entities, inter-connected for the
primary purpose of supply of goods and services required by end customers” [1999].
The term “inter-connect” implies that a supply network is not only a group of entities.
Even though their works are of great relevance, they are different. The entities are
connected through transaction of goods or services and no organisation controls the
network. Furthermore, the relations in a supply networks consist of a spectrum of
supply relationships ranging from tight long-term to loose short-term relationships.
5
2.2 The Network Perspective
The term “network” refers to two or more organisations involved in the same
transaction. Transaction means that organisations are connected and have long-term or
short-term relationships depending on the quality, quantity, and type of interaction
between the parties. With their relationships, however, organisations are interdependent,
that is, each link must examine the others for its own maintenance because
understanding the maintenance of other links is its dependency upon their performance.
Each link must maintain its performance not only because of its relations with other
links but also because of itself being confront to competitive pressure. Organisations
within the network can occupy different relations so they are not necessarily tied to a
specific tier level.
The network includes supplier and customers and also includes suppliers’ supplier or
suppliers’ a set of suppliers and the same in the customer side. The figure that we use to
describe supply networks is an hourglass shape as illustrated by Figure 2-1.
Figure 2-1: An “Hourglass” supply network
(Reproduced from Parunak and VanderBok, 1998)
The example process in a supply network begins from a manufacturer. On its supply
side or on the lower part of an hourglass, it is supplied by its suppliers or assemblers,
ConsumersDealers
Manufacturer
Assemblers
Suppliers
6
who in turn purchase their own material from their suppliers. On the demand side or on
the upper part of the hourglass, the manufacturer supplies products to its customers or
dealers (distributors), who in turn may have their own customers. The entities directly
connecting to the manufacturer are called ‘first tier’ customer/supplier. On the supply
side, they are supplied by ‘second tier’ supplier. However, some primarily ‘second tier’
supplier may supply the manufacturer directly and the same should happen in the
demand side.
2.3 Activities within Supply Networks
As mentioned above, processes within supply networks range from the purchasing
activity to the distribution or service delivery. Each process occupies different parts of
the supply network as shown in Figure 2-2. However, not only supply flows through
this networks, there is also information and currency.
Figure 2-2: Activities within Supply Networks
(Adapted from Slack et al, 1998)
2.3.1 Channel Management
This topic involves the management of a channel of distribution, which is a group of
individuals and organisations that direct the flow of product from the manufacturer to
First-tier customers
Manufacturer
Second-tier customers
First-tier suppliers
Second-tier suppliers
1. Channel management2. Material management3. Logistics4. Supply chain management
12
4
3
7
customers [Dibb et al, 2001]. Its aim is to provide customer satisfaction, that is, supply
products in the right time, right place, right quality and quantity. Channel management
focuses on the various types of channel structure, which is the number of links or
directions between the manufacturer and the end customers. Moreover it also focuses on
the behaviour within that structure, including power, conflict, leadership, and co-
operation in channel. Typically, the dominant feature of channel relationships was
power relationships and conflict. However, nowadays a comprehensive market
increasing in intensity, product technological complexity and economic pressure has
increased the need for organisations to seek mutually acceptable objective and strategy.
In contrast to coercion and conflict, interdependence, which implies a cooperation and
mutually beneficial relationship, is an appropriated strategy.
2.3.2 Material Management This concept originated from the purchasing function, which contacts with suppliers to
buy material or service and needs to understand the requirement of all processes and
capability of suppliers. Material management includes the function of purchasing,
expediting, inventory management, production planing and control and physical
distribution management by concentrating on material. These various activities take
place in different locations and are managed by different parts, which causes a difficulty
in controlling material flow efficiently. Central to the concept of material management,
it is reducing total cost as well as the acquisition and the management of material.
Moreover, its responsibility to the whole material movement and information flow
concerns quantity and lead time.
2.3.3 Logistics
Logistics refers to the total flow of finished goods downstream from the plant to the
customers. The term logistics is analogous to physical distribution management, which
8
involves the physical transportation of goods and service to customer [Slack et al,
1998]. However, logistics is adopted to extend to include more of the total flow of
materials and information, which is the information flow from customers to suppliers
and a flow of material going in the opposite direction. The concept is to smooth the
flow and make it continuous and also to minimise the delivery time from supplier to
end-user. Logistics coordinates the activities of the traditional distribution function
together with purchasing, material planing, manufacturing, marketing and research
development by concentrating on finished goods. The primary objective of the logistics
is to make a cost-effective response to customer’s service requirement and its focal
point is customer satisfaction.
2.3.4 Supply Chain Management
The term supply chain management was originated in the early 1980s, when Oliver and
Webber discussed the potential benefits of integrating, manufacturing, sale and
distribution [Harland, 1996]. The term is a strategic concept, which includes the long-
term consideration of supply management issues as well as a shorter-term control of
flow through the supply chain. For a long-term consideration, supply chain management
includes developing appropriate relationship types between individual link, i.e. between
supplier and their customer. For the shorter-term control, it includes developing and
understanding the dynamic effect (the Forrester Effect) which plays the role on the
amplification of demand changes that affect upstream operation within the supply chain.
The focus of supply chain management is on satisfying end customers by developing
the internal and external flow of material and information. There are two issues about
customers that is, firstly, customers who have the real currency in the supply chain can
trigger all activities along the whole supply chain. Secondly, customers are satisfied by
the value added into products along the value chain, which is a model of how businesses
receive raw material as input, add value to the raw materials through various processes,
and sell finished products to customers [bettermanagement, 2001]. Each organisation
9
within the supply chain passes on portions of that end-customer’s money to each other
and each retains a margin for the value it has added.
2.3.5 Lean Supply
Lean supply is the other theory related to supply networks. The concept of lean thinking
is to fuse the benefits of standardisation and responsiveness [cited by Holt and Root,
2001] by refining information and product exchange from one process to the next or one
organisation to the next. However, the central idea of lean thinking is to identify and
eliminate waste in order to achieve the objective of improvement in performance
through processes and product by developing, producing, and distributing products in
less time and expense, increase flexibility and customer responsiveness. Lean
production focus on
• Eliminating unnecessary steps
• Aligning all steps of an activity in a continuous flow
• Recombining labor into cross-functional teams dedicated to that activity
• Continually striving for improvement
[ION Project, 1999]
Womack and Jone developed the so-called ‘lean enterprise’, which is a group of
individuals, functions and legally separate but operationally synchronise companies
[cited by ION Project, 1999]. They focus on a value stream, which involve in supplying
goods and services in the maximum value to the customer. This idea is some part of the
notion of a supply network.
Lean supply is developed from a lean theory. It focuses on “lean” in a relationship,
which is more realistic and appropriate method of collaboration than partnership, that
are often dominated by customers. Even though lean concept has the general idea about
10
co-operation similar to the supply network concept, they emphasise the removal of
waste. Furthermore, the main concept of lean supply is the relationship of ‘quasi-firm’,
which gives equal importance to suppliers, and consumers, while all activities of supply
networks focus on providing customer satisfaction.
2.4 Insight supply networks
Most works on supply networks focus on specific industries such as automotive
industry or textiles and clothing [cited by ION Project, 1999]. This is because each
industry has a specific characteristic. For instance, in the automotive industry, we have
long supply networks, comprised of several tiers. One supply network is different from
another network and this divergence affects the nature and shape of networks.
Consequently, various strategies and approaches are discussed under supply networks
theme.
2.4.1 Structure
Supply networks are different in terms of size, shape, and ownership and these factors
affect the performance of the networks. The length of the networks or the number of
tiers affects the interdependence within networks. The longer the network, the more
independent the business, which means that since the components have independent
objectives the chain is more difficult to co-ordinate [Slack et al, 2001]. The breadth of
the network depends on how the organisation manages their suppliers. Single sourcing
and multi sourcing are discussed. Multi sourcing provides an ability to adapt to changes
in the environment through switching because of more contacts. However, Single
sourcing networks would be more rigid and stronger as there would be dense flows of
exchanges within them[cited by Harland, 1996].
11
2.4.2 Strategy
Related to the structure of networks, it is important to know the position of the
organisation. This refers to vertical integration, which is the extent to which the
organisation owns the network of which it is a part [Slack et al, 1998]. It means to
decide whether organisation will make a particular component itself or buy it from
supplier i.e. make or buy decision. Backward or upstream vertical integration or
expanding on the supply side allows an organisation to take control of its supplier.
Forward or downstream vertical integration takes an organisation closer to its customer
and allows more freedom for the organisation to make contact directly with its
customer. To take a network perspective, organisation can also choose collaborative
partnership in network and monitor your own and your competitors position in the
network. The other concern is about the competitive dimension. All five-performance
dimensions: quality, speed, dependability, flexibility and cost should be regarded in a
balance [Slack et al, 1998]. In addition, the most important concern is the relevance
within networks. The overall strategy within a network should be perceived more
informally as goal congruence [cited by ION Project, 1999].
2.4.3 Relationships
This topic discusses how organisations co-operate with each other and in which domain.
Vertical integration may make it easy to control activities, but limit the degree of
competition. In relationships, power can be seen as the ability to influence the decision
or action of other [cited by ION Project, 1999]. Power can be defined as knowledge,
resource, technology competence and information. In addition, power may locate in one
or several positions within a supply network, which affects how some companies can
control the network. The power between customer and supplier relates to the control of
activities and resources. Power may not balance in form of interdependence as buyers or
suppliers are more interested in long-term relationships. The other aspect of
12
relationships is trust, which is the key to keep organisations together in network and
have an influence especially in channel management. Trustworthiness in buyer-supplier
relationship is not acting in a purely self-serving manner, accurately disclosing relevant
information when requested, but changing supply specification, standard or cost to take
advantage of other parties and generally acting according to normally accepted ethical
standard [cited by ION Project, 1999].
2.4.4 Dynamics of Supply Networks
Many efforts to manage supply chains have led to frustration because of the dynamics
and complex nature of supply networks, especially in the upstream part. This topic was
demonstrated in the 1960s by Jay Forrester that certain dynamics exist between firms in
supply chains [Slack et al, 1998]. He identified that demand information about timing
and volume of requirements became increasingly distorted further upstream in supply
chain. This cause errors, inaccuracies and volatility. In the sense of networks, dynamics
can also govern network relationship. While individual relationships might endure, the
change to the total system of supplier relationship was rather large. This indicates that
networks are not static but change in dynamic manner as a result of external and
internal factors.
2.5 Summary
A supply network consists of a number of entities, inter-connected for the primary
purpose of supplying goods and services required by end customers. The degree of co-
operation between organisations ranges from loosely short term to tightly long term.
The supply network deals with the integrated processes of the purchasing activity,
through the operation and out to customers by the way of distribution or service
delivery activity. The supply network is a strategy and operation and is applicable in e-
13
commerce. However, the dynamic and complex nature of supply networks causes many
difficulties to predict and control. With this motivation, many efforts are contributed to
the study of supply networks.
2.6 Supply Networks in the experiments
In our experiments, we set a scenario of 3-tier supply networks as an upper part of an
hourglass diagram. Our supply network consists of a producer on the lowest layer,
dealers on the middle and consumers on the upper layer. The producer, who has a
limited stock, supplies products to the dealers and the dealers supply the products to the
consumers. The dealers have to maintain their stock level, fixed cost of operation and
sell price. Along with the products, messages and currency flow in the supply
networks. The diagram of our supply networks is shown below.
Figure 2-3: Our 3-tier Supply Networks
C C C C C
D D D
P
...
14
Chapter 3: Modeling and simulation
Model is a substitute for a real system. The informal models we actually use all the time
are the images we carry in our minds. Such images are simplified representations of
complex system and influence how we understand the world and how we take action
[Ford, 1999]. We can construct a model, which represents one system in order to
explore interesting phenomenon or behaviour. When we propose a model we
deliberately eliminate and simplify aspects of the real world [cited by Vasconcelos and
wooldridge, 2001] so as to make it easier to understand. However, with the simplicity of
model, reality with all its complexity should also be observed, its distinct aspects
isolated and classified with respect to their relevance depending on the purpose of the
model[Vasconcelos and wooldridge, 2001].
A simulation is the execution of a model, which consists of analysing the attribute of the
model of the surrounding world. If we regard a model as a static representation of the
real world, a simulation can be seen as a mapping among such model. The dynamics of
the real world can be represented, or simulated, as changes in the static models through
time [Vasconcelos, 2001]. We can analyse a model by using many approaches, some of
which provide theoretical method such as analytical approach, On the other hand, the
simulation approach provides a flexible and practical method. Moreover, computer
simulation model simulates the real system into computers in order to study that system
with much greater complexity, more simultaneous calculations and rapidly. A well-
designed model can be used to conduct experiments and then can describe the system
we are interested in.
In this chapter, we introduce 2 distinct modeling which are employed in business
scenario, which have been seen as dynamics. These two approaches are Equation-based
modeling (EBM) and Agent-based modeling (ABM). They both simulate the system by
constructing a model and execute but different in the form of the model and how it is
15
executed. EBM represents the system as a set of equation whereas ABM represents the
internal behaviour of each individual [Parunak et al, 1999]
3.1 Equation-Based Model
Equation-Based Model is a mathematical model that uses equations to present the
interconnection and dynamics in a system. The model is built by a set of equations,
which expresses the relation among variables, which are interesting factors in the
system.
Conventionally, EBM is mostly used in computational model and simulation of
dynamic system. System that is said dynamics is the system that change over time and
its composition affect each other, such as business system and social system. Most
modeling software in this field is visual modeling environment and also is developed
diagrammatically rather than lines of text command. In this part, we will present the use
of EMB in 2 modeling software .The first one is Vensim simulation which is mostly
used in the field of system dynamics. The latter is Simile which was design as a 'System
Dynamics plus objects' language and was used especially for the ecological,
environmental study.
3.1.1 System Dynamics
System dynamics is a methodology for studying and managing complex feedback
systems, such as one in business and other social systems. It studies how system
changes overtime. This field was originated in the 1960s with the work of Jay W.
Forrester [Ford, 1999].
16
Coyle defined systems dynamic as a method of analysing problems in which time is an
important factor, and which involve the study of how a system can be defended against,
or made to benefit from, the shocks which fall upon it from the outside world [cited by
Ford, 1999].
System dynamics can be applied to study situations in real world. This methodology
does not break the system up into smaller and smaller components but look at system’s
behaviour as a whole. The central concept to system dynamics is to understand how all
the objects in a system interact with one another. The objects and people in a system
interact through "feedback" loops, where a change in one component affects other
components over time and in turn that component affects the original component.
Feedback refers to the situation of cause and effect and loop refer to a closed chain of
that cause and effect [Ford , 1999]. Consequently, one cannot study each component
independently and predict how the system will behave. The study of the whole system
as a feedback system will lead to appropriate results.
3.1.2 Dynamic model Dynamic model is one category of mathematical model that represents how a system
changes over time. It will be used in system dynamics community to observe the
system. The fundamental dynamic patterns of system are growth, decay and
oscillations. The early work was Forrester ’s Industrial Dynamics. It was applied the
concept from feedback control theory. The other best-known work was Urban
Dynamics, which explained the pattern of rapid population growth and subsequent
decline in metropolitan in USA. There still are many works related to system dynamics
that were developed later by using equation-based model. Most works are in the field of
geography and environment.
17
For the software developed as dynamic model, it widely uses graphical notation for
representing continuous systems and equations to build the model. A system dynamics
diagram typically contains 4 main types of element: stock, flows, variable or converter,
and influences. Equations are put around the diagram. There is also a diagram of
feedback loop, which is a technique to portray the information feedback in the system.
Stocks are used to represent key variables in the model. They represent where the
accumulation takes place in the system. They can change over time but less rapidly than
other variables in the system, so they are responsible for the “momentum” in the
system.
Flow is used to represent variables that change the system to a new state. They are
actions that directly influence stocks and have the same units of measurement
Converter is another kind of variable that describes the flow. They also can be used to
calculate additional measures of the system performance.
Feedback loop is cause-and-effect relationship between each stock.
Equilibrium point is the point that we use to observe the system. To understand a
dynamics, we should notice the moment of equilibrium of the system at some point of
simulation.
Figure 3-1 : Flow diagram along with the corresponding feedback loop
(Reproduced from Ford, 1999)
Bank balance Interest added
Interest rate
++++
stockFlow
Converter Feedback loop Diagram
18
So as to illustrate the theory of EBM, two fascinating software developed on the basis
of this approach are demonstrated as the example. The first one is Simile, graphical
software of the University of Edinburgh with the simulation in environment. The
second one is Vensim, visual software of Ventana Systems, Inc with the simulation in
business process.
3.1.3 SIMILE
Simile is visual simulating modeling software especially for ecological, environmental
and related disciplines, developed by Institute of Ecology and Resource Management,
The University of Edinburgh [IERM, 2001]. It is a declarative modeling environment,
which different from a procedural approach in a conventional (procedural)
programming language, In declarative modeling, we represent a model as a set of facts
that are true about the model and the order in which we present the facts is irrelevant.
The full set of facts defining a model actually constitutes a specification for the model.
In this example model about population dynamics, we are interested in the population of
animal in each age level. The population represents the number of animals in the
population or the population density (number per unit area) .We will study its dynamics
influenced by reproduction rate and mortality rate. The population, which is our key
variable, is represented by 4 compartments, one for each of 4 age classes. The first one
represents the first year group, the second represents the number of animals aged 1-5
inclusive, the next animals 6-15 inclusive, and the fourth for all remaining animals.
The flow of population represented by arrow and bow-tie shows how the population
increases and decreases over time. The flow – in causing the increase in the population
comes from ‘ birth’, which depends on each age ’s reproduction rate. The flow from the
first year group to the second group is ‘aging’ or the animals that grow up to the other
age class. The flow- out causing the decrease in the population comes from ‘death’ ,
19
which depends on each age ’s mortality rate. We call both reproduction rate and
mortality rate converters. Reproduction is assumed to be density dependent .The
reproductive rate per individual, is influenced by total population size (declines as
population size increases), as well as is different for each age class. Note that the first
age class does not reproduce, so there is no a ‘births’ term for it. Mortality is the
mortality rate per individual, m, which is independent of population size but depends on
its age. There is a different m value for each age class.
Figure 3-2: Model of population dynamics (Copied from IERM, 2001)
When we run the model and plot the dynamics of the total population size. The graph
shows the variable called 'pop size', which is the sum of the population sizes for each
age class, changing over time.
20
Figure 3-3: Total population size (Copied by IERM, 2001)
This shows logistic growth, which actually will differ in detail, since the single-valued
parameters we had before are now different for each age class. We are able to inspect
the dynamics for each of the 4 age classes. We see that the stable total population size is
reflected in stable numbers in each of the 4 age classes, with different numbers in each
class reflecting their different population parameters.
Figure 3-4: Population size of 4-age classes (Copied from IERM, 2001)
21
Simile is stated that it can handle most model types such as 'differential equation model'
and 'individual-based model'- sometimes directly, sometimes with some recasting.
However, a model in Simile can combine what would normally be considered distinct
and non-combinable modeling approaches, thus it is possible to have a model that
combines, for example, differential equation, matrix, and individual-based modeling
[Muetzelfeldt and Taylor, 2001]. From the above simulation, implementation with
Simile using EBM is rather straightforward when important factors can be transformed
into equations. Some 'disaggregation' characteristic which is one type of component is
divided into a number of parts can be modeled by separating that component into sub-
component. In addition, there are many works of environmental area employing EBM
and the result is rewarding such as Mono Basin Project [Ford, 1999]. However, in the
field of business, whether EBM is suitable or not will be investigated further. As
mention above, the next example of equation-based simulation software is Vensim and
we will explore it with business scenario.
3.1.4 VenSim Simulation This simulation work is one in DASCh project – Dynamical analysis of Supply Chain –
which explore the dynamical behaviour of manufacturing supply network [Parunak et
al, 1998]. The model is built to explore dynamic supply chains using a set of ordinary
differential equations appearing in Vensim simulation environment.
“ Vensim is visual software to help conceptualise, build, and test system
dynamics models. It was created by Ventana System,Inc. as a high end tool to support
the company’s consulting projects for governments and business “ [Ford, 1999]
22
Vensim software uses a rectangular box and the arrow with bow-tie symbol to
represent stock and flow respectively. The simple example of business process
simulated by Vensim is the flow of material in the DASCH .
Figure 3-5: System Dynamics (ODE) Model (Copied from Parunak et al, 1998)
In the simulation of material flow, we are interested in the level of inventory,
which can map with stocks while flows are material flows that flow from one level to
another. The converters are rates of flows that directly influence the flows. From the
Figure 3-5, the 4 rectangular boxes represent the level of work in process and finished
good inventories of each site. The arrow with bow-tie represents material flow that
flows from one level to another and bow-tie or valve is rate of the flow. The rates
depend on other factors such as order period, order rate, production time and capacity.
These factors influence the flow by the symbol of single arrow. The cloud shape at the
upper-left corner represents external source, which is consumer, and producer for the
lower-right corner.
23
The dynamics of this model can be represented by the following set of ordinary
differential equations (ODE’s)
d(WIP3)/dt = orderRate – min(capacity , WIP3/productionTime)
d(Finished3)/dt = min(capacity , WIP3/productionTime) – A
d(WIP2)/dt = A – min(capacity , WIP2/productionTime)
d(Finished2)/dt = min(capacity , WIP3/productionTime) – B
A = orderRate if Finished3/orderPeriod + capacity > orderRate, otherwise 0;
B = orderRate if Finished2/orderPeriod + capacity > orderRate, otherwise 0;
[Parunak et al, 1998]
OrderRate is the rate of consumer orders to the chain;
ProductionTime is the time needed at site2 or site 3 to turn WIP to finished goods;
Capacity is the amount of WIP that site2 or site 3 can turn into finished goods each step
Figure 3-6 Inventory Oscillation in EBM (Copied from Parunak, 1998)
This model shows the interplay between site capacity and order rate. From the figure, it
demonstrates oscillations, for Demand/Capacity = 220/110 ,when the order rate
exceeds the site capacity.
This work provides satisfied numerical result within the limit of model’s feature. Most
aspects represented in EBM must be able to interpret into rate and level to create
equations. However, in real world, many behaviours are difficult to translate into
24
equations or level-rate concept, especially in business world. Therefore, these
behaviours can not be integrated in the model or with arduousness.
3.2 Agent-Based Model
In this section, we consider another approach to modeling and simulation, the agent-
based modeling. Agent-based modeling uses the approach of agent in order to analyse
the real world instead of using forms of mathematical relationships between variables
representing physical values, which can be measured in reality. ABM introduces
individuals, their behaviour, and their interactions. The main difference between EBM
and ABM is how it analyses the system. EBM will see the system as a whole because of
the dependency between components while ABM will pay attention to the
characteristics of each component, which is called agent.
Agents are independent, autonomous and rational components with an identity and
which interact with an environment [Vasconcelos and wooldridge, 2001]. Agents are
rational components in the sense that they are able to perform deduction or inference
using a representation of aspect of the real world. Moreover, they are autonomous in
their decision-making and their acting in the world, without being controlled by a
central unit. They exhibit intelligent behaviour based on their interaction and
communication with other agents, its environment and its internal reasoning.
Agent-based models are built from a collection of agents, which represent the system,
based on individual’s behaviour. Simulation of the system will explore its dynamic
aspects. A multi–agent simulation is based on the idea that it is possible to represent and
emulate the behaviour of entities which are active in the real world, and that is possible
to represent a phenomenon of the interaction of an assembly of agents with their own
operational autonomy[Ferber, 1999]. Like EBM, ABM performs tasks in complex,
dynamically changing environments. The interest in using ABM, is not only that the
25
collective behaviour of agents can be studied, but also individual’s behaviour, which is
changeable due to sophisticated reasoning. Moreover, ABM considers both quantitative
parameters (digital parameters) and qualitative parameters (individual behaviour).
Many motivations for employing ABM in the business scenario, especially in supply
networks bring about some pioneer works. We will explore two works in the field of
supply network. The first one is Simulation of Order fulfillment in divergent assembly
supply chains [Strader et al, 1998]. This project is interesting because it is implemented
on SWARM, which is new software supporting the development of multi-agent
simulation models. Nevertheless, it is claimed that this work provides the results on
inventory levels and cycle times but it provides no dynamical analysis [Parunak et al,
1999]. The second one is the Dasch project, which emphasises the dynamics behaviour
of supply networks, and uses this assumption in building a model.
3.2.1 Simulation of Order Fulfillment in Divergent Assembly Supply
Chains
This project employs multi-agent simulation to implement a supply chain scenario. The
management of supply chains is a difficult task involving coordination and decision-
making across organisational boundaries. Computational modeling using multi-agent
simulation are appropriate command and control [Strader et al, 1998]. The model is
used to study the impact of information sharing on order fulfillment in divergent
assembly supply chains. In such supply chain networks (SCN), a small number of
suppliers provide materials and sub-components, which will be assembled at factory or
at a distribution site depending on how complex the process is. Two main goals to
achieve for this type of supply chains are reducing the lead-time of the assembly-to-
order process, and managing the inventory and purchasing for the assembly. Figure 3-7
shows the interaction and message passing among agents.
26
Figure 3-7: SCN Agent Interactions in the Swarm Implementation
(Copied from Strader et al, 1998)
An entity ScnESwarm A receives an order from its customer ScnESwarm C. The order
flows to the order management agent (OrdM) who gets information from InvM, PrdP,
CapP and assigns a due date to the customer. The SCN management agent (ScnM) uses
material planing from MatP who obtains build plans from the production-planing
agent(PrdP) in order to choose suppliers in allocating material sources. Most activities
of these agents are incorporating the decision making, and information and material
processing.
They simulate this model by using 15 business entities and 5 tiers ,dealing with
manufacturing and assembly processes. The aim of the experiment is to evaluate the
order fulfillment process (OFP) whose main task is to estimate the demand for next
27
period and the due dates of incoming order. To achieve this goal, they use various
demand product policies such as make-to-order, make-to-stock, assembly-to-order so as
to predict the demand and different kind of information-sharing strategies.
This project gives two conclusions. Firstly, agent-modeling can be used in practice to
simulate order fulfillment in supply chains and be a tool to identify the impact of
various decision-making scenarios on performance measures such as cycle time and
inventory levels. Secondly, from the simulation of divergent assembly supply chains,
inventory costs are reduced while order cycle times remain relatively stable, which
means that information technology is important for supporting the order fulfillment
process in SCN.
We can observe that it is rather difficult to conduct such experiment, which use
decision-making approach by using EBM. In addition, the hierarchy of business entities
is not sensible for EBM.
3.2.2 The DASCh Project
The other work dealing with ABM for supply networks is the DASCh project which
employs ABM model system dynamics [Parunak et al, 1999]. With the same scenario as
EBM’s simulation, DASCh uses ABM, representing the various components of the
supply chain by software agents that emulate their actual behaviours.
28
Figure 3-8: The DASCh Supply Chain (Copied from Parunak et al, 1998)
The experiments involve a linear supply chain with four company agents. As seen in the
Figure 3-8 of the DASCh model, there are three kinds of agents, the company agent, the
PPIC agent and shipping agent. The company agent represents the different firms in the
supply networks. They consume material from their supplier (external component) and
transform it into output before sending it to its consumers (external component). PPIC
agents model the production planning and inventory control algorithms, supporting a
simple material planning model (MRP). Company agents use PPIC agents to determine
what input to order from their supplier, based on the orders from their customer.
Shipping agents move both information and material between company agents.
The simulation starts from orders and shipment from and to consumer whose demand
varied with noise. The Sites’ PPIC has to forecast the incoming orders for its product
and predict its future inventory and outgoing order for material. The suppliers with
make-to-order approach will supply material with some delay depending on when they
receive orders.
The results of this experiment emphasise variation in supply chain. It shows the
behaviour of amplification, correlation, persistence, and generation of variation in the
29
orders and inventory levels in the system. These phenomena introduce distortion in
order stream, which obscure the suppliers’ view (upstream) of the top-level consumer’s
demand.
According to DASCh, they state that some behaviours are difficult to translate into a
consistent rate-and-level formalism such as PPIC algorithms. A significant advantage of
using ABM in commercial application such as supply networks is shown in two ways.
First of all, each agent which represents firms or division can maintain internal
information about their operation. Agent’s internal behaviour is not required to be
visible to the rest of the system. Secondly, each agent corresponds one-to-one with the
individuals (e.g., firms or division of firms) in the system being model, so their
behaviour can be constructed to imitate the real behaviour. Consequently, ABM is
suited to domains, whose unit is the individual such as business domain.
30
Chapter 4: Experiments and Results
In this chapter, we present the experiments carried out in the two 2 approaches for
modeling. One is in Simile, our equation-based model, and the other is our agent-based
model. These experiments will be set up on a supply network scenario, which is
suggested as dynamic system. We will use three kinds of agents: producer, dealer and
consumer. A producer supplies products to dealers and the dealers supply the products
to consumers. Money circulates within the system as revenue and cost.
We conduct 3 experiments with both EBM and ABM in order to compare and contrast
the results. We create an equation-based model and an agent-based model for the first
experiment and adjust both models a little for the second and the third experiments. The
first experiment focuses on the profit of dealers. The second one focuses on the average
sell price and the third one focuses on the profit of dealers when there is the impact of
the other type of dealers.
In our first experiment we shall analyse the system by paying attention to a profit of
dealers when other factors are set in different way. All equations used in models are
based on simple principles of business. They are used on the grounds of plausibility for
business and suitability for our laboratory.
4.1 The first experiment
4.1.1 An equation-based model for supply networks As we have known that the early simulation work in system dynamics employs
equation-based model, we also will explore the dynamics of supply networks by
constructing and experimenting with an EBM by using Simile.
31
Figure 4-1: EBM for Supply Networks : Experiment 1
The Figure 4-1 shows the model of 3-tier supply networks comprising of 3 populations
of components: consumers, dealers and a producer. The right part shows money flowing
from the consumers (upper) to the producer (lower) while the left part shows products
flowing from the producer (lower) to the consumers (upper).
The lower-left rectangular box labeled “PStock” represents a producer’s stock at whose
zero level the system will end. The bow tie labeled “Ship1” represents the condition and
rate of products’ quantity delivered from the producer to the dealers. It is set to check
when a dealers’ stock is empty, the products will be delivered to the dealers’ stock
(Dstock1) at certain amount. While the products flow from the producer to the dealers,
dealers’ money flows to the producer as its cost. There are 2 kinds of costs that are “C1”
: variable cost and “OvCost” : fixed cost. Price1 is a product’s sell price, which varies
between each lot of products delivered from the producer.
32
VariableCost (c1) = Ship1*1/PStock ; Ship1 is a delivered amount of products per
lot
1/PStock is assumed as a product’s price,
whereas PStock is a number of producer’s
stock at the delivery time
Product’s price is determined based on the assumption that the more a number of
products the cheaper the product’s price.
FixedCost (OvCost) = x ; x is a constant number
SellPrice ( Price1) = [ Margin * UCost1 ] + UCost1 ; Margin is a constant number
UCost1 is a unit cost calculated
by C1/ Ship1
The upper-left rectangular labeled “CStock” represents a consumers’ stock, which is
filled every tick (one time interval) if the dealers’ stock is not empty, at the rate of
“Del1” which is set to 1 item per tick. At the same time money from consumers’ budget
: “CBudget” flows to the dealers at the rate of “Rev1” which is the sell price for that
product. “DProfit” is dealers’ profit calculated from revenue (Rev1) deducted by cost
(C1 + OvCost). Revenue flows into the dealers’ profit every time the dealers sell their
products whereas cost flows out at the time of the dealers’ stock delivered. Finally, we
will have the model’s equation as follow
Profit =[QuantitySold *((Margin * 1/ProducerStock) + 1/ProducerStock)] –
[(LotQuantity * 1/ProducerStock ) + FixedCost ]
When the model is executed, it runs step by step following the condition and equations
we have set. We count one step of execution as “tick”. From this model, we are
33
interested in the dealer’s profit and will investigate how it varies over time and compare
the dealers’ profit in different environment. With other factors constant, we change
“ProducerStock” variable, which controls the end of the system. We start from
“ProducerStock” 200 in the first simulation and add to 500 in the second simulation.
After that we will take turn to change fixed cost and then margin. The first set of graphs
is created as follow.
ProducerStock = 200
Margin = 1.5
Fixed cost = 0.025
Ship1 = 5
Figure 4-2: Simile Graphs1 : Experiment 1
34
The Figure 4-2 illustrates the growth of profit, revenue, and cost against time while X-
axis is time and Y-axis is money. The upper graphs show cost against time and revenue
against time from left to right. The graph grows in exponential pattern but at different
rate following the equations. For the lower-left graph, it demonstrates the dealers’
profit, which decrease below zero and then increase in exponential pattern. The lower-
right table is the data of profit and the highlight point is the break-event point, which is
at tick 8, or the product is sold 8 items. The profit graph at this point grows above zero.
This means that firms begin gaining profit after 8 ticks and have most profit at value
11.05. We can explain that, in the beginning phase, cost is higher than revenue and it
causes profit being under zero level. When time passes, revenue, which increases in
exponential rate will get higher than cost, which increases in slower exponential rate.
The break-event point that makes revenue higher than cost or makes profit above zero
depends on 3 variables. The first variable is a producer’s stock, which affects variable
cost. The second is fixed cost, which affects total cost and the third is margin, which
affects revenue .
In the second simulation, we run at “ProducerStock” = 500. The graphs show the same
pattern as that in the first time but in a different scale. The break-event point is at tick
18 and the dealers gain most profit at value 13.22. We can see that even though the
products in the system are increased, it does not affect the system significantly.
The other relevant factors affecting profit are margin and fixed cost. Next we will
simulate our model by changing fixed cost and margin respectively. The second set of
graphs shows the result as follow
ProducerStock = 500
Margin = 1.5
Fixed Cost = 0.05
Ship1 = 5
35
Figure 4-3: Simile Graphs2 : Experiment 1
All graphs exhibit similar growth patterns but the cost graph grows sharply. This
behaviour causes an increase in the break-event point obviously. From the data of the
profit on the right, it indicates the break-event point at tick 217 displaying the profit
0.008. At the end of the system, the profit is at 10.72 comparing to 13.22 of the previous
simulation, which is 18.91 % decrease. We can observe that fixed cost does not only
affect the profit but also influence the break-event point.
For the third set of graphs, we set margin at 3 and the other variables are as follow.
ProducerStock = 500
Margin = 3
FixedCost = 0.05
Ship1 = 5
36
Figure 4-4: Simile Graphs3 : Experiment1
The graphs illustrate that the profit increases up to 23.27 and the break-event point is at
tick 22.
From this EBM experiment, we can conclude that firms lost at the beginning phase of
investment and after that they will gain profit. There are at least 3 factors affecting how
long firms will gain profit and how much profit they can earn. The first is a quantity of
products supplied in the system. The more the products, the longer the firms can gain
profit. The second factor is fixed cost, which the firms should maintain at low price, and
this factor affects both the profit and the break-event point significantly. The third factor
is margin, which is relevant to fixed cost. If the firms have high fixed cost, they may set
margin at high level to gain an appropriate profit but they have to beware of sell price’s
competition.
4.1.2 An agent-based model for supply networks
As for an agent-based model, we use Sicstus Prolog in order to develop programs that
represent different kind of agents. Each kind can be replicated to any number of
populations. A number of agents communicate by sending messages to one another.
37
Consequently, two main issues are raised in building this model. Firstly, there should be
the amount of identical agents running in the model. In this supply networks scenario,
we need at least 3 kinds of agents: consumers, dealers, and a producer, each of which
can reproduce any number of agents to observe their dependent behaviour. Secondly,
the amount of these agents should run in parallel because parallelism in the execution of
simulation may make substantial performance improvement possible. Faster simulations
will expand the kinds of problems to which simulation can be applied. The ability to
speed up makes interactive, faster than real time [Unger, 1988].
‘Experiment and Lpad’, a tool that supports the replication of agents, and the automatic
upload and execution of a number of agents [Vasconcelos , 2000], is used as a platform
for this model. In view of the fact that prolog can be used as meta-programming which
is a program that generate and run other programs (in the same language), ‘Experiment’
exploits this technique in order to obtain different version of the models. Each type of
agent, which is a prolog program, is replicated as the given numbers and is linked to
other types of agent. By this methodology, our model allows for experiments to be
carried with minimal effort when changing parameters.
Agents run in parallel fashion and send messages to communicate with each other using
the tuple space. This mechanism is introduced in Lpad. As shown in Figure 4-5
Figure 4-5: ABM Lpad Platform(Reproduced from Vasconcelos , 2000)
Ag2
Ag1 Sv Agn
S1 S2 Sn LPad
...
38
When Lpad starts, it automatically starts up a Linda server process, Sv and Linda
client processes AG1,AG2..AGn , one for each S1,S2..Sn representing the prolog codes
for each agent. For each specification Si, Lpad automatically synthesises a self-
contained, executable SICStus Prolog program, fully compatible with the server process
set initially.
For each AGi, it can communicate to each other via Linda server process, Sv. Server
process manage the tuple space where the message can exchange. When agents need to
communicate to others, they just send the message to server .The message should have
its address (sender’s identity) and destination (receiver’s identity). Agents can receive
the message in the same way by checking within the tuple whether there are any
messages whose destination match their identity.
The model consists of three tiers in supply networks. The lowest layer is a producer,
which has a limited stock to supply to the middle layer, which are the dealers. The
dealers communicate with both the producer to order products, and consumers to supply
their order. The number of dealers and consumers varies from experiment to
experiment. Each dealer is linked to a number of consumers.
Figure 4-6: Supply Networks for ABM
A key variable used to measure the performance of the system is the profit of dealers
which is calculated from revenue received from consumers deducted by the cost paid to
C C C C C
D D D
P
...
39
a producer. We will explore the system by setting different factors that are expected to
affect the dealers’ profit. These variables are as follow
1. The number of consumers, dealers and the number of consumers linked to each
dealer
2. Quantity of product in producer stock
3. Margin and fixed cost
When we start the model, Agents will communicate with one another in order to
perform the following action
Consumer Dealer Producer
Requesting Request for item to
Dealer
Request for stock to
Producer
Offering Offer item to
Consumer
Offer stock to
Dealer
Confirming Confirm the offer to
Dealer
Confirm and deliver
product to Consumer
Refusing Refuse the offer to
Dealer
Refuse delivering
product to Consumer
due to temporary out
of stock
Consumers will send request to all relevant dealers in order to ask for the number of
products which is set to 1 item per order. In order to supply the products to the
consumers, the dealers usually maintain their stock’s level if the stock is empty, they
will sent the request to a producer to ask for the products. When the products are
delivered to the dealers, they have to pay money as their cost to the producer. At this
point, the sell price of this lot of product is determined. When the dealers receive
40
requests from consumers, they will send offer message with the sell price. The
consumers collect all messages from the dealers and choose the dealer that provide the
lowest price and send a message to confirm the order. For the other dealers that offer
higher price, they will receive a “refuse” message. The dealers wait for either a “refuse”
or a “confirm” message. For a confirm message, the dealers will check their stock
again, if they have enough stock they will reply “order-processed” message to confirm
the order. In case that they run out of stock, they will send “lot_out” to inform the
consumers that they have no stock for this price. Simulation will run until the producer
runs out of stock and broadcasts the messages “no_product” to all dealers. Each dealer
will die when it runs out of stock and no more stock supplied from the producer. The
dealers will broadcast the “out_of_stock” message to relevant consumers and when all
dealers die, finally, the consumers will die. The protocol for a message-passing is as
follow;
Consumers Vs Dealers
Consumers request product: “Ask_Product(quantity)”
Dealers offer the request: “Offer_Product(quantity , price)”
Consumers collect all message and compare price “Confirm” or “Refuse”
Dealers check their stock: “Order_Processed” or “ Lot_out”
Dealers broadcast a message when they die “No product”
Dealers Vs A Producer
Dealers request stock “Ask_Stock(quantity)”
A Producer offer stock “Offer_Stock( quantity, price)”
Dealers receive stock “Stock_Received”
A Producer broadcast message when it die “Out_of_stock”
41
Figure 4-7: A message-passing Diagram
The formulas used to calculate all prices are the same as in EBM, that is
VariableCost (c1) = Ship1*1/PStock ; Ship1 is a delivered amount of products per
lot
1/PStock is assumed as a product’s price,
whereas PStock is a number of producer’s
stock at the delivery time
FixedCost (OvCost) = x ; x is a constant number
SellPrice ( Price1) = [ Margin * UCost1 ] + UCost1 ; Margin is a constant number
UCost1 is a unit cost calculated
by C1/ Ship1
Profit =[QuantitySold *((Margin * 1/ProducerStock) + 1/ProducerStock)] –
[(LotQuantity * 1/ProducerStock ) + FixedCost ]
Consumer
Ask_Product
Offer_Product
Confirm / Refuse
Ask_Stock
Offer_Stock
Stock_ReceivedNo_Product
Out_of_Stock
Order_Processed / Lot_outProducerDealer
42
The advantage of ABM is we can explore individual’s behaviour. Three kinds of agents
– that are consumers, dealers, a producer – can have any number of their population and
for each population we can consider their behaviours separately.
For this first experiment, we are interested in the dealers’ profit. How it behaves over
time and which factors affect this behaviour are what we will investigate further. Profit
occurs when dealers communicate with consumers and a producer and is collected for
every loop of a dealer execution. Here, loop means the processes of the dealers ranging
from asking for stock from the producer and its processes corresponding to receiving
stock, and offering the consumers’ requests and its relevant processes. We compare the
growth of profit in various environments in which factors are set differently. First, we
will observe profit when producer’s stock is different. The reason we are interested in
this factor is that it is an external variable that firms or dealers can not control.
The first two graphs show the profit of dealers in the pattern of 20 consumers, 4
dealers, 1 producer and each consumer interacting with 2 dealers. Variables are set as
follow
ProducerStock = 200 for the first graph and 500 for the second one
Margin = 1.5
FixedCost = 0.025
43
Figure 4-8: ABM Graph1 : Experiment 1
44
Comparing these two graphs, we can point out some aspects. Each dealer behaves in a
similar manner, that is, it starts losing for some time and then it starts gaining profit.
When time passes, the difference from bottom to peak is higher. The graphs exhibit
oscillation in a curvilinear trend. They decline at the beginning phase in exponential
fashion and then they increase in exponential rate as well. The oscillation pattern
occurs because the dealers spend money to maintain their stock before they sell
products and this happens in cycle. The factor of “ProducerStock” shows us that if the
producer can provide a huge number of products in system, the dealers take a long time
to recover their losses. The lower graph, which “ProducerStock” = 500 shows the
break-event point, where profit is above zero, is at the half way of the system. In
addition, the interesting point we observe from this model is at the last phase, even
though all dealers’ profit increase in overall, one dealer’s profit decreases significantly.
It suggests a variation of noise from other dealers in this model.
We run the second simulation with the same variables but with a different number of
agents in order to discover any effects from this factor. The variables are
ProducerStock = 500
Margin = 1.5
FixedCost = 0.025
We will change our environment by running this simulation in the pattern of 100
consumers, 10 dealers, 1 producer and each consumer interacting with 5 dealers. The
graph displays the similar pattern as the previous ones but the trend is straighter.
Moreover, all dealers encounter lost almost system’s life cycle. It suggests the effect
from one dealer to the others and also shows a high competition in the system.
The last graph we will present the effect from the rest variables, margin and fixed cost.
We set environment as four dealers in the pattern of 20 consumers, 4 dealers, 1
producer and each consumer interacting with 2 dealers. The variables are
45
ProducerStock = 200
Margin = 2
FixedCost = 0.05
Figure 4-9: ABM Graph2 : Experiment 1
We make the value of margin and fixed cost larger to be 2 and 0.05. Unpredictably, the
graph starts a sharp downward movement and take long time before turning to upward.
From this phenomenon, we can conclude that fixed cost is more sensitive than margin.
Increase in fixed cost even in a small number originates a serious lost.
46
4.1.3 Compare and contrast the experimental results
The purpose of performing the experiment from two models – EBM and ABM is to
compare and contrast the experiments’ result from each simulation. We have built these
two models by using the same scenario that is their main formulas for calculating each
value are comparable. The difference of these two models is the EBM models each
component as a collection of population whereas the ABM models its components as
individual. In the EBM, one rectangle box represents a group of one kind of its
component, consequently we can not see what happen inside that box. In ABM, one
kind of agent can reproduce any number of its agents and within the same kind of
agents, they can act in order to respond to the others. For the Figure 4-10, the left graph
is from the EBM and the other is from the ABM.
47
Figure 4-10: Comparison for EBM and ABM graphs : Experiment 1
ProducerStock = 500
Margin = 1.5
FixedCost = 0.025
These two graphs display the same pattern but they are different in some ways. We use
a producer’s stock to control when the system should finish. With the same producer’s
stock, in ABM, the model takes shorter time interval (tick) to run the simulation
because in ABM, there are many dealers to consume and distribute products at one tick.
Moreover each dealer has to compete with each other to sell the products and this
phenomenon affect the break-event point. In EBM, dealers ‘ profit is below zero for a
few ticks after the system starts while in ABM, it takes much longer time. The most
important is that they represent values in different scale. It means even though we use
the same fixed cost rate, the value of profit at one tick is different. In addition, as we
have mentioned about the last phase in ABM, even though in general, the dealers’ profit
increase, one dealer ’s profit decrease significantly. This event does not show in EBM,
which see all dealers as a collection.
48
4.2 The second experiment
In our second experiment, we are interested in the sale price of products. Price is an
important factor in the company’s profit since it affects the profit equation in several
ways. It directly influences the equation because it is a major component. In the profit
equation, price is a key variable, which directly generates total revenue. Moreover, it
has an indirect impact because it can be a major determinant of the quantities sold [Dibb
et al, 2001]. Price competition is one strategy in business, which emphasises price as a
means to beat the price of competitors. However, in order to achieve a price competition
strategy, companies should maintain low cost also because cost is the other factor,
which directly affects profits. In this experiment, we aim to investigate the behaviour of
an average price. Moreover it is interesting to find out the average price that makes a
dealer gain profit the most.
We will investigate two average prices. The first is the average price that is the mean of
prices, which all dealers sell their products. It is calculated by the summation of all
dealers’ average price at each tick divided by a number of ticks. The second is the
average price that is the mean of prices, which each dealer sells its products. It is the
average price of each dealer, which is calculated by the summation of price that a dealer
sell its product at each tick divided by a number of tick. We investigate the first average
price in order to observe the behaviour of price over time and the second average price
in order to find out the price that the most profitable dealer sell its product in
competitive market. Similar to the first experiment, we will conduct the experiment
both in ABM and EBM and compare the results.
4.2.1 An equation-based model for supply networks
We use the same model as that in the first experiment but use different tools to collect
data.
49
For the first average price, we need the data of all dealers’ average price at each tick,
which can be collected by variable ‘Price1’ shown in Figure 4-11. Variable ‘price1’
represents the average prices of all dealers because of the feature of EBM that considers
its component as a collection. Consequently, a rectangular box of dealer ‘Dprofit’
represents a population of all dealers in the system. The model is run by using
parameters relevant to the previous experiment as the following values.
ProducerStock = 300
MarginOfPrice = 1.5
FixedCost = 0.025
LotQuantity=5
Figure 4-11: EBM for Supply Networks : Experiment 2
Tic k
The data of price every tick for calculating average price
Collect the value of price from this variable
50
From the data, price repeats its value 5 times before changing to a new value because
‘LotQuantity’, which is the products’ quantity per lot that a producer send to its dealers
is set at 5 items. Products from the same lot have the same price and the product is sold
1 item per tick therefore the product is sold at the same price 5 times. The result is
shown as below.
Figure 4-12: Average price from EBM : Experiment 2
The graph shows the average price for every 5 ticks because the products in the same lot
(5 items) that have the same cost are sold at the same price. In EBM, a price at one tick
represents the average price of a dealer’s population. From the graph, the price
increases in a curvilinear trend as well as profit, suggesting that the growth has been
exponential over time. Even more we can observe that the price increases sharply when
it gets closer to the last tick because of the inevitably high cost when the producer
cannot provide the products (according to our assumption that the resources will be
more expensive when time passes or there is the scarcity of products).
51
The second average price is the mean of price that each dealer sells its product over
time. EBM does not provide the price value of each dealer because of the approach of
the modeling so we calculate the average price of all dealers instead. From the data used
for plotting the above graph, we sum it and divided by a number of ticks to obtain the
average price. The average price is 0.0622294421, which is the price at tick 40.
Incoming question is whether average price corresponds to the quantity of producer’s
stock. To explore it, we run the other 2 simulations with the same parameters but
replace the value of ‘ProducerStock’ with 200 and 500. The results indicate that the
average price of small number of product in producer’s stock system is lower than the
bigger one. The average prices are 0.08165 for 200 of the products and 0.04182 in 500
of the products.
4.2.2 An agent-based model for supply networks As we have known, in ABM we can see the behaviour of dealers individually. Each
dealer communicates with consumers by sending an offer of products’ quantity and
price when the consumers request. We collect the price when each dealer send the offer
to its consumer and use this price to calculate the average price. Similar to EBM, we
will investigate 2 average prices. The first is the average price that is the mean of prices,
which all dealers sell their products. The second is the average price that is the mean of
prices, which each dealer sells its products. The model consists of 8 dealers with 20
consumers and 1 consumer interacting with 4 dealers with these variables.
ProducerStock = 300
MarginOfPrice = 1.5
FixedCost = 0.025
LotQuantity=5
For the first average price, in order to obtain the value at each tick, we sum the price
selling by 8 dealers at each tick and divided by the number of dealers. The average price
52
represents the mean of the price every dealer sell its items at each time. The graph
shows the average price changing every tick. We can observe that price increases in
exponential rate and grows sharply when it grows closer the last tick. The shape is
nearly the same as that in EBM but in a different scale, which comes from the basis of
the model.
Figure 4-13: Average price from ABM : Experiment 2
For the second average price, in order to obtain the value of each dealer, we sum the
price that a dealer sells its product over time and divided by the number of ticks. The
average price represents the mean of the price that the dealer sells its items over time.
The graph illustrates the average price ranging from the dealer that profited less (1) to
dealer that profited the most (8).
53
Figure 4-14: Average price of each dealer from ABM : Experiment 2
From the graph, we learn that the dealer that sells products at an expensive price will
not profit the most (Dealer 6). However, the dealer that sells in the same average price
(Dealer 2 and 5) profit differently. We can conclude that the average price is not a good
value using as a standard price because it does not exactly correspond to profit.
4.2.3 Compare and contrast the experimental results
In this experiment, we aim to investigate two average prices. The first is the average
price that is the mean of prices that all dealers sell their products. It is calculated by the
summation of all dealers’ average price at each tick divided by a number of ticks. The
second is the average price that is the mean of prices that each dealer sells its products.
It is the average price of each dealer, which is calculated by the summation of price the
54
dealer sell its product at each tick divided by a number of ticks. The results of the first
average price in EBM and ABM are as the graphs below.
Figure 4-15: Comparison for EBM and ABM graphs : Experiment 2
The left graph is in EBM whereas the right graph is in ABM. These two graphs display
the same pattern but in a different scale. Here, the different scale focuses on the x-axis,
which is 300 ticks in EBM and only 21 ticks in ABM. Similar to the first experiment’s
result, in ABM, there are many dealers consuming and distributing products at one tick
whereas in EBM, product is sold 1 item per one tick. The graphs also indicate that the
average price in ABM is lower than that in EBM because of the same reason. We can
conclude that, in real world, if we will use a simulation approach in one company in
order to simulate the business scenario that focuses on our company and there are
impacts from other companies, EBM may not give the appropriate or could not simulate
some situation. This is because in business, we concentrate on the organisation
individually rather than a group of organisations. Moreover for the average price that is
the mean of prices, which each dealer sells its products, we can not collect that
individual value in EBM because the same kind of component is seen as a collection,
which is the approach of EBM.
55
4.3 The third experiment
In our last experiment, we will investigate profit again but in a different way. We adjust
the system a little by including one more breed of dealers. Here we define ‘Breed’ as a
different type of the same agent. Dealers having different breed means the dealers are
set to have different variables such as a different margin. Therefore, we can compare
two different types of dealers in one system. In our scenario, we maintain a stock by
filling our stock when it reaches a critical level. How many units per lot the dealers
order from a producer is a variable that a manager has to decide. If the dealers order
products in a huge number, they can buy the products at a lower cost since we have the
assumption that the resources will be more expensive when time passes or there is the
scarcity of products. Moreover, the cost occurred in purchasing such as transportation
cost incurs less frequently. However, a major disadvantage is that we would have to
pay a large amount of money each time, which means losing interest if the money is in a
bank. The other cost is the cost of storing large amounts of product, which would be
expensive.
We use the same scenario as that in the first experiment but add one more kind of
dealers in our model. They have the same variables except for the quantity they ask for
a producer at one time and fixed cost. We will explore the behaviour of a profit as well
as the balance of ‘order quantity’ and ‘cost’ in this experiment.
4.3.1 An equation-based model for supply networks In Simile, we include one more set of dealers and a converter used for deciding from
which dealers consumers should buy products depending on the cheaper price that the
dealers provide.
56
Figure 4-16: EBM for Supply Networks : Experiment 3
The experiment starts at Producer’s stock 100 with only one different variable, ‘order
quantity’ and the other variables are as below.
Breed1 Breed2
OrderQuantity 5 3
Margin 1.5 1.5
FixedCost 0.025 0.025
57
Figure 4-17: EBM Graph1 :Experiment 3
The graphs above represent the profit of each dealer against time where time is the x-
axis. The left graph is the breed1 dealers’ profit with order quantity 5 whereas the right
one is the profit of dealers with order quantity 3. The graphs indicate that, with the
same cost and margin, the dealers who maintain a large stock have an opportunity to
gain more profit.
As we have mentioned about costs occurring in the large stock, we adjust one more
variable, FixedCost, in order to see how it relates to profit. Using our model, we tried
many values of fixed cost until at one value the breed2 dealer can gain more profit than
the breed1 dealer. This suggests that suitable order quantity can make the dealers gain
profit and the relevant cost should be in concern. It can be illustrated by the graphs
below.
Breed1 Breed2
OrderQuantity 5 3
Margin 0.5 1.5
FixedCost 0.025 0.025
ProducerStock = 100
58
Figure 4-18: EBM Graph2 : Experiment 3
The left graph is the profit of the dealers who order 5 items each time with fixed cost
0.5 whereas the other dealers order 3 item with fixed cost 0.025. The graph of breed2
reaches profit at 2.455 while breed1’s ends at 0.19.
4.3.2 An agent-based model for supply networks In our ABM, ‘Experiment and Lpad’ tool provides a facility for creating a new breed of
the same agent. We create 2 breeds of dealers, each of which contains different
variables. The environment of this experiment is set at 20 consumers with 4 dealers, 2
of which are the same breed and 1 consumer interacting with 4 dealers with only one
different variable which is ‘order quantity’
Breed1 Breed2
OrderQuantity 5 3
Margin 1.5 1.5
FixedCost 0.025 0.025
ProducerStock = 100
59
Figure 4-19: ABM Graph1 : Experiment 3
Figure 4-19 is the graph of 4 dealers’ profit. 2 dealers of bread 1 can gain more profit
than the others as the same result from EBM. Both breeds start selling their products
and gain profit in similar way at first. After that the difference between profits is more
significant when either time passes or resource ’s price increases.
In ABM, we also try to increase fixed cost of the breed1 dealers and the result indicates
the same. When we increase higher and higher fixed cost, the breed1 dealers gain less
profit while the breed2 dealers gain more profit and at some point the breed2 dealers
gain more profit than the breed1 dealers.
Ticks
Profit
Dealer1(Breed1)
Dealer3(Breed2)
Dealer2(Breed1)
Dealer4(Breed2)
60
4.3.3 Compare and contrast the experimental results
Figure 4-20: Comparison for EBM and ABM graphs : Experiment 3
In this experiment, we aim to investigate the behaviour of profit of two kinds of
dealer.Both models provide the method of creating 2 kinds of dealers. Moreover, we
can observe the fluctuation of profit both in EBM and ABM. The dealers have to pay
their money to buy products to fill their stock and this process causes the decrease in
their profit. The profit will increase when the dealers sell their products. The step-by-
step activity, which is the dealers filling their stock and then selling their product is
implemented in ABM. In EBM, we set this situation as the condition in equations. The
flow from a producer to the dealers is set to check when the dealers’ stock is empty, the
products will be delivered to the dealer’s stock at certain amount. While the products
flow from the producer to the dealers, dealers’ money flows to the producer as its cost.
Even though EBM can support the step-by-step activity in this case, there is an unusual
result at the start point. In EBM, at the beginning, both kinds of dealers have the empty
stock and they ask for products from the producer and the producer sell products to
them at the same time, which is opposite to the real situation. Actually, the producer can
sell products to only one dealer at one time, even though it can contact with many
dealers at that time. We can conclude that ABM is more flexible to implement a step-
by-step activity than EBM and provides more realistic.
61
Chapter 5: Conclusions and Future Work 5.1 Conclusions
In our work, we simulated the supply network scenario, a dynamic system, and used it
with Equation-based modeling (EBM) and Agent based modeling (ABM). Both EBM
and ABM are widely used in social, biology and computer science. Especially in system
dynamics, EBM is employed since this theory has originated. However, there is much
effort and motivation for employing ABM in many dynamic works such as in the
business field. In this chapter we will summarise our two approaches of modeling, then
compare and contrast both models as well as give a conclusion of how suitably these
models are employed within business scenario.
Both EBM and ABM are simulation approaches in order to investigate the dynamics of
system. In both approaches, a model representing the system will be constructed and be
executed experimentally. They are like laboratories, in which researchers can set up,
adjust and control the condition in order to observe the behaviour of their model, which
represents the system. In business, not only forecast values from conventional formula
can be calculated, but some interesting behaviours may emerge unpredictably.
The two distinct approaches of these two models are the fundamental relationships
among entities that they model and the level at which they focus their attention
[Parunak et al, 1999].
• EBM is conducted by a set of equations that represent the relationship among
variables. The result can be observed from the evolution of the variables over time.
Unlike EBM, ABM is conducted by behaviours through which individual
components (agent) interact with one another. One agent ’s behaviour may depend
on other agents’ but does not directly access the representation of those individuals’
behaviours [Parunak et al, 1999].
62
• EBM’s key components are grouped as a collection, whose action affects the value
of variables, which are related to form the equations. Furthermore, such variables
are the variables of the whole system or they are the system level variables. In
contrast, key components in ABM are represented as individuals so variables are
specific for each agent.
The following issues are the observation about both models for our supply network
scenario
• Most software supporting EBM feature a diagram-based language, whose users can
create a model by building a diagram so it is easy to construct the model even
though they are not programmers.
• EBM has a graphic representation. Most results are rather straightforward and easy
to understand because both graph and data represent the system. However, whether
the result is reliable depends on how closely to the real function or situation the
model is constructed.
• ABM is more flexible to conduct the model follow a determined situation. In
commercial functions, it is likely that agents have decision making or negotiation
functions, which are difficult to translate straightforward into flows and levels
patterns of EBM. For instance, in our ABM, consumers and dealers communicate to
each other more than once in one process such as the consumers have to ask for
items before the dealer send item back. In EBM, we can only create two flows, one
for money and the other for products and they will run at the same time following
the equations. Moreover in the sense of network, we can not build EBM to represent
the network relation between agents. In ABM we can set the number of consumers
communicating with dealers to create a network. Even though in our scenario both
EBM and ABM can have the function of decision-making such as in experiment3,
63
in more complicated model, it seems more difficult for EBM to include such
feature.
• ABM is more realistic, especially ABM in a distributed or concurrent
implementation. This issue can be discussed in 2 points, first is comparing to EBM
and second is comparing to other ABMs. In business, it is more practical to study
behaviour of population individually, which is opposite to the approach of EBM.
The same kinds of components, which EBM see them as a collection, actually they
have their individual behaviour. From the result of ABM Experiment 2, even though
all dealers are in the same environment, their price and profit indicate different
value. The second issue that makes our ABM more realistic comparing to other
methodology of ABM is that our ABM is based on distributed simulation. In real
world, communication between organisations happens simultaneously rather than
sequentially. For instance, when consumers are looking for dealers to supply their
resources, they definitely do not contact only one dealer at one time in order to
select the dealer who offer the best solution and fulfill their requirement.
Furthermore at the same time, this scenario happens to other pairs of consumers and
dealers. In our ABM, each agent represents one organisation that is independent and
is executed in parallel. They can perform their activity individually as in our model.
The consumer sends ‘ask_product’ to all related dealers at one time, and each dealer
communicates with and supplies products to all related consumers at one time.
However when either consumer or dealer chooses to communicate with any dealers
or consumers, only one consumer and one dealer can communicate each other at one
time and simultaneous.
• ABM provides individual analysis. Both EBM and ABM give the similar result in
the system level but in ABM, we can analyse at an individual level. Each agent
behaves individually and independently and gives different responses to other
agents. Consequently, we can see individual behaviour causing a reaction with each
other.
64
• ABM is more practical to be used in companies. As the benefit of simulation,
manager can play with the simulation to simulate some aspects in real business.
With ABM, it will give a practical view and real life in business because it can
simulate the event of sending a message and waiting for response including some
negotiation and decision-making.
5.2 Future Work
The following list contains some ideas about a future version of this approach to
enhance its performance and realism.
• This model consists of three tiers of supply networks, which are consumers dealers
and a producer. We can extend the model to be n-tier supply networks. For instance
we may include manufacturers and assemblers following an hourglass model.
• We can adjust some parts of code in order to make the model more realistic such as
in the part of a producer agent, we can determine a specific price to be increased at
every tick. In a dealer part, we may use first arrived, first served as its policy, for
instance, C1 and C2 may arrive at respective simulation times t1 < t2 which causes
C1 to always receive offer faster than C2 but they may arrive in either order. We
can choose a message from tuple space by checking the order and pick it up
sequentially rather than using a respective simulation time.
• In order to make the simulation user friendly, we can develop the front-end for this
model. This can be done by using Tcl/Tk, which is a language and a library to be
embedded in application programs and provide graphic interface. Sicstus Prolog
provide the tcltk library package, which is an interface to the Tcl/Tk language and
toolkit.
65
Bibliography
[Axtell, 2000] Robert Axtell. Why Agents? On the varied
motivations for agent computing in the social
sciences, 2000.
[Bettermanagement, 2001] Bettermanagement Home Page.
http://www.bettermanagement.com
[Clocksin and Mellish ,1994] W.F. Clocksin and C.S. Mellish. Programmimg in
Prolog Forth Edition. Springer-Verlag, 1994.
[Craig, 1994] Iain D Craig. A perspective on Multi-Agent
Systems. Research report 273 University of
warwick, 1994.
[Dibb et al, 2001] Sally Dibb, Lyndon Simkin, William M. Pride,
O.C. Ferrell. Marketing Concepts and strategies
Fourth European Edition. Houghton Mifflin, 2001.
[Ferber, 1999] Jacques Ferber. Multi-Agent Systems: An
Introduction to Distributed Artificial Intelligrence.
Addison Wesley Longman ,1999.
[Ford, 1999] Andrew Ford. Modeling the Environment: An
introduction to System Dynamics Modeling of
Environmental Systems. Island press, 1999.
66
[Gattorna and Walters, 1996] J.L. Gattorna and D.W. Walters. Managing the
supply chain : a strategic perspective. Macmillan
business, 1996.
[Harland, 1996] C.M Harland. Supply Chain Management:
Relationships, Chains and Networks. In British
Journal of Management, Vol. 7, Special Issue,
S63-S80 (March 1996).
[Holt and Root, 2001] Robin Holt and David Root. Supply Network
Reseach mapping, 2001. Available at :
http://www.cranfield.ac.uk/sims/quality/lean_map.html
[IERM ,2001] Institute of Ecology and Resource Management
Home Page, The University of Edinburgh.
http://www.ierm.ed.ac.uk/simile
[ION Project, 1999] ION Project. Supply Networks, 1999. British Telecom Labs. Available at :
http://www.lab.bt.com/people/callagjg/ion/supply.htm
[Muetzelfeldt and Taylor, 2001] Robert Muetzelfeldt and Jasper Taylor. Getting to
know Simile, 2001. Available at :
http://www.ierm.ed.ac.uk/simile/documents/paper1.pdf
67
[Parunak, 1998] H. Van Dyke Parunak. The DASCh Experience:
How to Model a Supply Chain. In Proceedings of
Second international Conference on Complex
Systems, 1998. Available at:
http://www.erim.org/~vparunak/iccs98.pdf
[Parunak and VanderBok, 1998] H. Van Dyke Parunak and Ray VanderBok.
Modeling The Extended Supply Network, 1998.
[Parunak et al, 1999] H. Van Dyke Parunak, Robert Savit, Rick L.
Riolo, Steven j. Clark. DASCh: Dynamic Analysis
of Supply Chains DASCh Final Report, 1999.
Available at http://www.erim.org/~vparunak/dasch99.pdf
[Parunak et al, 1998] H. Van Dyke Parunak, Robert Savit, Rick L.
Riolo.Agent-Based Modeling vs. Equation-Based
Modeling: A Case Study and Users’ Guide 1998.
In Proceedings of Multi-agent systems and Agent-
based Simulation (MABS'98), 10-25, Springer,
LNAI 1534, 1998.
Available at http://erim.org/~van/mabs98.pdf
[Patricia, 1994] Patricia E. Gaynor, Rickey C. Kirkpatrick.
Introduction to time-series modeling and
forecasting in business and economics . McGraw-
Hill, Inc, 1994.
68
[SDEP, 2001] The System Dynamics in Education Project
(SDEP) Available at http://sysdyn.mit.edu
[Slack et al, 1998] Nigel Slack, Stuart Chambers, Christine Harland,
Alan Harrison and Robert Johnston. Operations
Management Second Edition. Financial Times,
Prentice Hall, 1998.
[Strader et al, 1998] Troy J. Strader, Fu-Ren Lin and Michael J. Shaw
(1998). Simulation of Order Fulfillment in
Divergent Assembly Supply Chains. In Journal of
Artificial Societies and Social Simulation vol. 1,
no.2. Available at:
http://www.soc.surrey.ac.uk/JASSS/1/2/5.html
[Tayur et al, 2000] Sridhar Tayur, Ram Ganeshan, and Michael
Magazine. Quantitative models for supply chain
management. Kluwer Academic Publishers, 2000.
[Unger, 1988] Brian W. Unger. Distributed Simulation. In
Proceeding of the 1988 Winter Simulation
Conference.
[Vasconcelos , 2000] Wamberto Vasconcelos. Implementing a Generic
Agent Interpreter in Prolog. Technical Paper.
SLIE Research Grant, 2000.Available at:
http://www.dai.ed.ac.uk/daidb/students/wamb/
SLIE/agentsLinda.ps.gz
69
[Vasconcelos, 2001] Wamberto Vasconcelos .A Prolog Simulation
Platform for Logic-Based Multi-Agent Systems,
Technical Paper. SLIE Research Grant. 2001.
Available at:
http://www.dai.ed.ac.uk/daidb/students/wamb/SLI
E/masta2001.ps.gz
[Vasconcelos and wooldridge, 2001] Wamberto Vasconcelos and Michael Wooldridge.
Modelling Languages Chapter IV .In: SLIE
Research Grant Annual Report 2001. Authors:
Jaume Agusti, Leila Amgoud, Stuart Anderson,
Michael Fourman, Simon Parsons, David
Robertson, Jordi Sabater, Don Sannella, Carles
Sierra, Wamberto Vasconcelos, Christopher
Walton, Michael Wooldridge.
Available from authors upon request.
70
Appendix A
Program code % --------------------------------------------------------------------------------------------------- %File: Consumer.pl %Author: Wanwimol T. %Update:10 Sept, 2001 % --------------------------------------------------------------------------------------------------- :-[preamble]. :-[linda_part]. :-[common_part]. :-[msg_primitives]. %----------------------------------------------------------------------------------------------------- %A consumer checks whether there is at least one dealer is alive. loop(Budget):- identity(Ag), allDealers(Dealers), out(m(adm,Dealers)), check_dealer(Ag,Dealers,ND,NL), ND = 0, '!'(m(Ag,adm,log([die(Ag,Budget)]))). %----------------------------------------------------------------------------------------------------- %A consumer processes a transaction with dealers.
%The consumer checks whether there is at least one dealer alive and then sent
‘ask_order’ %message. The consumer waits for an ‘offer’ message including sell price
from each dealer. The %consumer compares the offer price , chooses the dealer with
which it will buy a product and send %‘confirm’ message. The consumer sends ‘refuse’
to the others and waits for either %‘order_processed’ or ‘lot_out’ message. If it
receives ‘order_processed’ message, the consumer %will calculate new budget.
loop(Budget):- identity(Ag), allDealers(Dealers), check_dealer(Ag,Dealers,ND,NL), out(m(adm,conwillask(Ag,ND,NL))), ask_order(Ag,Dealers,NL,AL), Will_buy_price is 0, Count is 0, collect_msg(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,AL), Price is Qty * NW, check_zero(Ag,NP,Qty,Price,Payprice),
71
NewBudget is Budget + Payprice, out(m(adm,newbudget(NewBudget))), loop(NewBudget). %----------------------------------------------------------------------------------------------------- %This procedure is to check whether there is live dealer, and gives a list of dead dealers check_dealer(Ag,[D|Dn],ND,NL):- check_dealer(Ag,[D|Dn],0,[],ND,NL). check_dealer(Ag,[],Dsurv,Dlist,ND,NL):- ND is Dsurv, NL = Dlist. check_dealer(Ag,[D|Dn],Dsurv,Dlist,ND,NL) :- rd_noblock(m(D,Ag,no_product)), out(m(adm,noprodms(Ag,D))), add(D,Dlist,NDlist), check_dealer(Ag,Dn,Dsurv,NDlist,ND,NL). check_dealer(Ag,[D|Dn],Dsurv,Dlist,ND,NL):- NDsurvive is Dsurv + 1, check_dealer(Ag,Dn,NDsurvive,Dlist,ND,NL). add(X,[],[X]). add(X,[H|T],[H,X|T]). mem(X,[X|_]). mem(X,[_|T]):- mem(X,T). %----------------------------------------------------------------------------------------------------- %This procedure is to send “ask_order” message to all live dealers ask_order(Ag,[D|Dn],NL,AL):- ask_order(Ag,[D|Dn],NL,[],AL). ask_order(Ag,[],NL,Alist,AL):- AL = Alist. ask_order(Ag,[D|Dn],NL,Alist,AL):- member(D,NL), ask_order(Ag,Dn,NL,Alist,AL),!. ask_order(Ag,[D|Dn],NL,Alist,AL):- out(m(Ag,D,ask(1))), add(D,Alist,Alist1), ask_order(Ag,Dn,NL,Alist1,AL). %----------------------------------------------------------------------------------------------------- %This procedure will give a list of related dealers
72
allDealers(Dealers):- addressees(Addr), setof(dealer(D),member(dealer(D),Addr),Dealers). %----------------------------------------------------------------------------------------------------- %This procedure is to send ‘confirm’ and ‘refuse’ message. check_zero(Ag,NP,Qty,Price,Payprice):- Qty = 0, Payprice is 0, NP = alldead. check_zero(Ag,NP,Qty,Price,Payprice):- Qty > 0, out(m(Ag,NP,confirm(Qty,Price))), out(m(adm,confirmzero(Ag,NP,Qty,Price))), getItem(Ag,NP,Price,Payprice). check_zero(Ag,NP,Qty,Price,Payprice):- Qty = 0, Payprice is 0, out(m(Ag,NP,refuse)), out(m(adm,refusezero(Ag,NP))). %----------------------------------------------------------------------------------------------------- getItem(Ag,NP,Price,Payprice):- getItem(Ag,NP,Price,Payprice,0). getItem(Ag,NP,Price,Payprice,1). getItem(Ag,NP,Price,Payprice,0):- in_noblock(m(NP,Ag,order_processed)), Payprice is Price, getItem(Ag,NP,Price,Payprice,1). getItem(Ag,NP,Price,Payprice,0):- in_noblock(m(NP,Ag,lot_out)), Payprice is 0. getItem(Ag,NP,Price,Payprice,1). getItem(Ag,NP,Price,Payprice,0):- getItem(Ag,NP,Price,Payprice,0). %----------------------------------------------------------------------------------------------------- %This procedure is to compare the offer and to choose an appropriate dealer collect_msg(Ag,0,Will_buy_price,Potential_dealer,Oitem,Qty,0,NW,NP,[]):- Qty is 0, NW is 0, NP = alldead. %for last loop collect_msg(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[]):- Count >= ND,
73
NW is Will_buy_price, NP = Potential_dealer, Qty is Oitem. collect_msg(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[D|Dn]):- Count < ND, buy_or_not(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[D|Dn]). %----------------------------------------------------------------------------------------------------- buy_or_not(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[D|Dn]):- Will_buy_price = 0, ND = 1, wait4offer(D,Ag,Item,UnitPrice), NCount is Count + 1, collect_msg(Ag,NCount,UnitPrice,D,Item,Qty,ND,NW,NP,Dn). buy_or_not(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[D|Dn]):- Will_buy_price = 0, wait4offer(D,Ag,Item,UnitPrice), NCount is Count + 1, collect_msg(Ag,NCount,UnitPrice,D,Item,Qty,ND,NW,NP,Dn). buy_or_not(Ag,Count,Will_buy_price,Potential_dealer,Oitem,Qty,ND,NW,NP,[D|Dn]):- Will_buy_price > 0, wait4offer(D,Ag,Item,UnitPrice), compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI), NCount is Count + 1, collect_msg(Ag,NCount,CW,CP,CI,Qty,ND,NW,NP,Dn). %----------------------------------------------------------------------------------------------------- wait4offer(D,Ag,Item,UnitPrice):- wait4offer(D,Ag,Item,UnitPrice,0). wait4offer(D,Ag,Item,UnitPrice,1):- Item is Item, UnitPrice is UnitPrice. wait4offer(D,Ag,Item,UnitPrice,I):- I = 0, rd_noblock(m(D,Ag,offer(Item,UnitPrice))), in(m(D,Ag,offer(Item,UnitPrice))), wait4offer(D,Ag,Item,UnitPrice,1). wait4offer(D,Ag,Item,UnitPrice,I):- I = 0, rd_noblock(m(D,Ag,no_product)), out(m(D,Ag,offer(0,10))), in(m(D,Ag,offer(Item,UnitPrice))), wait4offer(D,Ag,Item,UnitPrice,1).
74
wait4offer(D,Ag,Item,UnitPrice,I):- I = 0, wait4offer(D,Ag,Item,UnitPrice,0). %----------------------------------------------------------------------------------------------------- compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI):- compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI,0). compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI,F):- F = 1, CW is Will_buy_price, CP = Potential_dealer, CI is Oitem. compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI,F):- Will_buy_price =< UnitPrice, out(m(Ag,D,refuse)), out(m(adm,refusecp1(Ag,D))), compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI,1). compare_price(Ag,D,UnitPrice,Item,Will_buy_price,Potential_dealer,Oitem,CW,CP,CI,F):- Will_buy_price > UnitPrice, out(m(Ag,Potential_dealer,refuse)), out(m(adm,refusecp2(Ag,Potential_dealer))), compare_price(Ag,D,UnitPrice,Item,UnitPrice,D,Item,CW,CP,CI,1). %----------------------------------------------------------------------------------------------------- %The command is to execute the producer agent. The initial value is loop(InitBudget) :-initialise,rd(m(adm,all,start)), loop(0),terminate. % -------------------------------------------------------------------------- % EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF % -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------- %File: Dealer.pl %Author: Wanwimol T. %Update:10 Sept, 2001 % --------------------------------------------------------------------------------------------------- :-[preamble]. :-[linda_part]. :-[msg_primitives]. :-[common_part].
75
%------------------------------------------------------ %Case1: A dealer’s stock < a safety stock limit and a producer died %When a dealer’s stock is less than a stock limit, the dealer has to check whether a producer is %alive. If it finds ‘out_of_stock’ message from the producer, which means the producer died, the %dealer will send message ‘no_product’ to it customers and will die. We get a list of the dealer’s %profit from here. loop(Stock,Margin,[Profit|PL],Stockleft,Price):- Stockleft < Stock, identity(Ag), rd_noblock(m(P,Ag,out_of_stock)), %% out(m(adm,gotmsproddie(Ag))), sendAllMs(no_product), rev1([Profit|PL],W), out(m(adm,log(W))), out(m(adm,log([die(Ag)]))), out(m(adm,die(Ag))). %------------------------------------------------------ %Case2: A dealer’s stock < a safety stock limit and a producer is alive %When a dealer’s stock is less than a stock limit, the dealer has to check whether a producer is %alive. If the producer is alive, the dealer will send ‘ask_stock’ to order products to fulfill its %stock. New stock, cost, new profit, new price are calculated here. loop(Stock,Margin,[Profit|PL],Stockleft,Price):- Stockleft < Stock, identity(Ag), addressees(Addrs), member(producer(P),Addrs), out(m(Ag,producer(P),ask_stock(Stock))), receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin), add(NewProfit,[Profit|PL],ProfitL), loop(Stock,Margin,ProfitL,NewStockleft,NewPrice). %------------------------------------------------------ %Case3: A dealer has enough stock to process it transactions with its customers %The dealer wait for requests from customers and send back its offers including price. The dealer %waits for ‘confirm’ or ‘refuse’ message from customer. If the offer is confirmed, the dealer will %check its stock. If the dealer has enough stock for that order, it will send ‘offer_ processed’ and %wait for ‘stock_receive’ message. If the dealer has not enough stock, which comes from that %order message is checked later than others, the dealer will send ‘lot_out’ message. New stock, %revenue and new profit are calculated here. loop(Stock,Margin,[Profit|PL],Stockleft,Price):- receiveRequests(Price), confirm_or_not(Price,Stockleft,Profit,NewStockleft,NewProfit), add(NewProfit,[Profit|PL],ProfitL), loop(Stock,Margin,ProfitL,NewStockleft,Price). loop(Stock,Margin,[Profit|PL],Stockleft,Price):- loop(Stock,Margin,ProfitL,NewStockleft,Price). %---------------------------------------------------------------- % The procedure is receiving a stock from the producer and calculating cost, new stock and
76
% new profit. receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin):- receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,0). receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,1). receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,0):- in_noblock(m(producer(P),Ag,offer_stock(Add2stock,Cost))), out(m(Ag,producer(P),stock_received)), Ovcost(OV) UCost is Cost/Add2stock, NewPrice is (Margin*UCost)+UCost, NewProfit is Profit - Cost - OV, NewStockleft is Stockleft + Add2stock, receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,1). receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,0):- rd_noblock(m(producer(P),Ag,out_of_stock)), NewPrice is Price, NewProfit is Profit, NewStockleft is Stockleft, receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,1). receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,0):- receiveStock(producer(P),Ag,Profit,Stockleft,Price,NewProfit,NewStockleft,NewPrice,Margin,0). %------------------------ add(X,[],[X]). add(X,[H|T],[X,H|T]). rev1([],[]). rev1([H|T],L):-rev1(T,Z),append1(Z,[H],L). append1([],S,S). append1([X|S1],S2,[X|S3]):-append1(S1,S2,S3). %---------------------------------------------------------------
77
% receiveRequests(Requests/-) % this procedure obtains a list of requests for items from consumer agents receiveRequests(Rs):- identity(Ag), addressees(Addrs), my_setof(consumer(C), member(consumer(C),Addrs),Cs), receiveRequestsAux(Cs,Ag,Rs). receiveRequestsAux([],_,Rs). receiveRequestsAux([C|Cs],Ag,Rs):- in(m(C,Ag,ask(1))), out(m(Ag,C,offer(1,Rs))), receiveRequestsAux(Cs,Ag,Rs). receiveRequestsAux([_|Cs],Ag,Rs):- receiveRequestsAux(Cs,Ag,Rs). % --------------------------------------------------------------------------------------------------- %This procedure sends message M to related consumers. sendAllMs(M):- identity(Ag), allCons(Cons), sendAllMsAux(Cons,Ag,M). sendAllMsAux([],_,_). sendAllMsAux([C|Cs],Ag,M):- out(m(Ag,C,M)), out(m(adm,dealerwilldie(Ag,C,M))), sendAllMsAux(Cs,Ag,M). allCons(Cons):- addressees(Addr), setof(consumer(C),member(consumer(C),Addr),Cons). %------------------------------------------------------------------ % This procedure sends this message to the producer(P) requestOrders([]). requestOrders(Orders):- identity(Ag), addressees(Addrs), member(producer(P),Addrs), '!'(Ag,producer(P),request(Orders)). %----------------------------------------------------- %This procedure checks whether consumers send ‘confirm’ or ‘refuse’ message confirm_or_not(Price,Stockleft,Profit,NewStockleft,NewProfit):- identity(Ag), addressees(Addrs), my_setof(consumer(C),
78
member(consumer(C),Addrs),Cs), confirmAux(Cs,Ag,Price,Stockleft,Profit,NewStockleft,NewProfit). %---------------------------------------------------------------- % When the dealer receive ‘confirm’ message, it will check its stock.. confirmAux([],Ag,Price,Stockleft,Profit,NewStockleft,NewProfit):- NewStockleft is Stockleft, NewProfit is Profit. confirmAux([C|Cs],Ag,Price,Stockleft,Profit,NewStockleft,NewProfit):- in_noblock(m(C,Ag,confirm(Qty,Price))), check_stock(C,Ag,Qty,Price,Stockleft,Profit,NSL,NPF), confirmAux(Cs,Ag,Price,NSL,NPF,NewStockleft,NewProfit). confirmAux([C|Cs],Ag,Price,Stockleft,Profit,NewStockleft,NewProfit):- in_noblock(m(C,Ag,refuse)), NSL1 is Stockleft, NPF1 is Profit, confirmAux(Cs,Ag,Price,NSL1,NPF1,NewStockleft,NewProfit). confirmAux([C|Cs],Ag,Price,Stockleft,Profit,NewStockleft,NewProfit):- confirmAux([C|Cs],Ag,Price,Stockleft,Profit,NewStockleft,NewProfit). %----------------------------------------------------------------- %If the dealer has enough stock, it will send order_processed message, deduct its stock %and calculate new profit. If the dealer has not enough stock, it will send ‘lot_out’ message check_stock(C,Ag,Qty,Price,Stockleft,Profit,NSL,NPF):- Stockleft >= Qty, %%%out(m(adm,checkstock>order(Ag))), out(m(Ag,C,order_processed)), out(m(adm,order_processed(Ag,C))), NSL is Stockleft - 1, NPF is Profit + Price. check_stock(C,Ag,Qty,Price,Stockleft,Profit,NSL,NPF):- Stockleft < Qty, out(m(Ag,C,lot_out)), out(m(adm,lot_out(Ag,C))), NSL is Stockleft, NPF is Profit. % -------------------------------------------------------------------------- % EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF % -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------- %File: Dealer1_breed.pl %Author: Wanwimol T. %Update:10 Sept, 2001 % --------------------------------------------------------------------------------------------------- % This is to initial a variable : FixedCose
79
% ovcost(0.05). %The command is to execute the dealer agent. %The initial value is loop(SafetyLevel,MarginOfProfit,InitProfit,InitStock,InitPrice) :- initialise,rd(m(adm,all,start)),loop(5,1.5,[0],0,0) ,terminate % -------------------------------------------------------------------------- % EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF % -------------------------------------------------------------------------- % --------------------------------------------------------------------------------------------------- %File: Producer.pl %Author: Wanwimol T. %Update:10 Sept, 2001 % --------------------------------------------------------------------------------------------------- :-[preamble]. :-[linda_part]. %------------------------------------------------------ %Case1: A producer has not enough stock. %When a producer’s stock is less than 5, the producer will send die-message. This number should %be equal to the maximum delivery lot, if there is more than one breed of dealers. loop(Stock):- Stock < 5, identity(Ag), out(m(adm,producerwilldie(Ag))), sendAllRequest(offer_stock(0,0)), sendAllRequest(out_of_stock), out(m(adm,producerDIEDDDDD(Ag))), out(m(adm,log([die(Ag)]))), out(m(adm,die(Ag))). %------------------------------------------------------ %Case2: A producer has enough stock. %A producer waits for ‘ask_stock’ message from dealers. If there is any ‘ask_stock’ message, the %producer will send ‘offer_stock’ message including quantity and price. After that the producer %waits for ‘stock_receive’ message from the dealers, and calculates a new stock loop(Stock):- Stock >= 5, identity(Ag), in_noblock(m(D,Ag,ask_stock(Add2stock))), ProdPrice = 1/Stock, SalePrice = Add2stock * ProdPrice, out(m(Ag,D,offer_stock(Add2stock,SalePrice))), out(m(adm,offer_stock(Ag,D,Add2stock,SalePrice) ) ), in(m(D,Ag,stock_received)),
80
out(m(adm,gotreceivems(D))), NewStock = Stock - Add2stock, write(NewStock), out(m(adm,stockleft(NewStock))), loop(NewStock). loop(Stock):- loop(Stock). %---------------------------------- sendAllRequest(M):- identity(Ag), allDealers(Dealers), sendAllRequestAux(Dealers,Ag,M). sendAllRequestAux([],_,_). sendAllRequestAux([D|Ds],Ag,M):- out(m(Ag,D,M)), out(m(adm,willdie(Ag,D,M))), sendAllRequestAux(Ds,Ag,M). %--------------------------------------------------------------------------- allDealers(Dealers):- addressees(Addr), setof(dealer(D),member(dealer(D),Addr),Dealers). %---------------------------------------------------------------------------- receiveOffers(Offers):- identity(Ag), allDealers(Dealers), receiveOffersAux(Dealers,Ag,Offers). receiveOffersAux([],_,[]). receiveOffersAux([D|Ds],Ag,[m(D,Ag,offer(Qty,Price))|Offers]):- in_noblock(m(D,Ag,offer(Qty,Price))), receiveOffersAux(Ds,Ag,Offers). receiveOffersAux([D|Ds],Ag,Offers):- rd_noblock(m(D,dead)), receiveOffersAux(Ds,Ag,Offers). receiveOffersAux(Ds,Ag,Offers):- receiveOffersAux(Ds,Ag,Offers). %--------------------------------------------------------------------------- %The command is to execute the producer agent. The initial value is loop(ProducerStock) :- initialise,rd(m(adm,all,start)),loop(500),terminate. % -------------------------------------------------------------------------- % EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF % -------------------------------------------------------------------------- % --------------------------------------------------------------------------- % Program: experiment.pl
81
% Date: 04/06/2001 % Author: Wamberto W. Vasconcelos Adaped by: Wanwimol Thawornchak % Purpose: % This program builds and runs a multi-agent system from a specification. % --------------------------------------------------------------------------- :- use_module(library(lists)), use_module(library(system)), use_module(library(random)), use_module(library('linda/client')). % --------------------------------------------------------------------------- % startLPad % starts up a Linda server and connects this program as one client process startLPad:- startServer(_), initialiseClient(_). % --------------------------------------------------------------------------- % experiment(Exp/?,FileName/+) % runs experiment Exp and stores information on the run in FileName, a log % file. FileName *must* be provided. If a value for Exp is provided then % only the experiment with that name is run, otherwise we run the first % experiment. experiment(Exp,FileName):- setof(Label-MAS,mas(Exp,Label,MAS),MASs), % obtains all experiments open(FileName,append,Stream), % FileName is open nl(Stream), write(Stream,experiment:Exp), nl(Stream), simulateMASs(MASs,Stream), % run them nl(Stream), close(Stream). % close FileName % --------------------------------------------------------------------------- simulateMASs([],_):- % at end cleanTuple. % clean tuple space of messages simulateMASs([Label-MAS|MASs],Stream):- % for each Label-MAS nl, write('-----------------------'), write(Label), write('-----------------------'), startUp(MAS), % start up MAS nl(Stream), write(Stream,'% '), write(Stream,Label), supervise(Stream), % supervise execution cleanTuple, % clean tuple space simulateMASs(MASs,Stream). % do the same with rest... % ---------------------------------------------------------------------------
82
% mas(ExpName/+,Label/+,MAS/-) % ExpName is the name of the experiment. It has Label which will be used in % to identify the experiment in the log file. MAS is a list of runnable % Prolog programs -- these are the agents that will populate experiment % ExpName. ExpName and Label are just names, so there is nothing important % about their choice % NB.: The definitions of mas/3 given below are illustrative. They should be % adapted to different needs and experiments. The important thing to notice % is how populations can be related automatically. mas(exp1,label(exp1,c:20,all-all,d:4,all-all,p:1),MAS):- population(consumer, % define population of consumers 'consumer.pl', % using this species 'consumer_breed.pl', % and this breed 20,Cons), % 20 agents stored in list Cons population(dealer1, % define population of dealers 'dealer.pl', % using this species 'dealer1_breed.pl', % and this breed 2,Dealers1), % 2 agents stored in list Dealers population(dealer2, % define population of dealers 'dealer.pl', % using this species 'dealer2_breed.pl', % and this breed 2,Dealers2), % 2 agents stored in list Dealers population(producer, % define population of a producer 'producer.pl', % using this species 'producer_breed.pl', % and this breed 1,Producers), relate(Producers:all, Dealers1:all, ProducersR,Dealers1R), relate(ProducersR:all, Dealers2:all, ProducersRR,Dealers2R), relate(Dealers1R:all, Cons:all, Dealers1RR,ConsR), relate(Dealers2R:all, ConsR:all, Dealers2RR,ConsRR), append(ProducersRR,Dealers1RR,TmpPop1), % assemble list of all agents append(Dealers2RR,ConsRR,TmpPop2), append(TmpPop1,TmpPop2,MAS). % --------------------------------------------------------------------------- % population(Name/+,Species/+,Breed/+,Qty/+,Inds/-) % creates a population of Qty (an integer) agents of kind Name. Each agent
83
% is a list of the form % [identity(Id),addressees([]),(:-Species),(:-Breed)] % where Id is Name(No). The agents are stored in list Inds. population(Name,Species,Breed,Qty,Inds):- populationAux(1,Qty,Name,Species,Breed,Inds). % initial call populationAux(Ctr,Qty,_,_,_,[]):- % Qty has been reached Ctr > Qty, !. populationAux(Ctr,Qty,Name,Species,Breed,[I|Is]):- Id =.. [Name,Ctr], I = [identity(Id),addressees([]), (:-[Species]),(:-[Breed])], NewCtr is Ctr + 1, populationAux(NewCtr,Qty,Name,Species,Breed,Is). % --------------------------------------------------------------------------- % relate(IndL:OpL/+,IndR:OpR/+,IndLR/-,IndRR/+) % relates OpL agents of list IndL with OpR agents of list IndR. OpL and OpR % can be "all", "some" or any integer. The relationship is forged by % including the identity(Id) of the OpR agents in IndR into the fact % addressees(Addr) of OpL agents in IndL. The relationship should be % commutative -- if an agent ag1 has agent ag2 as an addressee, then % agent ag2 should also have ag1 as an addressee. relate(IndL:OpL,IndR:OpR,IndLR,IndRR):- getIds(IndL,IdsL), % get identifiers of IndL getIds(IndR,IdsR), % get identifiers of IndR relateIds(IdsL:OpL,IdsR:OpR,Graph), % build graph relating identifiers relateAux(IndL,Graph,IndLR), % distribute info of Graph relateAux(IndR,Graph,IndRR), % distribute info of Graph !. relateAux([],_,[]). % end of Inds? relateAux([Ind|Inds],Graph,[RInd|RInds]):- % for each Ind member(identity(Id),Ind), % get hold of identity(Id) my_setof(L,member(L-Id,Graph),LNs), % get all edges in Graph w/ L-Id my_setof(R,member(Id-R,Graph),RNs), % get all edges in Graph w/ Id-R append(LNs,RNs,Ns), % append the Ls and Rs remove_duplicates(Ns,NNs), % remove any duplicates addNodes(Ind,NNs,RInd), % add new addressees to Ind relateAux(Inds,Graph,RInds). % do the same for other Inds % --------------------------------------------------------------------------- % getIds(ListAgs/+,ListIds/-) % obtains ListIds, a list of identity(Id), in ListAgs. getIds([],[]). getIds([I|Is],[Id|Ids]):- member(identity(Id),I), getIds(Is,Ids).
84
% --------------------------------------------------------------------------- % addNodes(Ind/+,Ids/+,NewInd/-) % given an agent Ind, this routine adds Ids to the fact addressees(Addr). % In order to preserve the order of facts/rules in Ind, we have to traverse % the list. addNodes([],_,[]). addNodes([addressees(Addr)|Rs],NNs,[addressees(NewAddr)|Rs]):- !, append(Addr,NNs,NewAddr). addNodes([R|Rs],NNs,[R|NRs]):- addNodes(Rs,NNs,NRs). % --------------------------------------------------------------------------- % relateIds(IdL:OpL/+,IdR:OpR/+,Graph/-) % this procedure does the actual relating between the identifiers of agents. % The relationships are recorded in Graph as a list of edges L-R where L and % R are identifiers from IdL and IdR, respectively. % IdL and IdR are lists of identifiers (names of agents). This procedure % relates OpL (all, some or N) elements of IdL to OpR elements of IdR. An % element L is related to an element R if an entry L-R appears in Graph. relateIds(IdL:OpL,IdR:OpR,Graph):- selectIds(OpL,IdL,SIdL), % select OpL ids from IdL and relateIdsAux(SIdL,OpR,IdR,[],Graph). % relates them with OpR ids of IdR relateIdsAux([],_,_,G,G). % no more IdL... relateIdsAux([IdL|IdLs],OpR,IdR,TempG,G):- % for each selected IdL selectIds(OpR,IdR,SIdR), % select OpR IdR edges(SIdR,IdL,Edges), % build edges with them append(Edges,TempG,NTempG), % append new edges to TempG relateIdsAux(IdLs,OpR,IdR,NTempG,G). % do the same for IdLs % --------------------------------------------------------------------------- % selectIds(Op/+,Ids/+,SIds/-) % selects Op (all, some or integer N) elements from list Ids and stores them % in list SIds selectIds(all,L,L):- % select all... !. selectIds(some,L,SomeL):- % to select some elements from L... length(L,Size), % count number of elements randomSize(Size,RSize), % get a random number up to no. of elements selectIds(RSize,L,SomeL), % select this random number from L !. selectIds(some,L,SomeL):- % clause above may fail (because of random) selectIds(some,L,SomeL). % so try again (eventually it works...) selectIds(0,_,[]):- % to select 0 elements... !.
85
selectIds(N,[X|Xs],[X|NXs]):- % to select N elements random(T), % randomly choose a number T > 0.5, % if chose number > 0.5 NN is N - 1, % decrease counter selectIds(NN,Xs,NXs). % select more... selectIds(N,[_|Xs],NXs):- % if random number =< 0.5 selectIds(N,Xs,NXs). % skip element and try to get more... % --------------------------------------------------------------------------- % randomSize(Size/+,RSize/-) % obtains a positive random integer RSize less than or equal to Size randomSize(Size,RSize):- random(N), % get random number N (it's a decimal...) RSize is integer(N * 10), % multiply N by 10 and get the integer bit RSize > 0, % it must be greater than 0 RSize =< Size, % and less than or equal to Size !. randomSize(Size,RSize):- % if not possible, try again randomSize(Size,RSize). % (clause above may fail...) % --------------------------------------------------------------------------- % edges(ListIdsL/+,IdR/+,ListEdges/-) % builds a graph in ListEdges as a list of pairs IdL-IdR where IdL is an % element of ListIdsL. edges([],_,[]). edges([N|Ns],M,[N-M|Es]):- edges(Ns,M,Es). % --------------------------------------------------------------------------- % my_setof(A/-,B/+,C/-) % personal definition of setof that returns empty list if B has no answers. my_setof(A,B,C):- setof(A,B,C), % my_setof is setof... !. my_setof(_,_,[]). % but if it fails then we get the empty list % --------------------------------------------------------------------------- % startUp(Ags/+) % starts up the list of runnable Prolog programs Ags as background processes. startUp(Ags):- createFiles(Ags,0,Files), % create files with contents startUpAux(Files), % start them up sleep(5), deleteFiles(Files). % delete files startUpAux([]). % end of agents startUpAux([F|Fs]):- % for each file name F name('echo "[',P1), % * encode UNIX command with name(F,P2), % * its name
86
name(']." | sicstus > /dev/null &',P3), % * this is the rest of command append(P1,P2,P12), % the * above are ASCII characters append(P12,P3,ASCCommand), % [operating on a character level] name(Command,ASCCommand), % get actual command exec(Command,[null,null,null],_), % execute it startUpAux(Fs). % do the same with other files % --------------------------------------------------------------------------- % createFiles(Ags/+,N/+,FileNames/-) % given the list Ags of Prolog programs (list of lists) and the counter N, % write the content of each element in Ags onto a file and store its name % in list FileNames createFiles([],_,[]). % end? createFiles([Ag|Ags],N,[File|Files]):- % for each agent Ag (Prolog progr) name(N,ASCN), % get the ASC for N name(File,[97,103|ASCN]), % assemble the name of the file open(File,write,Line), % open the file writeFile(Ag,Line), % write the contents of Ag in it close(Line), % close file NN is N + 1, % increment counter createFiles(Ags,NN,Files). % do the same with Ags % --------------------------------------------------------------------------- % writeFile(ListClauses/+,Line/+) % writes ListClauses in Line writeFile([],_). writeFile([L|Ls],Line):- portray_clause(Line,L), writeFile(Ls,Line). % --------------------------------------------------------------------------- % deleteFiles(FileNames/+) % deletes the files whose names are specified in the list FileNames deleteFiles([]). % while it's not empty list... deleteFiles([F|Fs]):- % for each file name F name('rm -f ',P1), % assemble a command (ASCII...) name(F,P2), append(P1,P2,ASCCommand), name(Command,ASCCommand), % translate ASCII onto command exec(Command,[null,null,null],_), % execute it deleteFiles(Fs). % do the same with other Fs.. % --------------------------------------------------------------------------- % startServer(PId):- % this routine is responsible for generating and running the Linda server % process. The server program is stored in the file "server.pl" and is % created automatically. % When the server process is started, it creates a file "server.addr" which
87
% works as a Linda "handler" -- all client processes should have access to the % information concerning the Host:Port to which the server is "listening" and % this information is recorded in the file "server.addr". % This routine checks that the file "server.addr" is available. If the file % is found, the routine then checks that the server process is actually % running. % If the file isn't there or if the process isn't running, the routine starts % up a fresh server process. startServer(PId):- file_exists('server.addr'), % if file "server.addr" (handle) exists see('server.addr'), % open it, read(_:_-PId), % get PId, seen, % close it, and up(PId), % check that process is up !. startServer(PId):- % otherwise... createServerProgram, % create server program "server.pl" startServerAux, % start it up sleep(5), % wait a bit... (to update file) see('server.addr'), % open file with Linda handle read(_:_-PId), % get PId seen. % close it startServerAux:- exec('echo "[\'server.pl\']." | sicstus > /dev/null &', [null,null,null], _). % -------------------------------------------------------------------------- % up(+PId):- % holds if process PId is running up(PId):- concat(['ps -p ',PId,' | wc'],Command), % type this command in UNIX exec(Command,[null,pipe(Out),null],_), % and PId will be running get(Out,50). % if first returned Char is 2 createServerProgram:- tell('server.pl'), write(':- use_module(library(\'linda/server\')),'),nl, write(' use_module(library(\'system\')),'),nl, write(' pid(PId),'),nl, write(' linda((Host:Port)-(tell(\'server.addr\'),'),nl, write(' '), write('write(\''),write(\),write('\'\'),'),nl, write(' '), write('write(Host),'),nl, write(' '), write('write(\''),write(\),write('\':\'),'),nl, write(' '),
88
write('write(Port-PId),'),nl, write(' '), write('write(\'.\'),'),nl, write(' '), write('told)).'), told. % -------------------------------------------------------------------------- % initialiseClient(PId):- % starts up a connection between this program (which is a process) and the % other processes it starts up automatically. This predicate gets the process % id of the server process. % % NB: this routine is automatically executed whenever this program is loaded! initialiseClient(PId):- see('server.addr'), read(Host:Port-PId), seen, linda_client(Host:Port). % -------------------------------------------------------------------------- % killProcess(+ProcDescription):- % kills process(es) fitting ProcDescription. ProcDescription can be a list of % descriptors, or any of the descriptors process(AgName,PId), all, server, PId, % AgName. Appropriate messages are issued if things go wrong... killProcess([]). killProcess([Proc|Procs]):- % if list of descriptors killProcess(Proc), % kill each of them killProcess(Procs). killProcess(all):- % if killing "all" bagof_rd_noblock(process(AgName,PId), % get all process/2 tuples process(AgName,PId), Procs), !, killProcess(Procs), % kill them all removeMsgs(Procs), % remove process/2 tuples killProcess(server). % kill server killProcess(all):- % if there are no process/2 tuples killProcess(server). % just kill server killProcess(server):- % if kill server see('server.addr'), % see handle file read(_:_-PId), % get PId seen, kill(PId,9), % kill it nl, write('Server has been killed!!'). % issue message killProcess(process(AgName,PId)):- % if process/2 descriptor
89
up(PId), % and PId is up then kill(PId,9), % kill it concat(['Process ',PId, % assemble message ' with agent ', AgName, ' has been killed!!'],Msg), nl, write(Msg). % display message killProcess(PId):- % if PId descriptor integer(PId), rd_noblock(process(AgName,PId)), % check that process/2 tuple exists !, killProcess(process(AgName,PId)). % and kill it killProcess(AgName):- % if AgName descriptor rd_noblock(process(AgName,PId)), % check process/2 !, killProcess(process(AgName,PId)). % and kill it killProcess(PId):- % exceptions... concat(['Process ',PId, ' doesn\'t exist!!'],Msg), nl, write(Msg). % -------------------------------------------------------------------------- % removeMsgs(+ListOfTuples):- % deletes (using in/1) all the tuples in ListOfTuples from the tuple space removeMsgs([]). removeMsgs([M|Ms]):- in(M), removeMsgs(Ms). % -------------------------------------------------------------------------- % cleanUp:- % kills all processes and deletes all server files cleanUp:- killProcess(all), delete_file('server.pl',[ignore]), delete_file('server.addr',[ignore]), close_client. % -------------------------------------------------------------------------- % supervise:- % routine to supervise processes -- it records all messages "in transit" % in a log file % NB (1) a "adm(start)" tuple is sent to the tuple space, to be read by the % processes as the "go ahead". This design decision is also incorated % to the initialisation routine of each agent. % NB (2) the log file has a changing name in case successive experiments are % to be run (if the same name was used previous results would be lost)
90
% NB (3) we make use of the following convention: tuples adm(M) are to be % sent from the processes, where "M" is the actual message and adm/1 % is an outer "layer". This layer is removed by this routine and M is % stored in the tuple space. %------------------------------------------------------------------------- supervise(Stream):- sleep(5), out(m(adm,all,start)), % start message (see above) superviseAux(Stream). % loops... superviseAux(Stream):- % loops for messages messagesInTransit(Stream), % checks for them superviseAux(Stream). % carries on loop superviseAux(_):- % loops for messages \+ rd_noblock(process(_)). % checks if all dead superviseAux(Stream):- % loops for messages %-------------------------------------------------------------------------- messagesInTransit(Stream):- % retrieves messages in_noblock(m(adm,Msg)), % that match adm(M) logMsg(Stream,Msg), nl, write(Msg), % show it on screen returnMsg(Msg). % write M in tuple space messagesInTransit(Stream):- % retrieves messages in_noblock(m(_,adm,Msg)), % that match adm(M) logMsg(Stream,Msg), nl, write(Msg), % show it on screen returnMsg(Msg). % write M in tuple space % -------------------------------------------------------------------------- logMsg(Stream,log(List)):- % logs message log(List) nl(Stream), logMsgAux(Stream,List). % logs List logMsg(_,_). % otherwise disconsider logMsgAux(_,[]). logMsgAux(Stream,[X|Xs]):- logInfo(Stream,X), % log each element logMsgAux(Stream,Xs). logInfo(Stream,Term):- % only log particular info write(Stream,Term), write(Stream,' '). logInfo(_,_). % --------------------------------------------------------------------------
91
returnMsg(m(Or,Dst,M)):- % certain intercepted messages out(m(Or,Dst,M)). % have to be returned returnMsg(_). % -------------------------------------------------------------------------- % Auxiliary Routines % -------------------------------------------------------------------------- % concat(+ListStrings,?Concat):- % succeeds if Concat is the concatenation of the strings in ListStrings concat(ListStrings,Concat):- ListStrings = [Str1|Strings], concatList(Strings,Str1,Concat). concatList([],String,String). concatList([S|Ss],StringSoFar,String):- concat(StringSoFar,S,NewStringSoFar), concatList(Ss,NewStringSoFar,String). % -------------------------------------------------------------------------- % concat(+Str1+,+Str2,?Str1AndSrt2):- % succeeds if Str1AndStr2 is instantiated to the concatenation of % Str1 with Str2 concat(Str1,Str2,Str1andStr2):- name(Str1,ASCStr1), name(Str2,ASCStr2), append(ASCStr1,ASCStr2,ASCStr1andStr2), name(Str1andStr2,ASCStr1andStr2). % -------------------------------------------------------------------------- % cleanTuple % cleans tuple space by getting rid of all terms there... cleanTuple:- in_noblock(_), cleanTuple. cleanTuple. % !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! % commands executed at onset of this program... % !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :- startServer(_), initialiseClient(_). % -------------------------------------------------------------------------- % EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF -- EOF % ---------------------------------------------------------