-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathphiloSumo.cpp
110 lines (81 loc) · 3.18 KB
/
philoSumo.cpp
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
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "its/ITSModel.hh"
#include "petri/PNet.hh"
#include "its/composite/Composite.hh"
#include "scalar/CircularSet.hh"
#include "statistic.hpp"
using namespace its;
using namespace std;
void usage() {
cerr << "Instantiable Transition Systems: Philo example; package " << PACKAGE_STRING <<endl;
cerr << "Usage : philoITS NN [-ssD2/-ssDR/-ssDS see below] where NN is the mandatory size. Default is -ssD2 1" << endl;
cerr<< " -ssD2 INT : use 2 level depth for scalar sets. Integer provided defines level 2 block size." <<endl;
cerr<< " -ssDR INT : use recursive encoding for scalar sets. Integer provided defines number of blocks at highest levels." <<endl;
cerr<< " -ssDS INT : use alternative recursive encoding for scalar sets. Integer provided defines number of blocks at lowest level." <<endl;
}
void buildPhiloType (ITSModel & m) {
PNet net ("Philo") ;
net.addPlace ("Think");
net.addPlace ("Catch1");
net.addPlace ("Catch2");
net.addPlace ("Eat");
net.addPlace ("Fork");
net.setMarking("init","Think",1);
net.setMarking("init","Fork",1);
vLabel tname = "FF1a";
net.addTransition(tname, "getLeft" , PUBLIC);
net.addArc (PNet::ArcVal("Think",1), tname,INPUT);
net.addArc (PNet::ArcVal("Catch1",1), tname,OUTPUT);
tname = "FF1b";
net.addTransition(tname, "" , PRIVATE);
net.addArc (PNet::ArcVal("Think",1), tname,INPUT);
net.addArc (PNet::ArcVal("Fork",1), tname,INPUT);
net.addArc (PNet::ArcVal("Catch2",1), tname,OUTPUT);
tname = "FF2a";
net.addTransition(tname, "" , PRIVATE);
net.addArc (PNet::ArcVal("Catch1",1), tname,INPUT);
net.addArc (PNet::ArcVal("Fork",1), tname,INPUT);
net.addArc (PNet::ArcVal("Eat",1), tname,OUTPUT);
tname = "FF2b";
net.addTransition(tname, "getLeft" , PUBLIC);
net.addArc (PNet::ArcVal("Catch2",1), tname,INPUT);
net.addArc (PNet::ArcVal("Eat",1), tname,OUTPUT);
tname = "release";
net.addTransition(tname, tname , PUBLIC);
net.addArc (PNet::ArcVal("Eat",1), tname,INPUT);
net.addArc (PNet::ArcVal("Fork",1), tname,OUTPUT);
net.addArc (PNet::ArcVal("Think",1), tname,OUTPUT);
tname = "get";
net.addTransition(tname, tname , PUBLIC);
net.addArc (PNet::ArcVal("Fork",1), tname,INPUT);
tname = "put";
net.addTransition(tname, tname , PUBLIC);
net.addArc (PNet::ArcVal("Fork",1), tname,OUTPUT);
m.declareType (net);
}
void buildPhiloCircular (ITSModel & m, int n) {
CircularSet cs ("Philos");
cs.setSize(n);
cs.setInstance("pf","Philo",m);
cs.createStateDef("init","init");
vLabel sname = "get";
cs.addSynchronization(sname,"");
cs.addSyncPart(sname,CircularSet::CURRENT,labels_t(1,"get"));
cs.addSyncPart(sname,CircularSet::NEXT,labels_t(1,"getLeft"));
sname = "put";
cs.addSynchronization(sname,"");
cs.addSyncPart(sname,CircularSet::CURRENT,labels_t(1,"put"));
cs.addSyncPart(sname,CircularSet::NEXT,labels_t(1,"release"));
// cs.print(std::cout);
m.declareType(cs);
}
extern "C" void loadModel (its::ITSModel & model, int N) {
buildPhiloType (model);
buildPhiloCircular(model,N);
model.setInstance("Philos","main");
model.setInstanceState("init");
}