CPS: A CONCURRENT PRODUCTION SYSTEM
Mohammad G. Khayat*
and
Abdallah N. AI-Sukairi
Information and Computer Science Department King Fahd University of Petroleum & Minerals
Dhahran, Saudi Arabia
~I ~UJJI
rti
~J ~l.#1 4-.Ja ~ ~~~ .~J
y.rJ1 ~I~I ~ r~. 4=..1;1.1 ~WI .~J . 4=..1;1.1 ~WI i~ ~ i;wU 41 y.r ~I;
r
Uii l..A:.iJ ~ ~I lolA r~J: J
rlla:J1laU
4....;)1'-""'Jill
~J . ~JT
~b- j~ ~ rlla:J1 lolA ~J , ~\$ •...sl'; rl~1J !l..;...:.; 4..liit
.~'-'t"-;
~~1(
Y) 'r'~~I 41"... ( , ). r~1 4la..-1'y' ~u,;WI
J:L-
~I;"'-~I'-'t.,N
~~1(
~)
. ~.rJ.IJ ,.ll:l.IJ ,Y.rJ1 ~I~IJ , • ...sI"U1 ~ rUI ~) 4r rlla:J1 iJ~J
~j')Ul ~IJ.)~I..r!~ ~.rJ.' r~J
.
rlla:J1 ~w 4r ~. ~~ ~.,b .ll:l.1 r~JJ}>
jJlJ ~J
rlla:JllolA r'~I~..J lolA . rlla:J1J.s-
~l:.J , ~r..,.... • "
. y.rJ1 ~I~I ~ ~.)~~I ~l.I~~1 JI ~u,~~ 4=..1;1.1 ~WI
Jl....,.
•Address for correspondence : KFUPM Box No. 514
King Fahd University of Petroleum & Minerals Dhahran 31261, Saudi Arabia
January 1989 The Arabian Journal for Science and Engineering, Volume 14, Number 1.
119
M. G. Khayat and A. N. Al-Sukairi
ABSTRACT
Production systems play an important role in various domains such as knowledge engineering, cognitive modeling, natural language understanding, and the modeling and simulation of concurrent processing.
The design and implementation of an efficient production system that supports concurrent processing simulation and runs on a micro-computer are here presented. The Concurrent Production System (CPS) is an easy-to-use, forward
chaining concurrent production system. The main features of CPS are: (1) support of multiple concurrent production systems sharing the same memory; and (2) support of user-defined conflict resolution strategies to the extent that they can be specified as production systems. In addition, CPS supports other features such as dynamically changing production rules. The packaging of this combination of capabilities makes CPS unique and novel.
CPS consists of four modules: working memory, production rules, the interpreter, and the monitor. The interpreter of CPS uses the Rete Match Algorithm to improve the efficiency of the system. The CPS monitor provides the user with the interface to the system and the ability to monitor and trace a running production system.
CPS can serve as a software tool for designing and analyzing solutions to concurrency problems. It can also be used to build expert systems and to develop applications in areas that use production systems.
120 The Arabian Journal for Science and Engineering, Volume 14, Number 1. January 1989
M. G. Khayat and A. N. Al-Sukairi
CPS: A CONCURRENT PRODUCTION SYSTEM
1. INTRODUCTION
Production systems (PSs) [1, 2] were first intro
duced as a symbol manipulation system by Post in 1943. More recently, PSs have been used as a software tool in various domains such as games [3], cognitive modeling [4, 5], knowledge representation [6, 7], natural language understanding [8], concur
rency modeling [9, 10), and expert systems [11-13].
A typical PS consists of a working memory (WM), a set of production rules (rules), and an interpreter [2].
Working memory is used to store elements of data that reflect the state of the PS. It serves as a global data base for all rules. WM should have some initial elements representing the state of the problem to be solved by the system. Once the PS starts, WM elements are under total control of actions resulting from firing of rules. Rules use WM to store the state of the system and to store control information.
Therefore, usually new elements are added to the WM, and existing elements are modified or deleted.
Production rules store the system knowledge in terms of independent if-then rules. Each rule contains two parts: the IF part and the THEN part.
The IF part is a set of conditions. Conditions test for the absence or presence of certain memory elements or test relationships among elements in WM. If all conditions in a rule are satisfied by the current state of WM, then that rule is called an applicable rule.
The THEN part contains a list of zero or more actions. Actions can be almost anything, but they are usually operations to change the state of the working memory. Actions can add, delete, and modify working memory elements. They can be input/output operations to interact with the user; they can also add and delete production rules.
The interpreter is the part that runs the PS. It performs three main steps repeatedly: matching, conflict resolution, and firing. These three steps are performed in order, and represent one PS cycle.
Such a cycle is repeated by the interpreter until there are no more applicable rules or one of the executed actions is a halt action.
The first step in the cycle tests the applicability of all production rules by matching conditions against WM. Ifany rule is found to be applicable, it is placed in a special set containing all applicable rules. Such a
set is called the conflict set. This step is the most time-consuming operation in the system. Most PSs use some sort of pattern matching algorithms for this step, and therefore make the whole PS more efficient [14, 15].
Conflict resolution selects one rule (or· more) out of the conflict set according to certain rules known as conflict resolution strategy. This step is needed if the conflict set contains more than one rule. The selected rule is then passed to the last step. The selection strategy differs from one system to another depend
ing on the application domain. Possible selection strategies include rule order, recency order, and generality order.
In Rule order, all rules in the system are assigned unique ordering numbers, and the rule with the highest order is selected. In Recency order, the rule matching the most recent elements is selected. In Generality order, the rule with more conditions is selected.
Firing is the last step in a PS cycle. It simply executes the actions of the rule selected by the conflict resolution step. These actions usually involve changing the state of the WM.
The purpose of this research work is to design and implement a Concurrent Production System "CPS"
that overcomes some of the deficiencies of existing systems, such as ACT [16], PSNLST [17], OPS5 [18], and ROSIE [19]. These systems are not suitable for simulations requiring concurrent processing, which are an attractive application for production systems.
They only allow one production system to be defined in which only one production rule is fired. The conflict resolution strategies of the existing systems are not under user control. For example, the least-recently-applied rule strategy is adopted in these systems. One reason for this choice is to prevent infinite loops.
In addition, these systems are implemented on mini or mainframe computers. This problem is partially due to the need for a sizable memory in order to develop a production system.
CPS is a general production system designed and implemented to support the simulation of concurrent processing and to give the user the option to define the desired conflict resolution strategy. It supports multiple sub-production systems and multiple rule
January 1989 The Arabian Journal for Science and Engineering, Volume 14, Number 1. 121
M. G. Khayat and A. N. Al·Sukairi
firing. It accepts LISP functions (primitive and 2.1. The Monitor user-defined) as actions. It has a user-friendly
The C~S monitor performs the following tasks:
monitor, and uses a fast match algorithm to improve
its efficiency. Furthermore, it supports dynamic 1. Loading load files by compiling the production control over production rules. This feature is needed rules using the Rete Match Algorithm (see to design learning systems (adaptive systems). section 2.4). A load file contains a description of Finally, it runs on a micro-computer. This feature a production system. It mainly consists of the will enhance the usage of the system, while the production rules and the conflict resolution previous features make CPS a suitable tool to use in strategy. Since CPS supports concurrency, there concurrent processing simulation besides the other can be more than one PS where each is typical applications of production systems. represented by a load file.
2. Initializing the CPS working memory. The initial The next section of this paper describes the design
working memory (WM) elements are loaded and implementation of CPS. Section 3 illustrates
from a file. By default, the WM initially contains modeling concurrency problems in CPS. Section 4
no elements.
summarizes the outcome of the research work.
3. Running the interpreter to run the loaded PSs a given number of cycles.
2. CPS: A CONCURRENT PRODUCTION SYSTEM
4. Adding interactively a new element to the CPS consists of four modules: the monitor, the
working memory.
working memory (WM), production rules, and the
interpreter. The following sections describe in detail 5. Displaying the current working memory each module. The modules interact as shown in elements, and time tags associated with each
Figure 1. element (time tags are discussed in section 2.2).
User
~
I
"1/1
Monitor
---7:
:~---",..
,
Interpreter
I
"'J/
Working Production
Memory ~--- ---~ Rules
Figure 1. CPS General Structure
122
The Arabian Journal for Science and Engineering, Volume 14, Number 1. January 1989M. G. Khayat and A. N. Al-Sukairi
6. Deleting an existing element from WM.
7. Clearing working memory.
8. Displaying the conflict set of a PS.
9. Loading a file containing user defined functions that are written in LISP. Such functions can then be called as actions in the THEN part of production rules.
10. Quitting CPS.
2.2 VVorking ~emory
CPS has only one WM which can be shared by all sub-production systems. Henceforth a sub-produc
tion system is called a process. All processes use the same WM. The WM can be totally shared by all processes or partially shared where each process has its own local memory residing in a separate partition in the WM. Thus, CPS can support one global WM, independent local memories (one for each process), or a mix of the two.
The WM consists of a set of elements. Each element consists of an object along with its associ
ated attributes. Elements are stored as lists with each list containing an object and values of the attributes of that object.
Along with each element there is a time tag stored as the last entry in all element lists. An element with a larger tag is considered to be more recent. No two elements can hij.ve the same tag. The system keeps a record -of the last tag used; and if a new element enters the WM or an old element is modified, then the last tag is incremented and assigned to this element.
All objects and attributes used by any process must be defined only once by using a "DEFINE"
statement in that process. The DEFINE statement declares all objects and their attributes and specifies the order of the attributes.
The DEFINE statement also determines the extent of sharing WM. If the DEFINE statements are identical in all processes, it means that WM is totally shared. If part of the DEFINE statement is common to more than one process, then the WM is partially shared.
2.3. Production Rules
In CPS each process has its own set of production rules, which are not ordered. CPS rules are similar to
OPS5 rules [18]. Each rule has a unique name and two parts: IF and THEN. Rule names must be unique at the system level; therefore no two rules, even in different processes, can have identical names. The IF part is the condition part. It consists of one or more conditions, where each condition tests the presence or absence of a certain working memory element. The THEN part is the action part.
It consists of zero or more actions. The allowable actions are the following:
1. Adding a new element into WM. The new element added can be identical to an existing element, but the system will assign each a different time tag.
2. Deleting an existing WM element.
3. Modifying an element matched by a non
negated condition.
4. Halting the process containing the rule issuing this action.
5. Adding a new production rule by giving the specifications of a new rule. The new rule is added to the process containing the rule that initiated this action. It is compiled in the same way original rules are compiled.
6. Removing an existing rule by specifying its name.
7. Specifying any LISP primitive or user-defined function. All LISP 110 operations can also be used. All user-defined functions must be defined to CPS before running the system to make them recognizable during firing of applicable rules.
2.4. The Interpreter
The interpreter repeatedly performs the three tasks of a PS cycle: matching, conflict resolution, and firing. Since CPS supports concurrency, the three steps are repeated for each process. Matching is the most time-consuming step in any PS; therefore an efficient matching algorithm, the Rete Match Algorithm [14, 15] has been used in CPS to improve the efficiency of the system.
Conflict resolution in CPS is totally user-defined, and it must be specified for each process. The conflict resolution module is responsible for selecting a single rule out of the conflict set of each process.
The following strategies can be selected for conflict resolution.
January 1989 The Arabian Journal for Science and Engineering, Volume 14, Number 1.
123
M. G. Khayat and A. N. Al-Sukairi
2.4.1. Recency
The rule that matches the most recent elements is selected, provided that this rule is not the rule fired in the previous cycle (to avoid infinite loops). The tags are used to measure the recency of elements. The last updated or added element is the most recent one.
CPS determines the rule that matches the most recent elements by summing the tags of the elements satisfying each applicable rule. The rule with the highest sum is selected. This strategy is common in PSs, and it is often used in knowledge-based systems.
Specifying this strategy only requires the keyword (RECENCY).
2.4.2. No Conflict
Ifthe rules of a certain process are written in such a way that only one rule can be applicable in any cycle, then there is no conflict set. Specifying this strategy requires only the keyword (NO CONFLICT).
2.4.3. Queuing
The conflict set is treated as a queue. It selects the rule at the head of the queue; then it moves it to the tail of the queue after firing. New rules are always added to the tail of the queue, and existing ones can be removed from the queue without affecting the order. Specifying this strategy requires only the keyword (QUEUE).
2.4.4. User Interaction
The User interactively selects the rule to be fired.
CPS will prompt the user with the unique names of rules in the conflict set and will ask the user to enter the name of the desired rule. If the selected rule happens to be satisfied by more than one set of elements, then these sets of elements are again prompted with a number associated with each set, and the user is asked to select the number of the desired set. Specifying this strategy requires only the keyword (USER).
2.4.5. Priority
The rule with the highest priority is selected, provided that this rule is not the rule fired in the previous cycle (to avoide infinite loops). This strategy requires specifying priorities for the rules of the process specifying this strategy. Priorities must be integers. The larger the integer is, the higher the priority. If two rules hold the same priority integer, then one is arbitrarily selected.
124 The Arabian Journal for Science and Engineering, Volume 14,
2.4.6. Conflict Resolution Rules
The user writes another sub-production system serving as a conflict resolution strategy. Rules can be specified to select one rule out of the conflict set.
This is a very powerful feature. Conflict resolution rules should be carefully written to make sure that such rules will always select a single production rule in any cycle. The working memory of the conflict resolution rules is the conflict set. Conflict resolution rules cannot produce any action other than selecting a rule from the conflict set. Conflict resolution rules have the same structure as the production rules.
CPS manages multiple production systems by compiling the rules of each process into a separate network. Each network stores, besides the nodes, the conflict resolution strategy of the process it repre
sents. Yet if a process uses conflict rules, then another network is formed for that process by compiling the conflict rules. In this case the terminal nodes of the production rules network do not report to the conflict set but instead report to the conflict resolution network. All changes to WM from any process are formulated into network tokens and are passed in sequence to all networks. If a certain network does not deal with certain elements, they will simply be rejected in the first level of nodes.
Each process selects a candidate rule for firing. CPS tries to fire all such rules. It first fires the rule of the first process; then it checks whether the rule of the second process can be fired or not. Ifthis second rule can be fired, it will be fired and the system then checks the third one, and so on. A rule can be fired if it is not in conflict with a previously fired rule in the cycle. Such a conflict is deduced by storing the elements that are affected by the fired rules; and before firing a new rule, CPS checks whether this rule is accessing an element that has been accessed before. If so, then it is in conflict with another rule which was fired earlier. CPS in this case gives the user the option to halt the system or to abort the rule causing the conflict.
CPS can be used to design and analyze solutions to concurrency problems. CPS does not enforce any concurrency controls. The user must provide a mechanism within the specification of the process to control concurrency. This will provide an environment within which solutions to concurrency problems can be designed and analyzed for correctness.
Number 1. January 1989
2.S. CPS Implementation
In CPS a process is represented by a file that contains object definitions, production rules and the conflict resolution strategy. In addition, a file can be used to define the initial contents of the working memory. The Rete Match algorithm compiler com
piles the IF parts of production rules of each file into a special network. The THEN parts of productiqn rules of all files are all stored in a property list. After processing the initial WM elements, a conflict set is formed for each network. The conflict resolution strategy of each process is then applied to its conflict set, and one rule is selected from each. The THEN part of the rule of the first process is retrieved from the property list and the actions are executed. The interpreter then checks for any conflict before firing the rule of the second process. This will continue for all selected rules.
The CPS program is written in IQLISP [20]. It runs on IBM PC/XT or any other truly IBM PC compatible micro-computer. It runs under DOS; and requires at least 150 K of memory (including approx
imately 100 K for IQLISP and support functions).
The source code consists of approximately 2200 lines of LISP.
: 3 :
3
..:....-..r : 4 :
4M. G. Khayat and A. N. Al-Sukairi
3. EXAMPLES
This section presents two examples to demonstrate the use of CPS in modeling and simulation of concurrent processes.
3.1. Example 1: The Trame Intersection [21]
Four cars 1, 2, 3, and 4 arrive at an intersection at approximately the same time (Figure 2). To prevent accidents at four-way stop intersections, right-of-way regulations require that car 1 yield to car 2, car 2 to car 3 and so on. Cars can turn right, go straight or turn left. To turn right, car 1 requires quarter 1 of the intersection. To go straight, car 1 requires quarters 1 and 2. To turn left, car 1 requires quarters 1, 2, and 3. Similarly, the other cars 2, 3, and 4 require the relevant quarters of the intersection.
A solution of the problem can be stated as follows:
1. A car can turn right if the relevant quarter of the intersection is unoccupied. For example. car 1 can turn right if quarter 1 is unoccupied.
2. A car can go straight if the two relevant quarters of the intersection are unoccupied and there is no car to its right right. For example, car 1 can go straight if quarters 1 and 2 are unoccupied and there is no car 2 at the intersection.
2 : 2 :
+-
+
1
1 :
T
Figure 2
January 1989 The Arabian Journal for Science and Engineering. Volume 14. Number 1.
125
M. G. Khayat and A. N. AI-Sukairi
3. A car can turn left if the three relevant quarters are unoccupied and there is no car to its right attempting to go straight or tum left.
It is assumed that once a car is allowed to proceed, the relevant quarters of the intersection are declared occupied. Note also, that once a car coming from a certain direction is in the intersection, another
car from the same direction may arrive at the intersection.
To represent the above solution within CPS, let cars arriving from a certain direction be represented as a process. Thus there are four processes and correspondingly four load files. The load file of car 1 is shown in Figure 3.
(DEFINE (NOCAR NUM) (RQST CAR DRCT) (USE CAR QRTR»
(R RULEIOI
IF (NOCAR NUM= 1 )
THEN (DELETE 1) (ADD RQST CAR= 1 DRCT=RIGHT»
(R RULEI02
IF (NOCAR NUM= 1 )
THEN (DELETE 1) (ADD RQST CAR=l DRCT=STRAIGHT»
(R RULEI03
IF (NOCAR NUM= 1 )
THEN (DELETE 1) (ADD RQST CAR= 1 DRCT=LEFT»
(R RULEI04
IF. (NOCAR NUM=l) THEN (»
(R RULEI05
IF (RQST CAR=l DRCT=RIGHT) -(USE CAR=%X QRTR=l) THEN (ADD USE CAR=l QRTR=l)
(DELETE 1) (ADD NOCAR NUM= 1»
(R RULEI06
IF (RQST CAR= 1 DRCT=RIGHT) - (USE CAR=%X QRTR= 1) THEN (»
(R RULEI07
IF (RQST CAR=l DRCT=STRAIGHT) -(RQST CAR=2 DRCT=%X) -(USE CAR=%Y QRTR=l) -(USE CAR=%Z QRTR=2)
THEN (ADD USE CAR=l QRTR=l) (ADD USE CAR=l QRTR=2) (DELETE 1) (ADD NOCAR NUM=l»
(R RULEI08
IF (RQST CAR=l DRCT=STRAIGHT) -(RQST CAR=2 DRCT=%X) -(USE CAR=%Y QRTR=l) -(USE CAR=%Z QRTR=2)
THEN (»
(R RULEI09
IF (RQST CAR= 1 DRCT=LEFT) (RQST CAR=2 DRCT=STRAIGHT) (RQST CAR=2 DRCT=LEFT)
-(USE CAR=%X QRTR=l) (USE CAR=%Y QRTR=2) -(USE CAR=%Z QRTR=3)
THEN (ADD USE CAR=l QRTR=l) (ADD USE CAR=l QRTR=2)
(ADD USE CAR= 1 QRTR= 3) (DELETE 1) (ADD NOCAR NUM= 1 ) ) Figure 3 (Part)
126
The Arabian Journal for Science and Engineering. Volume 14. Number 1. January 1989M. G. Khayat and A. N. Al-Sukairi
(R RULEllO
IF (RQST CAR=l DRCT=LEFT) -:-(RQST CAR=2 DRCT=STRAIGHT) -(RQST CAR=2 DRCT=LEFT)
-(USE CAR=%X QRTR=l) -(USE CAR=%Y QRTR=2) -(USE CAR=%Z QRTR=3)
THEN (»
(R RULElll
IF (USE CAR=l QRTR=l) -(USE CAR=l QRTR=2) -(USE CAR=l QRTR=3) THEN (DELETE l»
(R RULEll2
IF (USE CAR=l QRTR=l) (USE CAR=l QRTR=2) -(USE CAR=l QRTR=3) THEN (»
(R RULEll3
IF (USE CAR=l QRTR=l) (USE CAR=l QRTR=2) -(USE CAR=l QRTR=3) THEN (DELETE 1 2»
(R RULEll4
IF (USE CAR=l QRTR=l) (USE CAR=l QRTR=2) -(USE CAR=l QRTR=3) THEN
(»
(R RULEll5
IF (USE CAR=l QRTR=1) (USE CAR=1 QRTR=2) (USE CAR=1 QRTR=3) THEN (DELETE 1 2 3»
(R RULE116
IF (USE CAR=1 QRTR=1) (USE CAR=1 QRTR=2) (USE CAR=1 QRTR=3) THEN (»
(USER)
Figure 3 (Continued)
The DEFINE statement defines the objects of this
proce~s. The object (NOCAR NUM) represents the nonpresence of a car whose number is NUM. The object (RQST CAR DRCT) represents a request made by a car to access the intersection. CAR can have the value 1, 2, 3, or 4; and DRCT can have the value RIGHT, STRAIGHT, or LEFT. The object (USE CAR QRTR) indicates that a car is accessing a quarter. CAR and QRTR can have the value 1, 2, 3, or 4.
RULE101, RULE102, RULE103, and RULE104 state that if there are no cars from direction 1 at the intersection then car 1 can appear and place a request to turn right (RULE101), go straight (RULE102), turn left (RULE103), or do nothing (RULE104). In case a request is made, the appro
priate request is added into WM, and the object satisfying the first condition is deleted in order to prevent any more requests from this direction until the current request is processed. Note that these
rules have the same IF condition, therefore they will be enabled if the condition is satisfied and the user must choose one to be fired since the (USER) conflict resolution policy is specified at the end of the load file. RULE104 (called an idling rule) allows for the non-arrival of car 1 at the intersection and for asynchronous operations.
RULE105 states if car 1 has a right-turn request and no car is accessing quarter 1, then car 1 can access quarter 1 (proceed to make the right turn). In addition, the request is deleted since it is satisfied and (NOCAR 1) is added to allow for a new arrival.
RULE106 is an idling rule. RULE107 states that if car 1 has a request to go straight, car 2 has no request (to turn right, go straight or turn left), and no cars are accessing quarters 1 and 2, then car 1 can proceed to access quarters 1 and 2 (i.e., go straight).
In addition, as in RULE105, the request is deleted and (NOCAR 1) is added. RULE108 is the idling rule for RULE107. RULE109 states that if car 1 has
January 1989 The Arabian Journal for Science and Engineering, Volume 14, Number I.
127
M. G. Khayat and A. N. Al-Sukairi
a left-turn request, car 2 has no request to go straight or turn left, and no car is accessing quarters 1, 2, or 3, then car 1 can proceed to access quarters 1, 2, and 3"(make the left turn). The request is deleted and (NOCAR 1) is added as done in RULEI05 and RULEI07. RULEII0 is an idling rule.
RULElll states if car 1 is only accessing quarter 1 (turning right) then it can exit the intersection by terminating access to quarter 1. RULEl12 is the corresponding idling rule. RULEl13 states that if car 1 is only accessing quarters 1 and 2 (going straight), it can exit the intersection by terminating access to quarters 1 and 2. RULEl14 is the corresponding idling rule. RULEl15 states if car 1 is accessing quarters 1, 2, and 3 (turning left), it can exit the intersection by terminating access to quarters 1, 2, and 3. RULEl16 is the corresponding idling rule.
The load file then specifies that the conflict resolu
tion strategy is to allow the user to choose the rule to be fired. Cars 2, 3, and 4 have analogous load files.
The working memory should be initialized to contain the objects (NOCAR 1), (NOCAR 2), (NOCAR 3), and (NOCAR 4) to denote the fact that there are no cars at the intersection. This can be accomplished by interactively adding these objects to WM or by defining an initial WM file to contain the list «NOCAR 1) (NOCAR 2) (NOCAR 3) (NOCAR 4)).
The above suggested solution will deadlock when the four cars attempt to go straight at the intersection from the four directions. This situation is depicted within CPS when WM contains the four requests.
Running the system in this case results in an empty conflict set for every process, indicating the deadlock situation.
In addition, the solution does not correctly handle the case when two cars in opposite directions attempt to turn left. Both cars can be accessing one of two possible quarters at the same time. Such a conflict can be detected in CPS in two ways. One way is to include an extra process whose function is to check for the simultaneous access of a resource by different processes. In our example, such a process may be as follows.
(DEFINE
(USE CAR QRTR»
(R RULEO
IF(USE CAR= %X QRTR=%Y) (USE CAR %X QRTR=%Y)
THEN (PRINT "ACCESS CONFLICT"»
The above rule states that if a quarter is being simultaneously access by two different cars then print an "ACCESS CONFLICT" message.
The second method for detecting the situation is inherent in CPS. Iftwo processes fire two rules in the same cycle such that those rules modify the same element of WM, CPS automatically produces an
"access conflict" message and gives the user the option to abort the action of one of the involved processes or to quit.
3.2. Example 2:
The Dining Philosophers Problem [22]
There are N philosophers who spend their lives either eating or thinking. Each philosopher is seated at a certain place around a circular table. In front of each philosopher there is a plate of spaghetti. To eat spaghetti requires two forks, but only N forks are available, one between each pair of philosophers.
The only forks a philosopher can pick up are those on his immediate right and left. Each philosopher is identical in structure, alternately eating then thinking. The problem is to simulate the behavior of the philosophers.
One solution proposes that a hungry philosopher first attempts to pick up his left fork. Ifhe succeeds, he then attempts to pick up his right fork. Ifthe right fork is available, he picks it up and begins eating;
otherwise, he puts down his left fork and repeats this cycle. After eating he puts down both forks.
To represent the above solution within CPS, let each philosopher be a process, therefore there should be N load files, where each file represents one philosopher. N objects FORKi, 0 <=i <=N-l, and FLAG with the attribute NAME are needed.
FLAG is used to indicate if a philosopher is holding one fork or two forks. The load file of a philosopher PI, is shown in Figure 4.
The first part of this load file is the DEFINE state
ment to define the objects to be used by the rules of this process. The second part is the production rules governing the philosopher. RULEll states that PI is hungry; therefore he first tries to pick up his left fork FORK1. If FORKI is available, he picks it up by deleting it from WM and he adds a flag "Pl-Fl" to indicate that PI is holding FORK1. RULE12, an idling rule, states that PI is not hungry; therefore he is thinking. RULE13 states that if there is a flag indicating that PI is holding FORKI and FORK2 is
128
The Arabian Journal for Science and Engineering, Volume 14, Number 1. January 1989M. G. Khayat and A. N. Al-Sukairi
(DEFINE (FORK1) (FORK2) (FLAG NAME»
(R RULE11 IF (FORK1)
THEN (DELETE 1) (ADD FLAG NAME=P1-F1»
(R RULE12 IF (FORK1) THEN (»
(R RULE13
IF (FLAG NAME=P1-F1) (FORK2)
THEN (DELETE 1) (DELETE 2) (ADD FLAG NAME=P1-EAT»
(R RULE14
IF (FLAG NAME=P1-F1) (FORK2) THEN (»
(R RULE15
IF (FLAG NAME=P1-F1) -(FORK2) THEN (DELETE 1) (ADD FORK1»
(R RULE16
IF (FLAG NAME=P1-F1) -(FORK2) THEN (»
(R RULE17
IF (FLAG NAME=P1-EAT)
THEN (DELETE 1) (ADD FORK1) (ADD FORK2»
(R RULE18
IF (FLAG NAME=P1-EAT) THEN (»
(USER)
Figure 4
available, then PI picks up FORK2 by deleting user will then select the rule to be fired in case it from WM; he also deletes the flag "PI-Fl" of more than one applicable rule. Initially WM and adds the flag "PI- EAT" to indicate that he is should have the following elements: (FORKI) ...
now eating. RULEI4,is the idling rule corresponding (FORKN).
to RULEI3. RULEI5 states that, if PI is holding
Within CPS, it is possible to follow a sequence of FORKI and FORK2 is not available, then PI
transitions in which a philosopher is starved. Assume puts down FO RKI by adding it back to WM and
that PI is holding his left fork and P2 is eating. Next, deleting the flag "PI-FI". RULE16 is the
P2 stops eating while PI is doing nothing (idling).
corresponding idling rule. RULEI? states that PI
Now P2 picks up his left and right forks in sequence, has eaten enough and is willing to go back to
thus starving Pl.
thinking; therefore he removes the flag "PI - EAT"
from WM and he adds the two forks he used If two adjacent philosophers attempt to pick the (FORKI and FORK2). RULEI8 states that, if PI is fork they share, at the same time, they will both eating, then he can continue eating. The third part of delete the fork from WM, in which case, CPS will this load file is the conflict resolution strategy used give an "access conflict" message and the user is by this process. Since each philosopher acts given the choice to abort the action of one of the arbitrarily, the USER option is adequate. Thus the philosophers or to' quit CPS.
January 1989 The Arabian Journal for Science and Engineering, Volume 14, Number 1. 129
M. G. Khayat and A. N. Al-Sukairi
4. CONCLUSION
CPS is a forward-chaining production system which is implemented on an IBM/PC. It functions well and has a reasonable response time.
CPS has the following features:
1. It is suitable for simulation of concurrent processing.
2. Conflict resolution is totally user-defined. This feature allows CPS to be used in a broad range of applications.
3. Efficient implementation is achieved by using the Rete Match algorithm.
4. It accepts LISP functions (primitive or us~r
defined) as actions in the THEN part. This puts the full power of LISP in the hands of the user.
5. Dynamic modification of rules in CPS permits developing adaptive systems (learning systems).
CPS can be further improved by:
1. Rewriting CPS using the IQLISP compiler which is 10 to 20 times faster than the existing interpreter.
2. Adding some more useful monitor commands, such as a command to display a certain rule.
3. Allowing some extra tests in the IF part.
4. Allowing attributes to have multiple values.
5. Allowing CPS to work in backward-chaining mode.
6. Extending the DEFINE statement to include specification of access rights to WM elements.
ACKNOWLEDGEMENT
The authors acknowledge the valuable comments and constructive suggestions of the referees of this paper.
REFERENCES
[1] E. Post, "Formal Reductions of the General Combinational Problem" , American Journal of Mathematics, 6S (1943), p. 197.
[2] R. Davis and J. King, An Overview of Production
Systems, Memo AIM~27I, Stanford Artificial Intelli
gence Laboratory. Stanford University, Computer Science Department, 1975.
[3] D. A. Waterman, "Generalization Learning Tech
niques for Automating the Learning of Heuristics", Artificial Intelligence, 1 (1970), p. 121.
[4] A. Newell, "A Theoretical Exploration of Mechanisms for Coding the Stimulus", in Coding Processes in Human Memory. ed. A. W. Melton and E. Martin. Washington, D. C.: Winston, 1972.
[5] A. Newell, "Production Systems: Models of Control Structures", in Visual Information Processing. ed.
W. G. Chase. New York: Academic Press, 1973, p. 463.
[6] R. Davis, B. Buchannan, and E. H. Shortliffe,
"Production Rules as a Representation for a Knowledge-Based Consultation Program", Artificial Intelligence, 8 (1977), p. 15.
[7] G. MaCalla and N. Cercone, "Approaches to Knowledge Representation", IEEE Computer, 6(10) (October 1983), p. 12.
[8] A. Barr and E. A. Feigenbaum, The Handbook of Artificial Intelligence, vol. 1. Los Altos, California:
William Kaufman, 1981.
[9] M. Gazaly, "Specification of Concurrent Processing Using Production System", Ph.D. Thesis, Oregon State University, 1981.
[10] M. D. Zisman, "Use of Production Systems for Modeling Asynchronous Concurrent Processes", in Pattern-Directed Inference Systems. ed.
D. A. Waterman and· F. Hayes~Roth. New York:
Academic Press, 1978.
[11] F. Hayes-Roth, D. Waterman, and D. Lenat, Building Expert System. Reading Massachussetts:
Addison-Wesley, 1983.
[12] F. Hayes-Roth, "Rule~Based Systems", Communica
tions of the Association for Computing Machinery, 28(9) (1985), p. 921.
[13] J. McDermott, "Rl: A Rule-Based Configurer of Com
puter Systems", Artificial Intelligence, 19 (1982), p. 39.
[14] C. L. Forgy, "On the Efficient Implementation qf Pro
duction Systems", Ph. D. Dissertation, Computer Sci
ence Department, Carnegie-Mellon University, 1979.
[15] C. L. Forgy, "Rete: A Fast Algorithm for the Many Pattern/Many Object Pattern Matching, Problem", Artificial Intelligence, 19 (1982), p. 17.
[16] J. Anderson, Language, Memory, and Thought.
Hillsdale, New Jersey: Lawrence Erlbaum Associates, 1967.
[17] M. Rychener, "Production Systems as a Programming
Language for Artificial Intelligence", Ph. D. Disser
tation, Carnegie-Mellon University, 1976.
[18] C. L. Forgy, "The OPS5 User's Manual", Technical Report. CMU-CS-8I-I35. Computer Science Depart
ment, Carnegie-Mellon University, 1981.
[19] J. Fain, H. Hayes-Roth, H. Sowizral, and
D. Watermann, Programming in ROSIE: An ];1tro
duction by Means of Examples, Technical Report N-1646-ARPA. Santa Monica, California: Rand Corporation, 1982.
[20] IQLISP Reference Manual. Seattle: Integral Quality, December 1984.
[21] S. S. Isloor and T. A. Marsland, "The Deadlock Problem: An Overview", IEEE Computer Magazine, 13(9) (1980), p. 58.
[22] R. C. Holt, G. S. Graham, E. D. Lazowska, and M. A. Scott, Structured Concurrent Programming with Operating Systems Applications. Reading, Massachussetts: Addison-Wesley, 1978.
Paper Received 1 December 1"'; Revised 1.7 December 1987.