1 | package PNlib
|
---|
2 |
|
---|
3 | model PC "Continuous Place"
|
---|
4 | Real t = if t_ < minMarks then minMarks else t_ "marking";
|
---|
5 | Real tSumIn(fixed = true, start = 0.0);
|
---|
6 | Real tSumIn_[nIn](each fixed = true, each start = 0.0);
|
---|
7 | Real tSumOut(fixed = true, start = 0.0);
|
---|
8 | Real tSumOut_[nOut](each fixed = true, each start = 0.0);
|
---|
9 | parameter Integer nIn = 0 "number of input transitions" annotation(Dialog(connectorSizing = true));
|
---|
10 | parameter Integer nOut = 0 "number of output transitions" annotation(Dialog(connectorSizing = true));
|
---|
11 | // *** MODIFIABLE PARAMETERS AND VARIABLES BEGIN ***
|
---|
12 | parameter Real startMarks = 0 "start marks" annotation(Dialog(enable = true, group = "Marks"));
|
---|
13 | parameter Real minMarks(min=0) = 0 "minimum capacity" annotation(Dialog(enable = true, group = "Marks"));
|
---|
14 | parameter Real maxMarks(min=minMarks) = PNlib.Constants.inf
|
---|
15 | "maximum capacity" annotation(Dialog(enable = true, group = "Marks"));
|
---|
16 | // *** MODIFIABLE PARAMETERS AND VARIABLES END ***
|
---|
17 | protected
|
---|
18 | Real t_(start = startMarks, fixed = true) "marking";
|
---|
19 | Real arcWeightIn[nIn] "weights of input arcs";
|
---|
20 | Real arcWeightOut[nOut] "weights of output arcs";
|
---|
21 | Real instSpeedIn[nIn] "instantaneous speed of input transitions";
|
---|
22 | Real instSpeedOut[nOut] "instantaneous speed of output transitions";
|
---|
23 | Real maxSpeedIn[nIn] "maximum speed of input transitions";
|
---|
24 | Real maxSpeedOut[nOut] "maximum speed of output transitions";
|
---|
25 | Real prelimSpeedIn[nIn] "preliminary speed of input transitions";
|
---|
26 | Real prelimSpeedOut[nOut] "preliminary speed of output transitions";
|
---|
27 | Boolean fireIn[nIn](each start = false, each fixed = true)
|
---|
28 | "Does any input transition fire?";
|
---|
29 | Boolean fireOut[nOut](each start = false, each fixed = true)
|
---|
30 | "Does any output transition fire?";
|
---|
31 | Boolean activeIn[nIn] "Are the input transitions active?";
|
---|
32 | Boolean activeOut[nOut] "Are the output transitions active?";
|
---|
33 | Boolean enabledByInPlaces[nIn]
|
---|
34 | "Are the input transitions enabled by all their input places?";
|
---|
35 | // *** BLOCKS BEGIN ***
|
---|
36 | // since no events are generated within functions!!!
|
---|
37 | Boolean feeding = Functions.anyTrue(pre(fireIn))
|
---|
38 | "Is the place fed by input transitions?";
|
---|
39 | Boolean emptying = Functions.anyTrue(vec= pre(fireOut))
|
---|
40 | "Is the place emptied by output transitions?";
|
---|
41 | Real firingSumIn = Functions.firingSumCon(fire=pre(fireIn), arcWeight=arcWeightIn, instSpeed=instSpeedIn)
|
---|
42 | "firing sum calculation";
|
---|
43 | Real firingSumOut = Functions.firingSumCon(fire= pre(fireOut), arcWeight= arcWeightOut, instSpeed= instSpeedOut)
|
---|
44 | "firing sum calculation";
|
---|
45 | // *** BLOCKS END ***
|
---|
46 | public
|
---|
47 | Interfaces.PlaceIn inTransition[nIn](each t = t_, each maxTokens = maxMarks, enable = activeIn, each emptied = emptying, each speedSum = firingSumOut, fire = fireIn, active = activeIn, arcWeight = arcWeightIn, instSpeed = instSpeedIn, maxSpeed = maxSpeedIn, prelimSpeed = prelimSpeedIn, enabledByInPlaces = enabledByInPlaces)
|
---|
48 | "connector for input transitions" annotation(Placement(transformation(origin = {-93, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-93, 0}, extent = {{-10, -10}, {10, 10}})));
|
---|
49 | Interfaces.PlaceOut outTransition[nOut](each t = t_, each minTokens = minMarks, enable = activeOut, each arcType = PNlib.Types.ArcType.normal_arc, each testValue = -1.0, each fed = feeding, each speedSum = firingSumIn, fire = fireOut, active = activeOut, arcWeight = arcWeightOut, instSpeed = instSpeedOut, maxSpeed = maxSpeedOut, prelimSpeed = prelimSpeedOut)
|
---|
50 | "connector for output transitions" annotation(Placement(transformation(origin = {93, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {93, 0}, extent = {{-10, -10}, {10, 10}})));
|
---|
51 | //initial equation
|
---|
52 | // fireIn = pre(fireIn);
|
---|
53 | // fireOut = pre(fireOut);
|
---|
54 | equation
|
---|
55 | // *** MAIN BEGIN ***
|
---|
56 | der(tSumIn) = firingSumIn;
|
---|
57 | // der(tSumIn_) = arcWeightIn .* instSpeedIn;
|
---|
58 | for i in 1:nIn loop
|
---|
59 | der(tSumIn_[i]) = if pre(fireIn[i]) then arcWeightIn[i] * instSpeedIn[i] else 0.0;
|
---|
60 | end for;
|
---|
61 | der(tSumOut) = firingSumOut;
|
---|
62 | // der(tSumOut_) = arcWeightOut .* instSpeedOut;
|
---|
63 | for i in 1:nOut loop
|
---|
64 | der(tSumOut_[i]) = if pre(fireOut[i]) then arcWeightOut[i] * instSpeedOut[i] else 0.0;
|
---|
65 | end for;
|
---|
66 | der(t_) = firingSumIn - firingSumOut
|
---|
67 | "calculation of continuous mark change";
|
---|
68 | // *** MAIN END ***
|
---|
69 | // *** ERROR MESSENGES BEGIN ***
|
---|
70 | assert(startMarks >= minMarks and startMarks <= maxMarks, "minMarks <= startMarks <= maxMarks");
|
---|
71 | // *** ERROR MESSENGES END ***
|
---|
72 | annotation(defaultComponentName = "P1", Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2}), graphics={ Ellipse(fillColor = {255, 255, 255},
|
---|
73 | fillPattern = FillPattern.Solid, extent = {{-86, 86}, {86, -86}}, endAngle = 360), Ellipse(fillColor = {255, 255, 255},
|
---|
74 | fillPattern = FillPattern.Solid, extent = {{-79, 79}, {79, -79}}, endAngle = 360), Text(origin = {0.5, -0.5}, extent = {{-1.5, 25.5}, {-1.5, -21.5}}, textString = DynamicSelect("%startMarks", if t > 0 then realString(t, 1, 2) else "0.0")), Text(extent = {{-74, -103}, {-74, -128}}, textString = "%name")}));
|
---|
75 | end PC;
|
---|
76 |
|
---|
77 | model TC "Continuous Transition"
|
---|
78 | parameter Integer nIn = 0 "number of input places" annotation(Dialog(connectorSizing = true));
|
---|
79 | parameter Integer nOut = 0 "number of output places" annotation(Dialog(connectorSizing = true));
|
---|
80 | // *** MODIFIABLE PARAMETERS AND VARIABLES BEGIN ***
|
---|
81 | Real maximumSpeed = 1 "maximum speed" annotation(Dialog(enable = true, group = "Maximum Speed"));
|
---|
82 | Real arcWeightIn[nIn] = fill(1, nIn) "arc weights of input places" annotation(Dialog(enable = true, group = "Arc Weights"));
|
---|
83 | Real arcWeightOut[nOut] = fill(1, nOut) "arc weights of output places" annotation(Dialog(enable = true, group = "Arc Weights"));
|
---|
84 | // *** MODIFIABLE PARAMETERS AND VARIABLES END ***
|
---|
85 | Boolean fire "Does the transition fire?";
|
---|
86 | Real instantaneousSpeed "instantaneous speed";
|
---|
87 | Real actualSpeed = if fire then instantaneousSpeed else 0.0;
|
---|
88 | Interfaces.TransitionOut[nOut] outPlaces(each active = activation.active, each fire = fire, each enabledByInPlaces = true, arcWeight = arcWeightOut, each instSpeed = instantaneousSpeed, each prelimSpeed = preliminarySpeed, each maxSpeed = maximumSpeed, t = tOut, maxTokens = maxTokens, emptied = emptied, speedSum = speedSumOut)
|
---|
89 | "connector for output places" annotation(Placement(transformation(origin = {47, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {47, 0}, extent = {{-10, -10}, {10, 10}})));
|
---|
90 | Interfaces.TransitionIn[nIn] inPlaces(each active = activation.active, each fire = fire, arcWeight = arcWeightIn, each instSpeed = instantaneousSpeed, each prelimSpeed = preliminarySpeed, each maxSpeed = maximumSpeed, t = tIn, minTokens = minTokens, fed = fed, enable = enableIn, speedSum = speedSumIn)
|
---|
91 | "connector for input places" annotation(Placement(visible = true, transformation(origin = {-47, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-47, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
92 | protected
|
---|
93 | Real tIn[nIn] "tokens of input places";
|
---|
94 | Real tOut[nOut] "tokens of output places";
|
---|
95 | Real minTokens[nIn] "minimum tokens of input places";
|
---|
96 | Real maxTokens[nOut] "maximum tokens of output places";
|
---|
97 | Real speedSumIn[nIn] "Input speeds of continuous input places";
|
---|
98 | Real speedSumOut[nOut] "Output speeds of continuous output places";
|
---|
99 | Boolean fed[nIn] "Are the input places fed by their input transitions?";
|
---|
100 | Boolean emptied[nOut]
|
---|
101 | "Are the output places emptied by their output transitions?";
|
---|
102 | Boolean enableIn[nIn]
|
---|
103 | "Is the transition enabled by all its discrete input transitions?";
|
---|
104 | // *** BLOCKS BEGIN ***
|
---|
105 | // since no events are generated within functions!!!
|
---|
106 | Blocks.activationCon activation(nIn = nIn, nOut = nOut, tIn = tIn, tOut = tOut, arcWeightIn = arcWeightIn, arcWeightOut = arcWeightOut, minTokens = minTokens, maxTokens = maxTokens, fed = fed, emptied = emptied, testValue = inPlaces.testValue, arcType = inPlaces.arcType)
|
---|
107 | "activation process";
|
---|
108 | Real preliminarySpeed = Functions.preliminarySpeed(nIn= nIn, nOut= nOut, arcWeightIn= arcWeightIn, arcWeightOut= arcWeightOut, speedSumIn= speedSumIn, speedSumOut= speedSumOut, maximumSpeed= maximumSpeed, active= activation.active, weaklyInputActiveVec= activation.weaklyInputActiveVec, weaklyOutputActiveVec= activation.weaklyOutputActiveVec)
|
---|
109 | "preliminary speed calculation";
|
---|
110 | // *** BLOCKS END ***
|
---|
111 | equation
|
---|
112 | // *** MAIN BEGIN ***
|
---|
113 | fire = activation.active and not maximumSpeed <= 0 "firing process";
|
---|
114 | instantaneousSpeed = max(min(maximumSpeed, preliminarySpeed), 0.0)
|
---|
115 | "instantaneous speed calculation";
|
---|
116 | // *** MAIN END ***
|
---|
117 | annotation(defaultComponentName = "T1", Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics={ Rectangle(extent = {{-40, 100}, {40, -100}}, lineColor = {0, 0, 0}, fillColor = DynamicSelect({255, 255, 255}, if fire then {255, 255, 0} else {255, 255, 255}),
|
---|
118 | fillPattern = FillPattern.Solid), Text(extent = {{-2, -116}, {-2, -144}}, lineColor = {0, 0, 0}, textString = DynamicSelect(" ", if animateSpeed == 1 and fire > 0.5 then if instantaneousSpeed > 0 then realString(instantaneousSpeed, 1, 2) else "0.0" else " ")), Text(extent = {{-4, 139}, {-4, 114}}, lineColor = {0, 0, 0}, textString = "%name")}), Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics));
|
---|
119 | end TC;
|
---|
120 |
|
---|
121 | package Interfaces
|
---|
122 | "contains the connectors for the Petri net component models"
|
---|
123 |
|
---|
124 | connector PlaceIn
|
---|
125 | "part of place model to connect places to input transitions"
|
---|
126 | output Real t "Marking of the place" annotation(HideResult = true);
|
---|
127 | output Real maxTokens "Maximum capacity of the place" annotation(HideResult = true);
|
---|
128 | output Boolean enable
|
---|
129 | "Which of the input transitions are enabled by the place?" annotation(HideResult = true);
|
---|
130 | output Boolean emptied
|
---|
131 | "Is the continuous place emptied by output transitions?" annotation(HideResult = true);
|
---|
132 | output Real speedSum "Output speed of a continuous place" annotation(HideResult = true);
|
---|
133 | input Boolean active "Are the input transitions active?" annotation(HideResult = true);
|
---|
134 | input Boolean fire "Do the input transitions fire?" annotation(HideResult = true);
|
---|
135 | input Real arcWeight "Arc weights of input transitions" annotation(HideResult = true);
|
---|
136 | input Boolean enabledByInPlaces
|
---|
137 | "Are the input transitions enabled by all theier input places?" annotation(HideResult = true);
|
---|
138 | input Real instSpeed
|
---|
139 | "Instantaneous speeds of continuous input transitions" annotation(HideResult = true);
|
---|
140 | input Real prelimSpeed
|
---|
141 | "Preliminary speeds of continuous input transitions" annotation(HideResult = true);
|
---|
142 | input Real maxSpeed "Maximum speeds of continuous input transitions" annotation(HideResult = true);
|
---|
143 | annotation(Diagram(graphics={ Polygon(fillColor = {95, 95, 95},
|
---|
144 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}}, lineColor = {0, 0, 0})}), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics={ Polygon(
|
---|
145 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}})}));
|
---|
146 | end PlaceIn;
|
---|
147 |
|
---|
148 | connector PlaceOut
|
---|
149 | "part of place model to connect places to output transitions"
|
---|
150 | output Real t "Marking of the place" annotation(HideResult = true);
|
---|
151 | output Real minTokens "Minimum capacity of the place" annotation(HideResult = true);
|
---|
152 | output Boolean enable
|
---|
153 | "Which of the output transitions are enabled by the place?" annotation(HideResult = true);
|
---|
154 | output PNlib.Types.ArcType arcType
|
---|
155 | "Type of output arcs ([1]normal, [2]test, [3]inhibition, or [4]read)" annotation(HideResult = true);
|
---|
156 | output Real testValue "Test value of a test or inhibitor arc" annotation(HideResult = true);
|
---|
157 | output Boolean fed "Is the continuous place fed by input transitions?" annotation(HideResult = true);
|
---|
158 | output Real speedSum "Input speed of a continuous place" annotation(HideResult = true);
|
---|
159 | input Boolean active "Are the output transitions active?" annotation(HideResult = true);
|
---|
160 | input Boolean fire "Do the output transitions fire?" annotation(HideResult = true);
|
---|
161 | input Real arcWeight "Arc weights of output transitions" annotation(HideResult = true);
|
---|
162 | input Real instSpeed
|
---|
163 | "Instantaneous speeds of continuous output transitions" annotation(HideResult = true);
|
---|
164 | input Real prelimSpeed
|
---|
165 | "Preliminary speeds of continuous output transitions" annotation(HideResult = true);
|
---|
166 | input Real maxSpeed "Maximum speeds of continuous output transitions" annotation(HideResult = true);
|
---|
167 | annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics={ Polygon(fillColor = {255, 255, 255},
|
---|
168 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}})}), Diagram(graphics={ Polygon(fillColor = {215, 215, 215},
|
---|
169 | fillPattern = FillPattern.Solid, points = {{-72, 100}, {68, 0}, {-72, -100}, {-72, 100}}, lineColor = {0, 0, 0})}));
|
---|
170 | end PlaceOut;
|
---|
171 |
|
---|
172 | connector TransitionIn
|
---|
173 | "part of transition model to connect transitions to input places"
|
---|
174 | input Real t "Markings of input places" annotation(HideResult = true);
|
---|
175 | input Real minTokens "Minimum capacites of input places" annotation(HideResult = true);
|
---|
176 | input Boolean enable "Is the transition enabled by input places?" annotation(HideResult = true);
|
---|
177 | input PNlib.Types.ArcType arcType
|
---|
178 | "Type of output arcs ([1]normal, [2]test, [3]inhibition, or [4]read)" annotation(HideResult = true);
|
---|
179 | input Real testValue "Test value of a test or inhibitor arc" annotation(HideResult = true);
|
---|
180 | input Boolean fed "Are the continuous input places fed?" annotation(HideResult = true);
|
---|
181 | input Real speedSum "Input speeds of continuous input places" annotation(HideResult = true);
|
---|
182 | output Boolean active "Is the transition active?" annotation(HideResult = true);
|
---|
183 | output Boolean fire "Does the transition fire?" annotation(HideResult = true);
|
---|
184 | output Real arcWeight "Input arc weights of the transition" annotation(HideResult = true);
|
---|
185 | output Real instSpeed "Instantaneous speed of a continuous transition" annotation(HideResult = true);
|
---|
186 | output Real prelimSpeed "Preliminary speed of a continuous transition" annotation(HideResult = true);
|
---|
187 | output Real maxSpeed "Maximum speed of a continuous transition" annotation(HideResult = true);
|
---|
188 | annotation(Diagram(graphics={ Polygon(fillColor = {95, 95, 95},
|
---|
189 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}}, lineColor = {0, 0, 0})}), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics={ Polygon(
|
---|
190 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}})}));
|
---|
191 | end TransitionIn;
|
---|
192 |
|
---|
193 | connector TransitionOut
|
---|
194 | "part of transition model to connect transitions to output places"
|
---|
195 | input Real t "Markings of output places" annotation(HideResult = true);
|
---|
196 | input Real maxTokens "Maximum capacities of output places" annotation(HideResult = true);
|
---|
197 | input Boolean enable "Is the transition enabled by output places?" annotation(HideResult = true);
|
---|
198 | input Boolean emptied "Are the continuous output places emptied?" annotation(HideResult = true);
|
---|
199 | input Real speedSum "Output speeds of continuous output places" annotation(HideResult = true);
|
---|
200 | output Boolean active "Is the transition active?" annotation(HideResult = true);
|
---|
201 | output Boolean fire "Does the transition fire?" annotation(HideResult = true);
|
---|
202 | output Real arcWeight "Output arc weights of the transition" annotation(HideResult = true);
|
---|
203 | output Boolean enabledByInPlaces
|
---|
204 | "Is the transition enabled by all input places?" annotation(HideResult = true);
|
---|
205 | output Real instSpeed "Instantaneous speed of a continuous transition" annotation(HideResult = true);
|
---|
206 | output Real prelimSpeed "Preliminary speed of a continuous transition" annotation(HideResult = true);
|
---|
207 | output Real maxSpeed "Maximum speed of a continuous transition" annotation(HideResult = true);
|
---|
208 | annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics={ Polygon(fillColor = {255, 255, 255},
|
---|
209 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}})}), Diagram(graphics={ Polygon(fillColor = {215, 215, 215},
|
---|
210 | fillPattern = FillPattern.Solid, points = {{-70, 100}, {70, 0}, {-70, -100}, {-70, 100}}, lineColor = {0, 0, 0})}));
|
---|
211 | end TransitionOut;
|
---|
212 | end Interfaces;
|
---|
213 |
|
---|
214 | package Blocks
|
---|
215 | "contains blocks with specific procedures that are used in the Petri net component models"
|
---|
216 |
|
---|
217 | block activationCon "activation process of continuous transitions"
|
---|
218 | parameter input Integer nIn "number of input places";
|
---|
219 | parameter input Integer nOut "number of output places";
|
---|
220 | input Real tIn[:] "marking of input places";
|
---|
221 | input Real tOut[:] "marking of output places";
|
---|
222 | input Real arcWeightIn[:] "arc weights of input places";
|
---|
223 | input Real arcWeightOut[:] "arc weights of output places";
|
---|
224 | input Real minTokens[:] "minimum capacities of input places";
|
---|
225 | input Real maxTokens[:] "maximum capacities of output places";
|
---|
226 | input Boolean fed[:] "input places are fed?";
|
---|
227 | input Boolean emptied[:] "output places are emptied?";
|
---|
228 | input PNlib.Types.ArcType arcType[:] "arc type of input places";
|
---|
229 | input Real testValue[:] "test values of test and inhibitor arcs";
|
---|
230 | output Boolean active "activation of transition";
|
---|
231 | output Boolean weaklyInputActiveVec[nIn]
|
---|
232 | "places that causes weakly input activation";
|
---|
233 | output Boolean weaklyOutputActiveVec[nOut]
|
---|
234 | "places that causes weakly output activation";
|
---|
235 | algorithm
|
---|
236 | active := true;
|
---|
237 | weaklyInputActiveVec := fill(false, nIn);
|
---|
238 | weaklyOutputActiveVec := fill(false, nOut);
|
---|
239 |
|
---|
240 | //check input places
|
---|
241 | for i in 1:nIn loop
|
---|
242 | // normal arc
|
---|
243 | if arcType[i] == PNlib.Types.ArcType.normal_arc then
|
---|
244 | if tIn[i] <= minTokens[i] then
|
---|
245 | if fed[i] then
|
---|
246 | weaklyInputActiveVec[i] := true;
|
---|
247 | else
|
---|
248 | active := false;
|
---|
249 | end if;
|
---|
250 | end if;
|
---|
251 | // inhibitor arc
|
---|
252 | elseif arcType[i] == PNlib.Types.ArcType.inhibitor_arc then
|
---|
253 | if not tIn[i] < testValue[i] then
|
---|
254 | active := false;
|
---|
255 | end if;
|
---|
256 | end if;
|
---|
257 | end for;
|
---|
258 |
|
---|
259 | //output places
|
---|
260 | for i in 1:nOut loop
|
---|
261 | if tOut[i] >= maxTokens[i] and not emptied[i] then
|
---|
262 | active := false;
|
---|
263 | elseif tOut[i] >= maxTokens[i] and emptied[i] then
|
---|
264 | weaklyOutputActiveVec[i] := true;
|
---|
265 | end if;
|
---|
266 | end for;
|
---|
267 | end activationCon;
|
---|
268 | end Blocks;
|
---|
269 |
|
---|
270 | package Functions
|
---|
271 |
|
---|
272 | function anyTrue "Is any entry of a Boolean vector true?"
|
---|
273 | input Boolean vec[:];
|
---|
274 | output Boolean anytrue;
|
---|
275 | algorithm
|
---|
276 | anytrue := false;
|
---|
277 | for i in 1:size(vec, 1) loop
|
---|
278 | if vec[i] then
|
---|
279 | anytrue := true;
|
---|
280 | end if;
|
---|
281 | end for;
|
---|
282 | end anyTrue;
|
---|
283 |
|
---|
284 | function firingSumCon "calculates the firing sum of continuous places"
|
---|
285 | input Boolean fire[:] "firability of transitions";
|
---|
286 | input Real arcWeight[:] "arc weights";
|
---|
287 | input Real instSpeed[:] "istantaneous speed of transitions";
|
---|
288 | output Real conFiringSum "continuous firing sum";
|
---|
289 | algorithm
|
---|
290 | conFiringSum := 0.0;
|
---|
291 | for i in 1:size(fire, 1) loop
|
---|
292 | if fire[i] then
|
---|
293 | conFiringSum := conFiringSum + arcWeight[i] * instSpeed[i];
|
---|
294 | end if;
|
---|
295 | end for;
|
---|
296 | end firingSumCon;
|
---|
297 |
|
---|
298 | function preliminarySpeed
|
---|
299 | "calculates the preliminary speed of a continuous transition"
|
---|
300 | input Integer nIn "number of input places";
|
---|
301 | input Integer nOut "number of output places";
|
---|
302 | input Real arcWeightIn[:] "input arc weights";
|
---|
303 | input Real arcWeightOut[:] "output arc weights";
|
---|
304 | input Real speedSumIn[:] "input speed";
|
---|
305 | input Real speedSumOut[:] "output speed";
|
---|
306 | input Real maximumSpeed "maximum speed";
|
---|
307 | input Boolean active "activation";
|
---|
308 | input Boolean weaklyInputActiveVec[:]
|
---|
309 | "places that causes weakly input activation";
|
---|
310 | input Boolean weaklyOutputActiveVec[:]
|
---|
311 | "places that causes weakly output activation";
|
---|
312 | output Real prelimSpeed "preliminary speed";
|
---|
313 | algorithm
|
---|
314 | prelimSpeed := maximumSpeed;
|
---|
315 | for i in 1:nIn loop
|
---|
316 | if weaklyInputActiveVec[i] and speedSumIn[i] / arcWeightIn[i] < prelimSpeed then
|
---|
317 | prelimSpeed := speedSumIn[i] / arcWeightIn[i];
|
---|
318 | end if;
|
---|
319 | end for;
|
---|
320 | for i in 1:nOut loop
|
---|
321 | if weaklyOutputActiveVec[i] and speedSumOut[i] / arcWeightOut[i] < prelimSpeed then
|
---|
322 | prelimSpeed := speedSumOut[i] / arcWeightOut[i];
|
---|
323 | end if;
|
---|
324 | end for;
|
---|
325 | end preliminarySpeed;
|
---|
326 | end Functions;
|
---|
327 |
|
---|
328 | package Constants
|
---|
329 | "contains constants which are used in the Petri net component models"
|
---|
330 |
|
---|
331 | constant Real inf = 9.999999999999999e+059
|
---|
332 | "Biggest Real number such that inf and -inf are representable on the machine";
|
---|
333 | end Constants;
|
---|
334 |
|
---|
335 | package Types
|
---|
336 |
|
---|
337 | type ArcType = enumeration(
|
---|
338 | normal_arc,
|
---|
339 | inhibitor_arc);
|
---|
340 | end Types;
|
---|
341 |
|
---|
342 | package Examples
|
---|
343 |
|
---|
344 | model Test6
|
---|
345 | PNlib.PC P1(nOut = 1, startMarks = 1) annotation(Placement(visible = true, transformation(origin = {-30, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
346 | PNlib.PC P2(nIn = 1, maxMarks = 0.4) annotation(Placement(visible = true, transformation(origin = {30, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
347 | PNlib.TC T1(nIn = 1, nOut = 1) annotation(Placement(visible = true, transformation(origin = {0, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
348 | equation
|
---|
349 | connect(T1.outPlaces[1], P2.inTransition[1]) annotation(Line(points = {{4.7, 10}, {4.7, 10}, {20.7, 10}}));
|
---|
350 | connect(P1.outTransition[1], T1.inPlaces[1]) annotation(Line(points = {{-20.7, 10}, {-20.7, 10}, {-4.7, 10}}));
|
---|
351 | annotation(Diagram(coordinateSystem(extent = {{-60, -20}, {60, 40}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-60, -20}, {60, 40}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-006));
|
---|
352 | end Test6;
|
---|
353 | annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
|
---|
354 | end Examples;
|
---|
355 | annotation(uses(Modelica(version="3.2.1")));
|
---|
356 | end PNlib;
|
---|
357 | model PNlib_Examples_Test6
|
---|
358 | extends PNlib.Examples.Test6;
|
---|
359 | annotation(experiment(
|
---|
360 | StartTime=0,
|
---|
361 | StopTime=1,
|
---|
362 | Tolerance=1e-006));
|
---|
363 | end PNlib_Examples_Test6;
|
---|