Merge lp:~tapaal-contributor/verifypn/Fix-partition-id-clash-1939939 into lp:verifypn

Proposed by Thomas Pedersen
Status: Merged
Approved by: Jiri Srba
Approved revision: 250
Merged at revision: 249
Proposed branch: lp:~tapaal-contributor/verifypn/Fix-partition-id-clash-1939939
Merge into: lp:verifypn
Diff against target: 187 lines (+54/-21)
5 files modified
include/PetriEngine/Colored/EquivalenceVec.h (+2/-0)
src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp (+17/-14)
src/PetriEngine/Colored/EquivalenceVec.cpp (+28/-2)
src/PetriEngine/Colored/IntervalGenerator.cpp (+6/-5)
src/PetriEngine/Colored/PartitionBuilder.cpp (+1/-0)
To merge this branch: bzr merge lp:~tapaal-contributor/verifypn/Fix-partition-id-clash-1939939
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Peter Gjøl Jensen Approve
Review via email: mp+407346@code.launchpad.net

Commit message

Fix place id clashing under unfolding

To post a comment you must log in.
Revision history for this message
Peter Gjøl Jensen (peter-gjoel) wrote :

Passes the consistency check.

review: Approve
Revision history for this message
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/PetriEngine/Colored/EquivalenceVec.h'
2--- include/PetriEngine/Colored/EquivalenceVec.h 2021-06-21 09:39:53 +0000
3+++ include/PetriEngine/Colored/EquivalenceVec.h 2021-08-18 16:43:45 +0000
4@@ -26,6 +26,8 @@
5 return _equivalenceClasses;
6 }
7
8+ const uint32_t getUniqueIdForColor(const Colored::Color *color) const;
9+
10
11 const std::vector<bool> & getDiagonalTuplePositions() const{
12 return _diagonalTuplePositions;
13
14=== modified file 'src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp'
15--- src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2021-07-17 13:05:59 +0000
16+++ src/PetriEngine/Colored/ColoredPetriNetBuilder.cpp 2021-08-18 16:43:45 +0000
17@@ -519,17 +519,7 @@
18 transitionHasVarOutArcs = true;
19 }
20
21- //If there is a varaible which was not found on an input arc or in the guard, we give it
22- //the full interval
23- for(auto* var : variables){
24- for(auto& varmap : transition.variableMaps){
25- if(varmap.count(var) == 0){
26- Colored::interval_vector_t intervalTuple;
27- intervalTuple.addInterval(var->colorType->getFullInterval());
28- varmap[var] = std::move(intervalTuple);
29- }
30- }
31- }
32+
33
34 //Apply partitioning to unbound outgoing variables such that
35 // bindings are only created for colors used in the rest of the net
36@@ -545,6 +535,19 @@
37 }
38 }
39 }
40+ } else {
41+ // Else if partitioning was not computed or diagonal
42+ // and there is a varaible which was not found on an input arc or in the guard,
43+ // we give it the full interval
44+ for(auto* var : variables){
45+ for(auto& varmap : transition.variableMaps){
46+ if(varmap.count(var) == 0){
47+ Colored::interval_vector_t intervalTuple;
48+ intervalTuple.addInterval(var->colorType->getFullInterval());
49+ varmap[var] = std::move(intervalTuple);
50+ }
51+ }
52+ }
53 }
54
55 auto intervals = arc.expr->getOutputIntervals(transition.variableMaps);
56@@ -712,7 +715,6 @@
57
58 void ColoredPetriNetBuilder::unfoldTransition(uint32_t transitionId) {
59 const Colored::Transition &transition = _transitions[transitionId];
60-
61 if(_fixpointDone || _partitionComputed){
62 FixpointBindingGenerator gen(transition, _colors, symmetric_var_map[transitionId]);
63 size_t i = 0;
64@@ -811,13 +813,14 @@
65 if(!_partitionComputed || _partition[arc.place].isDiagonal()){
66 id = newColor->getId();
67 } else {
68- id = _partition[arc.place].getColorEqClassMap().find(newColor)->second->id() + newColor->getId();
69+ id = _partition[arc.place].getUniqueIdForColor(newColor);
70 }
71 const std::string& pName = _ptplacenames[place.name][id];
72+
73 if (pName.empty()) {
74 unfoldPlace(&place, newColor, arc.place, id);
75 }
76-
77+
78 if (arc.input) {
79 _ptBuilder.addInputArc(pName, tName, false, color.second);
80 } else {
81
82=== modified file 'src/PetriEngine/Colored/EquivalenceVec.cpp'
83--- src/PetriEngine/Colored/EquivalenceVec.cpp 2021-06-22 13:10:13 +0000
84+++ src/PetriEngine/Colored/EquivalenceVec.cpp 2021-08-18 16:43:45 +0000
85@@ -23,7 +23,7 @@
86 }
87 }
88 newIntervalTuple.addInterval(std::move(singleInterval));
89- continue;
90+ break;
91 }
92 }
93 }
94@@ -51,7 +51,7 @@
95 }
96
97 void EquivalenceVec::addColorToEqClassMap(const Color *color){
98- for(auto& eqClass : _equivalenceClasses){
99+ for(auto& eqClass : _equivalenceClasses){
100 std::vector<uint32_t> colorIds;
101 color->getTupleId(colorIds);
102 if(eqClass.containsColor(colorIds, _diagonalTuplePositions)){
103@@ -82,5 +82,31 @@
104 }
105 }
106 }
107+
108+ //Add color ids of diagonal positions as we represent partitions with diagonal postitions
109+ //as a single equivalence class to save space, but they should not be partition together
110+ const uint32_t EquivalenceVec::getUniqueIdForColor(const Colored::Color *color) const {
111+ PetriEngine::Colored::EquivalenceClass *eqClass = _colorEQClassMap.find(color)->second;
112+
113+ std::vector<uint32_t> colorTupleIds;
114+ std::vector<uint32_t> newColorTupleIds;
115+ bool hasDiagonalPositions;
116+ color->getTupleId(colorTupleIds);
117+ for(uint32_t i = 0; i < colorTupleIds.size(); i++){
118+ if(_diagonalTuplePositions[i]){
119+ newColorTupleIds.push_back(colorTupleIds[i]);
120+ } else {
121+ hasDiagonalPositions = true;
122+ newColorTupleIds.push_back(eqClass->intervals().back().getLowerIds()[i]);
123+ }
124+ }
125+
126+ if(hasDiagonalPositions){
127+ return eqClass->id() + color->getColorType()->getColor(newColorTupleIds)->getId();
128+ }
129+
130+ return eqClass->id();
131+
132+ }
133 }
134 }
135\ No newline at end of file
136
137=== modified file 'src/PetriEngine/Colored/IntervalGenerator.cpp'
138--- src/PetriEngine/Colored/IntervalGenerator.cpp 2021-06-24 11:38:08 +0000
139+++ src/PetriEngine/Colored/IntervalGenerator.cpp 2021-08-18 16:43:45 +0000
140@@ -146,7 +146,8 @@
141 localVarMap[pair.first] = varIntervals;
142 }
143
144- if(validInterval){
145+ //Only add valid intervals. Ensure one empty map is always added if there are intervals
146+ if(validInterval && (!localVarMap.empty() || variableMaps.empty())){
147 variableMaps.push_back(std::move(localVarMap));
148 }
149 }
150@@ -159,7 +160,7 @@
151 //If we have not found intervals for any place yet, we fill the intervals from this place
152 //Else we restrict the intervals we already found to only keep those that can also be matched in this place
153 if(variableMaps.empty()){
154- fillVarMaps(variableMaps, placeArcInterval.second, intervalTupleSize, j);
155+ fillVarMaps(variableMaps, placeArcInterval.second, intervalTupleSize, j);
156 } else {
157 std::vector<VariableIntervalMap> newVarMapVec;
158
159@@ -177,13 +178,13 @@
160 }
161 }
162
163- if(allVarsAssigned){
164+ if(allVarsAssigned && (!localVarMap.empty() || newVarMapVec.empty())){
165 newVarMapVec.push_back(std::move(localVarMap));
166 }
167
168 }
169- }
170- variableMaps = std::move(newVarMapVec);
171+ }
172+ variableMaps = std::move(newVarMapVec);
173 }
174 //If we did not find any intervals for an arc, then the transition cannot be activated
175 if(variableMaps.empty()){
176
177=== modified file 'src/PetriEngine/Colored/PartitionBuilder.cpp'
178--- src/PetriEngine/Colored/PartitionBuilder.cpp 2021-07-05 21:22:08 +0000
179+++ src/PetriEngine/Colored/PartitionBuilder.cpp 2021-08-18 16:43:45 +0000
180@@ -85,6 +85,7 @@
181 if(eqVec.second.isDiagonal()){
182 continue;
183 }
184+
185 const ColorType *colorType = _places[eqVec.first].type;
186 for(uint32_t i = 0; i < colorType->size(); i++){
187 const Color *color = &(*colorType)[i];

Subscribers

People subscribed via source and target branches