Merge lp:~verifypn-maintainers/verifypn/multiplePlaceBounds into lp:~verifypn-maintainers/verifypn/trunk

Proposed by Jiri Srba
Status: Merged
Approved by: Jiri Srba
Approved revision: 65
Merged at revision: 64
Proposed branch: lp:~verifypn-maintainers/verifypn/multiplePlaceBounds
Merge into: lp:~verifypn-maintainers/verifypn/trunk
Diff against target: 272 lines (+105/-30)
4 files modified
PetriEngine/Structures/StateSet.h (+14/-2)
PetriParse/QueryXMLParser.cpp (+53/-18)
PetriParse/QueryXMLParser.h (+4/-2)
VerifyPN.cpp (+34/-8)
To merge this branch: bzr merge lp:~verifypn-maintainers/verifypn/multiplePlaceBounds
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+291113@code.launchpad.net

Commit message

Added the possiblity to check for multiple place bounds.

Description of the change

Added possibliy to check for multiple place bounds.

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

tested and seems to work

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'PetriEngine/Structures/StateSet.h'
2--- PetriEngine/Structures/StateSet.h 2016-03-24 11:11:38 +0000
3+++ PetriEngine/Structures/StateSet.h 2016-04-06 13:32:00 +0000
4@@ -23,6 +23,9 @@
5 #include <iostream>
6 #include "State.h"
7
8+extern unsigned int maxplacesbound;
9+extern std::vector<size_t>* placelistboundindex;
10+
11 namespace PetriEngine { namespace Structures {
12
13 // Big int used for state space statistics
14@@ -70,8 +73,17 @@
15 std::pair<iter, bool> result = this->insert(state);
16 // update the max token bound for each place in the net (only for newly discovered markings)
17 if (result.second) {
18- for(size_t i = 0; i < _places; i++) {
19- _maxPlaceBound[i] = std::max<unsigned int>(state->marking()[i],_maxPlaceBound[i]);
20+
21+ if (placelistboundindex == NULL) { // single places in the place bound check
22+ for (size_t i = 0; i < _places; i++) {
23+ _maxPlaceBound[i] = std::max<unsigned int>(state->marking()[i], _maxPlaceBound[i]);
24+ }
25+ } else { // multiple places in the place bound check
26+ unsigned int sum = 0;
27+ for (int i=0; i < (*placelistboundindex).size(); i++) {
28+ sum += state->marking()[(*placelistboundindex)[i]];
29+ }
30+ maxplacesbound = std::max<unsigned int>(sum, maxplacesbound);
31 }
32 }
33 return result.second;
34
35=== modified file 'PetriParse/QueryXMLParser.cpp'
36--- PetriParse/QueryXMLParser.cpp 2015-04-21 20:16:43 +0000
37+++ PetriParse/QueryXMLParser.cpp 2016-04-06 13:32:00 +0000
38@@ -34,12 +34,12 @@
39 // QueryXMLParser::~QueryXMLParser() { };
40
41
42-bool QueryXMLParser::parse(const std::string& xml){
43+bool QueryXMLParser::parse(const std::string& xml, int query){
44 //Parse the xml
45 DOMElement* root = DOMElement::loadXML(xml);
46 bool parsingOK;
47 if (root) {
48- parsingOK = parsePropertySet(root);
49+ parsingOK = parsePropertySet(root, query);
50 } else {
51 parsingOK=false;
52 }
53@@ -50,17 +50,30 @@
54 }
55
56
57-bool QueryXMLParser::parsePropertySet(DOMElement* element){
58+bool QueryXMLParser::parsePropertySet(DOMElement* element, int query){
59 if (element->getElementName()!="property-set") {
60 fprintf(stderr,"ERROR missing property-set\n");
61 return false; // missing property-set element
62 }
63 DOMElements elements = element->getChilds();
64 DOMElements::iterator it;
65+ int count=1;
66 for(it = elements.begin(); it != elements.end(); it++){
67+ if (count == query) {
68 if (!parseProperty(*it)) {
69 return false;
70 };
71+ } else {
72+ QueryItem queryItem;
73+ queryItem.id = "";
74+ queryItem.queryText = "";
75+ queryItem.negateResult = false;
76+ queryItem.isPlaceBound = false;
77+ queryItem.placeNameForBound = "X";
78+ queryItem.parsingResult = QueryItem::UNSUPPORTED_QUERY;
79+ queries.push_back(queryItem);
80+ }
81+ count++;
82 }
83 return true;
84 }
85@@ -73,7 +86,7 @@
86 string id;
87 string queryText;
88 bool negateResult=false;
89- bool isPlaceBound=false;
90+ bool isPlaceBound=false;
91 string placeNameForBound;
92 bool tagsOK=true;
93
94@@ -199,20 +212,42 @@
95 } else if (elementName == "place-bound") {
96 queryText = "EF ";
97 DOMElements children = booleanFormula->getChilds();
98- if (children.size() != 1) {
99- return false; // we support only place-bound for one place
100- }
101- if (children[0]->getElementName() != "place") {
102- return false;
103- }
104- placeNameForBound = parsePlace(children[0]);
105- if (placeNameForBound=="") {
106- return false; // invalid place name
107- }
108- queryText += "\""+placeNameForBound+"\""+" < 0";
109- negateResult = false;
110- isPlaceBound = true;
111- return true;
112+ if (children.size() == 0) {
113+ return false;
114+ }
115+
116+ if (children.size() == 1) {
117+ if (children[0]->getElementName() != "place") {
118+ return false;
119+ }
120+ placeNameForBound = parsePlace(children[0]);
121+ if (placeNameForBound == "") {
122+ return false; // invalid place name
123+ }
124+ queryText += "\"" + placeNameForBound + "\"" + " < 0";
125+ negateResult = false;
126+ isPlaceBound = true;
127+ placelistbound = NULL;
128+ return true;
129+ } else {
130+ placelistbound = new std::vector<std::string>;
131+ for (int i = 0; i < children.size(); i++) {
132+ if (children[i]->getElementName() != "place") {
133+ return false;
134+ }
135+ placeNameForBound = parsePlace(children[i]);
136+ if (placeNameForBound == "") {
137+ return false; // invalid place name
138+ }
139+ queryText += "(\"" + placeNameForBound + "\"" + " < 0)";
140+ if (i<children.size()-1) queryText += " and ";
141+ placelistbound->push_back(placeNameForBound);
142+ }
143+ placeNameForBound = "Multiple Place Bound";
144+ negateResult = false;
145+ isPlaceBound = true;
146+ return true;
147+ }
148 } else {
149 return false;
150 }
151
152=== modified file 'PetriParse/QueryXMLParser.h'
153--- PetriParse/QueryXMLParser.h 2014-07-06 11:12:11 +0000
154+++ PetriParse/QueryXMLParser.h 2016-04-06 13:32:00 +0000
155@@ -29,6 +29,8 @@
156
157 using namespace std;
158
159+extern std::vector<std::string>* placelistbound;
160+
161 class QueryXMLParser {
162 public:
163 QueryXMLParser(const PNMLParser::TransitionEnablednessMap &transitionEnabledness);
164@@ -50,12 +52,12 @@
165 typedef Queries::iterator QueriesIterator;
166 Queries queries;
167
168- bool parse(const string& xml);
169+ bool parse(const string& xml, int query);
170 void printQueries();
171 void printQueries(int i);
172
173 private:
174- bool parsePropertySet(XMLSP::DOMElement* element);
175+ bool parsePropertySet(XMLSP::DOMElement* element, int query);
176 bool parseProperty(XMLSP::DOMElement* element);
177 bool parseTags(XMLSP::DOMElement* element);
178 bool parseFormula(XMLSP::DOMElement* element, string &queryText, bool &negateResult, bool &isPlaceBound, string &placeNameForBound);
179
180=== modified file 'VerifyPN.cpp'
181--- VerifyPN.cpp 2016-04-06 11:43:13 +0000
182+++ VerifyPN.cpp 2016-04-06 13:32:00 +0000
183@@ -94,6 +94,10 @@
184
185 bool printstatistics;
186
187+std::vector<std::string>* placelistbound = NULL; // for multiple place bounds
188+std::vector<size_t>* placelistboundindex = NULL; // list of place indexes in multiple place bounds
189+unsigned int maxplacesbound = 0;
190+
191 double diffclock(clock_t clock1, clock_t clock2){
192 double diffticks = clock1 - clock2;
193 double diffms = (diffticks*1000)/CLOCKS_PER_SEC;
194@@ -465,7 +469,7 @@
195 parser.parse(buffer.str(), &builder);
196 parser.makePetriNet();
197
198- inhibarcs = parser.getInhibitorArcs(); // Remember inhibitor arcs
199+ inhibarcs = parser.getInhibitorArcs(); // Remember inhibitor arcs
200 transitionEnabledness = parser.getTransitionEnabledness(); // Remember conditions for transitions
201
202 //Build the petri net
203@@ -528,7 +532,7 @@
204 string querystr = buffer.str(); // including EF and AG
205 //Parse XML the queries and querystr let be the index of xmlquery
206 if (xmlquery > 0) {
207- if (!XMLparser.parse(querystr)) {
208+ if (!XMLparser.parse(querystr, xmlquery)) {
209 fprintf(stderr, "Error: Failed parsing XML query file\n");
210 fprintf(stdout, "DO_NOT_COMPETE\n");
211 return ErrorCode;
212@@ -666,16 +670,26 @@
213 //-------------------------------------------------------------------//
214 //----------------------- Reachability search -----------------------//
215 //-------------------------------------------------------------------//
216+
217+ const std::vector<std::string>& tnames = net->transitionNames();
218+ const std::vector<std::string>& pnames = net->placeNames();
219+
220+ if (placelistbound != NULL) {
221+ placelistboundindex = new std::vector<size_t>;
222+ for (int i = 0; i < placelistbound->size(); i++) {
223+ for (size_t j = 0; j < pnames.size(); j++) {
224+ if (((*placelistbound)[i]) == pnames[j]) {
225+ placelistboundindex->push_back(j);
226+ }
227+ }
228+ }
229+ }
230+
231 ReachabilityResult result = strategy->reachable(*net, m0, v0, query);
232
233
234 //----------------------- Output Result -----------------------//
235
236- const std::vector<std::string>& tnames = net->transitionNames();
237- const std::vector<std::string>& pnames = net->placeNames();
238-
239-
240-
241 if (statespaceexploration) {
242 retval = UnknownCode;
243 unsigned int placeBound = 0;
244@@ -707,15 +721,27 @@
245 fprintf(stdout, "\nQuery is satisfied.\n\n");
246 } else if(retval == FailedCode) {
247 if (xmlquery>0 && XMLparser.queries[xmlquery-1].isPlaceBound) {
248+ if (placelistbound == NULL) {
249 // find index of the place for reporting place bound
250 for(size_t p = 0; p < result.maxPlaceBound().size(); p++) {
251 if (pnames[p]==XMLparser.queries[xmlquery-1].placeNameForBound) {
252 fprintf(stdout, "FORMULA %s %d TECHNIQUES SEQUENTIAL_PROCESSING EXPLICIT STRUCTURAL_REDUCTION\n", XMLparser.queries[xmlquery-1].id.c_str(), result.maxPlaceBound()[p]);
253 fprintf(stdout, "\nMaximum number of tokens in place %s: %d\n\n",XMLparser.queries[xmlquery-1].placeNameForBound.c_str(),result.maxPlaceBound()[p]);
254- retval = UnknownCode;
255+ retval = UnknownCode;
256 break;
257 }
258 }
259+ } else {
260+ fprintf(stdout, "FORMULA %s %d TECHNIQUES SEQUENTIAL_PROCESSING EXPLICIT STRUCTURAL_REDUCTION\n", XMLparser.queries[xmlquery-1].id.c_str(), maxplacesbound);
261+ fprintf(stdout, "\nMaximum number of tokens in places");
262+ for (int i = 0; i < placelistboundindex->size(); i++) {
263+ size_t index = (*placelistboundindex)[i];
264+ fprintf(stdout, " %s", pnames[index].c_str());
265+ if (i < placelistboundindex->size() - 2) fprintf(stdout, ",");
266+ if (i == placelistboundindex->size() - 2) fprintf(stdout, " and");
267+ }
268+ fprintf(stdout, ": %d\n\n", maxplacesbound);
269+ }
270 } else {
271 if (xmlquery>0) {
272 fprintf(stdout, "FORMULA %s FALSE TECHNIQUES SEQUENTIAL_PROCESSING EXPLICIT STRUCTURAL_REDUCTION\n", XMLparser.queries[xmlquery-1].id.c_str());

Subscribers

People subscribed via source and target branches