Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GSPN.cpp
Go to the documentation of this file.
2
3#include <unordered_map>
4
5#include <boost/lexical_cast.hpp>
6
10
11namespace storm {
12namespace gspn {
14 return ttId | (1ull << ((sizeof(ttId) * CHAR_BIT) - 1));
15}
16
18 return itId;
19}
20
22 return (tId << 1) >> 1;
23}
24
26 return tId;
27}
28
29GSPN::GSPN(std::string const& name, std::vector<Place> const& places, std::vector<ImmediateTransition<WeightType>> const& itransitions,
30 std::vector<TimedTransition<RateType>> const& ttransitions, std::vector<TransitionPartition> const& partitions,
31 std::shared_ptr<storm::expressions::ExpressionManager> const& exprManager,
32 std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantsSubstitution)
33 : name(name),
34 places(places),
35 immediateTransitions(itransitions),
36 timedTransitions(ttransitions),
37 partitions(partitions),
38 exprManager(exprManager),
39 constantsSubstitution(constantsSubstitution) {}
40
41uint64_t GSPN::getNumberOfPlaces() const {
42 return places.size();
43}
44
46 return immediateTransitions.size();
47}
48
50 return timedTransitions.size();
51}
52
53std::vector<storm::gspn::TimedTransition<GSPN::RateType>> const& GSPN::getTimedTransitions() const {
54 return this->timedTransitions;
55}
56
57std::vector<storm::gspn::ImmediateTransition<GSPN::WeightType>> const& GSPN::getImmediateTransitions() const {
58 return this->immediateTransitions;
59}
60
61std::vector<storm::gspn::Place> const& GSPN::getPlaces() const {
62 return places;
63}
64
65std::shared_ptr<storm::gspn::Marking> GSPN::getInitialMarking(std::map<uint64_t, uint64_t>& numberOfBits, uint64_t const& numberOfTotalBits) const {
66 auto m = std::make_shared<storm::gspn::Marking>(getNumberOfPlaces(), numberOfBits, numberOfTotalBits);
67 for (auto& place : getPlaces()) {
68 m->setNumberOfTokensAt(place.getID(), place.getNumberOfInitialTokens());
69 }
70 return m;
71}
72
73std::vector<TransitionPartition> const& GSPN::getPartitions() const {
74 return partitions;
75}
76
77storm::gspn::Place const* GSPN::getPlace(uint64_t id) const {
78 if (id < places.size()) {
79 assert(places.at(id).getID() == id);
80 return &places.at(id);
81 }
82 return nullptr;
83}
84
86 if (id < places.size()) {
87 assert(places.at(id).getID() == id);
88 return &places.at(id);
89 }
90 return nullptr;
91}
92
93storm::gspn::Place const* GSPN::getPlace(std::string const& name) const {
94 for (auto& place : places) {
95 if (place.getName() == name) {
96 return &place;
97 }
98 }
99 return nullptr;
100}
101
102storm::gspn::Place* GSPN::getPlace(std::string const& name) {
103 for (auto& place : places) {
104 if (place.getName() == name) {
105 return &place;
106 }
107 }
108 return nullptr;
109}
110
112 for (auto& trans : timedTransitions) {
113 if (name == trans.getName()) {
114 return &trans;
115 }
116 }
117 return nullptr;
118}
119
121 for (auto& trans : immediateTransitions) {
122 if (name == trans.getName()) {
123 return &trans;
124 }
125 }
126 return nullptr;
127}
128
129storm::gspn::Transition const* GSPN::getTransition(std::string const& id) const {
130 auto trans = getTimedTransition(id);
131 if (trans != nullptr) {
132 return trans;
133 }
134
135 return getImmediateTransition(id);
136}
137
138std::shared_ptr<storm::expressions::ExpressionManager> const& GSPN::getExpressionManager() const {
139 return exprManager;
140}
141
142std::map<storm::expressions::Variable, storm::expressions::Expression> const& GSPN::getConstantsSubstitution() const {
143 return constantsSubstitution;
144}
145
146void GSPN::setCapacities(std::unordered_map<std::string, uint64_t> const& mapping) {
147 for (auto const& entry : mapping) {
148 storm::gspn::Place* place = getPlace(entry.first);
149 STORM_LOG_THROW(place != nullptr, storm::exceptions::InvalidArgumentException, "No place with name " << entry.first);
150 place->setCapacity(entry.second);
151 }
152}
153
154void GSPN::writeDotToStream(std::ostream& outStream) const {
155 outStream << "digraph " << this->getName() << " {\n";
156
157 // print places with initial marking (not printed is the capacity)
158 outStream << "\t" << "node [shape=ellipse]\n";
159 for (auto& place : this->getPlaces()) {
160 outStream << "\t" << place.getName() << " [label=\"" << place.getName() << "(" << place.getNumberOfInitialTokens();
161 outStream << ")\"];\n";
162 }
163
164 // print transitions with weight/rate
165 outStream << "\t" << "node [shape=box]\n";
166
167 for (auto& trans : this->getImmediateTransitions()) {
168 outStream << "\t" << trans.getName() << " [fontcolor=white, style=filled, fillcolor=black, label=<" << trans.getName()
169 << "<br/><FONT POINT-SIZE=\"10\"> π = " + std::to_string(trans.getPriority()) << "</FONT>>];\n";
170 }
171
172 for (auto& trans : this->getTimedTransitions()) {
173 outStream << "\t" << trans.getName() << " [label=\"" << trans.getName();
174 outStream << "(" << trans.getRate() << ")\"];\n";
175 STORM_LOG_WARN_COND(trans.hasSingleServerSemantics(), "Unable to export non-trivial transition semantics"); // TODO
176 }
177
178 // print arcs
179 for (auto& trans : this->getImmediateTransitions()) {
180 for (auto const& inEntry : trans.getInputPlaces()) {
181 if (trans.getOutputPlaces().count(inEntry.first) == 0) {
182 outStream << "\t" << places.at(inEntry.first).getName() << " -> " << trans.getName() << "[label=\""
183 << (inEntry.second > 1 ? std::to_string(inEntry.second) : "") << "\"];\n";
184 }
185 }
186
187 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
188 if (trans.getOutputPlaces().count(inhEntry.first) == 0) {
189 outStream << "\t" << places.at(inhEntry.first).getName() << " -> " << trans.getName() << "[arrowhead=\"dot\", label=\""
190 << (inhEntry.second > 1 ? std::to_string(inhEntry.second) : "") << "\"];\n";
191 }
192 }
193
194 for (auto const& outEntry : trans.getOutputPlaces()) {
195 if (trans.getInhibitionPlaces().count(outEntry.first) == 1) {
196 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[arrowtail=\"dot\", label=\""
197 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\", dir=both];\n";
198 } else if (trans.getInputPlaces().count(outEntry.first) == 1) {
199 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[label=\""
200 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\", dir=both];\n";
201 } else {
202 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[label=\""
203 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\"];\n";
204 }
205 }
206 }
207
208 for (auto& trans : this->getTimedTransitions()) {
209 for (auto const& inEntry : trans.getInputPlaces()) {
210 if (trans.getOutputPlaces().count(inEntry.first) == 0) {
211 outStream << "\t" << places.at(inEntry.first).getName() << " -> " << trans.getName() << "[label=\""
212 << (inEntry.second > 1 ? std::to_string(inEntry.second) : "") << "\"];\n";
213 }
214 }
215
216 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
217 if (trans.getOutputPlaces().count(inhEntry.first) == 0) {
218 outStream << "\t" << places.at(inhEntry.first).getName() << " -> " << trans.getName() << "[arrowhead=\"dot\", label=\""
219 << (inhEntry.second > 1 ? std::to_string(inhEntry.second) : "") << "\"];\n";
220 }
221 }
222
223 for (auto const& outEntry : trans.getOutputPlaces()) {
224 if (trans.getInhibitionPlaces().count(outEntry.first) == 1) {
225 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[arrowtail=\"dot\", label=\""
226 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\", dir=both];\n";
227 } else if (trans.getInputPlaces().count(outEntry.first) == 1) {
228 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[label=\""
229 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\", dir=both];\n";
230 } else {
231 outStream << "\t" << trans.getName() << " -> " << places.at(outEntry.first).getName() << "[label=\""
232 << (outEntry.second > 1 ? std::to_string(outEntry.second) : "") << "\"];\n";
233 }
234 }
235 }
236
237 outStream << "}\n";
238}
239
240void GSPN::setName(std::string const& name) {
241 this->name = name;
242}
243
244std::string const& GSPN::getName() const {
245 return this->name;
246}
247
248bool GSPN::isValid() const {
249 bool result = true;
250 result |= testPlaces();
251 result |= testTransitions();
252
253 return result;
254}
255
256bool GSPN::testPlaces() const {
257 std::vector<std::string> namesOfPlaces;
258 std::vector<uint64_t> idsOfPlaces;
259 bool result = true;
260
261 for (auto const& place : this->getPlaces()) {
262 if (std::find(namesOfPlaces.begin(), namesOfPlaces.end(), place.getName()) != namesOfPlaces.end()) {
263 STORM_PRINT_AND_LOG("duplicates states with the name \"" + place.getName() + "\"\n");
264 result = false;
265 }
266
267 if (std::find(idsOfPlaces.begin(), idsOfPlaces.end(), place.getID()) != idsOfPlaces.end()) {
268 STORM_PRINT_AND_LOG("duplicates states with the id \"" + boost::lexical_cast<std::string>(place.getID()) + "\"\n");
269 result = false;
270 }
271
272 if (place.getNumberOfInitialTokens() > place.getNumberOfInitialTokens()) {
273 STORM_PRINT_AND_LOG("number of initial tokens is greater than the capacity for place \"" + place.getName() + "\"\n");
274 result = false;
275 }
276 }
277
278 return result;
279}
280
281bool GSPN::testTransitions() const {
282 bool result = true;
283
284 // for (auto const& transition : this->getImmediateTransitions()) {
285 // if (transition.getInputPlaces().empty() &&
286 // transition.getInhibitionPlaces().empty()) {
287 // STORM_PRINT_AND_LOG("transition \"" + transition.getName() + "\" has no input or inhibition place\n")
288 // result = false;
289 // }
290 //
291 // if (transition.getOutputPlaces().empty()) {
292 // STORM_PRINT_AND_LOG("transition \"" + transition.getName() + "\" has no output place\n")
293 // result = false;
294 // }
295 // }
296 //
297 // for (auto const& transition : this->getTimedTransitions()) {
298 // if (transition.getInputPlaces().empty() &&
299 // transition.getInputPlaces().empty()) {
300 // STORM_PRINT_AND_LOG("transition \"" + transition.getName() + "\" has no input or inhibition place\n")
301 // result = false;
302 // }
303 //
304 // if (transition.getOutputPlaces().empty()) {
305 // STORM_PRINT_AND_LOG("transition \"" + transition.getName() + "\" has no output place\n")
306 // result = false;
307 // }
308 // }
309 //
310 // //test if places exists in the gspn
311 // for (auto const& transition : this->getImmediateTransitions()) {
312 // for (auto &placePtr : transition.getInputPlaces()) {
313 // bool foundPlace = false;
314 // for (auto const& place : places) {
315 // if (place.getName() == placePtr->getName()) {
316 // foundPlace = true;
317 // }
318 // }
319 // if (!foundPlace) {
320 // STORM_PRINT_AND_LOG("input place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found \n")
321 // result = false;
322 // }
323 // }
324 //
325 // for (auto &placePtr : transition.getInhibitionPlaces()) {
326 // bool foundPlace = false;
327 // for (auto const& place : places) {
328 // if (place.getName() == placePtr->getName()) {
329 // foundPlace = true;
330 // }
331 // }
332 // if (!foundPlace) {
333 // STORM_PRINT_AND_LOG("inhibition place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found
334 // \n") result = false;
335 // }
336 // }
337 //
338 // for (auto &placePtr : transition.getOutputPlaces()) {
339 // bool foundPlace = false;
340 // for (auto const& place : places) {
341 // if (place.getName() == placePtr->getName()) {
342 // foundPlace = true;
343 // }
344 // }
345 // if (!foundPlace) {
346 // STORM_PRINT_AND_LOG("output place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found
347 // \n") result = false;
348 // }
349 // }
350 // }
351 //
352 // for (auto const& transition : this->getTimedTransitions()) {
353 // for (auto &placePtr : transition.getInputPlaces()) {
354 // bool foundPlace = false;
355 // for (auto const& place : places) {
356 // if (place.getName() == placePtr->getName()) {
357 // foundPlace = true;
358 // }
359 // }
360 // if (!foundPlace) {
361 // STORM_PRINT_AND_LOG("input place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found \n")
362 // result = false;
363 // }
364 // }
365 //
366 // for (auto &placePtr : transition.getInhibitionPlaces()) {
367 // bool foundPlace = false;
368 // for (auto const& place : places) {
369 // if (place.getName() == placePtr->getName()) {
370 // foundPlace = true;
371 // }
372 // }
373 // if (!foundPlace) {
374 // STORM_PRINT_AND_LOG("inhibition place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found
375 // \n") result = false;
376 // }
377 // }
378 //
379 // for (auto &placePtr : transition.getOutputPlaces()) {
380 // bool foundPlace = false;
381 // for (auto const& place : places) {
382 // if (place.getName() == placePtr->getName()) {
383 // foundPlace = true;
384 // }
385 // }
386 // if (!foundPlace) {
387 // STORM_PRINT_AND_LOG("output place \"" + placePtr->getName() + "\" of transition \"" + transition.getName() + "\" was not found
388 // \n") result = false;
389 // }
390 // }
391 // }
392
393 return result;
394}
395
396void GSPN::setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layout) const {
397 placeLayout[placeId] = layout;
398}
399void GSPN::setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const& layout) const {
400 transitionLayout[transitionId] = layout;
401}
402
403void GSPN::setPlaceLayoutInfo(std::map<uint64_t, LayoutInfo> const& placeLayout) const {
404 this->placeLayout = placeLayout;
405}
406void GSPN::setTransitionLayoutInfo(std::map<uint64_t, LayoutInfo> const& transitionLayout) const {
407 this->transitionLayout = transitionLayout;
408}
409
410std::map<uint64_t, LayoutInfo> const& GSPN::getPlaceLayoutInfos() const {
411 return this->placeLayout;
412}
413
414std::map<uint64_t, LayoutInfo> const& GSPN::getTransitionLayoutInfos() const {
415 return this->transitionLayout;
416}
417
418void GSPN::toPnpro(std::ostream& stream) const {
419 auto space = " ";
420 auto space2 = " ";
421 auto space3 = " ";
422 auto projectName = "storm-export"; // TODO add to args
423 stream << "<project name=\"" << projectName << "\" version=\"121\">\n";
424 stream << space << "<gspn name=\"" << getName() << "\" >\n";
425
426 u_int32_t x = 1;
427 stream << space2 << "<nodes>\n";
428 for (auto& place : places) {
429 stream << space3 << "<place marking=\"" << place.getNumberOfInitialTokens() << "\" ";
430 stream << "name =\"" << place.getName() << "\" ";
431 if (placeLayout.count(place.getID()) > 0) {
432 stream << "x=\"" << placeLayout.at(place.getID()).x << "\" ";
433 stream << "y=\"" << placeLayout.at(place.getID()).y << "\" ";
434 } else {
435 stream << "x=\"" << x << "\" ";
436 stream << "y=\"1\" ";
437 }
438 stream << "/>\n";
439 x = x + 3;
440 }
441 x = 1;
442 for (auto& trans : timedTransitions) {
443 stream << space3 << "<transition name=\"" << trans.getName() << "\" ";
444 stream << "type=\"EXP\" ";
445 // stream << "nservers-x=\"" << trans.getRate() << "\" ";
446 // Use single-server semantics for GSPNs:
447 // timed rates are independent of number of tokens in input places
448 stream << "nservers=\"1\" ";
449 // Note: The rate is translated to a number showing the decimal figures so GreatSPN can process it
450 stream << "delay=\"" << std::showpoint << trans.getRate() << "\" ";
451 if (transitionLayout.count(trans.getID()) > 0) {
452 stream << "x=\"" << transitionLayout.at(trans.getID()).x << "\" ";
453 stream << "y=\"" << transitionLayout.at(trans.getID()).y << "\" ";
454 } else {
455 stream << "x=\"" << x << "\" ";
456 stream << "y=\"4\" ";
457 }
458 stream << "/>\n";
459 x = x + 3;
460 }
461 for (auto& trans : immediateTransitions) {
462 stream << space3 << "<transition name=\"" << trans.getName() << "\" ";
463 stream << "type=\"IMM\" ";
464 stream << "priority=\"" << trans.getPriority() << "\" ";
465 stream << "weight=\"" << trans.getWeight() << "\" ";
466 if (transitionLayout.count(trans.getID()) > 0) {
467 stream << "x=\"" << transitionLayout.at(trans.getID()).x << "\" ";
468 stream << "y=\"" << transitionLayout.at(trans.getID()).y << "\" ";
469 } else {
470 stream << "x=\"" << x << "\" ";
471 stream << "y=\"4\" ";
472 }
473 stream << "/>\n";
474 x = x + 3;
475 }
476 stream << space2 << "</nodes>\n";
477
478 stream << space2 << "<edges>\n";
479 for (auto& trans : timedTransitions) {
480 for (auto const& inEntry : trans.getInputPlaces()) {
481 stream << space3 << "<arc ";
482 stream << "head=\"" << trans.getName() << "\" ";
483 stream << "tail=\"" << places.at(inEntry.first).getName() << "\" ";
484 stream << "kind=\"INPUT\" ";
485 stream << "mult=\"" << inEntry.second << "\" ";
486 stream << "/>\n";
487 }
488 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
489 stream << space3 << "<arc ";
490 stream << "head=\"" << trans.getName() << "\" ";
491 stream << "tail=\"" << places.at(inhEntry.first).getName() << "\" ";
492 stream << "kind=\"INHIBITOR\" ";
493 stream << "mult=\"" << inhEntry.second << "\" ";
494 stream << "/>\n";
495 }
496 for (auto const& outEntry : trans.getOutputPlaces()) {
497 stream << space3 << "<arc ";
498 stream << "head=\"" << places.at(outEntry.first).getName() << "\" ";
499 stream << "tail=\"" << trans.getName() << "\" ";
500 stream << "kind=\"OUTPUT\" ";
501 stream << "mult=\"" << outEntry.second << "\" ";
502 stream << "/>\n";
503 }
504 }
505 for (auto& trans : immediateTransitions) {
506 for (auto const& inEntry : trans.getInputPlaces()) {
507 stream << space3 << "<arc ";
508 stream << "head=\"" << trans.getName() << "\" ";
509 stream << "tail=\"" << places.at(inEntry.first).getName() << "\" ";
510 stream << "kind=\"INPUT\" ";
511 stream << "mult=\"" << inEntry.second << "\" ";
512 stream << "/>\n";
513 }
514 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
515 stream << space3 << "<arc ";
516 stream << "head=\"" << trans.getName() << "\" ";
517 stream << "tail=\"" << places.at(inhEntry.first).getName() << "\" ";
518 stream << "kind=\"INHIBITOR\" ";
519 stream << "mult=\"" << inhEntry.second << "\" ";
520 stream << "/>\n";
521 }
522 for (auto const& outEntry : trans.getOutputPlaces()) {
523 stream << space3 << "<arc ";
524 stream << "head=\"" << places.at(outEntry.first).getName() << "\" ";
525 stream << "tail=\"" << trans.getName() << "\" ";
526 stream << "kind=\"OUTPUT\" ";
527 stream << "mult=\"" << outEntry.second << "\" ";
528 stream << "/>\n";
529 }
530 }
531 stream << space2 << "</edges>\n";
532 stream << space << "</gspn>\n";
533 stream << "</project>\n";
534}
535
536void GSPN::toPnml(std::ostream& stream) const {
537 std::string space = " ";
538 std::string space2 = " ";
539 std::string space3 = " ";
540 std::string space4 = " ";
541
542 stream << "<pnml>\n";
543 stream << space << "<net id=\"" << getName() << "\">\n";
544
545 // add places
546 for (const auto& place : places) {
547 stream << space2 << "<place id=\"" << place.getName() << "\">\n";
548 stream << space3 << "<initialMarking>\n";
549 stream << space4 << "<value>Default," << place.getNumberOfInitialTokens() << "</value>\n";
550 stream << space3 << "</initialMarking>\n";
551 if (place.hasRestrictedCapacity()) {
552 stream << space3 << "<capacity>\n";
553 stream << space4 << "<value>Default," << place.getCapacity() << "</value>\n";
554 stream << space3 << "</capacity>\n";
555 }
556 stream << space2 << "</place>\n";
557 }
558
559 // add immediate transitions
560 for (const auto& trans : immediateTransitions) {
561 stream << space2 << "<transition id=\"" << trans.getName() << "\">\n";
562 stream << space3 << "<rate>\n";
563 stream << space4 << "<value>" << trans.getWeight() << "</value>\n";
564 stream << space3 << "</rate>\n";
565 stream << space3 << "<timed>\n";
566 stream << space4 << "<value>false</value>\n";
567 stream << space3 << "</timed>\n";
568 stream << space2 << "</transition>\n";
569 }
570
571 // add timed transitions
572 for (const auto& trans : timedTransitions) {
573 STORM_LOG_WARN_COND(trans.hasInfiniteServerSemantics(), "Unable to export non-trivial transition semantics"); // TODO
574 stream << space2 << "<transition id=\"" << trans.getName() << "\">\n";
575 stream << space3 << "<rate>\n";
576 stream << space4 << "<value>" << trans.getRate() << "</value>\n";
577 stream << space3 << "</rate>\n";
578 stream << space3 << "<timed>\n";
579 stream << space4 << "<value>true</value>\n";
580 stream << space3 << "</timed>\n";
581 stream << space2 << "</transition>\n";
582 }
583
584 uint64_t i = 0;
585 // add arcs for immediate transitions
586 for (const auto& trans : immediateTransitions) {
587 // add input arcs
588 for (auto const& inEntry : trans.getInputPlaces()) {
589 stream << space2 << "<arc ";
590 stream << "id=\"arc" << i++ << "\" ";
591 stream << "source=\"" << places.at(inEntry.first).getName() << "\" ";
592 stream << "target=\"" << trans.getName() << "\" ";
593 stream << ">\n";
594
595 stream << space3 << "<inscription>\n";
596 stream << space4 << "<value>Default," << inEntry.second << "</value>\n";
597 stream << space3 << "</inscription>\n";
598
599 stream << space3 << "<type value=\"normal\" />\n";
600
601 stream << space2 << "</arc>\n";
602 }
603
604 // add inhibition arcs
605 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
606 stream << space2 << "<arc ";
607 stream << "id=\"arc" << i++ << "\" ";
608 stream << "source=\"" << places.at(inhEntry.first).getName() << "\" ";
609 stream << "target=\"" << trans.getName() << "\" ";
610 stream << ">\n";
611
612 stream << space3 << "<inscription>\n";
613 stream << space4 << "<value>Default," << inhEntry.second << "</value>\n";
614 stream << space3 << "</inscription>\n";
615
616 stream << space3 << "<type value=\"inhibition\" />\n";
617
618 stream << space2 << "</arc>\n";
619 }
620
621 // add output arcs
622 for (auto const& outEntry : trans.getOutputPlaces()) {
623 stream << space2 << "<arc ";
624 stream << "id=\"arc" << i++ << "\" ";
625 stream << "source=\"" << trans.getName() << "\" ";
626 stream << "target=\"" << places.at(outEntry.first).getName() << "\" ";
627 stream << ">\n";
628
629 stream << space3 << "<inscription>\n";
630 stream << space4 << "<value>Default," << outEntry.second << "</value>\n";
631 stream << space3 << "</inscription>\n";
632
633 stream << space3 << "<type value=\"normal\" />\n";
634
635 stream << space2 << "</arc>\n";
636 }
637 }
638
639 // add arcs for immediate transitions
640 for (const auto& trans : timedTransitions) {
641 // add input arcs
642 for (auto const& inEntry : trans.getInputPlaces()) {
643 stream << space2 << "<arc ";
644 stream << "id=\"arc" << i++ << "\" ";
645 stream << "source=\"" << places.at(inEntry.first).getName() << "\" ";
646 stream << "target=\"" << trans.getName() << "\" ";
647 stream << ">\n";
648
649 stream << space3 << "<inscription>\n";
650 stream << space4 << "<value>Default," << inEntry.second << "</value>\n";
651 stream << space3 << "</inscription>\n";
652
653 stream << space3 << "<type value=\"normal\" />\n";
654
655 stream << space2 << "</arc>\n";
656 }
657
658 // add inhibition arcs
659 for (auto const& inhEntry : trans.getInhibitionPlaces()) {
660 stream << space2 << "<arc ";
661 stream << "id=\"arc" << i++ << "\" ";
662 stream << "source=\"" << places.at(inhEntry.first).getName() << "\" ";
663 stream << "target=\"" << trans.getName() << "\" ";
664 stream << ">\n";
665
666 stream << space3 << "<inscription>\n";
667 stream << space4 << "<value>Default," << inhEntry.second << "</value>\n";
668 stream << space3 << "</inscription>\n";
669
670 stream << space3 << "<type value=\"inhibition\" />\n";
671
672 stream << space2 << "</arc>\n";
673 }
674
675 // add output arcs
676 for (auto const& outEntry : trans.getOutputPlaces()) {
677 stream << space2 << "<arc ";
678 stream << "id=\"arc" << i++ << "\" ";
679 stream << "source=\"" << trans.getName() << "\" ";
680 stream << "target=\"" << places.at(outEntry.first).getName() << "\" ";
681 stream << ">\n";
682
683 stream << space3 << "<inscription>\n";
684 stream << space4 << "<value>Default," << outEntry.second << "</value>\n";
685 stream << space3 << "</inscription>\n";
686
687 stream << space3 << "<type value=\"normal\" />\n";
688
689 stream << space2 << "</arc>\n";
690 }
691 }
692
693 stream << space << "</net>\n";
694 stream << "</pnml>\n";
695}
696
697void GSPN::toJson(std::ostream& stream) const {
698 return storm::gspn::GspnJsonExporter::toStream(*this, stream);
699}
700
701void GSPN::writeStatsToStream(std::ostream& stream) const {
702 stream << "Number of places: " << getNumberOfPlaces() << '\n';
703 stream << "Number of timed transitions: " << getNumberOfTimedTransitions() << '\n';
704 stream << "Number of immediate transitions: " << getNumberOfImmediateTransitions() << '\n';
705}
706} // namespace gspn
707} // namespace storm
bool isValid() const
Performe some checks.
Definition GSPN.cpp:248
static uint64_t immediateTransitionIdToTransitionId(uint64_t)
Definition GSPN.cpp:17
uint64_t getNumberOfPlaces() const
Returns the number of places in this gspn.
Definition GSPN.cpp:41
static uint64_t timedTransitionIdToTransitionId(uint64_t)
Definition GSPN.cpp:13
storm::gspn::ImmediateTransition< GSPN::WeightType > const * getImmediateTransition(std::string const &name) const
Returns the immediate transition with the corresponding name.
Definition GSPN.cpp:120
uint64_t getNumberOfTimedTransitions() const
Definition GSPN.cpp:49
uint64_t getNumberOfImmediateTransitions() const
Definition GSPN.cpp:45
void toPnml(std::ostream &stream) const
Definition GSPN.cpp:536
void setName(std::string const &name)
Set the name of the gspn to the given name.
Definition GSPN.cpp:240
void setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const &layout) const
Definition GSPN.cpp:399
std::map< uint64_t, LayoutInfo > const & getTransitionLayoutInfos() const
Definition GSPN.cpp:414
GSPN(std::string const &name, std::vector< Place > const &places, std::vector< ImmediateTransition< WeightType > > const &itransitions, std::vector< TimedTransition< RateType > > const &ttransitions, std::vector< TransitionPartition > const &partitions, std::shared_ptr< storm::expressions::ExpressionManager > const &exprManager, std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantsSubstitution=std::map< storm::expressions::Variable, storm::expressions::Expression >())
Definition GSPN.cpp:29
std::vector< ImmediateTransition< GSPN::WeightType > > const & getImmediateTransitions() const
Returns the vector of immediate transitions in this gspn.
Definition GSPN.cpp:57
void setCapacities(std::unordered_map< std::string, uint64_t > const &mapping)
Set Capacities of places according to name->capacity map.
Definition GSPN.cpp:146
static uint64_t transitionIdToTimedTransitionId(uint64_t)
Definition GSPN.cpp:21
std::shared_ptr< storm::gspn::Marking > getInitialMarking(std::map< uint64_t, uint64_t > &numberOfBits, uint64_t const &numberOfTotalBits) const
Definition GSPN.cpp:65
void toJson(std::ostream &stream) const
Export GSPN in Json format.
Definition GSPN.cpp:697
std::map< storm::expressions::Variable, storm::expressions::Expression > const & getConstantsSubstitution() const
Gets an assignment of occurring constants of the GSPN to their value.
Definition GSPN.cpp:142
void writeStatsToStream(std::ostream &stream) const
Definition GSPN.cpp:701
std::vector< TransitionPartition > const & getPartitions() const
Definition GSPN.cpp:73
std::vector< storm::gspn::Place > const & getPlaces() const
Returns the places of this gspn.
Definition GSPN.cpp:61
std::map< uint64_t, LayoutInfo > const & getPlaceLayoutInfos() const
Definition GSPN.cpp:410
storm::gspn::Transition const * getTransition(std::string const &name) const
Returns the transition with the corresponding name.
Definition GSPN.cpp:129
void setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const &layout) const
Definition GSPN.cpp:396
void toPnpro(std::ostream &stream) const
Definition GSPN.cpp:418
storm::gspn::TimedTransition< GSPN::RateType > const * getTimedTransition(std::string const &name) const
Returns the timed transition with the corresponding name.
Definition GSPN.cpp:111
std::shared_ptr< storm::expressions::ExpressionManager > const & getExpressionManager() const
Obtain the expression manager used for expressions over GSPNs.
Definition GSPN.cpp:138
storm::gspn::Place const * getPlace(uint64_t id) const
Returns the place with the corresponding id.
Definition GSPN.cpp:77
static uint64_t transitionIdToImmediateTransitionId(uint64_t)
Definition GSPN.cpp:25
std::vector< TimedTransition< GSPN::RateType > > const & getTimedTransitions() const
Returns the vector of timed transitions in this gspn.
Definition GSPN.cpp:53
std::string const & getName() const
Returns the name of the gspn.
Definition GSPN.cpp:244
void writeDotToStream(std::ostream &outStream) const
Write the gspn in a dot(graphviz) configuration.
Definition GSPN.cpp:154
static void toStream(storm::gspn::GSPN const &gspn, std::ostream &os)
This class provides methods to store and retrieve data for a place in a gspn.
Definition Place.h:12
void setCapacity(boost::optional< uint64_t > const &capacity)
Sets the capacity of tokens of this place.
Definition Place.cpp:30
This class represents a transition in a gspn.
Definition Transition.h:14
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
#define STORM_PRINT_AND_LOG(message)
Definition macros.h:68
LabParser.cpp.
Definition cli.cpp:18