-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraffic_light_nightly.erl
127 lines (104 loc) · 6.4 KB
/
traffic_light_nightly.erl
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
% traffic_light_nightly.erl
%
% This is a generated file. Do not edit it, but rather its source and
% run perpetuum to produce a new version of this file.
%
% Please file issues with https://github.com/vanrein/perpetuum/issues
%
% With compliments from the ARPA2.net / InternetWide.org project and
% from SURFnet!
%
-module( 'traffic_light_nightly' ).
-behaviour( gen_perpetuum ).
-export([
start_link/3, start/3,
stop/1, stop/2,
transit/0, places/0,
initial_placebits/0, initial_marking/1,
transmap/1, sentinel/1
]).
% Transitions in their standard order of occurrence
%
transit() -> [ 'go', 'stop', 'dawn', 'caution', 'sunset' ].
% Places in their standard order of occurrence
%
places() -> [ 'green', 'red', 'yellow', 'night_service' ].
% Initial bitfield vector is 60 or N*64 bits long, N>=3, with
% 4 bits for all of the 4 places,
% and the sign bit to spare for possible future use with timeouts.
% Return the initial place bits for this Petri Net.
%
initial_placebits() -> 13.
% Return the initial marking for this Petri Net,
% parameterised with the number of place bits,
% even though we have no current use for it.
%
initial_marking( 13 ) -> 268435456.
% Return a transmap beyond N bit integers; initially, N=%d.
% The transmap is only read and usually remains literal;
% Only very large Petri Nets need to scale up dynamically.
%
transmap( 13 ) -> #{
'go' => { 1, 16384, 36030996176445440 },
'stop' => { 16384, 268435456, 72055395148898304 },
'dawn' => { 4398046511104, 0, 72055395148898304 },
'caution' => { 268435456, 1, 36030996176445440 },
'sunset' => { 0, 4398046511104, 36030996176445440 }
};
transmap( 46 ) -> #{
'go' => { 1, 140737488355328, 196159429230835167666443327649089441799873760730032373760 },
'stop' => { 140737488355328, 19807040628566084398385987584, 392318858461666153943161930796436325338288287324345204736 },
'dawn' => { 2787593149816327892691964784081045188247552, 0, 392318858461666153943161930796436325338288287324345204736 },
'caution' => { 19807040628566084398385987584, 1, 196159429230835167666443327649089441799873760730032373760 },
'sunset' => { 0, 2787593149816327892691964784081045188247552, 196159429230835167666443327649089441799873760730032373760 }
};
transmap( 62 ) -> #{
'go' => { 1, 9223372036854775808, 3618502788666131107378912139983164668196959155616864085176980227473685872640 },
'stop' => { 9223372036854775808, 85070591730234615865843651857942052864, 7237005577332262213580867704581326693132172498517173409397235297162966859776 },
'dawn' => { 784637716923335095479473677900958302012794430558004314112, 0, 7237005577332262213580867704581326693132172498517173409397235297162966859776 },
'caution' => { 85070591730234615865843651857942052864, 1, 3618502788666131107378912139983164668196959155616864085176980227473685872640 },
'sunset' => { 0, 784637716923335095479473677900958302012794430558004314112, 3618502788666131107378912139983164668196959155616864085176980227473685872640 }
};
transmap( 78 ) -> #{
'go' => { 1, 604462909807314587353088, 66749594872528440074844538745740052230355115279921883197918652326963382063150890069719431249920 },
'stop' => { 604462909807314587353088, 365375409332725729550921208179070754913983135744, 133499189745056880149688746207655458513648433691379689393949224135920639041426142057161834889216 },
'dawn' => { 220855883097298041197912187592864814478435487109452369765200775161577472, 0, 133499189745056880149688746207655458513648433691379689393949224135920639041426142057161834889216 },
'caution' => { 365375409332725729550921208179070754913983135744, 1, 66749594872528440074844538745740052230355115279921883197918652326963382063150890069719431249920 },
'sunset' => { 0, 220855883097298041197912187592864814478435487109452369765200775161577472, 66749594872528440074844538745740052230355115279921883197918652326963382063150890069719431249920 }
};
transmap( 94 ) -> #{
'go' => { 1, 39614081257132168796771975168, 1231312693637327475383720003160570633684353517336756598883345109105880649879601537624645584363617442853446850969600 },
'stop' => { 39614081257132168796771975168, 1569275433846670190958947355801916604025588861116008628224, 2462625387274654950767440006227893160541872039269379026238376672976002436389220904551283407717126119502087303725056 },
'dawn' => { 62165404551223330269422781018352605012557018849668464680057997111644937126566671941632, 0, 2462625387274654950767440006227893160541872039269379026238376672976002436389220904551283407717126119502087303725056 },
'caution' => { 1569275433846670190958947355801916604025588861116008628224, 1, 1231312693637327475383720003160570633684353517336756598883345109105880649879601537624645584363617442853446850969600 },
'sunset' => { 0, 62165404551223330269422781018352605012557018849668464680057997111644937126566671941632, 1231312693637327475383720003160570633684353517336756598883345109105880649879601537624645584363617442853446850969600 }
};
transmap( N ) when N div 64 == 0 ->
gen_perpetuum:reflow_transmap( transmap( 13 ),4,13,N ).
% Return the sentinel value for a Petri Net of given
% number of place bits. Again, mostly literal.
%
sentinel( 13 ) -> 36030996176445440;
sentinel( 46 ) -> 196159429230835167666443327649089441799873760730032373760;
sentinel( 62 ) -> 3618502788666131107378912139983164668196959155616864085176980227473685872640;
sentinel( 78 ) -> 66749594872528440074844538745740052230355115279921883197918652326963382063150890069719431249920;
sentinel( 94 ) -> 1231312693637327475383720003160570633684353517336756598883345109105880649879601537624645584363617442853446850969600;
sentinel( N ) -> gen_perpetuum:reflow_sentinel( sentinel( 13 ),4,13,N ).
% Construct a new process running traffic_light_nightly instances
% as specialisations of the gen_perpetuum behaviour.
%
% Provided parameters are the standard {M,F,A} form for callbacks,
% used for processing transitions under application logic.
%
start_link( CallbackMod,CallbackFun,CallbackArg ) ->
InitArgs = [ self(),?MODULE,[ CallbackMod,CallbackFun,CallbackArg ] ],
proc_lib:start_link( gen_perpetuum,init,InitArgs ).
%
start( CallbackMod,CallbackFun,CallbackArg ) ->
InitArgs = [ self(),?MODULE,[ CallbackMod,CallbackFun,CallbackArg ] ],
proc_lib:start( gen_perpetuum,init,InitArgs ).
% Stop a running process with a traffic_light_nightly instance
%
stop( Pid ) -> Pid ! { stop,normal }.
stop( Pid,Reason ) -> Pid ! { stop,Reason }.
%% End of generated file traffic_light_nightly.erl