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