Queues and service points are represented as sets, which in their turn are the names o f the respective keys under which the Prolog term s are to be stored. A ll set names are stored likewise in a m aster set.
The following MICROSIM statement for the definition of a set has been implemented using the following syntax:
v s e t ( ' s e t _ n a s e ‘ ( 1 , 2 , 3 , 6 , 7 ) ) .
where 'set_name' is the name under which the set is to be defined. The arguments (numbers 1 to 7) at present are dummies. In MICROSIM these are the scre en display attributes associated with the set being defined. The dummy argum ents hold the place fo r possible future developments related to graphics.
The following set operation/inspection primitives were implemented:
v a d d f i T o a d d an e n t i t y b e f o r e t h e f i r s t e l e e e n t in a s e t v a d d la T o a d d an e n t i t y a f t e r t h e l a s t e l e e e n t in a s e t v l o a d T o ad d s p e c i f i e d e n t i t i e s in a s e t v d e l e t e T o r e m o ve an e n t i t y fr o m a s e t v b e h e a d T o r e a o v e t h e f i r s t e le m e n t o f a s e t v b e t a i l T o r e m o ve t h e l a s t e le m e n t o f a s e t move T o m ove an e le m e n t fr o m o n e s e t t o a n o t h e r v em p ty T o r e m o ve a l l e le m e n t s fro m a s e t is _ e m p t y T o b a c k t r a c k i f t h e s e t i s n o t e m p t y . is _ n o t _ e m p t y T o b a c k t r a c k i f t h e s e t i s em pty h e a d _ t a i l R e t u r n s b o t h f i r s t an d l a s t e le m e n t s o f a s e t . ( b ) R e s o u r c e s
In MICROSIM resources are not specially declared. It was thought convenient to have a separate representation for resources (also referred to in the sim ulation literature as service facilities) as this tends to make the execution o f sim ulation
91
faster, because of the reduced overhead of set operations. Conceptually a resource has two possible states: busy and idle. This was implemented as a section o f the d atabase with the name of the resource as a key and the number of resources as the number o f terms (atoms) as 'busy' or 'idle'
The follow ing syntax has been used fo r declaring a resource:
v r e s o u r c e ( 'resource name ' , «number >)
The follow in g operation/inspect ion primitives related to resources have been implemented:
s e t _ b u s y s e t _ l d l e g e t _ l d l e
( c ) E n t i t y C l a s s e s
Classes o f entities are declared by using the following syntax:
v c l a s s ( • c l a s s _ n a m e ' ( 1 , 2 ) , « a t t r i b u t e s » , « n u m b e r » ) .
The arguments 1 and 2 are dummy graphic arguments for future use. «attributes» is an integer specifying the number o f attributes each entity may have and «number» specifies the size o f the class.
The classes o f the entities have been implemented as an entry fo r the class name stored under a key for the master class, where the names of all the classes declared a r e stored. The attributes have been stored as terms in a B -tree with the index number o f the entity in the class as the key.
The following operation/inspect ion primitives related to the attributes of the entities have been implemented:
g e t _ a t t s e t _ a t t
92
( B ) REPR ESENTATIONS FOR THE MODEL DYNAMICS ( a ) E v e n t s
The set o f events are stored as a part of the program database as a set of Prolog clauses w ith the predicate 'event' and arity 2. For example the following event clause:
• v e n t ( e n d _ s e r v i c e ( E n t i t y ) , a c t i o n s ) : - ■ o v e ( E n t i t y , s « t _ l , s e t _ 2 ) ,
s e t i d l e ( B a c h i n e ) .
means that when the event named 'end service' is processed the Entity on which the event has been scheduled is to be moved from 'se t_l' to 'set_2', and the resource called machine is to be set to its idle state from its current busy state.
(b) Activities
Each a ctivity is represented by two clauses with the predicate 'activity' and arity 2. A s an exam ple the following two Prolog clauses specify an activity:
a c t i v l t y ( s t a r t _ s « r v i c e , c o n d i t i o n s ) : - i s _ n o t _ e e p t y ( q u e u e ) ,
g e t i d l e ( e a c h i n e ) .
activity(start_service(Entity), actions) :- headtail(queue. Entity, _), ■ove(Entity, queue, set_l), set_busy(Machine),
s c h e d u l e ( e n d _ s e r v i c e . E n t i t y , 5 . 0 ) .
The first 'activity' clause represents the conditions which must be satisfied before the activity 'start_service' can begin. In the exam ple above it checks that the queue is not empty and the resource 'machine' is in an idle state. The second 'activity* clause represents the actions which the simulation executive is required to perform to alter the state o f the model when the conditions in the first clause are met. In the example above it identifies the head entity in the queue into the Prolog v ariable "Entity" and then moves the specific entity from 'queue' to 'set l' and sets the resource 'machine' to the state 'busy' and the completion o f the activity is scheduled.