3#ifdef STORM_HAVE_XERCES
13bool isOnlyWhitespace(std::string
const& in) {
14 return std::all_of(in.begin(), in.end(), [](
char c) { return std::isspace(static_cast<unsigned char>(c)); });
21 if (storm::adapters::getName(elementRoot) ==
"pnml") {
22 traversePnmlElement(elementRoot);
25 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Failed to identify the root element.\n");
27 return builder.buildGspn();
30void PnmlParser::traversePnmlElement(xercesc::DOMElement
const*
const element) {
32 for (uint_fast64_t i = 0;
i < element->getAttributes()->getLength(); ++
i) {
33 auto attr = element->getAttributes()->item(i);
34 auto name = storm::adapters::getName(attr);
42 for (uint_fast64_t i = 0;
i < element->getChildNodes()->getLength(); ++
i) {
43 auto child = element->getChildNodes()->item(i);
44 auto name = storm::adapters::getName(child);
47 traverseNetOrPage(child);
48 }
else if (isOnlyWhitespace(name)) {
58void PnmlParser::traverseNetOrPage(xercesc::DOMNode
const*
const node) {
60 for (uint_fast64_t i = 0;
i < node->getAttributes()->getLength(); ++
i) {
61 auto attr = node->getAttributes()->item(i);
62 auto name = storm::adapters::getName(attr);
65 builder.setGspnName(storm::adapters::XMLtoString(attr->getNodeValue()));
69 STORM_PRINT_AND_LOG(
"unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) +
"): " + name +
"\n");
74 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
75 auto child = node->getChildNodes()->item(i);
76 auto name = storm::adapters::getName(child);
78 if (name ==
"place") {
80 }
else if (name ==
"transition") {
81 traverseTransition(child);
82 }
else if (name ==
"arc") {
84 }
else if (name ==
"page") {
87 traverseNetOrPage(child);
88 }
else if (isOnlyWhitespace(name)) {
93 STORM_PRINT_AND_LOG(
"unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) +
"): " + name +
"\n");
98void PnmlParser::traversePlace(xercesc::DOMNode
const*
const node) {
99 std::string placeName;
101 std::pair<bool, uint_fast64_t> numberOfInitialTokens(
false, defaultNumberOfInitialTokens);
102 std::pair<bool, boost::optional<uint64_t>> capacity(
false, boost::none);
105 for (uint_fast64_t i = 0;
i < node->getAttributes()->getLength(); ++
i) {
106 auto attr = node->getAttributes()->item(i);
107 auto name = storm::adapters::getName(attr);
110 placeName = storm::adapters::XMLtoString(attr->getNodeValue());
119 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
120 auto child = node->getChildNodes()->item(i);
121 auto name = storm::adapters::getName(child);
123 if (name ==
"initialMarking") {
124 numberOfInitialTokens.first =
true;
125 numberOfInitialTokens.second = traverseInitialMarking(child);
126 }
else if (name ==
"capacity") {
127 capacity.first =
true;
128 capacity.second = traverseCapacity(child);
129 }
else if (isOnlyWhitespace(name)) {
131 }
else if (name ==
"name" || name ==
"graphics") {
140 if (!numberOfInitialTokens.first) {
145 if (!capacity.first) {
149 builder.addPlace(capacity.second, numberOfInitialTokens.first ? numberOfInitialTokens.second : 0, placeName);
152void PnmlParser::traverseTransition(xercesc::DOMNode
const*
const node) {
154 std::pair<bool, bool> timed(
false, defaultTransitionType);
155 std::pair<bool, std::string> value(
false,
"");
157 uint_fast64_t priority = defaultPriority;
160 for (uint_fast64_t i = 0;
i < node->getAttributes()->getLength(); ++
i) {
161 auto attr = node->getAttributes()->item(i);
162 auto name = storm::adapters::getName(attr);
165 id = storm::adapters::XMLtoString(attr->getNodeValue());
174 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
175 auto child = node->getChildNodes()->item(i);
176 auto name = storm::adapters::getName(child);
178 if (name ==
"rate") {
180 value.second = traverseTransitionValue(child);
181 }
else if (name ==
"timed") {
183 timed.second = traverseTransitionType(child);
184 }
else if (name ==
"priority") {
185 priority = traversePriority(child);
186 }
else if (isOnlyWhitespace(name)) {
188 }
else if (name ==
"graphics" || name ==
"name" || name ==
"orientation") {
201 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"unknown transition type (transition=" +
id +
")\n");
209 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"unknown transition rate (transition=" +
id +
")\n");
211 builder.addTimedTransition(priority, std::stod(value.second),
id);
218 builder.addImmediateTransition(priority, std::stod(value.second),
id);
222void PnmlParser::traverseArc(xercesc::DOMNode
const*
const node) {
224 std::pair<bool, std::string> source(
false,
"");
225 std::pair<bool, std::string> target(
false,
"");
226 std::pair<bool, std::string> type(
false, defaultArcType);
227 std::pair<bool, uint_fast64_t> multiplicity(
false, defaultMultiplicity);
231 for (uint_fast64_t i = 0;
i < node->getAttributes()->getLength(); ++
i) {
232 auto attr = node->getAttributes()->item(i);
233 auto name = storm::adapters::getName(attr);
235 if (name ==
"source") {
237 source.second = storm::adapters::XMLtoString(attr->getNodeValue());
238 }
else if (name ==
"target") {
240 target.second = storm::adapters::XMLtoString(attr->getNodeValue());
241 }
else if (name ==
"id") {
242 id = storm::adapters::XMLtoString(attr->getNodeValue());
251 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
252 auto child = node->getChildNodes()->item(i);
253 auto name = storm::adapters::getName(child);
254 if (name ==
"type") {
256 type.second = traverseArcType(child);
257 }
else if (name ==
"inscription") {
258 multiplicity.first =
true;
259 multiplicity.second = traverseMultiplicity(child);
260 }
else if (isOnlyWhitespace(name)) {
262 }
else if (name ==
"graphics" || name ==
"arcpath" || name ==
"tagged") {
275 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"unknown arc source (arc=" +
id +
")\n");
280 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"unknown arc target (arc=" +
id +
")\n");
282 if (!multiplicity.first) {
288 if (type.second ==
"normal") {
289 builder.addNormalArc(source.second, target.second, multiplicity.second);
290 }
else if (type.second ==
"inhibition") {
291 builder.addInhibitionArc(source.second, target.second, multiplicity.second);
293 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Arc type '" << type.second <<
"' in arc '" <<
id <<
"' is unknown.");
297uint_fast64_t PnmlParser::traverseInitialMarking(xercesc::DOMNode
const*
const node) {
298 uint_fast64_t result = defaultNumberOfInitialTokens;
299 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
300 auto child = node->getChildNodes()->item(i);
301 auto name = storm::adapters::getName(child);
302 if (name ==
"text") {
303 result = std::stoull(storm::adapters::getName(child->getFirstChild()));
304 }
else if (name ==
"value") {
305 auto value = storm::adapters::getName(child->getFirstChild());
306 value = value.substr(std::string(
"Default,").length());
307 result = std::stoull(value);
308 }
else if (isOnlyWhitespace(name)) {
310 }
else if (name ==
"graphics") {
321int_fast64_t PnmlParser::traverseCapacity(xercesc::DOMNode
const*
const node) {
322 int_fast64_t result = defaultCapacity;
323 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
324 auto child = node->getChildNodes()->item(i);
325 auto name = storm::adapters::getName(child);
326 if (name ==
"value") {
327 auto value = storm::adapters::getName(child->getFirstChild());
328 if (value.find(
"Default,") == 0) {
329 value = value.substr(std::string(
"Default,").length());
331 result = std::stoull(value);
332 }
else if (name ==
"graphics") {
334 }
else if (isOnlyWhitespace(name)) {
345uint_fast64_t PnmlParser::traverseMultiplicity(xercesc::DOMNode
const*
const node) {
346 uint_fast64_t result = defaultMultiplicity;
347 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
348 auto child = node->getChildNodes()->item(i);
349 auto name = storm::adapters::getName(child);
350 if (name ==
"value") {
351 auto value = storm::adapters::getName(child->getFirstChild());
352 if (value.find(
"Default,") == 0) {
353 value = value.substr(std::string(
"Default,").length());
355 result = std::stoull(value);
356 }
else if (name ==
"graphics") {
358 }
else if (isOnlyWhitespace(name)) {
369std::string PnmlParser::traverseTransitionValue(xercesc::DOMNode
const*
const node) {
371 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
372 auto child = node->getChildNodes()->item(i);
373 auto name = storm::adapters::getName(child);
374 if (name ==
"value") {
375 result = storm::adapters::getName(child->getFirstChild());
376 }
else if (isOnlyWhitespace(name)) {
387bool PnmlParser::traverseTransitionType(xercesc::DOMNode
const*
const node) {
389 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
390 auto child = node->getChildNodes()->item(i);
391 auto name = storm::adapters::getName(child);
392 if (name ==
"value") {
393 result = storm::adapters::getName(child->getFirstChild()) ==
"true" ? true :
false;
394 }
else if (isOnlyWhitespace(name)) {
405std::string PnmlParser::traverseArcType(xercesc::DOMNode
const*
const node) {
406 for (uint_fast64_t i = 0;
i < node->getAttributes()->getLength(); ++
i) {
407 auto attr = node->getAttributes()->item(i);
408 auto name = storm::adapters::getName(attr);
409 if (name ==
"value") {
410 return storm::adapters::XMLtoString(attr->getNodeValue());
417 return defaultArcType;
420uint_fast64_t PnmlParser::traversePriority(xercesc::DOMNode
const*
const node) {
421 uint_fast64_t result = defaultPriority;
422 for (uint_fast64_t i = 0;
i < node->getChildNodes()->getLength(); ++
i) {
423 auto child = node->getChildNodes()->item(i);
424 auto name = storm::adapters::getName(child);
425 if (name ==
"text") {
426 result = std::stoull(storm::adapters::getName(child->getFirstChild()));
427 }
else if (name ==
"value") {
428 auto value = storm::adapters::getName(child->getFirstChild());
429 value = value.substr(std::string(
"Default,").length());
430 result = std::stoull(value);
431 }
else if (isOnlyWhitespace(name)) {
433 }
else if (name ==
"graphics") {
#define STORM_LOG_THROW(cond, exception, message)
#define STORM_PRINT_AND_LOG(message)