Browse Source

add priorities to the parser and an example

Former-commit-id: 1b072a730e
tempestpy_adaptions
ThomasH 8 years ago
parent
commit
3854feae87
  1. 3
      examples/gspn/tiny/tiny01.pnml
  2. 29
      src/parser/GspnParser.cpp
  3. 10
      src/parser/GspnParser.h

3
examples/gspn/tiny/tiny01.pnml

@ -74,6 +74,9 @@
<timed>
<value>true</value>
</timed>
<priority>
<text>2</text>
</priority>
</transition>
<arc id="arc1" source="p1" target="t1">
<inscription>

29
src/parser/GspnParser.cpp

@ -188,6 +188,7 @@ namespace storm {
std::pair<bool, bool> timed(false, defaultTransitionType);
std::pair<bool, std::string> value(false, defaultTransitionValue);
std::string id;
uint_fast64_t priority;
// parse attributes
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) {
@ -207,11 +208,13 @@ namespace storm {
auto name = getName(child);
if (name.compare("rate") == 0) {
value.first =true;
value.first = true;
value.second = traverseTransitionValue(child);
} else if (name.compare("timed") == 0) {
timed.first = true;
timed.second = traverseTransitionType(child);
} else if (name.compare("priority") == 0) {
priority = traversePriority(child);
} else if (std::all_of(name.begin(), name.end(), isspace)) {
// ignore node (contains only whitespace)
} else if (name.compare("graphics") == 0 ||
@ -235,6 +238,7 @@ namespace storm {
}
transition.setRate(std::stod(value.second));
transition.setName(id);
transition.setPriority(priority);
gspn.addTimedTransition(transition);
} else {
storm::gspn::ImmediateTransition<storm::gspn::GSPN::WeightType> transition;
@ -243,6 +247,7 @@ namespace storm {
}
transition.setWeight(std::stod(value.second));
transition.setName(id);
transition.setPriority(priority);
gspn.addImmediateTransition(transition);
}
}
@ -469,6 +474,28 @@ namespace storm {
return defaultArcType;
}
uint_fast64_t GspnParser::traversePriority(xercesc::DOMNode const* const node) {
uint_fast64_t result = defaultPriority;
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) {
auto child = node->getChildNodes()->item(i);
auto name = getName(child);
if (name.compare("text") == 0) {
result = std::stoull(getName(child->getFirstChild()));
} else if (name.compare("value") == 0) {
auto value = getName(child->getFirstChild());
value = value.substr(std::string("Default,").length());
result = std::stoull(value);
} else if (std::all_of(name.begin(), name.end(), isspace)) {
// ignore node (contains only whitespace)
} else if (name.compare("graphics") == 0) {
// ignore these tags
} else {
STORM_PRINT_AND_LOG("unknown child (node=priority): " + name + "\n");
}
}
return result;
}
std::string GspnParser::XMLtoString(const XMLCh *xmlString) {
char* tmp = xercesc::XMLString::transcode(xmlString);
auto result = std::string(tmp);

10
src/parser/GspnParser.h

@ -109,6 +109,13 @@ namespace storm {
*/
std::string traverseArcType(xercesc::DOMNode const* const node);
/**
* Traverse a priority node.
* @param node The priority node.
* @return Returns the priority of the transition.
*/
uint_fast64_t traversePriority(xercesc::DOMNode const* const node);
/*!
* Gives the name of the current node.
*
@ -148,6 +155,9 @@ namespace storm {
// default multiplicity for arcs
uint_fast64_t defaultMultiplicity = 1;
//default priority for transitions
uint_fast64_t defaultPriority = 0;
};
}
}

Loading…
Cancel
Save