-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.pml
More file actions
134 lines (114 loc) · 2.76 KB
/
Factory.pml
File metadata and controls
134 lines (114 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Bri Miskovitz
*/
/*
* Number of equipment pieces made in a days worth of work.
*/
#define DAYSWORK 8
/*
* Capacity of each channel (equipment or messages).
*/
#define CAPACITY 2
/*
* Types of electronic equipment produced.
*/
mtype = {DOMESTIC, INTERNATIONAL} ;
/*
* Stop message.
*/
mtype = {STOP} ;
/*
* Channels to pass equipment and messages from place to place.
*/
chan ManufacturerToDistributer = [CAPACITY] of {mtype} ;
chan DistributerToDomestic = [CAPACITY] of {mtype} ;
chan DistributerToInternational = [CAPACITY] of {mtype} ;
/*
* Inline procedure to choose an equipment type and
* assign it to mtype parameter 'product'
*
* USE THIS WHERE REQUIRED IN THE MANUFACTURER PROCESS
*/
inline choose(product) {
if
:: product = DOMESTIC ;
:: product = INTERNATIONAL ;
fi;
}
/*
* The Manufacturer process.
*/
active proctype Manufacturer() {
byte next_product = STOP ;
byte equipment_count = 0 ;
do
::
if
:: equipment_count < DAYSWORK ->
choose(next_product) ;
printf("Manufactured a new %e equipment \n", next_product) ;
equipment_count++ ;
ManufacturerToDistributer ! next_product ;
:: else ->
printf("Manufacture done \n") ;
ManufacturerToDistributer ! STOP ;
break ;
fi;
od;
}
/*
* The Distributer process
*/
active proctype Distributer() {
byte domestic_count = 0 ;
byte international_count = 0 ;
do
:: ManufacturerToDistributer ? DOMESTIC ->
printf("Distribute receives Domestic product \n") ;
domestic_count++ ;
DistributerToDomestic ! DOMESTIC ;
:: ManufacturerToDistributer ? INTERNATIONAL ->
printf("Distribute receives International product \n") ;
international_count++ ;
DistributerToInternational ! INTERNATIONAL ;
:: ManufacturerToDistributer ? STOP ->
printf("Distributer is done after %d domestic and %d international pieces \n", domestic_count, international_count) ;
DistributerToDomestic ! STOP ;
DistributerToInternational ! STOP ;
break ;
od;
}
/*
* The Domestic Warehouse process
*/
active proctype Domestic() {
byte piece_count = 0 ;
do
::
if
:: DistributerToDomestic ? DOMESTIC ->
piece_count++ ;
printf("Domestic warehouse receives another piece \n") ;
:: DistributerToDomestic ? STOP ->
printf("Domestic warehouse closes after receiving %d pieces \n", piece_count) ;
break ;
fi;
od;
}
/*
* The International Warehouse process
*/
active proctype International() {
byte piece_count = 0 ;
do
::
if
:: DistributerToInternational ? INTERNATIONAL ->
piece_count++ ;
printf("International warehouse receives another piece \n") ;
:: DistributerToInternational ? STOP ->
printf("International warehouse closes after receiving %d pieces \n", piece_count) ;
break ;
fi;
od;
}