diff --git a/src/parser/GspnParser.cpp b/src/parser/GspnParser.cpp index 3a1a1a3e9..c604ffe62 100644 --- a/src/parser/GspnParser.cpp +++ b/src/parser/GspnParser.cpp @@ -200,20 +200,21 @@ void storm::parser::GspnParser::parseTransition(xercesc::DOMNode *node) { } if (timed) { - auto transition = storm::gspn::TimedTransition(); - transition.setRate(std::stoull(rate)); + auto transition = std::make_shared>(); + transition->setRate(std::stoull(rate)); gspn.addTimedTransition(transition); - this->stringToTransition[id] = &transition; + this->stringToTransition[id] = transition; } else { - auto transition = storm::gspn::ImmediateTransition(); - transition.setWeight(std::stoull(rate)); + auto transition = std::make_shared>(); + transition->setWeight(std::stoull(rate)); gspn.addImmediateTransition(transition); - this->stringToTransition[id] = &transition; + this->stringToTransition[id] = transition; } } void storm::parser::GspnParser::parseArc(xercesc::DOMNode *node) { std::string source, target, type; + uint64_t cardinality; for (uint64_t i = 0; i < node->getAttributes()->getLength(); ++i) { auto attr = node->getAttributes()->item(i); @@ -222,7 +223,7 @@ void storm::parser::GspnParser::parseArc(xercesc::DOMNode *node) { source = XMLtoString(attr->getNodeValue()); } else if (name.compare("target") == 0) { target = XMLtoString(attr->getNodeValue()); - } else if(name.compare("id") == 0) { + } else if (name.compare("id") == 0) { // ignore these tags } else { std::cout << "arc" << std::endl; @@ -235,6 +236,8 @@ void storm::parser::GspnParser::parseArc(xercesc::DOMNode *node) { auto name = getName(child); if (name.compare("type") == 0) { type = parseType(child); + } else if(name.compare("inscription") == 0) { + cardinality = parseCapacity(child); } else if (std::all_of(name.begin(), name.end(), isspace)) { // ignore node (contains only whitespace) } else if (name.compare("graphics") == 0 || @@ -245,6 +248,38 @@ void storm::parser::GspnParser::parseArc(xercesc::DOMNode *node) { std::cout << "unkown child: " << name << std::endl; } } + //determine if it is an outgoing or incoming arc + { + auto it1 = stringToState.find(source); + auto it2 = stringToTransition.find(target); + if (it1 != stringToState.end() && it2 != stringToTransition.end()) { + // incoming arc + if (type.compare("normal") == 0) { + auto transition = stringToTransition[target]; + transition->setInputArcCardinality(stringToState[source], cardinality); + } else { + std::cout << "arc" << std::endl; + std::cout << "unkown type: " << type << std::endl; + } + return; + } + } + { + auto it1 = stringToTransition.find(source); + auto it2 = stringToState.find(target); + if (it1 != stringToTransition.end() && it2 != stringToState.end()) { + // outgoing arc + if (type.compare("normal") == 0) { + auto transition = stringToTransition[source]; + transition->setOutputArcCardinality(stringToState[target], cardinality); + } else { + std::cout << "arc" << std::endl; + std::cout << "unkown type: " << type << std::endl; + } + return; + } + } + std::cout << "found an arc with no correpsonding transition" << std::endl; } std::string storm::parser::GspnParser::getName(xercesc::DOMNode *node) { @@ -343,3 +378,24 @@ std::string storm::parser::GspnParser::parseType(xercesc::DOMNode *node) { } return ""; } + +uint64_t storm::parser::GspnParser::parseCapacity(xercesc::DOMNode *node) { + uint64_t result= 0; + for (uint64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { + auto child = node->getChildNodes()->item(i); + auto name = getName(child); + 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 { + std::cout << "capacity" << std::endl; + std::cout << "unkown child: " << name << std::endl; + } + } + return result; +} diff --git a/src/parser/GspnParser.h b/src/parser/GspnParser.h index 8e3978a33..23758704a 100644 --- a/src/parser/GspnParser.h +++ b/src/parser/GspnParser.h @@ -35,7 +35,7 @@ namespace storm { std::map stringToState; // maps the transition id to a pointer to the transition - std::map stringToTransition; + std::map> stringToTransition; // the constructed gspn storm::gspn::GSPN gspn; @@ -122,6 +122,11 @@ a */ * Parse a type node. */ std::string parseType(xercesc::DOMNode* node); + + /*! + * Parse a capacity node. + */ + uint64_t parseCapacity(xercesc::DOMNode* node); }; } } diff --git a/src/storage/gspn/GSPN.cpp b/src/storage/gspn/GSPN.cpp index 409125f1a..cea9aa313 100644 --- a/src/storage/gspn/GSPN.cpp +++ b/src/storage/gspn/GSPN.cpp @@ -18,10 +18,10 @@ uint64_t storm::gspn::GSPN::getNumberOfPlaces() { return initialMarking.getNumberOfPlaces(); } -void storm::gspn::GSPN::addImmediateTransition(storm::gspn::ImmediateTransition &transition) { +void storm::gspn::GSPN::addImmediateTransition(std::shared_ptr> transition) { this->immediateTransitions.push_back(transition); } -void storm::gspn::GSPN::addTimedTransition(storm::gspn::TimedTransition &transition) { +void storm::gspn::GSPN::addTimedTransition(std::shared_ptr> transition) { this->timedTransitions.push_back(transition); } diff --git a/src/storage/gspn/GSPN.h b/src/storage/gspn/GSPN.h index 41221157e..6da283a01 100644 --- a/src/storage/gspn/GSPN.h +++ b/src/storage/gspn/GSPN.h @@ -32,14 +32,14 @@ namespace storm { uint64_t getNumberOfPlaces(); - void addImmediateTransition(ImmediateTransition& transition); - void addTimedTransition(TimedTransition& transition); + void addImmediateTransition(std::shared_ptr> transition); + void addTimedTransition(std::shared_ptr> transition); private: // set containing all immediate transitions - std::vector> immediateTransitions; + std::vector>> immediateTransitions; // set containing all timed transitions - std::vector> timedTransitions; + std::vector>> timedTransitions; // initial marking storm::gspn::Marking initialMarking; diff --git a/src/storm-gspn.cpp b/src/storm-gspn.cpp index 450d57652..cc68438f9 100644 --- a/src/storm-gspn.cpp +++ b/src/storm-gspn.cpp @@ -18,6 +18,7 @@ int main(const int argc, const char** argv) { // Parse GSPN from xml auto parser = storm::parser::GspnParser(); auto gspn = parser.parse(argv[1]); + std::cout << "Parsing complete!" << std::endl; // Construct MA