23
26
private BSONAlg bsonAlg;
25
private Collection<ONGroup> abstractGroups;
26
private Collection<ONGroup> bhvGroups;
28
private Collection<Node> checkedNodes = new HashSet<Node>();
28
private Collection<ONGroup> upperGroups;
29
private Collection<ONGroup> lowerGroups;
30
32
public SimulationAlg(SON net){
33
35
bsonAlg = new BSONAlg(net);
35
abstractGroups = bsonAlg.getAbstractGroups(net.getGroups());
36
bhvGroups = bsonAlg.getBhvGroups(net.getGroups());
39
private Collection<Node> getSyncMinimum (TransitionNode e, Collection<Path> sync, Collection<TransitionNode> enabledEvents){
40
Collection<Node> result = new HashSet<Node>();
41
HashSet<Node> syncEvents = new HashSet<Node>();
42
//get related synchronous events
43
for(Path cycle : sync){
45
syncEvents.addAll(cycle);
47
//e is in synchronous cycle
48
if(!syncEvents.isEmpty()){
49
for(Node n : syncEvents){
50
//add all related synchronous cycle to result
51
if(enabledEvents.contains(n) && !result.contains(n)){
53
//continue to check the event which is the pre-aysn-event of related synchronous cycle
54
for(TransitionNode pre : getPreAsynEvents((TransitionNode)n)){
55
if(!syncEvents.contains(pre) && enabledEvents.contains(pre)){
56
result.addAll(getSyncMinimum((TransitionNode)pre, sync, enabledEvents));
60
if(!enabledEvents.contains(n))
61
throw new RuntimeException("algorithm error: has unenabled event in sync cycle "+net.getNodeReference(n));
64
//e is not in synchronous cycle but has pre asyn event
65
else if(!getPreAsynEvents(e).isEmpty() && enabledEvents.contains(e)){
66
if(!result.contains(e))
69
for(TransitionNode n : getPreAsynEvents(e))
70
if(!result.contains(n) && enabledEvents.contains(n)){
72
result.addAll(getSyncMinimum((TransitionNode)n, sync, enabledEvents));
82
* return minimal execution set of a given node.
83
* contain other nodes which have synchronous with the clicked node.
85
public List<TransitionNode> getMinFires (TransitionNode e, Collection<Path> sync, Collection<TransitionNode> enabledEvents){
86
List<TransitionNode> result = new ArrayList<TransitionNode>();
88
for(Node n : getSyncMinimum(e, sync, enabledEvents))
89
if(n instanceof TransitionNode)
90
result.add((TransitionNode)n);;
96
private Collection<Node> getMaxFireSet(TransitionNode e, Collection<Path> sync, Collection<TransitionNode> enabledEvents){
97
Collection<Node> result = new HashSet<Node>();
98
Collection<Node> syncEvents = new HashSet<Node>();
100
for(Path cycle : sync){
101
if(cycle.contains(e))
102
syncEvents.addAll(cycle);
105
if(!syncEvents.isEmpty()){
106
for(Node n : syncEvents){
107
if(enabledEvents.contains(n) && !result.contains(n)){
110
for(TransitionNode post : this.getPostAsynEvents((TransitionNode)n)){
111
if(!syncEvents.contains(post) && enabledEvents.contains(post)){
113
result.addAll(getMaxFireSet((TransitionNode)post, sync, enabledEvents));
118
if(!enabledEvents.contains(n))
119
throw new RuntimeException("algorithm error: has unenable event in sync cycle");
122
else if(!getPostAsynEvents(e).isEmpty() && enabledEvents.contains(e)){
123
if(!result.contains(e))
126
for(TransitionNode n : getPostAsynEvents(e))
127
if(!result.contains(n) && enabledEvents.contains(n)){
129
result.addAll(getMaxFireSet((TransitionNode)n, sync, enabledEvents));
138
public List<TransitionNode> getMaxFires (TransitionNode e, Collection<Path> sync, Collection<TransitionNode> enabledEvents){
139
List<TransitionNode> result = new ArrayList<TransitionNode>();
141
for(Node n : getMaxFireSet(e, sync, enabledEvents))
142
if(n instanceof TransitionNode)
143
result.add((TransitionNode)n);
148
private boolean isPNEnabled (TransitionNode e) {
149
// gather number of connections for each pre-place
150
for (Node n : net.getPreset(e)){
151
if(n instanceof Condition)
152
if (!((Condition)n).isMarked())
37
upperGroups = bsonAlg.getUpperGroups(net.getGroups());
38
lowerGroups = bsonAlg.getLowerGroups(net.getGroups());
41
public List<TransitionNode> getMinFire(TransitionNode e, Collection<Path> sync, Collection<TransitionNode> fireList, boolean isRev){
42
List<TransitionNode> result = null;
44
result = getForwordMinFire(e, sync, fireList);
46
result = getRevMinFire(e, sync, fireList);
53
public Map<PlaceNode, Boolean> getInitialMarking(){
54
HashMap<PlaceNode, Boolean> result = new HashMap<PlaceNode, Boolean>();
55
Collection<ONGroup> upperGroups = bsonAlg.getUpperGroups(net.getGroups());
56
Collection<ONGroup> lowerGroups = bsonAlg.getLowerGroups(net.getGroups());
58
for(PlaceNode c : net.getPlaceNodes())
61
for(ONGroup group : net.getGroups()){
62
if(upperGroups.contains(group))
63
for(Condition c : getInitial(group.getConditions())){
66
//an initial state of a lower group is the initial state of SON
67
//if all of its upper conditions are the initial states.
68
else if(lowerGroups.contains(group)){
69
for(Condition c : getInitial(group.getConditions())){
70
boolean isInitial = true;
71
Collection<Condition> set = bsonAlg.getUpperConditions(c);
72
for(Condition c2 : set){
74
ONGroup group2 = net.getGroup(c2);
75
if(!set.containsAll(getInitial(group2.getConditions())))
84
for(Condition c : getInitial(group.getConditions())){
93
* return minimal execution set for a given node.
94
* contain other nodes which have synchronous and PRE- relation with the selected one.
96
private List<TransitionNode> getForwordMinFire(TransitionNode e, Collection<Path> sync, Collection<TransitionNode> fireList){
97
List<TransitionNode> result = new ArrayList<TransitionNode>();
98
Collection<TransitionNode> u = new ArrayList<TransitionNode>();
99
Stack<TransitionNode> stack = new Stack<TransitionNode>();
104
while(!stack.empty()){
106
if(!result.contains(e)){
110
//event in sync cycle belongs to the result
111
for(Path cycle : sync){
112
if(cycle.contains(e))
113
for(Node e2 : cycle){
114
if(e2 instanceof TransitionNode && u.contains(e2)){
116
stack.push((TransitionNode)e2);
118
else if(!fireList.contains(e2)){
119
throw new RuntimeException
120
("algorithm error: unenabled event in sync cycle"+net.getNodeReference(e2));
124
//event which is the preset w.r.t weak causality, of selected event belongs to the result.
125
if(!getPreAsynEvents(e).isEmpty()){
126
for(TransitionNode e3 : getPreAsynEvents(e)){
129
stack.push((TransitionNode)e3);
139
* return maximal execution set for a given node.
140
* contain other nodes which have synchronous and POST- relation with the selected one.
142
private List<TransitionNode> getRevMinFire(TransitionNode e, Collection<Path> sync, Collection<TransitionNode> fireList){
143
List<TransitionNode> result = new ArrayList<TransitionNode>();
144
Collection<TransitionNode> u = new ArrayList<TransitionNode>();
145
Stack<TransitionNode> stack = new Stack<TransitionNode>();
150
while(!stack.empty()){
152
if(!result.contains(e)){
157
for(Path cycle : sync){
158
if(cycle.contains(e))
159
for(Node e2 : cycle){
160
if(e2 instanceof TransitionNode && u.contains(e2)){
162
stack.push((TransitionNode)e2);
164
else if(!fireList.contains(e2)){
165
throw new RuntimeException
166
("algorithm error: unenabled event in sync cycle"+net.getNodeReference(e2));
170
if(!getPostAsynEvents(e).isEmpty()){
171
for(TransitionNode e3 : getPostAsynEvents(e)){
174
stack.push((TransitionNode)e3);
183
final public List<TransitionNode> getEnabledNodes(Collection<Path> sync, Map<Condition, Collection<Phase>> phases, boolean isRev){
184
List<TransitionNode> result = null;
186
result = getEnabled(sync, phases);
188
result = getRevEnabled(sync, phases);
194
private boolean isONEnabled (TransitionNode e) {
155
195
if(net.getPreset(e).isEmpty())
161
private boolean isSyncEnabled(TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases){
162
Collection<Node> relatedSync = new HashSet<Node>();
163
//get nodes which have synchronous relation with e
164
for(Path cycle : sync){
165
if(cycle.contains(e))
166
relatedSync.addAll(cycle);
169
if(relatedSync.contains(e)){
170
checkedNodes.addAll(relatedSync);
171
for(Node n : relatedSync)
172
if(n instanceof TransitionNode){
173
if(!isPNEnabled((TransitionNode)n) || !isBhvEnabled((TransitionNode)n, phases))
175
for(TransitionNode pre : getPreAsynEvents((TransitionNode)n)){
176
if(!relatedSync.contains(pre)){
177
if(!isAsynEnabled((TransitionNode)n, sync, phases)
178
|| !isBhvEnabled((TransitionNode)n, phases))
188
private boolean isAsynEnabled(TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases){
189
//get pre-channel place q of e
190
198
for (Node n : net.getPreset(e)){
191
if(n instanceof ChannelPlace)
192
//if q is un-marked (synchronous semantic)
193
if (((ChannelPlace)n).isMarked() == false)
194
//get the input transition node of q, if it is unenabled then e is unenabled
195
for(Node node : net.getPreset(n)){
196
if(node instanceof TransitionNode && !checkedNodes.contains(node)){
197
if(!isPNEnabled((TransitionNode)node)
198
||!isSyncEnabled((TransitionNode)node, sync, phases)
199
||!isAsynEnabled((TransitionNode)node, sync, phases)
200
||!isBhvEnabled((TransitionNode)node, phases))
199
if(n instanceof Condition)
200
if (!((Condition)n).isMarked())
208
private boolean isBhvEnabled(TransitionNode e, Map<Condition, Phase> phases){
209
//if e is abstract event, e is enabled if the maximal phase of e's pre-condition is marked
210
for(ONGroup group : abstractGroups){
207
private boolean isBSONEnabled(TransitionNode e, Map<Condition, Collection<Phase>> phases){
208
//if e is upper event, e is BSON enabled if every condition in the maximal phases of e is marked
209
for(ONGroup group : upperGroups){
211
210
if(group.getComponents().contains(e)){
212
for(Node pre : getPrePNSet(e))
213
if(pre instanceof Condition){
214
Phase phase = phases.get((Condition)pre);
215
for(Condition max : bsonAlg.getMaximalPhase(phase))
211
for(Node pre : getPrePNSet(e)){
212
Condition c = (Condition)pre;
213
Collection<Phase> phase = phases.get(c);
214
Collection<Condition> max = bsonAlg.getMaximalPhase(phase);
215
for(Condition c2 : max)
223
for(ONGroup group : bhvGroups){
223
//if e is lower event, e is BSON enabled if every e's upper condition is marked
224
for(ONGroup group : lowerGroups){
224
225
if(group.getComponents().contains(e)){
225
for(Condition c : phases.keySet()){
230
//2. either the pre- or post condition of e not belong to c's phase
231
if((!phases.get(c).containsAll(getPrePNSet(e))
232
&& phases.get(c).containsAll(getPostPNSet(e)))
233
|| (!phases.get(c).containsAll(getPostPNSet(e))
234
&& phases.get(c).containsAll(getPrePNSet(e)))){
226
for(Condition c : bsonAlg.getUpperConditions(e))
239
//e is un-enabled if the pre- and post-conditions of e all belong to the phase of c.
240
if(phases.get(c).containsAll(getPostPNSet(e))
241
&& phases.get(c).containsAll(getPrePNSet(e)))
249
final public boolean isEnabled (TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases){
250
checkedNodes.clear();
252
&& isSyncEnabled(e, sync, phases)
253
&& isAsynEnabled(e, sync, phases)
254
&& isBhvEnabled(e, phases)){
235
private List<TransitionNode> getEnabled(Collection<Path> sync, Map<Condition, Collection<Phase>> phases){
236
List<TransitionNode> result = new ArrayList<TransitionNode>();
237
Collection<Node> del = new HashSet<Node>();
238
Stack<TransitionNode> stack = new Stack<TransitionNode>();
240
//ON and BSON enabled
241
for(TransitionNode e : net.getTransitionNodes()){
242
if(isONEnabled(e) && isBSONEnabled(e, phases)){
248
for(Path cycle : sync){
250
if(n instanceof TransitionNode && !result.contains(n)){
258
for(TransitionNode e : result){
259
LinkedList<Node> visit = new LinkedList<Node>();
262
while(!stack.isEmpty()){
266
TransitionNode e2 = null;
267
for(Node pre : net.getPreset(e)){
268
if(pre instanceof ChannelPlace){
269
if(!((ChannelPlace)pre).isMarked()){
270
for(Node pre2 : net.getPreset(pre)){
271
if(visit.contains(pre2)){
274
else if(!result.contains(pre2) || del.contains(pre2)){
275
// e2 = (TransitionNode)pre2;
282
else if(!visit.contains(pre2)){
283
e2 = (TransitionNode)pre2;
291
while(!stack.isEmpty()){
293
if(!visit.isEmpty() && e==visit.peekLast()){
304
result.removeAll(del);
260
public void fire(Collection<TransitionNode> fireList) throws InvalidStructureException{
262
for(TransitionNode e : fireList){
263
for (SONConnection c : net.getSONConnections(e)) {
264
if (c.getSemantics() == Semantics.PNLINE && e==c.getFirst()) {
265
Condition to = (Condition)c.getSecond();
267
throw new InvalidStructureException("Token amount > 1: "+net.getNodeReference(to));
270
if (c.getSemantics() == Semantics.PNLINE && e==c.getSecond()) {
271
Condition from = (Condition)c.getFirst();
273
throw new InvalidStructureException("Token amount = 0: "+net.getNodeReference(from));
274
from.setMarked(false);
276
if (c.getSemantics() == Semantics.ASYNLINE && e==c.getFirst()){
277
ChannelPlace to = (ChannelPlace)c.getSecond();
278
if(fireList.containsAll(net.getPostset(to)) && fireList.containsAll(net.getPreset(to)))
279
to.setMarked(((ChannelPlace)to).isMarked());
282
throw new InvalidStructureException("Token amount > 1: "+net.getNodeReference(to));
286
if (c.getSemantics() == Semantics.ASYNLINE && e==c.getSecond()){
287
ChannelPlace from = (ChannelPlace)c.getFirst();
288
if(fireList.containsAll(net.getPostset(from)) && fireList.containsAll(net.getPreset(from)))
289
from.setMarked(((ChannelPlace)from).isMarked());
292
throw new InvalidStructureException("Token amount = 0: "+net.getNodeReference(from));
293
from.setMarked(false);
297
//if e is an abstract events, get preMax - maximal phase of e's input, and postMin - minimal phase of e' output
298
Collection<Condition> preMax = new HashSet<Condition>();
299
Collection<Condition> postMin = new HashSet<Condition>();
300
for(Node pre : getPrePNSet(e)){
301
if(bsonAlg.isAbstractCondition(pre))
302
preMax.addAll(bsonAlg.getMaximalPhase(bsonAlg.getPhase((Condition)pre)));
304
for(Node post : getPostPNSet(e)){
305
if(bsonAlg.isAbstractCondition(post))
306
postMin.addAll(bsonAlg.getMinimalPhase(bsonAlg.getPhase((Condition)post)));
308
//if preMax and postMin are in separate ONs.
309
if(!preMax.containsAll(postMin)){
310
boolean isFinal=true;
311
//if preMax are the final states of an ON
312
for(Condition fin : preMax){
318
//token in preMax sets to false if none of corresponding abstract conditions is marked
320
for(Condition fin : preMax){
322
for(Node c : bsonAlg.getAbstractConditions(fin)){
323
if(((Condition)c).isMarked())
326
if(fin.isMarked() && tokens == 0)
327
fin.setMarked(false);
330
//if postMin are the initial states of another ON
331
boolean isInitial = true;
332
for(Condition init : postMin){
333
if(!isInitial(init)){
338
//token in postMin sets to true if ALL corresponding abstract conditions is marked
340
for(Condition ini : postMin){
343
for(Node c : bsonAlg.getAbstractConditions(ini)){
345
if(((Condition)c).isMarked())
348
if(!ini.isMarked() && tokens == count)
356
308
//reverse simulation
358
final public boolean isUnfireEnabled (TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases) {
359
checkedNodes.clear();
360
if(isPNUnEnabled(e) && isSyncUnEnabled(e, sync, phases) && this.isAsynUnEnabled(e, sync, phases) && isBhvUnEnabled(e, phases))
366
private boolean isPNUnEnabled (TransitionNode e) {
310
private boolean isRevONEnabled (TransitionNode e) {
311
if(net.getPostset (e).isEmpty())
367
314
for (Node n : net.getPostset(e)){
368
315
if(n instanceof Condition)
369
316
if (!((Condition)n).isMarked())
372
if(net.getPostset(e).isEmpty())
377
private boolean isSyncUnEnabled(TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases){
378
HashSet<Node> relatedSync = new HashSet<Node>();
380
for(Path cycle : sync){
381
if(cycle.contains(e))
382
relatedSync.addAll(cycle);
385
if(relatedSync.contains(e)){
386
checkedNodes.addAll(relatedSync);
387
for(Node n : relatedSync)
388
if(n instanceof TransitionNode){
389
if(!this.isPNUnEnabled((TransitionNode)n) || !this.isBhvUnEnabled((TransitionNode)n, phases))
323
private boolean isRevBSONEnabled(TransitionNode e, Map<Condition, Collection<Phase>> phases){
324
//if e is upper event, e is BSON unfire enabled if every condition in the minimal phases of e is marked
325
for(ONGroup group : upperGroups){
326
if(group.getComponents().contains(e)){
327
for(Node post : getPostPNSet(e)){
328
Condition c = (Condition)post;
329
Collection<Phase> phase = phases.get(c);
330
Collection<Condition> min = bsonAlg.getMinimalPhase(phase);
331
for(Condition c2 : min)
391
for(Node post : this.getPostAsynEvents((TransitionNode)n)){
392
if(post instanceof TransitionNode && !relatedSync.contains(post)){
393
if(!this.isAsynUnEnabled((TransitionNode)n, sync, phases)||!this.isBhvUnEnabled((TransitionNode)n, phases))
402
private boolean isAsynUnEnabled(TransitionNode e, Collection<Path> sync, Map<Condition, Phase> phases){
404
for (Node n : net.getPostset(e)){
405
if(n instanceof ChannelPlace)
406
if (((ChannelPlace)n).isMarked() == false)
407
for(Node node : net.getPostset(n)){
408
if(node instanceof TransitionNode && !checkedNodes.contains(node)){
409
if(!this.isPNUnEnabled((TransitionNode)node)
410
||!this.isSyncUnEnabled((TransitionNode)node, sync, phases)
411
||!this.isAsynUnEnabled((TransitionNode)node, sync, phases)
412
||!this.isBhvUnEnabled((TransitionNode)node, phases))
420
private boolean isBhvUnEnabled(TransitionNode e, Map<Condition, Phase> phases){
421
for(ONGroup group : abstractGroups){
422
if(group.getComponents().contains(e)){
423
for(Node pre : getPostPNSet(e))
424
if(pre instanceof Condition){
425
Phase phase = phases.get((Condition)pre);
426
for(Condition min : bsonAlg.getMinimalPhase(phase))
434
for(ONGroup group : bhvGroups){
339
//if e is lower event, e is BSON enabled if every e's upper condition is marked
340
for(ONGroup group : lowerGroups){
435
341
if(group.getComponents().contains(e)){
436
for(Condition c : phases.keySet()){
438
if((!phases.get(c).containsAll(getPrePNSet(e))
439
&& phases.get(c).containsAll(getPostPNSet(e)))
440
|| (!phases.get(c).containsAll(getPostPNSet(e))
441
&& phases.get(c).containsAll(getPrePNSet(e))))
342
for(Condition c : bsonAlg.getUpperConditions(e))
443
343
if(!c.isMarked())
444
if(phases.get(c).containsAll(getPostPNSet(e)) && phases.get(c).containsAll(getPrePNSet(e)))
452
public void unFire(Collection<TransitionNode> fireList) throws InvalidStructureException{
453
for(TransitionNode e : fireList){
454
for (SONConnection c : net.getSONConnections(e)) {
455
if (c.getSemantics() == Semantics.PNLINE && e==c.getSecond()) {
456
Condition to = (Condition)c.getFirst();
458
throw new InvalidStructureException("Reverse Token amount > 1: "+net.getNodeReference(to));
461
if (c.getSemantics() == Semantics.PNLINE && e==c.getFirst()) {
462
Condition from = (Condition)c.getSecond();
464
throw new InvalidStructureException("Reverse Token amount = 0: "+net.getNodeReference(from));
465
from.setMarked(false);
467
if (c.getSemantics() == Semantics.ASYNLINE && e==c.getSecond()){
468
ChannelPlace to = (ChannelPlace)c.getFirst();
469
if(fireList.containsAll(net.getPreset(to)) && fireList.containsAll(net.getPostset(to)))
470
to.setMarked(((ChannelPlace)to).isMarked());
473
throw new InvalidStructureException("Reverse Token amount > 1: "+net.getNodeReference(to));
474
to.setMarked(!to.isMarked());
476
if (c.getSemantics() == Semantics.ASYNLINE && e==c.getFirst()){
477
ChannelPlace from = (ChannelPlace)c.getSecond();
478
if(fireList.containsAll(net.getPreset(from)) && fireList.containsAll(net.getPostset(from)))
479
from.setMarked(((ChannelPlace)from).isMarked());
482
throw new InvalidStructureException("Reverse Token amount = 0: "+net.getNodeReference(from));
483
from.setMarked(!from.isMarked());
488
//if e is an abstract events, get preMax - maximal phase of e's input, and postMin - minimal phase of e' output
489
Collection<Condition> preMax = new HashSet<Condition>();
490
Collection<Condition> postMin = new HashSet<Condition>();
491
for(Node pre : getPrePNSet(e)){
492
if(bsonAlg.isAbstractCondition(pre))
493
preMax.addAll(bsonAlg.getMaximalPhase(bsonAlg.getPhase((Condition)pre)));
495
for(Node post : getPostPNSet(e)){
496
if(bsonAlg.isAbstractCondition(post))
497
postMin.addAll(bsonAlg.getMinimalPhase(bsonAlg.getPhase((Condition)post)));
499
//if preMax and postMin are in separate ONs.
500
if(!preMax.containsAll(postMin)){
501
boolean isFinal=true;
502
//if preMax are the final states of an ON
503
for(Condition fin : preMax){
509
//token in preMax sets to true if all of corresponding abstract conditions is marked
511
for(Condition fin : preMax){
514
for(Node c : bsonAlg.getAbstractConditions(fin)){
516
if(((Condition)c).isMarked())
519
if(!fin.isMarked() && tokens == count)
523
//if postMin are the initial states of another ON
524
boolean isInitial = true;
525
for(Condition init : postMin){
526
if(!isInitial(init)){
531
//token in postMin sets to false if none of corresponding abstract conditions is marked
533
for(Condition ini : postMin){
535
for(Node c : bsonAlg.getAbstractConditions(ini)){
536
if(((Condition)c).isMarked())
539
if(ini.isMarked() && tokens == 0)
540
ini.setMarked(false);
350
private List<TransitionNode> getRevEnabled(Collection<Path> sync, Map<Condition, Collection<Phase>> phases){
351
List<TransitionNode> result = new ArrayList<TransitionNode>();
352
Collection<Node> del = new HashSet<Node>();
353
Stack<TransitionNode> stack = new Stack<TransitionNode>();
355
//ON and BSON enabled
356
for(TransitionNode e : net.getTransitionNodes()){
357
if(isRevONEnabled(e) && isRevBSONEnabled(e, phases)){
363
for(Path cycle : sync){
365
if(n instanceof TransitionNode && !result.contains(n)){
373
for(TransitionNode e : result){
374
LinkedList<Node> visit = new LinkedList<Node>();
377
while(!stack.isEmpty()){
381
TransitionNode e2 = null;
382
for(Node post : net.getPostset(e)){
383
if(post instanceof ChannelPlace){
384
if(!((ChannelPlace)post).isMarked()){
385
for(Node post2 : net.getPostset(post)){
386
if(visit.contains(post2)){
389
else if(!result.contains(post2) || del.contains(post2)){
390
// e2 = (TransitionNode)pre2;
397
else if(!visit.contains(post2)){
398
e2 = (TransitionNode)post2;
406
while(!stack.isEmpty()){
408
if(!visit.isEmpty() && e==visit.peekLast()){
419
result.removeAll(del);
423
public void setMarking(Collection<TransitionNode> step, Map<Condition, Collection<Phase>> phases, boolean isRev) throws InvalidStructureException{
427
revFire(step, phases);
431
* token setting after forward fire.
433
private void fire(Collection<TransitionNode> step, Map<Condition, Collection<Phase>> phases) throws InvalidStructureException{
435
for(TransitionNode e : step){
436
for(Node post : net.getPostset(e)){
437
if(post instanceof PlaceNode)
438
if(((PlaceNode)post).isMarked())
439
throw new InvalidStructureException("Token amount > 1: "+net.getNodeReference(post));
443
for(TransitionNode e : step){
444
for(Node pre : net.getPreset(e)){
445
//if e is upper event, remove marking for every maximal phase of pre{e}.
446
if(bsonAlg.isUpperCondition(pre)){
447
Condition c = (Condition)pre;
448
Collection<Condition> maxSet = bsonAlg.getMaximalPhase(phases.get(c));
449
for(Condition c2 : maxSet)
453
for(Node post : net.getPostset(e)){
454
//set marking for each post node of step U
455
if((post instanceof PlaceNode) && net.getSONConnectionType(e, post) != Semantics.SYNCLINE)
456
((PlaceNode)post).setMarked(true);
457
//if e is upper event, set marking for every minimal phase of post{e}.
458
if(bsonAlg.isUpperCondition(post)){
459
Condition c = (Condition)post;
460
Collection<Condition> minSet = bsonAlg.getMinimalPhase(phases.get(c));
461
for(Condition c2 : minSet)
467
for(TransitionNode e : step){
468
//remove marking for each pre node of step U
469
for(Node pre : net.getPreset(e)){
470
if((pre instanceof PlaceNode) && net.getSONConnectionType(e, pre) != Semantics.SYNCLINE)
471
((PlaceNode)pre).setMarked(false);
478
* token setting after reverse fire.
480
private void revFire(Collection<TransitionNode> step, Map<Condition, Collection<Phase>> phases) throws InvalidStructureException{
482
for(TransitionNode e : step){
483
for(Node pre : net.getPreset(e)){
484
if(pre instanceof PlaceNode)
485
if(((PlaceNode)pre).isMarked())
486
throw new InvalidStructureException("Token amount > 1: "+net.getNodeReference(pre));
490
for(TransitionNode e : step){
491
for(Node post : net.getPostset(e)){
492
//if e is upper event, remove marking for every minimal phase of pre{e}.
493
if(bsonAlg.isUpperCondition(post)){
494
Condition c = (Condition)post;
495
Collection<Condition> minSet = bsonAlg.getMinimalPhase(phases.get(c));
496
for(Condition c2 : minSet)
500
for(Node pre : net.getPreset(e)){
501
//set marking for each post node of step U
502
if((pre instanceof PlaceNode) && net.getSONConnectionType(e, pre) != Semantics.SYNCLINE)
503
((PlaceNode)pre).setMarked(true);
504
//if e is upper event, set marking for every minimal phase of post{e}.
505
if(bsonAlg.isUpperCondition(pre)){
506
Condition c = (Condition)pre;
507
Collection<Condition> maxSet = bsonAlg.getMaximalPhase(phases.get(c));
508
for(Condition c2 : maxSet)
514
for(TransitionNode e : step){
515
//remove marking for each post node of step U
516
for(Node post : net.getPostset(e)){
517
if((post instanceof PlaceNode) && net.getSONConnectionType(e, post) != Semantics.SYNCLINE)
518
((PlaceNode)post).setMarked(false);