Line data Source code
1 : /*******************************************************************************
2 : * *
3 : * Cosmos:(C)oncept et (O)utils (S)tatistique pour les (Mo)deles *
4 : * (S)tochastiques *
5 : * *
6 : * Copyright (C) 2009-2012 LSV & LACL *
7 : * Authors: Paolo Ballarini Benoît Barbot & Hilal Djafri *
8 : * Website: http://www.lsv.ens-cachan.fr/Software/cosmos *
9 : * *
10 : * This program is free software; you can redistribute it and/or modify *
11 : * it under the terms of the GNU General Public License as published by *
12 : * the Free Software Foundation; either version 3 of the License, or *
13 : * (at your option) any later version. *
14 : * *
15 : * This program is distributed in the hope that it will be useful, *
16 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 : * GNU General Public License for more details. *
19 : * *
20 : * You should have received a copy of the GNU General Public License along *
21 : * with this program; if not, write to the Free Software Foundation, Inc., *
22 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
23 : * file Gspn-Writer-Color.cpp *
24 : * Created by Benoit Barbot on 17/04/15. *
25 : *******************************************************************************
26 : */
27 :
28 : #include <assert.h>
29 : #include <sstream>
30 : #include <algorithm>
31 :
32 : #include "Gspn-Writer-Color.hpp"
33 : #include "../casesWriter.hpp"
34 :
35 : using namespace std;
36 :
37 33 : Gspn_Writer_Color::Gspn_Writer_Color(GspnType& mgspn,parameters& Q):Gspn_Writer(mgspn,Q){}
38 :
39 29 : void Gspn_Writer_Color::writeEnabledDisabledBinding(ofstream &SpnF)const{
40 29 : SpnF << "const abstractBinding* "<<objName<<"nextPossiblyEnabledBinding(size_t targettr,const abstractBinding& b,size_t *bindingNum)const {" << endl;
41 29 : SpnF << "\tswitch(lastTransition*(tr+1) + targettr){"<< endl;
42 513 : for(size_t trit = 0; trit != MyGspn.tr;++trit){
43 484 : if(!MyGspn.transitionStruct[trit].varDomain.empty())
44 1474 : for (size_t trit2= 0; trit2 != MyGspn.tr; ++trit2) {
45 2796 : set<size_t> varList = MyGspn.transitionStruct[trit2].varDomain;
46 1398 : if(!varList.empty()){
47 :
48 1398 : size_t nbp = 0;
49 1398 : size_t pivotplace = MyGspn.pl;
50 1398 : bool fallback = false;
51 36538 : for(size_t itp = 0; itp!=MyGspn.pl; ++itp){
52 : //Check that that there is at least one variable on the two arcs
53 140560 : if(MyGspn.access(MyGspn.outArcsStruct,trit,itp).isColored
54 140560 : && MyGspn.access(MyGspn.inArcsStruct,trit2,itp).isColored
55 : ){
56 : //Check that there is only one token on each arcs
57 400 : if(MyGspn.access(MyGspn.outArcsStruct,trit,itp).coloredVal.size()==1
58 400 : && MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal.size()==1){
59 : //Check that the token is not the ALL token.
60 384 : if(!MyGspn.access(MyGspn.outArcsStruct,trit,itp).coloredVal[0].hasAll &&
61 288 : !MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].hasAll){
62 96 : nbp++;
63 96 : pivotplace = itp;
64 198 : for(size_t varpt = 0;varpt < MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].field.size(); ++varpt){
65 102 : if(MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].Flags[varpt] == CT_VARIABLE){
66 102 : varList.erase(MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].field[varpt].intVal);
67 : }
68 : }
69 0 : }else fallback = true;//Handling of ALL token not yet implemented
70 : }else
71 4 : fallback= true; // Handling of several token not yet implemented
72 : } else {
73 : //Sychronization over an uncolored place
74 35040 : nbp++;
75 35040 : pivotplace= itp;
76 : }
77 : }
78 1398 : if ( nbp==1 && varList.empty() && !fallback) {
79 : // Here we implement only the case with one place one token on the arc
80 : // For all other casess fall back to enumeration.
81 0 : SpnF << "\tcase " << trit*(MyGspn.tr+1) + trit2 <<
82 0 : ":\t//" << MyGspn.transitionStruct[trit].name << "->"
83 0 : << MyGspn.placeStruct[pivotplace].name <<
84 0 : "->" << MyGspn.transitionStruct[trit2].name << endl;
85 0 : SpnF << "\t{"<< endl;
86 0 : SpnF << "\t\tif(*bindingNum==1)return NULL;" << endl; //return NULL if it is the second call
87 0 : SpnF << "\t\tsize_t btotal = b.idTotal();" << endl;
88 0 : assert(pivotplace < MyGspn.pl);
89 0 : const auto tok = MyGspn.access(MyGspn.outArcsStruct,trit,pivotplace);
90 0 : assert(tok.coloredVal.size()>0 && tok.coloredVal[0].field.size());
91 0 : const auto cc1 = tok.coloredVal[0];
92 0 : SpnF << "\t\tbtotal += " << ((cc1.varIncrement[0]
93 0 : + MyGspn.colClasses[cc1.field[0].intVal].colors.size()) % MyGspn.colClasses[cc1.field[0].intVal].colors.size() ) *
94 0 : varMultiplier(cc1.field[0].intVal) << ";"<< endl;
95 : //Compute the number of the new binding in the global numerotation.
96 :
97 0 : SpnF << "\t\tsize_t bloc = Transition[targettr].bindingLinkTable[btotal];" << endl;
98 0 : SpnF << "\t\tif(bloc==string::npos)return NULL;" << endl;
99 :
100 0 : SpnF << "\t\t*bindingNum=1;" << endl;
101 0 : SpnF << "\t\treturn &(Transition[targettr].bindingList[bloc]);" << endl;
102 0 : SpnF << "\t}"<< endl;
103 1398 : }else if(fallback){
104 4 : SpnF << "\t\t//Fallback:" << MyGspn.transitionStruct[trit].name << "->" << MyGspn.transitionStruct[trit2].name << endl;
105 1394 : } else if(varList.size() < MyGspn.transitionStruct[trit2].varDomain.size()){
106 95 : SpnF << "\t\t//Partial synch over variable: " << MyGspn.transitionStruct[trit].name << "->" << MyGspn.transitionStruct[trit2].name << " var ";
107 98 : for (set<size_t>::const_iterator itset = varList.begin(); itset != varList.end(); ++itset) {
108 3 : SpnF << MyGspn.colVars[*itset].name << ", ";
109 : }
110 95 : SpnF << "Not set" <<endl;
111 : }
112 : }
113 : }
114 : }
115 29 : SpnF << "\tdefault:"<< endl;
116 29 : SpnF << "\t\tif(*bindingNum==Transition[targettr].bindingList.size())return NULL;"<<endl;
117 29 : SpnF << "\t\t*bindingNum = *bindingNum +1;"<< endl;
118 29 : SpnF << "\t\treturn &(Transition[targettr].bindingList[*bindingNum-1]);"<< endl;
119 29 : SpnF << "}}"<< endl;
120 :
121 29 : SpnF << "const abstractBinding* "<<objName<<"nextPossiblyDisabledBinding(size_t targettr,const abstractBinding& b,size_t *bindingNum)const {" << endl;
122 29 : SpnF << "\tswitch(lastTransition*(tr+1) + targettr){"<< endl;
123 :
124 513 : for(size_t trit = 0; trit != MyGspn.tr;++trit){
125 484 : if(!MyGspn.transitionStruct[trit].varDomain.empty())
126 1474 : for (size_t trit2= 0; trit2 != MyGspn.tr; ++trit2) {
127 2796 : set<size_t> varList = MyGspn.transitionStruct[trit2].varDomain;
128 1398 : if(!varList.empty()){
129 :
130 1398 : size_t nbp = 0;
131 1398 : size_t pivotplace= MyGspn.pl;
132 1398 : bool fallback = false;
133 36538 : for(size_t itp = 0; itp!=MyGspn.pl; ++itp){
134 : //Check that that there is at least one variable on the two arcs
135 140560 : if(MyGspn.access(MyGspn.inArcsStruct,trit,itp).isColored
136 140560 : && MyGspn.access(MyGspn.inArcsStruct,trit2,itp).isColored){
137 : //Check that there is only one token on each arcs
138 448 : if(MyGspn.access(MyGspn.inArcsStruct,trit,itp).coloredVal.size()==1
139 448 : && MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal.size()==1){
140 : //Check that the token is not the ALL token.
141 444 : if(!MyGspn.access(MyGspn.inArcsStruct,trit,itp).coloredVal[0].hasAll &&
142 333 : !MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].hasAll){
143 111 : nbp++;
144 111 : pivotplace = itp;
145 229 : for(size_t varpt = 0;varpt < MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].field.size(); ++varpt){
146 118 : if(MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].Flags[varpt] == CT_VARIABLE){
147 118 : varList.erase(MyGspn.access(MyGspn.inArcsStruct,trit2,itp).coloredVal[0].field[varpt].intVal);
148 : }
149 : }
150 0 : }else fallback = true;//Handling of ALL token not yet implemented
151 : }else {
152 1 : fallback= true; // Handling of several token not yet implemented
153 : }
154 : }else {
155 : //Sychronization over an uncolored place
156 35028 : nbp++;
157 35028 : pivotplace= itp;
158 : }
159 : }
160 1398 : if ( nbp==1 && varList.empty() && !fallback) {
161 : // Here we implement only the case with one place one token on the arc
162 : // For all other casess fall back to enumeration.
163 1 : SpnF << "\tcase " << trit*(MyGspn.tr+1) + trit2 <<
164 1 : ":\t//" << MyGspn.transitionStruct[trit].name << "->"
165 1 : << MyGspn.placeStruct[pivotplace].name <<
166 4 : "->" << MyGspn.transitionStruct[trit2].name << endl;
167 1 : SpnF << "\t{"<< endl;
168 1 : SpnF << "\t\tif(*bindingNum==1)return NULL;" << endl; //return NULL if it is the second call
169 1 : SpnF << "\t\tsize_t btotal = b.idTotal();" << endl;
170 1 : assert(pivotplace < MyGspn.pl);
171 2 : const auto tok = MyGspn.access(MyGspn.inArcsStruct,trit,pivotplace);
172 1 : assert(tok.coloredVal.size()>0 && tok.coloredVal[0].field.size());
173 2 : const auto cc1 = tok.coloredVal[0];
174 2 : SpnF << "\t\tbtotal += " << ((cc1.varIncrement[0]
175 1 : + MyGspn.colClasses[cc1.field[0].intVal].colors.size()) % MyGspn.colClasses[cc1.field[0].intVal].colors.size() ) *
176 2 : varMultiplier(cc1.field[0].intVal) << ";"<< endl;
177 : //Compute the number of the new binding in the global numerotation.
178 :
179 1 : SpnF << "\t\tsize_t bloc = Transition[targettr].bindingLinkTable[btotal];" << endl;
180 1 : SpnF << "\t\tif(bloc==string::npos)return NULL;" << endl;
181 :
182 1 : SpnF << "\t\t*bindingNum=1;" << endl;
183 1 : SpnF << "\t\treturn &(Transition[targettr].bindingList[bloc]);" << endl;
184 1 : SpnF << "\t}"<< endl;
185 1397 : }else if(fallback){
186 1 : SpnF << "\t\t//Fallback:" << MyGspn.transitionStruct[trit].name << "->" << MyGspn.transitionStruct[trit2].name << endl;
187 1396 : } else if(varList.size() < MyGspn.transitionStruct[trit2].varDomain.size()){
188 99 : SpnF << "\t\t//Partial synch over variable: " << MyGspn.transitionStruct[trit].name << "->" << MyGspn.transitionStruct[trit2].name << " var ";
189 100 : for (set<size_t>::const_iterator itset = varList.begin(); itset != varList.end(); ++itset) {
190 1 : SpnF << MyGspn.colVars[*itset].name << ", ";
191 : }
192 99 : SpnF << "Not set" <<endl;
193 : }
194 : }
195 : }
196 : }
197 :
198 :
199 29 : SpnF << "\tdefault:"<< endl;
200 29 : SpnF << "\t\tif(*bindingNum==Transition[targettr].bindingList.size())return NULL;"<<endl;
201 29 : SpnF << "\t\t*bindingNum = *bindingNum +1;"<< endl;
202 29 : SpnF << "\t\treturn &(Transition[targettr].bindingList[*bindingNum-1]);"<< endl;
203 29 : SpnF << "}}"<< endl;
204 :
205 :
206 : /*SpnF << "\tconst abstractBinding* result = &(Transition[targettr].bindingList[*bindingNum]);"<< endl;
207 : SpnF << "\tif(*bindingNum==Transition[targettr].bindingList.size()-1){*bindingNum= string::npos;}"<<endl;
208 : SpnF << "\telse{*bindingNum = *bindingNum +1;};"<< endl;
209 : SpnF << "\treturn result;"<< endl;
210 : SpnF << "}"<< endl;*/
211 :
212 29 : }
213 :
214 4 : void Gspn_Writer_Color::writeEnabledDisabledBindingSet(ofstream &SpnF)const{
215 : //SpnF << "const abstMarkIter = new abstractMarkingIterator();";
216 4 : SpnF << "const abstractBinding* "<<objName<<"nextPossiblyEnabledBinding(size_t targettr,const abstractBinding& b,size_t *bindingNum)const {" << endl;
217 :
218 : // Switch sur les transitions :
219 :
220 : // 1. récupérer les variables d'entrées
221 : // 2. itérer sur les places d'entrées
222 4 : SpnF << "\t\tassert(false);" << endl;
223 : /*
224 : SpnF << "\t\tif(*bindingNum==Transition[targettr].bindingList.size())return NULL;"<<endl;
225 : SpnF << "\t\t*bindingNum = *bindingNum +1;"<< endl;
226 : SpnF << "\t\treturn &(Transition[targettr].bindingList[*bindingNum-1]);"<< endl;
227 : */
228 4 : SpnF << "}"<< endl;
229 :
230 4 : SpnF << "const abstractBinding* "<<objName<<"nextPossiblyDisabledBinding(size_t targettr,const abstractBinding& b,size_t *bindingNum)const {" << endl;
231 4 : SpnF << "\t\tassert(false);" << endl;
232 : /*
233 : SpnF << "\t\tif(*bindingNum==Transition[targettr].bindingList.size())return NULL;"<<endl;
234 : SpnF << "\t\t*bindingNum = *bindingNum +1;"<< endl;
235 : SpnF << "\t\treturn &(Transition[targettr].bindingList[*bindingNum-1]);"<< endl;
236 : */
237 4 : SpnF << "}"<< endl;
238 :
239 4 : }
240 :
241 19 : void Gspn_Writer_Color::printloot(ofstream& fs, const colorDomain& dom, size_t nesting )const{
242 : //const colorDomain& dom = MyGspn.colDoms[domain];
243 19 : if(nesting == dom.colorClassIndex.size()){
244 18 : stringstream mult;
245 9 : mult << "x.mult";
246 9 : if(P.is_domain_impl_set){
247 0 : mult << "(";
248 0 : for (size_t count = 0 ; count < dom.colorClassIndex.size(); count++ ) {
249 0 : mult << (count ==0?"":",") << "c" << count ;
250 : }
251 0 : mult << ")";
252 19 : }else for (size_t count = 0 ; count < dom.colorClassIndex.size(); count++ ) {
253 10 : mult << "[c" << count << "]";
254 : }
255 :
256 :
257 9 : fs << "\t\tif(" << mult.str() << ")\n\t\t";
258 9 : fs << "\t\t\toutprintloot << "<< mult.str();
259 9 : fs << "<< \"<\"";
260 19 : for (size_t count = 0 ; count < dom.colorClassIndex.size(); count++ ) {
261 10 : if( count > 0)fs << " << \",\"";
262 10 : fs << " << Color_"<< MyGspn.colClasses[dom.colorClassIndex[count]].name << "_names[c" << count << "]";
263 : }
264 9 : fs << "<< \">,\";\n";
265 9 : return;
266 : }
267 10 : fs << "\tfor(size_t c" << nesting << " = 0 ; c"<<nesting<<"< Color_";
268 10 : fs << MyGspn.colClasses[dom.colorClassIndex[nesting]].name << "_Total; c";
269 10 : fs << nesting << "++ )\n";
270 10 : printloot(fs, dom, nesting+1);
271 : }
272 :
273 :
274 13 : void Gspn_Writer_Color::writeDomainToken(std::ofstream &header, const colorDomain & it)const{
275 : //token class def
276 13 : header << "\nstruct " << it.tokname() << "{\n";
277 13 : vector<size_t>::const_iterator itcol;
278 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
279 14 : header << "\t" << MyGspn.colClasses[*itcol].cname() << " c" << itcol - it.colorClassIndex.begin() << ";\n";
280 : }
281 13 : header << "\tint mult;\n";
282 :
283 13 : header << "\t" << it.tokname() << "( ";
284 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
285 14 : header << " "<<MyGspn.colClasses[*itcol].cname() << " cv" << itcol - it.colorClassIndex.begin()<< " = ("<< MyGspn.colClasses[*itcol].cname() << ")0, " ;
286 : }
287 13 : header << "int v =1) {\n";
288 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
289 14 : size_t pos = itcol - it.colorClassIndex.begin();
290 14 : header << "\t\tc" << pos << "= cv"<<pos <<";\n";
291 : }
292 13 : header << "\t\tmult = v;\n\t}\n";
293 :
294 :
295 13 : header << "\t" << it.tokname() << "( ";
296 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
297 14 : header << "const "<<MyGspn.colClasses[*itcol].name << "_Token& cv" << itcol - it.colorClassIndex.begin()<< ", " ;
298 : }
299 13 : header << "int v =1) {\n";
300 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
301 14 : size_t pos = itcol - it.colorClassIndex.begin();
302 14 : header << "\t\tc" << pos << "= cv";
303 14 : header << pos << ".c0" << ";\n";
304 : }
305 13 : header << "\t\tmult = v;\n\t}\n";
306 :
307 13 : header << "\t" << it.tokname() << " operator * (size_t v){\n";
308 13 : header << "\t\tmult *= v;\n\t\treturn *this;\n\t}\n";
309 :
310 13 : header << "\tvoid print(std::ostream& out) const {\n\t\tout << mult << \"<\" <<";
311 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
312 14 : if(itcol != it.colorClassIndex.begin())header << "<< \" , \" << ";
313 14 : if( MyGspn.colClasses[*itcol].type == ColorClassType::Continuous ){
314 0 : header << "c" << itcol - it.colorClassIndex.begin();
315 : } else {
316 14 : header << " Color_"<< MyGspn.colClasses[*itcol].name << "_names[c" << itcol - it.colorClassIndex.begin() << "]";
317 : }
318 : }
319 13 : header << " << \">\";\n";
320 13 : header << "\t}\n";
321 :
322 13 : if(it.isBounded){
323 13 : header << "\tvoid iter() {\n";
324 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
325 14 : size_t pos = itcol - it.colorClassIndex.begin();
326 14 : header << "\t\tif( c" << pos << "< ("<< MyGspn.colClasses[*itcol].cname() << ")(Color_";
327 14 : header << MyGspn.colClasses[*itcol].name << "_Total - 1) )";
328 14 : header << "{ c"<< pos << " = ("<< MyGspn.colClasses[*itcol].cname() << ")(c"<< pos <<"+ 1); return;};\n";
329 14 : header << "c"<< pos << " = ("<< MyGspn.colClasses[*itcol].cname() << ")(0);\n";
330 : }
331 13 : header << "\t}\n";
332 :
333 13 : if (it.colorClassIndex.size()==1 && MyGspn.colClasses[it.colorClassIndex[0]].type == ColorClassType::Cyclic) {
334 4 : header << "\t" << it.tokname() << " next(int i)const {\n";
335 4 : header << "\t\t" << it.tokname() << " x(("<< MyGspn.colClasses[it.colorClassIndex[0]].cname() << ")((c0 +i) % Color_";
336 4 : header << MyGspn.colClasses[it.colorClassIndex[0]].name << "_Total), ";
337 4 : header << " mult);\n\t\treturn x;}\n";
338 : }
339 :
340 13 : header << "\tbool islast()const {\n\t\treturn (";
341 27 : for (itcol = it.colorClassIndex.begin(); itcol != it.colorClassIndex.end() ; ++itcol ) {
342 14 : size_t pos = itcol - it.colorClassIndex.begin();
343 14 : if (pos > 0)header << " && ";
344 14 : header << " c" << pos << "== ("<< MyGspn.colClasses[*itcol].cname() << ")(Color_";
345 14 : header << MyGspn.colClasses[*itcol].name << "_Total -1) ";
346 : }
347 13 : header << " );\n\t}\n";
348 : }
349 :
350 : /* header << "\tbool operator > (const " << it.tokname() << " x){\n";
351 : header << "\t\treturn mult > x.mult ;\n\t}\n"; // Solution temporaire, il faudrait peut-être vérifier que c'est bien des tokens du même type ?
352 : header << "\tbool operator < (const " << it.tokname() << " x){\n";
353 : header << "\t\treturn mult < x.mult ;\n\t}\n"; */
354 :
355 13 : header << "\tbool operator > (const int x){\n";
356 13 : header << "\t\treturn mult > x ;\n\t}\n";
357 13 : header << "\tbool operator < (const int x){\n";
358 13 : header << "\t\treturn mult < x ;\n\t}\n";
359 :
360 13 : header << "\tbool operator < (const " << it.tokname() << " &tok) const {\n"; // Comparaison demandée par la structure Map
361 27 : for (size_t colIndex=0; colIndex< it.colorClassIndex.size(); colIndex++ ) {
362 : // Comparaison en ordre lexico
363 14 : header << "\t\tif (c" << colIndex << " < tok.c" << colIndex << ") { return true; }\n";
364 14 : header << "\t\tif (c" << colIndex << " > tok.c" << colIndex << ") { return false; }\n";
365 : }
366 13 : header << "\t\treturn false;\n";
367 13 : header << "\t}\n";
368 :
369 13 : header << "\tbool same_color (const " << it.tokname() << " &tok) const {\n";
370 27 : for (size_t colIndex=0; colIndex< it.colorClassIndex.size(); colIndex++ ) {
371 14 : header << "\t\tif (c" << colIndex << " != tok.c" << colIndex << ") { return false; }\n";
372 : }
373 13 : header << "\t\treturn true;\n";
374 13 : header << "\t}\n";
375 :
376 :
377 :
378 13 : header << "};\n";
379 :
380 13 : }
381 :
382 9 : void Gspn_Writer_Color::writeDomainTable(std::ofstream &SpnCppFile , std::ofstream &header, const colorDomain & it)const{
383 :
384 18 : stringstream domaindecl;
385 18 : stringstream colorArgsName;
386 18 : stringstream colorArrayAccess;
387 18 : stringstream colorArrayAccess2;
388 18 : stringstream colorArrayAccess3;
389 18 : stringstream allCondition;
390 18 : stringstream forLoop;
391 18 : stringstream colorTypeFor;
392 :
393 57 : for (vector<size_t>::const_iterator it2 = it.colorClassIndex.begin();
394 38 : it2 != it.colorClassIndex.end(); ++it2 ) {
395 10 : let cc = MyGspn.colClasses[*it2];
396 10 : domaindecl << "[ Color_" << cc.name << "_Total ]";
397 10 : size_t countCol = it2 - it.colorClassIndex.begin();
398 10 : if(countCol > 0){
399 1 : colorArgsName << ",";
400 1 : allCondition << " && ";
401 1 : colorArrayAccess3 << " * ";
402 : }
403 : //, Color_"<< cc.name <<"_Total
404 10 : colorArgsName << cc.cname() << " c" << countCol;
405 10 : colorArrayAccess << "[c" << countCol << "]";
406 10 : colorArrayAccess2 << "[i" << countCol << "]";
407 10 : if( cc.staticSubclasses.empty() ){
408 10 : colorArrayAccess3 << "1";
409 : } else {
410 0 : colorArrayAccess3 << " (x.c" << countCol << " < Color_"<< cc.name << "_All ? 1 : ( "<<cc.name<< "_SubClass_Table[ x.c"<< countCol << " - Color_"<< cc.name << "_All -1 ] ? 1 : 0) ) ";
411 : }
412 :
413 10 : allCondition << "c" << countCol << " != Color_" << cc.name << "_All";
414 :
415 10 : forLoop << "\t\t\tfor( int i" <<
416 20 : countCol <<"= ( c" << countCol << " == Color_" << cc.name << "_All ? 0 : c" << countCol << ");";
417 10 : forLoop << "i" << countCol <<"< ( c" << countCol << " == Color_" << cc.name << "_All ? Color_"<< cc.name <<"_Total : c" << countCol << "+1);";
418 10 : forLoop << "i" << countCol << "++)\n";
419 :
420 10 : colorTypeFor << "\t\tfor( int i" << countCol <<"= ( x.c" << countCol << "< Color_" << cc.name << "_All ? x.c" << countCol << " :0 );";
421 10 : colorTypeFor << "i" << countCol <<"< ( x.c" << countCol << "< Color_" << cc.name << "_All ? x.c" << countCol << "+1 : Color_"<< cc.name <<"_Total);";
422 10 : colorTypeFor << "i" << countCol << "++)\n";
423 : }
424 :
425 9 : header << "struct " << it.cname() << ":";
426 :
427 18 : vector<size_t> domcontains = vector<size_t>();
428 9 : for(let it2 : it.colorClassIndex)if( count(domcontains.begin(),domcontains.end(),it2) ==0)domcontains.push_back(it2);
429 9 : for (auto it2 = domcontains.begin(); it2 != domcontains.end(); ++it2) header << (it2 == domcontains.begin()?" ":", ") << "contains_" << MyGspn.colClasses[*it2].cname();
430 9 : header << " {\n\tint mult" << domaindecl.str() << ";\n";
431 9 : header << "\t" << it.cname() << "(size_t v =0) { fill( (int*)mult ,((int*)mult) + sizeof(mult)/sizeof(int), v );}"<< endl;
432 9 : header << "\t" << it.cname() << "(" << colorArgsName.str() << ") {\n";
433 : //header << "\t\t" << "memset(&mult,0 , sizeof(mult));\n";
434 9 : header << "\t\t" << "fill( (int*)mult ,((int*)mult) + sizeof(mult)/sizeof(int), 0 );"<< endl;
435 9 : header << "\t\t" << "if(" << allCondition.str() << ")\n";
436 9 : header << "\t\t\t" << "mult" << colorArrayAccess.str() << " = 1 ;\n";
437 9 : header << "\t\telse{\n";
438 9 : header << forLoop.str() << "\t\t\t\tmult" << colorArrayAccess2.str() << " = 1 ;\n";
439 9 : header << "\t\t}\n";
440 9 : header << "\t}\n";
441 :
442 : /*header << "\t" << it.cname() << "(" << colorTypeConstructor.str() << "){" << endl;
443 : header << "\t\tfill( (int*)mult ,((int*)mult) + sizeof(mult)/sizeof(int), 0 );"<<endl;
444 : header << colorTypeFor.str();
445 : header << "\t\tmult" << colorArrayAccess2.str() << " = "<< colorArrayAccess3.str() << " ;" << endl;
446 : header << "\t}" << endl;*/
447 :
448 :
449 : // header << "\tint mult("<<
450 9 : header << "\tsize_t copyVector(vector<int> &v ,size_t s)const{\n";
451 9 : header << "\t\tcopy((int*)mult,(int*)mult + sizeof(mult)/sizeof(int), v.begin() + s );\n\t\treturn s+sizeof(mult)/sizeof(int);\n\t}\n";
452 9 : header << "\tsize_t setVector(const vector<int> &v ,size_t s){\n";
453 9 : header << "\t\tcopy(v.begin() + s, v.begin() + s + sizeof(mult)/sizeof(int), (int*)mult );\n\t\treturn s+sizeof(mult)/sizeof(int);\n\t}\n";
454 :
455 :
456 :
457 9 : header << "\t" << it.cname() << "& operator = (const " << it.cname() << "& x){\n";
458 9 : header << "\t\tcopy((int*)x.mult,(int*)x.mult + sizeof(mult)/sizeof(int),(int*)mult);\n\t\treturn *this;\n\t}\n";
459 :
460 9 : header << "\t" << it.cname() << "& operator = (const " << it.tokname() << "& x){\n";
461 9 : header << "\t\t" << "fill( (int*)mult ,((int*)mult) + sizeof(mult)/sizeof(int), 0 );"<< endl;
462 9 : header << "\t\t*this += x;\n\t\treturn *this;\n\t}\n";
463 :
464 9 : header << "\tbool operator == (const " << it.cname() << "& x){\n";
465 9 : header << "\t\treturn equal((int*)mult, ((int*)mult) + sizeof(mult)/sizeof(int), (int*)x.mult);\n\t}\n";
466 :
467 9 : header << "\tbool operator < (const " << it.cname() << "& x){\n";
468 9 : header << "\t\treturn equal((int*)mult, ((int*)mult) + sizeof(mult)/sizeof(int), (int*)x.mult,std::less<int>());\n\t}\n";
469 :
470 9 : header << "\tbool operator > (const " << it.cname() << "& x){\n";
471 9 : header << "\t\treturn equal((int*)mult, ((int*)mult) + sizeof(mult)/sizeof(int), (int*)x.mult,std::greater<int>());\n\t}\n";
472 :
473 9 : header << "\t" << it.cname() << " operator * (int v){\n";
474 9 : header << "\t\tfor(size_t count = 0 ; count < sizeof(mult)/sizeof(int);count++) ((int*)mult)[count]*= v;\n\t\treturn *this;\n\t}\n";
475 :
476 9 : header << "\t" << it.cname() << "& operator += (const " << it.cname() << "& x){\n";
477 9 : header << "\t\tfor(size_t count = 0 ; count < sizeof(mult)/sizeof(int);count++)";
478 9 : header << "\n\t\t\t((int*)mult)[count]+= ((int*)x.mult)[count] ;\n";
479 9 : header << "\t\treturn *this;\n\t}\n";
480 :
481 9 : header << "\t" << it.cname() << "& operator += (const " << it.tokname() << "& x){\n";
482 9 : header << colorTypeFor.str();
483 9 : header << "\t\tmult";
484 57 : for (vector<size_t>::const_iterator it2 = it.colorClassIndex.begin();
485 38 : it2 != it.colorClassIndex.end(); ++it2 ) {
486 10 : header << "[ i" << it2- it.colorClassIndex.begin() << " ]" ;
487 : }
488 9 : header << " += "<< colorArrayAccess3.str() << "* x.mult;\n\t\treturn *this;\n\t}\n";
489 :
490 9 : header << "\t" << it.cname() << " operator + (const " << it.tokname() << "& x) && {\n";
491 9 : header << "\t\t"<< it.cname()<< " d(*this);\n\t\td+=x;\n ";
492 9 : header << "\t\treturn d;\n\t}\n";
493 :
494 9 : header << "\t" << it.cname() << "& operator -= (const " << it.tokname() << "& x){\n";
495 9 : header << colorTypeFor.str();
496 9 : header << "\t\tmult";
497 57 : for (vector<size_t>::const_iterator it2 = it.colorClassIndex.begin();
498 38 : it2 != it.colorClassIndex.end(); ++it2 ) {
499 10 : header << "[ i" << it2- it.colorClassIndex.begin() << " ]" ;
500 : }
501 9 : header << " -= "<< colorArrayAccess3.str() << "* x.mult;\n\t\treturn *this;\n\t}\n";
502 :
503 9 : header << "\tbool operator < (const " << it.tokname() << "& x)const{\n";
504 9 : header << "\t\treturn mult";
505 57 : for (vector<size_t>::const_iterator it2 = it.colorClassIndex.begin();
506 38 : it2 != it.colorClassIndex.end(); ++it2 ) {
507 10 : header << "[ x.c" << it2- it.colorClassIndex.begin() << " ]" ;
508 : }
509 9 : header << " < x.mult;\n\t}\n";
510 :
511 9 : header << "\tbool operator >= (const " << it.tokname() << "& x)const{\n";
512 9 : header << "\t\treturn mult";
513 57 : for (vector<size_t>::const_iterator it2 = it.colorClassIndex.begin();
514 38 : it2 != it.colorClassIndex.end(); ++it2 ) {
515 10 : header << "[ x.c" << it2- it.colorClassIndex.begin() << " ]" ;
516 : }
517 9 : header << " >= x.mult;\n\t}\n";
518 :
519 9 : header << "\t" << it.cname() << " operator + (const " << it.cname() << "& x) &&{\n";
520 9 : header << "\t\t"<< it.cname() << " returnval = *this; returnval+= x;\n";
521 9 : header << "\t\treturn returnval;\n\t}\n";
522 :
523 9 : header << "\t" << it.cname() << "& operator -= (const " << it.cname() << "& x){\n";
524 9 : header << "\t\tfor(size_t count = 0 ; count < sizeof(mult)/sizeof(int);count++)";
525 9 : header << "\n\t\t\t((int*)mult)[count]-= ((int*)x.mult)[count] ;\n";
526 9 : header << "\t\treturn *this;\n\t}\n";
527 :
528 9 : header << "\t" << it.cname() << " operator - (const " << it.cname() << "& x)const{\n";
529 9 : header << "\t\t"<< it.cname() << " returnval = *this; returnval-= x;\n";
530 9 : header << "\t\treturn returnval;\n\t}\n";
531 :
532 9 : header << "\tint card (void){\n";
533 9 : header << "\tint acc=0;\n";
534 9 : header << "\t\tfor(size_t count = 0 ; count < sizeof(mult)/sizeof(int);count++)";
535 9 : header << "\n\t\t\tacc += ((int*)mult)[count] ;\n";
536 9 : header << "\t\treturn acc;\n\t}\n";
537 :
538 19 : for( let cci : domcontains){
539 10 : let cc = MyGspn.colClasses[cci];
540 10 : header << "\tvirtual void apply_perm("<< cc.cname() <<",const std::vector<size_t> &index){\n";
541 10 : header << "\t\t"<< it.cname() <<" temp = *this ;\n";
542 : //header << "\t\tstd::copy( mult, mult + sizeof(mult)/sizeof(int), temp);\n";
543 :
544 20 : stringstream forloop2;
545 20 : stringstream accessperm;
546 22 : for (auto it2 = it.colorClassIndex.begin(); it2 != it.colorClassIndex.end(); ++it2 ) {
547 12 : size_t countCol = it2 - it.colorClassIndex.begin();
548 12 : forloop2 << "\t\tfor( int i" << countCol <<"= 0 ; i" << countCol <<"< Color_"<< MyGspn.colClasses[*it2].name <<"_Total ;";
549 12 : forloop2 << "i" << countCol << "++)\n";
550 12 : if(*it2 == cci){
551 10 : accessperm << "[ index[i"<< countCol <<"] ]";
552 : }else{
553 2 : accessperm << "[ i"<< countCol <<" ]";
554 : }
555 : }
556 :
557 10 : header << forloop2.str();
558 10 : header << "\t\t\tmult" << colorArrayAccess2.str() << " = temp.mult" << accessperm.str();
559 10 : header << ";" << endl;
560 10 : header << "\t}\n";
561 : }
562 :
563 19 : for( let cci : domcontains){
564 10 : let cc = MyGspn.colClasses[cci];
565 10 : header << "\tvirtual int compare("<< cc.cname() <<",int cci,int ccj)const{\n";
566 :
567 20 : stringstream forloop2;
568 20 : stringstream accesspermi;
569 20 : stringstream accesspermj;
570 22 : for (auto it2 = it.colorClassIndex.begin(); it2 != it.colorClassIndex.end(); ++it2 ) {
571 12 : size_t countCol = it2 - it.colorClassIndex.begin();
572 12 : if(*it2 != cci){
573 2 : forloop2 << "\t\tfor( int i" << countCol <<"= 0 ; i" << countCol <<"< Color_"<< MyGspn.colClasses[*it2].name <<"_Total ;";
574 2 : forloop2 << "i" << countCol << "++)\n";
575 : }
576 12 : if(*it2 == cci){
577 10 : accesspermi << "[ cci ]";
578 10 : accesspermj << "[ ccj ]";
579 : }else{
580 2 : accesspermi << "[ i"<< countCol <<" ]";
581 2 : accesspermj << "[ i"<< countCol <<" ]";
582 : }
583 : }
584 :
585 10 : header << forloop2.str() << "\t\t{"<<endl;;
586 10 : header << "\t\t\tif(mult" << accesspermi.str() << " > mult" << accesspermj.str() <<")return 1;" << endl;
587 10 : header << "\t\t\tif(mult" << accesspermi.str() << " < mult" << accesspermj.str() <<")return -1;" << endl;
588 10 : header << "\t\t}"<< endl;
589 :
590 10 : header << "\t\treturn 0;" << endl;
591 10 : header << "\t}\n";
592 : }
593 :
594 :
595 9 : header << "};\n";
596 : //end of domain class definition
597 :
598 :
599 9 : header << it.cname() << " operator + (const " << it.tokname() << "& t1 ,const " << it.tokname() << "& t2 )\n\n;";
600 9 : header << "std::ostream& operator << (std::ostream& out, const " << it.cname() << "& x);" << endl;
601 :
602 9 : SpnCppFile << "" << it.cname() << " operator + (const " << it.tokname() << "& t1 ,const " << it.tokname() << "& t2 ){\n";
603 9 : SpnCppFile << "\t"<< it.cname() << " d; d += t1; d+=t2 ;\n";
604 9 : SpnCppFile << "\treturn d;\n}\n";
605 :
606 :
607 9 : SpnCppFile << "std::ostream& operator << (std::ostream& out, const " << it.cname();
608 9 : SpnCppFile << "& x) {\n";
609 9 : SpnCppFile << "\tstringstream outprintloot;" << endl;
610 9 : printloot(SpnCppFile, it, 0);
611 9 : SpnCppFile << "\tout << \"(\" << outprintloot.str() << \")\";" << endl;
612 9 : SpnCppFile << "\treturn out;\n}\n";
613 :
614 9 : SpnCppFile << "inline bool contains(const "<<it.cname() << "& d1, const " << it.cname() << "& d2){";
615 9 : SpnCppFile << "\treturn (d1-d2) > -1;\n";
616 9 : SpnCppFile << "}\n";
617 :
618 9 : SpnCppFile << "inline bool contains(const "<<it.cname() << "& d1, const " << it.tokname() << "& tok){";
619 9 : SpnCppFile << "\treturn d1 >= tok;\n";
620 9 : SpnCppFile << "}\n";
621 9 : }
622 :
623 4 : void Gspn_Writer_Color::writeDomainSet(std::ofstream &SpnCppFile , std::ofstream &header, const colorDomain & it)const{
624 4 : if(it.isBounded){
625 4 : header << "typedef IterableDomainGen< " << it.tokname();
626 0 : } else header << "typedef DomainGen< " << it.tokname();
627 : /* for (let it2 : it.colorClassIndex) header << (it2==it.colorClassIndex[0]?" ":", ") << "contains_" << MyGspn.colClasses[it2].cname(); */
628 4 : header << "> " << it.cname() << ";" << endl;
629 :
630 4 : SpnCppFile << "inline bool contains(const "<<it.cname() << "& d1, const " << it.cname() << "& d2){";
631 : //SpnCppFile << "\treturn (d1-d2) > -1;\n";
632 4 : SpnCppFile << "\treturn d1 >= d2;\n";
633 4 : SpnCppFile << "}\n";
634 :
635 4 : SpnCppFile << "inline bool contains(const "<<it.cname() << "& d1, const " << it.tokname() << "& tok){";
636 4 : SpnCppFile << "\treturn d1 >= tok;\n";
637 4 : SpnCppFile << "}\n";
638 :
639 4 : }
640 :
641 4 : void Gspn_Writer_Color::writeNextBindingSet(std::ofstream &SpnCppFile , std::ofstream &header)const{
642 : using namespace text_output;
643 4 : header << "#include <boost/functional/hash.hpp>" <<endl;
644 4 : header << "class abstractBindingIteratorImpl {\n";
645 4 : header << "public:\n";
646 4 : header << "\tbool isValid = false;"<< endl;
647 8 : const auto macroVar = MyGspn.computeMacroVar();
648 :
649 8 : for (let var : macroVar) {
650 4 : const auto &domain = MyGspn.colDoms[var.second.second];
651 4 : header << "//iterator on: "<< var.first << " over domain "<< domain.name << endl;
652 4 : header << "\tmap<"<< domain.tokname() << ", unsigned int>::const_iterator itMacroVar_"<< var.second.first << ";\n";
653 : }
654 :
655 8 : for (let var : MyGspn.colVars) {
656 4 : let classname = MyGspn.colDoms[var.type];
657 4 : let colclass = MyGspn.colClasses[classname.colorClassIndex[0]];
658 4 : header << "\t"<< colclass.cname() <<" itVar_" << var.name << " =";
659 4 : if(colclass.type != ColorClassType::Continuous){
660 4 : header << "Color_" << colclass.name << "_" << colclass.colors[0].name << " ;"<< endl;
661 : } else {
662 0 : header << "0; " << endl;
663 : }
664 : }
665 :
666 4 : header << "\nprivate:";
667 :
668 8 : casesHandler bindingcases("t");
669 8 : casesHandler isCoherentCases("t");
670 8 : casesHandler resetCases("t");
671 :
672 30 : for (size_t t = 0; t < MyGspn.tr ; t++){
673 52 : stringstream nextcase;
674 52 : stringstream coherentcase;
675 52 : stringstream resetcase;
676 :
677 26 : let trans = MyGspn.transitionStruct[t];
678 :
679 : //varlist is the set of all variable used by the transition.
680 52 : auto varlist = set<size_t>(trans.varDomain);
681 :
682 : //for each marcro variable i.e. a token shape :
683 54 : for (let tokmap : macroVar) {
684 28 : let tokid= tokmap.second.first;
685 : //let vardomain = MyGspn.colDoms[varmap.second.second];
686 :
687 : //currtok is a coloured tocken of the net.
688 28 : let currtok = tokmap.first;
689 :
690 : //varSet is the set of variable used in the tocken
691 53 : const auto varSet = currtok.varSet();
692 :
693 : //We compute the intersection of this macro var with the set of all variables
694 53 : vector<size_t> inter(varSet.size());
695 28 : vector<size_t>::iterator it;
696 28 : it=set_intersection(varSet.begin(),varSet.end(),varlist.begin(),varlist.end(),inter.begin());
697 28 : inter.resize(it - inter.begin());
698 :
699 : //if the intersection is empty skip this macro var
700 28 : if( !MyGspn.isInVar(currtok, t) || inter.empty() )continue;
701 : //remove variable from the list of variable.
702 25 : for(let v:inter)varlist.erase(v);
703 :
704 25 : nextcase << "//chosing Macro Var " << tokid << " -> " << currtok << endl;
705 :
706 25 : auto leading_place = MyGspn.placeStruct.size();
707 : //On choisit une place sur laquelle on iter.
708 219 : for (let place : MyGspn.placeStruct){
709 : //arcmult is a set of token labelling arc place.id -> t
710 413 : let arcmult = MyGspn.access(MyGspn.inArcsStruct, t, place.id);
711 :
712 : //The labelling of the arc contain the macrovar currtok
713 245 : if ( any_of(arcmult.coloredVal.begin(), arcmult.coloredVal.end(), [&](const coloredToken& tok){return tok==currtok;})) {
714 25 : leading_place = place.id;
715 25 : nextcase << "// place " << place.name << " is leading for " << currtok << endl;
716 :
717 25 : resetcase << "\t\t\titMacroVar_" << tokid << " = m._PL_" << place.name << ".tokens.begin();" << endl;
718 25 : resetcase << "\t\t\tisValid &= itMacroVar_" << tokid << " != m._PL_" << place.name << ".tokens.end();" << endl;
719 :
720 : //nextcase << "\t\t\tif (itMacroVar_" << tokid << " == m._PL_" << place.name << ".tokens.end())return false;" << endl;
721 25 : nextcase << "\t\t\titMacroVar_" << tokid << "++;" << endl;
722 25 : nextcase << "\t\t\tif (itMacroVar_" << tokid << " == m._PL_" << place.name << ".tokens.end()) {" << endl;
723 25 : nextcase << "\t\t\t\titMacroVar_" << tokid << " = m._PL_" << place.name << ".tokens.begin();" << endl;
724 25 : nextcase << "\t\t\t} else {" << endl;
725 50 : stringstream updatevar;
726 50 : for(size_t i=0; i< currtok.field.size();i++ )if(currtok.Flags[i]==CT_VARIABLE){
727 25 : let cvar = MyGspn.colVars[currtok.field[i].intVal];
728 25 : let classname = MyGspn.colDoms[cvar.type];
729 25 : let colclass = MyGspn.colClasses[classname.colorClassIndex[0]];
730 25 : updatevar << "\t\t\titVar_" << cvar.name << "= (" << colclass.cname() ;
731 25 : updatevar << ") (itMacroVar_" << tokid << "->first.c" << i << " - ";
732 25 : updatevar << currtok.varIncrement[i] << ");\n";
733 : }
734 25 : nextcase << "\t" << updatevar.str();
735 25 : resetcase << updatevar.str();
736 25 : nextcase << "\t\t\t\treturn true;"<< endl;
737 25 : nextcase << "\t\t\t}" << endl;
738 :
739 25 : nextcase << updatevar.str();
740 :
741 :
742 25 : break;
743 : }
744 : }
745 :
746 584 : for (let place : MyGspn.placeStruct)if(place.id != leading_place){
747 1068 : let vartemp = MyGspn.access(MyGspn.inArcsStruct, t, place.id);
748 534 : if (vartemp.containsVar(tokid)) {
749 8 : for(let tok : vartemp.coloredVal){
750 4 : coherentcase << "// check coherence for "<< currtok << " on "<< place.name << " with token ";
751 4 : text_output::operator<<(coherentcase, tok) << endl;
752 : }
753 : }
754 : }
755 : }
756 :
757 : //If no leading place iterate over the color class
758 27 : for( let varid : varlist ){
759 1 : auto& currvar = MyGspn.colVars[varid];
760 1 : const auto& vardom = MyGspn.colDoms[currvar.type];
761 1 : if(vardom.isBounded){
762 1 : nextcase << "\n\t\t\tif (itVar_" << currvar.name << " != (((size_t) Color_" << vardom.name << "_Total) - 1) ) { ";
763 1 : nextcase << "\n\t\t\t\titVar_" << currvar.name << "= ("+vardom.name +"_Color_Classe)(itVar_" << currvar.name << "+1); return true;";
764 1 : nextcase << "\n\t\t\t}";
765 1 : nextcase << "\n\t\t\titVar_" << currvar.name << " = ("+vardom.name +"_Color_Classe)0;";
766 : }
767 : }
768 :
769 26 : resetcase << "if( !isCoherent(t,m)){ next(t,m); }; " << endl;
770 :
771 26 : nextcase << "\n\t\t\treturn false;";
772 26 : bindingcases.addCase(t, nextcase.str(),MyGspn.transitionStruct[t].name);
773 26 : isCoherentCases.addCase(t, coherentcase.str(),MyGspn.transitionStruct[t].name);
774 26 : resetCases.addCase(t, resetcase.str(),MyGspn.transitionStruct[t].name);
775 : }
776 4 : header << "\n\tbool nextInterieur(size_t& t,const abstractMarkingImpl& m) {\n";
777 4 : header << bindingcases;
778 4 : header << "\nreturn false;";
779 4 : header << "\n\t}"<<endl;
780 :
781 4 : header << "public:"<< endl;
782 4 : header << "\tbool operator==(const abstractBindingIteratorImpl &other) const {"<< endl;
783 4 : header << "\t\tif(isValid != other.isValid)return false;" << endl;
784 : //all invalid iterator are equal
785 4 : header << "\t\tif(!isValid && !other.isValid)return true;" << endl;
786 8 : for (let var : macroVar) {
787 4 : header << "\t\tif(itMacroVar_"<< var.second.first << " != other.itMacroVar_"<< var.second.first << ")return false;"<< endl;
788 : }
789 4 : header << "\t\treturn true;\n\t}"<< endl;
790 4 : header << "\tbool operator!=(const abstractBindingIteratorImpl &other)const {"<<endl;
791 4 : header << "\t\treturn !(*this == other);"<< endl;
792 4 : header << "\t}"<< endl;
793 :
794 4 : header << "\tvoid reset(size_t& t,abstractMarkingImpl& m){"<< endl;
795 4 : header << "\t\tisValid = true;"<< endl;
796 4 : if (P.verbose > 4) {
797 0 : header << "\n\t\tcerr << \"abstractBindingIteratorImpl has been reset for transition.\\n\";"<<endl;
798 : }
799 8 : for (let var : MyGspn.colVars) {
800 4 : let classname = MyGspn.colDoms[var.type];
801 4 : let colclass = MyGspn.colClasses[classname.colorClassIndex[0]];
802 4 : if(colclass.type != Continuous)
803 : header << "\t\titVar_"
804 : << var.name
805 : << " = Color_"
806 : << colclass.name
807 : << "_"
808 4 : << colclass.colors[0].name
809 4 : << " ;"
810 4 : << endl;
811 :
812 : }
813 :
814 4 : header << resetCases;
815 4 : header << "\t}"<< endl;
816 :
817 : //header << "\nprivate:\n";
818 :
819 : // header << "\tsize_t _ITVAR_" << var.name << ";\n";
820 : // header << "\tbool _ISDEFITVAR_" << var.name << ";\n";
821 4 : header << "private:"<< endl;
822 4 : header << "\tstatic const abstractBindingIteratorImpl endIt();"<< endl;
823 4 : header << "\n\tbool isCoherent(size_t& t,const abstractMarkingImpl& m) {" << endl;
824 : /*for (let var : MyGspn.colVars) {
825 : header << "\t\tIsDefItVar_" << var.name << " = false;" << endl;
826 : }*/
827 8 : casesHandler bindingcasesB("t");
828 30 : for (size_t t = 0; t < MyGspn.tr ; t++){
829 52 : stringstream newcase;
830 : // liste des variables utilisé par la transition.
831 26 : const auto& trans = MyGspn.transitionStruct[t];
832 52 : auto varlist = trans.varDomain;
833 :
834 52 : vector<bool> isVisited(MyGspn.placeStruct.size(),false);
835 : /* for (let var : varlist) {
836 : auto& currvar = MyGspn.colVars[var];
837 : bool isUsed = false;
838 : for (let place : MyGspn.placeStruct) {
839 : if (isUsed) { continue; }
840 : isUsed = true;
841 : }
842 : //if (not isUsed) { newcase << "\t _ISDEFITVAR_" << currvar.name << " = true;\n"; }
843 : } */
844 :
845 : // TODO : sortir le _ISDEFITVAR_ du code généré vers le code générateur
846 : /* TO CHECK if NEEDED
847 : for (let place : MyGspn.placeStruct) {
848 : bool placeVue = false;
849 : let vartempB = MyGspn.access(MyGspn.inArcsStruct, t, place.id).coloredVal;
850 : for (const auto& vartemp : vartempB) {
851 : if (not placeVue) {
852 : if(place.colorDom != UNCOLORED_DOMAIN){
853 : newcase << "\n\t\t\tif (m._PL_" << place.name << ".tokens.empty()) { return false; }";
854 : } else {
855 : newcase << "\n\t\t\tif (m._PL_" << place.name << "==0) { return false; }";
856 : }
857 : placeVue = true;
858 : }
859 : for (size_t varnum = 0;varnum < vartemp.field.size();varnum++) {
860 : //for (let var : vartemp) {
861 : if (not (vartemp.Flags[varnum] == CT_VARIABLE)) {
862 : cerr << "Un élément de l'arc n'est pas une variable" << endl;
863 : exit(EXIT_FAILURE);
864 : }
865 : auto& currvar = MyGspn.colVars[vartemp.field[varnum].intVal];
866 : newcase << "\n\t\t\tif (IsDefItVar_" << currvar.name << ") {";
867 : newcase << "\n\t\t\t\tif (not (ItVar_" << currvar.name << " == (*ItPl_" << place.name << ").first.c" << varnum << ")) { return false; }";
868 : // Cas où la variable est déjà définie
869 : newcase << "\n\t\t\t}";
870 : newcase << "\n\t\t\telse {";
871 : // _IT_place : token ds un Domain
872 : newcase << "\n\t\t\t\tItVar_" << currvar.name << " = (*ItPl_" << place.name << ").first.c" << varnum << ";";
873 : newcase << "\n\t\t\t\tIsDefItVar_" << currvar.name << " = true;";
874 : newcase << "\n\t\t\t\t}";
875 : }
876 : }
877 : }*/
878 26 : if(trans.guard.is_concrete() && trans.guard.boolVal){
879 0 : newcase << "\n\t\t\treturn true;";
880 : } else {
881 :
882 26 : newcase << "\n\t\t\treturn " << trans.guard << ";";
883 : }
884 26 : bindingcasesB.addCase(t, newcase.str(),MyGspn.transitionStruct[t].name);
885 : }
886 : // Lister les variables, mettre des valeurs "tentatives" en parcourant les valeurs actuelles
887 : // des différents itérateurs. Si échec/Collision => forcer le next
888 : //bindingcasesB.writeCases(header);
889 4 : header << bindingcasesB << endl;
890 4 : header << "\n\t}";
891 :
892 4 : header << "\npublic:"<<endl;
893 :
894 4 : header << "\tvoid next(size_t& t,const abstractMarkingImpl& m){"<<endl;;
895 : //SpnCppFile << "\nbool abstractBindingIteratorImpl::next(size_t& t, abstractMarkingImpl& m) {";
896 4 : header << "\t\tbool is_coherent = false;"<<endl;
897 4 : if (P.verbose > 4) {
898 0 : header << "\n\t\tcerr << \"abstractBindingIteratorImpl::next has been called.\\n\";";
899 0 : header << "\n\t\tcerr << \"[Call Values :] Found New ?\" << isValid << \" Is Coherent?\" << is_coherent << \"\\n\";"<< endl;
900 : }
901 4 : header << "\t\twhile (( !is_coherent) && isValid) {"<<endl;
902 4 : header << "\t\t\tisValid = nextInterieur(t,m);"<<endl;
903 4 : header << "\t\t\tis_coherent = isCoherent(t,m);"<<endl;
904 4 : if (P.verbose > 4) {
905 0 : header << "\t\t\tcerr << \"Found New ?\" << isValid << \" Is Coherent?\" << is_coherent << \"\\n\";"<<endl;
906 : }
907 4 : header << "\t\t}"<<endl;
908 4 : header << "\t\tisValid &= is_coherent;\n"<<endl;
909 : // Tant que c'est pas cohérent, je pop le next itérateur
910 4 : header << "\t}"<<endl;
911 :
912 : // Créer une fonction qui génère concreteBinding ?
913 4 : header << "\n\tsize_t getIndex(){"<<endl;
914 : //SpnCppFile << "size_t abstractBindingIteratorImpl::getIndex() {";
915 4 : header << "\t\tsize_t accum = 0;"<<endl;
916 8 : for (let var : MyGspn.colVars) {
917 4 : size_t varclass = var.type;
918 4 : let vardom = MyGspn.colDoms[varclass];
919 4 : let varcc = MyGspn.colClasses[vardom.colorClassIndex[0]];
920 4 : if(varcc.type != ColorClassType::Continuous ){
921 4 : header << "\t\tboost::hash_combine(accum, itVar_" << var.name << " );"<<endl;
922 : }else {
923 0 : header << "\t\tboost::hash_combine(accum, itVar_" << var.name << ");"<<endl;
924 : }
925 : }
926 4 : header << "\t\treturn accum;"<< endl;;
927 4 : header << "\t}"<<endl << endl;
928 :
929 4 : header << "\tabstractBinding getBinding(){"<< endl;
930 : //header << "abstractBinding abstractBindingIteratorImpl::getBinding() {";
931 4 : header << "\t\tabstractBinding newBind;" << endl;
932 8 : for (let var : MyGspn.colVars) {
933 4 : size_t varclass = var.type;
934 4 : const auto& classname = MyGspn.colDoms[varclass].name;
935 4 : header << "\t\tnewBind.P->" << var.name << ".c0 = (" << classname << "_Color_Classe) itVar_" << var.name << ";"<< endl;
936 : }
937 4 : header << "\t\tnewBind.idcount = getIndex();"<<endl;;
938 4 : header << "\t\treturn newBind;"<< endl;
939 4 : header << "\t}"<<endl;
940 :
941 :
942 4 : header << "};\n";
943 4 : }
944 :
945 33 : void Gspn_Writer_Color::writeMarkingClasse(ofstream &SpnCppFile,ofstream &header)const{
946 45 : for(let it : MyGspn.colClasses){
947 12 : switch (it.type) {
948 : case ColorClassType::Cyclic:
949 : case ColorClassType::Asymmetric:
950 12 : header << "enum " << it.cname() << ": int {\n";
951 138 : for (let it2: it.colors ) {
952 126 : header << "\tColor_" << it.name << "_" << it2.name << ",\n";
953 : }
954 12 : header << "\tColor_" << it.name << "_Total,\n";
955 12 : header << "\tColor_"<< it.name << "_All\n";
956 12 : for( let css : it.staticSubclasses){
957 0 : header << ",\n\tColor_" << it.name << "_SubClass_" << css.name;
958 : }
959 12 : header << "\n};\n";
960 :
961 12 : header << "extern const char *Color_"<< it.name << "_names[];\n";
962 12 : break;
963 :
964 : case ColorClassType::Continuous:
965 0 : header << "typedef double "<< it.cname() << ";" << endl;
966 0 : break;
967 : }
968 12 : header << "struct contains_"<< it.cname() << "{"<< endl;
969 12 : header << "\tvirtual void apply_perm("<< it.cname() << ",const std::vector<size_t> &index)=0;"<<endl;
970 12 : header << "\tvirtual int compare("<< it.cname() << ",int,int) const =0;"<<endl;
971 12 : header << "};"<< endl;
972 :
973 12 : for( const auto &css : it.staticSubclasses){
974 0 : header << "static const bool " << it.name << "_SubClass_" << css.name;
975 0 : header << " [Color_" << it.name << "_Total]= {";
976 0 : for( auto it2 = it.colors.begin(); it2 != it.colors.end(); ++it2){
977 0 : if(it2 != it.colors.begin()) header << ",";
978 :
979 0 : header << (count_if(css.colors.begin(),css.colors.end(),[&](const color & c){return (it2->id == c.id); } )>0);
980 : }
981 0 : header << " };" << endl;
982 : }
983 12 : header << "static const bool*" << it.name << "_SubClass_Table[ " << it.staticSubclasses.size()<<"] = {" ;
984 12 : for( auto css =it.staticSubclasses.begin() ; css != it.staticSubclasses.end(); ++css){
985 0 : if(css != it.staticSubclasses.begin())header << ",";
986 0 : header << it.name << "_SubClass_" << css->name;
987 : }
988 12 : header << "};" <<endl;
989 :
990 :
991 12 : header << "inline bool contains(" << it.cname() << " c , const bool sub[]){ return sub[(int)c]; }" << endl;
992 :
993 : }
994 :
995 33 : header << "#include \"marking.hpp\"" << endl;
996 33 : header << "#include \"markingTemplate.hpp\"" << endl;
997 :
998 138 : for (vector<colorDomain>::const_iterator it = MyGspn.colDoms.begin()+1;
999 92 : it != MyGspn.colDoms.end(); ++it ) {
1000 13 : writeDomainToken(header, *it);
1001 13 : if (P.is_domain_impl_set) { writeDomainSet(SpnCppFile, header, *it); }
1002 9 : else { writeDomainTable(SpnCppFile, header, *it ); }
1003 : }
1004 :
1005 33 : Gspn_Writer::writeMarkingClasse(SpnCppFile, header);
1006 :
1007 33 : if (P.is_domain_impl_set) {
1008 4 : writeNextBindingSet(SpnCppFile, header);
1009 : }else {
1010 29 : header << "\nclass abstractBindingIteratorImpl {";
1011 29 : header << "\npublic:";
1012 29 : header << "\n\tconst static bool isValid =false;";
1013 29 : header << "\n\tvoid reset(size_t,const abstractMarkingImpl& m){};";
1014 29 : header << "\n\tvoid next(size_t& t,const abstractMarkingImpl& m){};";
1015 29 : header << "\n\tsize_t getIndex(){return 0;};";
1016 29 : header << "\n\tabstractBinding getBinding(){return abstractBinding();};";
1017 29 : header << "\n};\n";
1018 : }
1019 :
1020 33 : SpnCppFile << "\nvoid abstractBindingIterator::reset(size_t t,const abstractMarking& m) {";
1021 33 : SpnCppFile << "\n\tP->reset(t,*(m.P));";
1022 33 : SpnCppFile << "\n};";
1023 :
1024 33 : SpnCppFile << "\nbool abstractBindingIterator::isValid()const {";
1025 33 : SpnCppFile << "\n\treturn P->isValid;";
1026 33 : SpnCppFile << "\n};";
1027 :
1028 33 : SpnCppFile << "\nabstractBindingIterator::abstractBindingIterator(const abstractMarking& m) {";
1029 33 : SpnCppFile << "\n\tP = new abstractBindingIteratorImpl;";
1030 33 : SpnCppFile << "\n\t//reset(m);";
1031 33 : SpnCppFile << "\n};";
1032 :
1033 33 : SpnCppFile << "\nvoid abstractBindingIterator::next(size_t& t,const abstractMarking& m) {";
1034 33 : SpnCppFile << "\n\tP->next(t,*(m.P));";
1035 33 : SpnCppFile << "\n};";
1036 :
1037 33 : SpnCppFile << "\nabstractBindingIterator::~abstractBindingIterator() {";
1038 33 : SpnCppFile << "\n\tdelete(P);";
1039 33 : SpnCppFile << "\n};";
1040 :
1041 33 : SpnCppFile << "\nsize_t abstractBindingIterator::getIndex() {";
1042 33 : SpnCppFile << "\n\treturn P->getIndex();";
1043 33 : SpnCppFile << "\n};";
1044 :
1045 33 : SpnCppFile << "\nabstractBinding abstractBindingIterator::getBinding() {";
1046 33 : SpnCppFile << "\n\treturn P->getBinding();";
1047 33 : SpnCppFile << "\n};\n";
1048 138 : }
1049 :
|