-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcepts.html
244 lines (222 loc) · 10.4 KB
/
concepts.html
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>C++ Concepts — Semi-Markov 1.0 documentation</title>
<link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="top" title="Semi-Markov 1.0 documentation" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li><a href="index.html">Semi-Markov 1.0 documentation</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">C++ Concepts</a><ul>
<li><a class="reference internal" href="#generalized-stochastic-petri-net">Generalized Stochastic Petri Net</a></li>
<li><a class="reference internal" href="#marking">Marking</a></li>
<li><a class="reference internal" href="#gspnstate">GSPNState</a></li>
</ul>
</li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/concepts.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="c-concepts">
<h1>C++ Concepts<a class="headerlink" href="#c-concepts" title="Permalink to this headline">¶</a></h1>
<div class="section" id="generalized-stochastic-petri-net">
<h2>Generalized Stochastic Petri Net<a class="headerlink" href="#generalized-stochastic-petri-net" title="Permalink to this headline">¶</a></h2>
<p>A generalized stochastic Petri net (GSPN) describes the relationship
among places and transitions which define a semi-Markov system.
The C++ concept of a GSPN first identifies the type of the
identifiers for places and for transitions.:</p>
<div class="highlight-python"><pre>typedef undefined PlaceKey;
typedef undefined TransitionKey;</pre>
</div>
<p>Then there are two functions that express which transitions depend on
which places. The first retrieves that part of the GSPN relevant to a
particular transition, which are the input and output places, the
stochiometric coefficients associated with those edges, and the type of
token expected at each place. The second function calls a unary function
on each transition which relates to any of a given set of places.:</p>
<div class="highlight-python"><pre>template<typename GSPN>
std::vector<std::tuple<PlaceKey,int,int>>
NeighborsOfTransition(const GSPN& g, TransitionKey transition_id);
auto func=[] (trans_t<GSPN> neighbor_id)->void;
template<typename GSPN, typename Functor>
void NeighborsOfPlaces(const GSPN& g, const std::set<PlaceKey>& place_id,
Functor func);</pre>
</div>
<p>Together, these two functions determine which transitions can affect or be
affected by the firing of a given transition.</p>
<p>Unstated, but important, necessary conditions are that the places form
a vector space and that the transitions form a vector space. In addition,
the places connected to a transition are ordered. This is how we enforce
that they be distinguishable, unlike those in simpler Petri nets.</p>
<p>The last part of the GSPN concept is the transition itself, represented
only by its transition id and its distribution. The <tt class="docutils literal"><span class="pre">enabled</span></tt> function
checks the local marking to see whether a transition is enabled and,
if so, returns the distribution associated with that transition. The
Distribution object doesn’t depend on the local marking.:</p>
<div class="highlight-python"><pre>template<typename GSPN, typename UserState, typename LocalMarking>
std::tuple<bool,Distribution>
Enabled(const GSPN&, const UserState&, const LocalMarking&,
double enabling_time, double current_time);</pre>
</div>
<p>The firing of a transition is the last part of the GSPN concept.:</p>
<div class="highlight-python"><pre>template<typename GSPN, typename State, typename LocalMarking, typename RNG>
void Fire(const GSPN&, UserState&, LocalMarking&, RNG&);</pre>
</div>
<p>The random number generator is necessary because firing may select
a random token from the marking at a place.</p>
<p>What <em>isn’t</em> in this concept? There is no explicit representation of
the transitions themselves. The GSPN presents its embedded Markov matrix
as a set of distributions. Whether to construct an explicit list of
transition objects, and how to construct them, is a representational issue
for the GSPN object.</p>
</div>
<div class="section" id="marking">
<h2>Marking<a class="headerlink" href="#marking" title="Permalink to this headline">¶</a></h2>
<p>The marking represents mutually-exlusive subsets of the total
state of the system so that we can represent independent
competing processes which affect each other by modifying subsets
of the state. The marking is the set of all tokens at all places,
where the places are identified by place ids.</p>
<p>In this library, we permit the marking at each place to contain
only one type of token, with possible subclasses. There may be
different token types, which we call layers. The marking is
accessed in a type-safe way by specifying the token layer to retrieve.:</p>
<div class="highlight-python"><pre>template<typename... TokenContainers>
class Marking
{
public:
};
template<typename LAYER>
void Add(Marking&, place_t<GSPN>, token_t<Marking,LAYER>);
template<typename LAYER>
void Length(const Marking&, place_t<GSPN>);
template<typename LAYER>
void Length(const Marking&, place_t<GSPN>, color_t<Marking,LAYER>);
template<typename LAYER, typename UnaryOperator>
std::tuple<std::resultof<UnaryOperator>,bool>
Get(const Marking&, place_t<Marking>, UnaryOperator& functor);
template<typename LayerFrom, typename LayerTo>
void
Move(const Marking&, place_t<Marking,LayerFrom>, place_t<Marking,LayerTo>, size_t);
template<typename LayerFrom, typename LayerTo, typename UnaryOperator>
void
MoveModify(const Marking&, place_t<Marking,LayerFrom>, place_t<Marking,LayerTo>,
size_t, UnaryOperator& functor);</pre>
</div>
<p>It is possible to move tokens between layers with the same token type.
A <tt class="docutils literal"><span class="pre">TokenContainer</span></tt> holds the tokens. There are two types, <tt class="docutils literal"><span class="pre">Colored</span></tt>
and <tt class="docutils literal"><span class="pre">Uncolored</span></tt>. The color of a token comes from a traits class:</p>
<div class="highlight-python"><pre>template<typename Token>
TokenColor
{
typedef void type;
}
template<typename Token>
UniqueColor
{
static const bool value=true;
};</pre>
</div>
<p>A color is unique if there will only be one token of any given color
at a place.</p>
<p>If we were to ask what should be stored in the marking and what in
the state, the answer is that the embedded Markov class of this library
will automatically track changes to the marking and update the
transition distributions and enabling times, so any state whose change
necessitates a change to enabling times belongs in the marking.
Otherwise, the user will need to signal to the embedded Markov
matrix when the state has been changed by hand.</p>
<p>Other changes in the state of the environment, such as temperature
affects on transition rates, can be handled as distribution functions
that depend on the current semi-Markov simulation time.</p>
</div>
<div class="section" id="gspnstate">
<h2>GSPNState<a class="headerlink" href="#gspnstate" title="Permalink to this headline">¶</a></h2>
<p>The GSPNState has three members, the marking, which represents all tokens
at all places, the enabling time of every enabled transition, and
the current time of the semi-Markov model, which is the sum of all
transition intervals since the start of the simulation.:</p>
<div class="highlight-python"><pre>template<typename GSPN, typename Marking, typename UserState>
class GSPNState
{
public:
typedef Marking Marking;
Marking marking;
double CurrentTime() const;
double SetTime(double);
UserState user;
TransitionKey last_transition;
};</pre>
</div>
<p>The GSPNState re-advertises the <tt class="docutils literal"><span class="pre">Marking</span></tt> type through a public typedef.</p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li><a href="index.html">Semi-Markov 1.0 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2014, Andrew Dolgert, David Schneider.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>