Browse Source
refactorign of gspns: use ints as identifiers on more places, use the builder in the parsing process, split the parsers for project files and pnml, as well as some minor stuff
refactorign of gspns: use ints as identifiers on more places, use the builder in the parsing process, split the parsers for project files and pnml, as well as some minor stuff
Former-commit-id:tempestpy_adaptionsf6cab8208b
[formerly9ef5558433
] Former-commit-id:cb48f9e55a
sjunges
8 years ago
16 changed files with 1878 additions and 1787 deletions
-
42src/adapters/XercesAdapter.h
-
652src/builder/ExplicitGspnModelBuilder.cpp
-
344src/builder/ExplicitGspnModelBuilder.h
-
64src/builder/JaniGSPNBuilder.h
-
343src/parser/GreatSpnEditorProjectParser.cpp
-
42src/parser/GreatSpnEditorProjectParser.h
-
889src/parser/GspnParser.cpp
-
169src/parser/GspnParser.h
-
446src/parser/PnmlParser.cpp
-
142src/parser/PnmlParser.h
-
251src/storage/gspn/GSPN.cpp
-
70src/storage/gspn/GSPN.h
-
141src/storage/gspn/GspnBuilder.cpp
-
64src/storage/gspn/GspnBuilder.h
-
2src/storage/gspn/ImmediateTransition.h
-
4src/storage/jani/JSONExporter.cpp
@ -0,0 +1,42 @@ |
|||
#pragma once |
|||
|
|||
|
|||
#include <xercesc/parsers/XercesDOMParser.hpp> |
|||
#include <xercesc/util/XMLString.hpp> |
|||
|
|||
|
|||
#include <xercesc/dom/DOM.hpp> |
|||
#include <xercesc/sax/HandlerBase.hpp> |
|||
#include <xercesc/util/PlatformUtils.hpp> |
|||
|
|||
|
|||
|
|||
namespace storm { |
|||
namespace adapters { |
|||
inline std::string XMLtoString(const XMLCh *xmlString) { |
|||
char* tmp = xercesc::XMLString::transcode(xmlString); |
|||
auto result = std::string(tmp); |
|||
delete tmp; |
|||
return result; |
|||
} |
|||
|
|||
inline std::string getName(xercesc::DOMNode const* node) { |
|||
switch (node->getNodeType()) { |
|||
case xercesc::DOMNode::NodeType::ELEMENT_NODE: { |
|||
auto elementNode = (xercesc::DOMElement *) node; |
|||
return XMLtoString(elementNode->getTagName()); |
|||
} |
|||
case xercesc::DOMNode::NodeType::TEXT_NODE: { |
|||
return XMLtoString(node->getNodeValue()); |
|||
} |
|||
case xercesc::DOMNode::NodeType::ATTRIBUTE_NODE: { |
|||
return XMLtoString(node->getNodeName()); |
|||
} |
|||
default: { |
|||
assert(false); |
|||
return ""; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,326 +1,326 @@ |
|||
#include "src/builder/ExplicitGspnModelBuilder.h"
|
|||
|
|||
#include "src/models/sparse/StandardRewardModel.h"
|
|||
|
|||
#include "src/utility/macros.h"
|
|||
#include "src/exceptions/NotImplementedException.h"
|
|||
#include "src/storage/expressions/ExpressionManager.h"
|
|||
#include "src/parser/FormulaParser.h"
|
|||
#include "src/storage/expressions/ExpressionEvaluator.h"
|
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
template<typename ValueType> |
|||
storm::models::sparse::MarkovAutomaton<ValueType> ExplicitGspnModelBuilder<ValueType>::translateGspn(storm::gspn::GSPN const& gspn, std::string const& formula) { |
|||
// set the given gspn and compute the limits of the net
|
|||
this->gspn = gspn; |
|||
computeCapacities(gspn); |
|||
|
|||
// markings maps markings to their corresponding rowgroups (indices)
|
|||
markings = storm::storage::BitVectorHashMap<uint_fast64_t>(numberOfTotalBits, 100); |
|||
builder = storm::storage::SparseMatrixBuilder<double>(0, 0, 0, false, true); |
|||
|
|||
// add initial marking to todo list
|
|||
auto bitvector = gspn.getInitialMarking(numberOfBits, numberOfTotalBits)->getBitVector(); |
|||
findOrAddBitvectorToMarkings(*bitvector); |
|||
currentRowIndex = 0; |
|||
|
|||
// vector marking markovian states (vector contains an 1 if the state is markovian)
|
|||
storm::storage::BitVector markovianStates(0); |
|||
|
|||
// vector containing the exit rates for the markovian states
|
|||
std::vector<ValueType> exitRates; |
|||
|
|||
|
|||
while (!todo.empty()) { |
|||
// take next element from the todo list
|
|||
auto currentBitvector = todo.front(); |
|||
todo.pop_front(); |
|||
auto currentMarking = storm::gspn::Marking(gspn.getNumberOfPlaces(), numberOfBits, *currentBitvector); |
|||
|
|||
// increment list of states by one
|
|||
markovianStates.resize(markovianStates.size() + 1, 0); |
|||
|
|||
// create new row group for the current marking
|
|||
builder.newRowGroup(markings.getValue(*currentBitvector)); |
|||
|
|||
std::cout << "work on: " << *currentBitvector << std::endl; |
|||
|
|||
auto enabledImmediateTransitions = getEnabledImmediateTransition(currentMarking); |
|||
if (!enabledImmediateTransitions.empty()) { |
|||
markovianStates.set(currentRowIndex, 0); |
|||
exitRates.push_back(0); |
|||
|
|||
auto partitions = partitonEnabledImmediateTransitions(currentMarking, enabledImmediateTransitions); |
|||
addRowForPartitions(partitions, currentMarking); |
|||
} else { |
|||
|
|||
auto enabledTimedTransitions = getEnabledTimedTransition(currentMarking); |
|||
if (!enabledTimedTransitions.empty()) { |
|||
markovianStates.set(currentRowIndex, 1); |
|||
|
|||
auto accRate = getAccumulatedRate(enabledTimedTransitions); |
|||
std::cout << "\t\tacc. rate: " << accRate << std::endl; |
|||
exitRates.push_back(accRate); |
|||
|
|||
addRowForTimedTransitions(enabledTimedTransitions, currentMarking, accRate); |
|||
} else { |
|||
markovianStates.set(currentRowIndex, 1); |
|||
} |
|||
} |
|||
++currentRowIndex; |
|||
} |
|||
|
|||
auto matrix = builder.build(); |
|||
|
|||
// create expression manager and add variables from the gspn
|
|||
auto expressionManager = std::make_shared<storm::expressions::ExpressionManager>(); |
|||
for (auto& place : gspn.getPlaces()) { |
|||
expressionManager->declareIntegerVariable(place.getName()); |
|||
} |
|||
|
|||
// parse formula
|
|||
storm::parser::FormulaParser formulaParser(expressionManager); |
|||
auto formulaPtr = formulaParser.parseSingleFormulaFromString(formula); |
|||
auto atomicFormulas = formulaPtr->getAtomicExpressionFormulas(); |
|||
|
|||
// create empty state labeling
|
|||
storm::models::sparse::StateLabeling labeling(markings.size()); |
|||
storm::expressions::ExpressionEvaluator<double> expressionEvaluator(*expressionManager); |
|||
|
|||
std::cout << std::endl; |
|||
std::cout << "build labeling:" << std::endl; |
|||
for (auto& atomicFormula : atomicFormulas) { |
|||
std::cout << atomicFormula; |
|||
auto label = atomicFormula->toString(); |
|||
labeling.addLabel(label); |
|||
|
|||
for (auto statePair : markings) { |
|||
auto marking = storm::gspn::Marking(gspn.getNumberOfPlaces(), numberOfBits, statePair.first); |
|||
for (auto& place : gspn.getPlaces()) { |
|||
auto variable = expressionManager->getVariable(place.getName()); |
|||
expressionEvaluator.setIntegerValue(variable, marking.getNumberOfTokensAt(place.getID())); |
|||
} |
|||
bool hold = expressionEvaluator.asBool(atomicFormula->getExpression()); |
|||
if (hold) { |
|||
labeling.addLabelToState(label, statePair.second); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
//auto labeling = getStateLabeling();
|
|||
|
|||
return storm::models::sparse::MarkovAutomaton<double>(matrix, labeling, markovianStates, exitRates); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void ExplicitGspnModelBuilder<ValueType>::addRowForPartitions(std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> const& partitions, storm::gspn::Marking const& currentMarking) { |
|||
for (auto& partition : partitions) { |
|||
std::cout << "\tnew partition:" << std::endl; |
|||
auto accWeight = getAccumulatedWeight(partition); |
|||
std::cout << "\t\tacc. weight: " << accWeight << std::endl; |
|||
|
|||
std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> weights; |
|||
for (auto& trans : partition) { |
|||
std::cout << "\t\ttransname: " << trans->getName() << std::endl; |
|||
auto newMarking = trans->fire(currentMarking); |
|||
std::cout << "\t\t\t target marking: " << *newMarking.getBitVector() << std::endl; |
|||
|
|||
findOrAddBitvectorToMarkings(*newMarking.getBitVector()); |
|||
|
|||
auto it = weights.find(markings.getValue(*newMarking.getBitVector())); |
|||
double currentWeight = 0; |
|||
if (it != weights.end()) { |
|||
currentWeight = weights.at(markings.getValue(*newMarking.getBitVector())); |
|||
} |
|||
currentWeight += trans->getWeight() / accWeight; |
|||
weights[markings.getValue(*newMarking.getBitVector())] = currentWeight; |
|||
} |
|||
|
|||
addValuesToBuilder(weights); |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void ExplicitGspnModelBuilder<ValueType>::addRowForTimedTransitions(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& enabledTimedTransitions, storm::gspn::Marking const& currentMarking, double const& accRate) { |
|||
std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> rates; |
|||
for (auto& trans : enabledTimedTransitions) { |
|||
std::cout << "\t\ttransname: " << trans->getName() << std::endl; |
|||
auto newMarking = trans->fire(currentMarking); |
|||
std::cout << "\t\t\t target marking: " << *newMarking.getBitVector() << std::endl; |
|||
|
|||
findOrAddBitvectorToMarkings(*newMarking.getBitVector()); |
|||
|
|||
auto it = rates.find(markings.getValue(*newMarking.getBitVector())); |
|||
double currentWeightRate = 0; |
|||
if (it != rates.end()) { |
|||
currentWeightRate = rates.at(markings.getValue(*newMarking.getBitVector())); |
|||
} |
|||
currentWeightRate += trans->getRate() / accRate; |
|||
rates[markings.getValue(*newMarking.getBitVector())] = currentWeightRate; |
|||
|
|||
} |
|||
|
|||
addValuesToBuilder(rates); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void ExplicitGspnModelBuilder<ValueType>::addValuesToBuilder(std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> const& values) { |
|||
for (auto& it : values) { |
|||
std::cout << "\t\tadd value \"" << it.second << "\" to " << getBitvector(it.first) << std::endl; |
|||
builder.addNextValue(currentRowIndex, it.first, it.second); |
|||
} |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> ExplicitGspnModelBuilder<ValueType>::partitonEnabledImmediateTransitions( |
|||
storm::gspn::Marking const& marking, |
|||
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& enabledImmediateTransitions) { |
|||
decltype(partitonEnabledImmediateTransitions(marking, enabledImmediateTransitions)) result; |
|||
|
|||
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> weightedTransitions; |
|||
|
|||
for (auto& trans : enabledImmediateTransitions) { |
|||
if (trans->noWeightAttached()) { |
|||
decltype(weightedTransitions) singleton; |
|||
singleton.push_back(trans); |
|||
result.push_back(singleton); |
|||
} else { |
|||
weightedTransitions.push_back(trans); |
|||
} |
|||
} |
|||
|
|||
if (weightedTransitions.size() != 0) { |
|||
result.push_back(weightedTransitions); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
double ExplicitGspnModelBuilder<ValueType>::getAccumulatedWeight(std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& vector) const { |
|||
double result = 0; |
|||
|
|||
for (auto &trans : vector) { |
|||
result += trans->getWeight(); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
void ExplicitGspnModelBuilder<ValueType>::computeCapacities(storm::gspn::GSPN const& gspn) { |
|||
uint_fast64_t sum = 0; |
|||
for (auto& place : gspn.getPlaces()) {//TODO
|
|||
numberOfBits[place.getID()] = 1; |
|||
sum += numberOfBits[place.getID()]; |
|||
} |
|||
|
|||
// compute next multiple of 64
|
|||
uint_fast64_t rem = sum % 64; |
|||
numberOfTotalBits = sum + 64 - rem; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> ExplicitGspnModelBuilder<ValueType>::getEnabledTimedTransition( |
|||
storm::gspn::Marking const& marking) { |
|||
std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>>result; |
|||
|
|||
uint_fast64_t highestSeenPriority = 0; |
|||
|
|||
for (auto& trans_ptr : gspn.getTimedTransitions()) { |
|||
if (trans_ptr->isEnabled(marking)) { |
|||
if (trans_ptr->getPriority() > highestSeenPriority) { |
|||
highestSeenPriority = trans_ptr->getPriority(); |
|||
result.clear(); |
|||
} |
|||
result.push_back(trans_ptr); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> ExplicitGspnModelBuilder<ValueType>::getEnabledImmediateTransition( |
|||
storm::gspn::Marking const& marking) { |
|||
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>result; |
|||
|
|||
uint_fast64_t highestSeenPriority = 0; |
|||
|
|||
for (auto& trans_ptr : gspn.getImmediateTransitions()) { |
|||
if (trans_ptr->isEnabled(marking)) { |
|||
if (trans_ptr->getPriority() > highestSeenPriority) { |
|||
highestSeenPriority = trans_ptr->getPriority(); |
|||
result.clear(); |
|||
} |
|||
result.push_back(trans_ptr); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
double ExplicitGspnModelBuilder<ValueType>::getAccumulatedRate(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& vector) { |
|||
double result = 0; |
|||
for (auto trans_ptr : vector) { |
|||
result += trans_ptr->getRate(); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
storm::storage::BitVector ExplicitGspnModelBuilder<ValueType>::getBitvector(uint_fast64_t const& index) { |
|||
for (auto it = markings.begin(); it != markings.end(); ++it) { |
|||
if (std::get<1>(*it) == index) { |
|||
return std::get<0>(*it); |
|||
} |
|||
} |
|||
return storm::storage::BitVector(); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
uint_fast64_t ExplicitGspnModelBuilder<ValueType>::findOrAddBitvectorToMarkings(storm::storage::BitVector const &bitvector) { |
|||
auto index = markings.findOrAdd(bitvector, nextRowGroupIndex); |
|||
|
|||
if (index == nextRowGroupIndex) { |
|||
// bitvector was not already in the map
|
|||
++nextRowGroupIndex; |
|||
// bitvector was also never in the todo list
|
|||
todo.push_back(std::make_shared<storm::storage::BitVector>(bitvector)); |
|||
} |
|||
return index; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
storm::models::sparse::StateLabeling ExplicitGspnModelBuilder<ValueType>::getStateLabeling() const { |
|||
storm::models::sparse::StateLabeling labeling(markings.size()); |
|||
|
|||
std::map<uint_fast64_t , std::string> idToName; |
|||
for (auto& place : gspn.getPlaces()) { |
|||
idToName[place.getID()] = place.getName(); |
|||
labeling.addLabel(place.getName()); |
|||
} |
|||
|
|||
auto it = markings.begin(); |
|||
for ( ; it != markings.end() ; ++it) { |
|||
auto bitvector = std::get<0>(*it); |
|||
storm::gspn::Marking marking(gspn.getNumberOfPlaces(), numberOfBits, bitvector); |
|||
for (auto i = 0; i < marking.getNumberOfPlaces(); i++) { |
|||
if (marking.getNumberOfTokensAt(i) > 0) { |
|||
std::cout << i << std::endl; |
|||
labeling.addLabelToState(idToName.at(i), i); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return labeling; |
|||
} |
|||
|
|||
template class ExplicitGspnModelBuilder<double>; |
|||
} |
|||
} |
|||
//#include "src/builder/ExplicitGspnModelBuilder.h"
|
|||
//
|
|||
//#include "src/models/sparse/StandardRewardModel.h"
|
|||
//
|
|||
//#include "src/utility/macros.h"
|
|||
//#include "src/exceptions/NotImplementedException.h"
|
|||
//#include "src/storage/expressions/ExpressionManager.h"
|
|||
//#include "src/parser/FormulaParser.h"
|
|||
//#include "src/storage/expressions/ExpressionEvaluator.h"
|
|||
//
|
|||
//namespace storm {
|
|||
// namespace builder {
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// storm::models::sparse::MarkovAutomaton<ValueType> ExplicitGspnModelBuilder<ValueType>::translateGspn(storm::gspn::GSPN const& gspn, std::string const& formula) {
|
|||
// // set the given gspn and compute the limits of the net
|
|||
// this->gspn = gspn;
|
|||
// computeCapacities(gspn);
|
|||
//
|
|||
// // markings maps markings to their corresponding rowgroups (indices)
|
|||
// markings = storm::storage::BitVectorHashMap<uint_fast64_t>(numberOfTotalBits, 100);
|
|||
// builder = storm::storage::SparseMatrixBuilder<double>(0, 0, 0, false, true);
|
|||
//
|
|||
// // add initial marking to todo list
|
|||
// auto bitvector = gspn.getInitialMarking(numberOfBits, numberOfTotalBits)->getBitVector();
|
|||
// findOrAddBitvectorToMarkings(*bitvector);
|
|||
// currentRowIndex = 0;
|
|||
//
|
|||
// // vector marking markovian states (vector contains an 1 if the state is markovian)
|
|||
// storm::storage::BitVector markovianStates(0);
|
|||
//
|
|||
// // vector containing the exit rates for the markovian states
|
|||
// std::vector<ValueType> exitRates;
|
|||
//
|
|||
//
|
|||
// while (!todo.empty()) {
|
|||
// // take next element from the todo list
|
|||
// auto currentBitvector = todo.front();
|
|||
// todo.pop_front();
|
|||
// auto currentMarking = storm::gspn::Marking(gspn.getNumberOfPlaces(), numberOfBits, *currentBitvector);
|
|||
//
|
|||
// // increment list of states by one
|
|||
// markovianStates.resize(markovianStates.size() + 1, 0);
|
|||
//
|
|||
// // create new row group for the current marking
|
|||
// builder.newRowGroup(markings.getValue(*currentBitvector));
|
|||
//
|
|||
// std::cout << "work on: " << *currentBitvector << std::endl;
|
|||
//
|
|||
// auto enabledImmediateTransitions = getEnabledImmediateTransition(currentMarking);
|
|||
// if (!enabledImmediateTransitions.empty()) {
|
|||
// markovianStates.set(currentRowIndex, 0);
|
|||
// exitRates.push_back(0);
|
|||
//
|
|||
// auto partitions = partitonEnabledImmediateTransitions(currentMarking, enabledImmediateTransitions);
|
|||
// addRowForPartitions(partitions, currentMarking);
|
|||
// } else {
|
|||
//
|
|||
// auto enabledTimedTransitions = getEnabledTimedTransition(currentMarking);
|
|||
// if (!enabledTimedTransitions.empty()) {
|
|||
// markovianStates.set(currentRowIndex, 1);
|
|||
//
|
|||
// auto accRate = getAccumulatedRate(enabledTimedTransitions);
|
|||
// std::cout << "\t\tacc. rate: " << accRate << std::endl;
|
|||
// exitRates.push_back(accRate);
|
|||
//
|
|||
// addRowForTimedTransitions(enabledTimedTransitions, currentMarking, accRate);
|
|||
// } else {
|
|||
// markovianStates.set(currentRowIndex, 1);
|
|||
// }
|
|||
// }
|
|||
// ++currentRowIndex;
|
|||
// }
|
|||
//
|
|||
// auto matrix = builder.build();
|
|||
//
|
|||
// // create expression manager and add variables from the gspn
|
|||
// auto expressionManager = std::make_shared<storm::expressions::ExpressionManager>();
|
|||
// for (auto& place : gspn.getPlaces()) {
|
|||
// expressionManager->declareIntegerVariable(place.getName());
|
|||
// }
|
|||
//
|
|||
// // parse formula
|
|||
// storm::parser::FormulaParser formulaParser(expressionManager);
|
|||
// auto formulaPtr = formulaParser.parseSingleFormulaFromString(formula);
|
|||
// auto atomicFormulas = formulaPtr->getAtomicExpressionFormulas();
|
|||
//
|
|||
// // create empty state labeling
|
|||
// storm::models::sparse::StateLabeling labeling(markings.size());
|
|||
// storm::expressions::ExpressionEvaluator<double> expressionEvaluator(*expressionManager);
|
|||
//
|
|||
// std::cout << std::endl;
|
|||
// std::cout << "build labeling:" << std::endl;
|
|||
// for (auto& atomicFormula : atomicFormulas) {
|
|||
// std::cout << atomicFormula;
|
|||
// auto label = atomicFormula->toString();
|
|||
// labeling.addLabel(label);
|
|||
//
|
|||
// for (auto statePair : markings) {
|
|||
// auto marking = storm::gspn::Marking(gspn.getNumberOfPlaces(), numberOfBits, statePair.first);
|
|||
// for (auto& place : gspn.getPlaces()) {
|
|||
// auto variable = expressionManager->getVariable(place.getName());
|
|||
// expressionEvaluator.setIntegerValue(variable, marking.getNumberOfTokensAt(place.getID()));
|
|||
// }
|
|||
// bool hold = expressionEvaluator.asBool(atomicFormula->getExpression());
|
|||
// if (hold) {
|
|||
// labeling.addLabelToState(label, statePair.second);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// }
|
|||
//
|
|||
// //auto labeling = getStateLabeling();
|
|||
//
|
|||
// return storm::models::sparse::MarkovAutomaton<double>(matrix, labeling, markovianStates, exitRates);
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// void ExplicitGspnModelBuilder<ValueType>::addRowForPartitions(std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> const& partitions, storm::gspn::Marking const& currentMarking) {
|
|||
// for (auto& partition : partitions) {
|
|||
// std::cout << "\tnew partition:" << std::endl;
|
|||
// auto accWeight = getAccumulatedWeight(partition);
|
|||
// std::cout << "\t\tacc. weight: " << accWeight << std::endl;
|
|||
//
|
|||
// std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> weights;
|
|||
// for (auto& trans : partition) {
|
|||
// std::cout << "\t\ttransname: " << trans.getName() << std::endl;
|
|||
// auto newMarking = trans.fire(currentMarking);
|
|||
// std::cout << "\t\t\t target marking: " << *newMarking.getBitVector() << std::endl;
|
|||
//
|
|||
// findOrAddBitvectorToMarkings(*newMarking.getBitVector());
|
|||
//
|
|||
// auto it = weights.find(markings.getValue(*newMarking.getBitVector()));
|
|||
// double currentWeight = 0;
|
|||
// if (it != weights.end()) {
|
|||
// currentWeight = weights.at(markings.getValue(*newMarking.getBitVector()));
|
|||
// }
|
|||
// currentWeight += trans.getWeight() / accWeight;
|
|||
// weights[markings.getValue(*newMarking.getBitVector())] = currentWeight;
|
|||
// }
|
|||
//
|
|||
// addValuesToBuilder(weights);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// void ExplicitGspnModelBuilder<ValueType>::addRowForTimedTransitions(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& enabledTimedTransitions, storm::gspn::Marking const& currentMarking, double const& accRate) {
|
|||
// std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> rates;
|
|||
// for (auto& trans : enabledTimedTransitions) {
|
|||
// std::cout << "\t\ttransname: " << trans.getName() << std::endl;
|
|||
// auto newMarking = trans.fire(currentMarking);
|
|||
// std::cout << "\t\t\t target marking: " << *newMarking.getBitVector() << std::endl;
|
|||
//
|
|||
// findOrAddBitvectorToMarkings(*newMarking.getBitVector());
|
|||
//
|
|||
// auto it = rates.find(markings.getValue(*newMarking.getBitVector()));
|
|||
// double currentWeightRate = 0;
|
|||
// if (it != rates.end()) {
|
|||
// currentWeightRate = rates.at(markings.getValue(*newMarking.getBitVector()));
|
|||
// }
|
|||
// currentWeightRate += trans.getRate() / accRate;
|
|||
// rates[markings.getValue(*newMarking.getBitVector())] = currentWeightRate;
|
|||
//
|
|||
// }
|
|||
//
|
|||
// addValuesToBuilder(rates);
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// void ExplicitGspnModelBuilder<ValueType>::addValuesToBuilder(std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> const& values) {
|
|||
// for (auto& it : values) {
|
|||
// std::cout << "\t\tadd value \"" << it.second << "\" to " << getBitvector(it.first) << std::endl;
|
|||
// builder.addNextValue(currentRowIndex, it.first, it.second);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> ExplicitGspnModelBuilder<ValueType>::partitonEnabledImmediateTransitions(
|
|||
// storm::gspn::Marking const& marking,
|
|||
// std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& enabledImmediateTransitions) {
|
|||
// decltype(partitonEnabledImmediateTransitions(marking, enabledImmediateTransitions)) result;
|
|||
//
|
|||
// std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> weightedTransitions;
|
|||
//
|
|||
// for (auto& trans : enabledImmediateTransitions) {
|
|||
// if (trans.noWeightAttached()) {
|
|||
// decltype(weightedTransitions) singleton;
|
|||
// singleton.push_back(trans);
|
|||
// result.push_back(singleton);
|
|||
// } else {
|
|||
// weightedTransitions.push_back(trans);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// if (weightedTransitions.size() != 0) {
|
|||
// result.push_back(weightedTransitions);
|
|||
// }
|
|||
//
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// double ExplicitGspnModelBuilder<ValueType>::getAccumulatedWeight(std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& vector) const {
|
|||
// double result = 0;
|
|||
//
|
|||
// for (auto &trans : vector) {
|
|||
// result += trans.getWeight();
|
|||
// }
|
|||
//
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// void ExplicitGspnModelBuilder<ValueType>::computeCapacities(storm::gspn::GSPN const& gspn) {
|
|||
// uint_fast64_t sum = 0;
|
|||
// for (auto& place : gspn.getPlaces()) {//TODO
|
|||
// numberOfBits[place.getID()] = 1;
|
|||
// sum += numberOfBits[place.getID()];
|
|||
// }
|
|||
//
|
|||
// // compute next multiple of 64
|
|||
// uint_fast64_t rem = sum % 64;
|
|||
// numberOfTotalBits = sum + 64 - rem;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> ExplicitGspnModelBuilder<ValueType>::getEnabledTimedTransition(
|
|||
// storm::gspn::Marking const& marking) {
|
|||
// std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>>result;
|
|||
//
|
|||
// uint_fast64_t highestSeenPriority = 0;
|
|||
//
|
|||
// for (auto& trans : gspn.getTimedTransitions()) {
|
|||
// if (trans.isEnabled(marking)) {
|
|||
// if (trans.getPriority() > highestSeenPriority) {
|
|||
// highestSeenPriority = trans.getPriority();
|
|||
// result.clear();
|
|||
// }
|
|||
// result.push_back(trans);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> ExplicitGspnModelBuilder<ValueType>::getEnabledImmediateTransition(
|
|||
// storm::gspn::Marking const& marking) {
|
|||
// std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>result;
|
|||
//
|
|||
// uint_fast64_t highestSeenPriority = 0;
|
|||
//
|
|||
// for (auto& trans : gspn.getImmediateTransitions()) {
|
|||
// if (trans.isEnabled(marking)) {
|
|||
// if (trans.getPriority() > highestSeenPriority) {
|
|||
// highestSeenPriority = trans.getPriority();
|
|||
// result.clear();
|
|||
// }
|
|||
// result.push_back(trans);
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// double ExplicitGspnModelBuilder<ValueType>::getAccumulatedRate(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& vector) {
|
|||
// double result = 0;
|
|||
// for (auto trans : vector) {
|
|||
// result += trans.getRate();
|
|||
// }
|
|||
//
|
|||
// return result;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// storm::storage::BitVector ExplicitGspnModelBuilder<ValueType>::getBitvector(uint_fast64_t const& index) {
|
|||
// for (auto it = markings.begin(); it != markings.end(); ++it) {
|
|||
// if (std::get<1>(*it) == index) {
|
|||
// return std::get<0>(*it);
|
|||
// }
|
|||
// }
|
|||
// return storm::storage::BitVector();
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// uint_fast64_t ExplicitGspnModelBuilder<ValueType>::findOrAddBitvectorToMarkings(storm::storage::BitVector const &bitvector) {
|
|||
// auto index = markings.findOrAdd(bitvector, nextRowGroupIndex);
|
|||
//
|
|||
// if (index == nextRowGroupIndex) {
|
|||
// // bitvector was not already in the map
|
|||
// ++nextRowGroupIndex;
|
|||
// // bitvector was also never in the todo list
|
|||
// todo.push_back(std::make_shared<storm::storage::BitVector>(bitvector));
|
|||
// }
|
|||
// return index;
|
|||
// }
|
|||
//
|
|||
// template<typename ValueType>
|
|||
// storm::models::sparse::StateLabeling ExplicitGspnModelBuilder<ValueType>::getStateLabeling() const {
|
|||
// storm::models::sparse::StateLabeling labeling(markings.size());
|
|||
//
|
|||
// std::map<uint_fast64_t , std::string> idToName;
|
|||
// for (auto& place : gspn.getPlaces()) {
|
|||
// idToName[place.getID()] = place.getName();
|
|||
// labeling.addLabel(place.getName());
|
|||
// }
|
|||
//
|
|||
// auto it = markings.begin();
|
|||
// for ( ; it != markings.end() ; ++it) {
|
|||
// auto bitvector = std::get<0>(*it);
|
|||
// storm::gspn::Marking marking(gspn.getNumberOfPlaces(), numberOfBits, bitvector);
|
|||
// for (auto i = 0; i < marking.getNumberOfPlaces(); i++) {
|
|||
// if (marking.getNumberOfTokensAt(i) > 0) {
|
|||
// std::cout << i << std::endl;
|
|||
// labeling.addLabelToState(idToName.at(i), i);
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// return labeling;
|
|||
// }
|
|||
//
|
|||
// template class ExplicitGspnModelBuilder<double>;
|
|||
// }
|
|||
//}
|
@ -1,172 +1,172 @@ |
|||
#ifndef STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
|||
#define STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
|||
|
|||
#include <string> |
|||
|
|||
#include "src/models/sparse/MarkovAutomaton.h" |
|||
#include "src/models/sparse/StandardRewardModel.h" |
|||
#include "src/storage/BitVector.h" |
|||
#include "src/storage/BitVectorHashMap.h" |
|||
#include "src/storage/gspn/GSPN.h" |
|||
#include "src/storage/gspn/ImmediateTransition.h" |
|||
#include "src/storage/gspn/TimedTransition.h" |
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
/*! |
|||
* This class provides the facilities for building an markov automaton. |
|||
*/ |
|||
template<typename ValueType=double> |
|||
class ExplicitGspnModelBuilder { |
|||
public: |
|||
|
|||
/*! |
|||
* Builds an MarkovAutomaton from the given GSPN. |
|||
* |
|||
* @param gspn The gspn whose semantic is covered by the MarkovAutomaton |
|||
* @return The resulting MarkovAutomaton |
|||
*/ |
|||
storm::models::sparse::MarkovAutomaton<ValueType> translateGspn(storm::gspn::GSPN const& gspn, std::string const& formula); |
|||
private: |
|||
|
|||
/*! |
|||
* Add for each partition a new row in the probability matrix. |
|||
* |
|||
* @param partitions The partitioned immediate transitions. |
|||
* @param currentMarking The current marking which is considered at the moment. |
|||
*/ |
|||
void addRowForPartitions(std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> const& partitions, storm::gspn::Marking const& currentMarking); |
|||
|
|||
|
|||
/*! |
|||
* Add row for a markovian state. |
|||
* |
|||
* @param enabledTimedTransitions List of enabled timed transitions. |
|||
* @param currentMarking The current marking which is considered at the moment. |
|||
* @param accRate The sum of all rates of the enabled timed transisitons |
|||
*/ |
|||
void addRowForTimedTransitions(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& enabledTimedTransitions, storm::gspn::Marking const& currentMarking, double const& accRate); |
|||
|
|||
/*! |
|||
* Struct for comparing unsigned integer for maps |
|||
*/ |
|||
struct cmpByIndex { |
|||
bool operator()(const uint_fast64_t &a, const uint_fast64_t &b) const { |
|||
return a < b; |
|||
} |
|||
}; |
|||
|
|||
/*! |
|||
* This method insert the values from a map into the matrix |
|||
* |
|||
* @param values The values which are inserted |
|||
*/ |
|||
void addValuesToBuilder(std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> const& values); |
|||
|
|||
|
|||
/*! |
|||
* This method partitions all enabled immediate transitions w.r.t. a marking. |
|||
* All enabled weighted immediate transitions are in one vector. Between these transitions |
|||
* is chosen probabilistically by the weights. |
|||
* |
|||
* All other enabled non-weighted immediate transitions are in an singleton vector. |
|||
* Between different vectors is chosen non-deterministically. |
|||
* |
|||
* @param marking The current marking which is considered. |
|||
* @param enabledImmediateTransistions A vector of enabled immediate transitions. |
|||
* @return The vector of vectors which is described above. |
|||
*/ |
|||
std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> partitonEnabledImmediateTransitions(storm::gspn::Marking const& marking, std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& enabledImmediateTransitions); |
|||
|
|||
/*! |
|||
* Computes the accumulated weight of immediate transisions which are stored in a list. |
|||
* |
|||
* @param vector List of immediate transisitions. |
|||
*/ |
|||
double getAccumulatedWeight(std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& vector) const; |
|||
|
|||
/*! |
|||
* Compute the upper bound for the number of tokens in each place. |
|||
* Also computes the number of bits which are used to store a marking. |
|||
* |
|||
* @param gspn The corresponding gspn. |
|||
*/ |
|||
void computeCapacities(storm::gspn::GSPN const& gspn); |
|||
|
|||
/*! |
|||
* Returns the vector of enabled timed transition with the highest priority. |
|||
* |
|||
* |
|||
* @param marking The current marking which is considered. |
|||
* @return The vector of enabled timed transitions. |
|||
*/ |
|||
std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> getEnabledTimedTransition( |
|||
storm::gspn::Marking const& marking); |
|||
|
|||
/*! |
|||
* Returns the vector of active immediate transition with the highest priority. |
|||
* |
|||
* @param marking The current marking which is considered. |
|||
* @return The vector of enabled immediate transitions. |
|||
*/ |
|||
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> getEnabledImmediateTransition( |
|||
storm::gspn::Marking const& marking); |
|||
|
|||
/*! |
|||
* Computes the accumulated rate of a vector of timed transitions. |
|||
* |
|||
* @param vector The vector of timed transitions. |
|||
* @return The accumulated rate. |
|||
*/ |
|||
double getAccumulatedRate(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& vector); |
|||
|
|||
// is only needed for debugging purposes |
|||
// since markings is injective, we can determine the bitvector |
|||
storm::storage::BitVector getBitvector(uint_fast64_t const& index); |
|||
|
|||
/*! |
|||
* Adds the bitvector to the marking-map. |
|||
* If the bitvector corresponds to a new marking the bitvector is added to the todo list. |
|||
* |
|||
* @return The rowGroup index for the bitvector. |
|||
*/ |
|||
uint_fast64_t findOrAddBitvectorToMarkings(storm::storage::BitVector const& bitvector); |
|||
|
|||
/*! |
|||
* Computes the state labeling and returns it. |
|||
* Every state is labeled with its name. |
|||
* |
|||
* @return The computed state labeling. |
|||
*/ |
|||
storm::models::sparse::StateLabeling getStateLabeling() const; |
|||
|
|||
|
|||
// contains the number of bits which are used the store the number of tokens at each place |
|||
std::map<uint_fast64_t, uint_fast64_t> numberOfBits; |
|||
|
|||
// contains the number of bits used to create markings |
|||
uint_fast64_t numberOfTotalBits; |
|||
|
|||
// maps bitvectors (markings w.r.t. the capacity) to their rowgroup |
|||
storm::storage::BitVectorHashMap<uint_fast64_t> markings = storm::storage::BitVectorHashMap<uint_fast64_t>(64, 1); |
|||
|
|||
// a list of markings for which the outgoing edges need to be computed |
|||
std::deque<std::shared_ptr<storm::storage::BitVector>> todo; |
|||
|
|||
//the gspn which is transformed |
|||
storm::gspn::GSPN gspn; |
|||
|
|||
// the next index for a new rowgroup |
|||
uint_fast64_t nextRowGroupIndex = 0; |
|||
|
|||
// builder object which is used to create the probability matrix |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
|
|||
// contains the current row index during the computation |
|||
uint_fast64_t currentRowIndex; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif //STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
|||
//#ifndef STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
|||
//#define STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
|||
// |
|||
//#include <string> |
|||
// |
|||
//#include "src/models/sparse/MarkovAutomaton.h" |
|||
//#include "src/models/sparse/StandardRewardModel.h" |
|||
//#include "src/storage/BitVector.h" |
|||
//#include "src/storage/BitVectorHashMap.h" |
|||
//#include "src/storage/gspn/GSPN.h" |
|||
//#include "src/storage/gspn/ImmediateTransition.h" |
|||
//#include "src/storage/gspn/TimedTransition.h" |
|||
// |
|||
//namespace storm { |
|||
// namespace builder { |
|||
// |
|||
// /*! |
|||
// * This class provides the facilities for building an markov automaton. |
|||
// */ |
|||
// template<typename ValueType=double> |
|||
// class ExplicitGspnModelBuilder { |
|||
// public: |
|||
// |
|||
// /*! |
|||
// * Builds an MarkovAutomaton from the given GSPN. |
|||
// * |
|||
// * @param gspn The gspn whose semantic is covered by the MarkovAutomaton |
|||
// * @return The resulting MarkovAutomaton |
|||
// */ |
|||
// storm::models::sparse::MarkovAutomaton<ValueType> translateGspn(storm::gspn::GSPN const& gspn, std::string const& formula); |
|||
// private: |
|||
// |
|||
// /*! |
|||
// * Add for each partition a new row in the probability matrix. |
|||
// * |
|||
// * @param partitions The partitioned immediate transitions. |
|||
// * @param currentMarking The current marking which is considered at the moment. |
|||
// */ |
|||
// void addRowForPartitions(std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> const& partitions, storm::gspn::Marking const& currentMarking); |
|||
// |
|||
// |
|||
// /*! |
|||
// * Add row for a markovian state. |
|||
// * |
|||
// * @param enabledTimedTransitions List of enabled timed transitions. |
|||
// * @param currentMarking The current marking which is considered at the moment. |
|||
// * @param accRate The sum of all rates of the enabled timed transisitons |
|||
// */ |
|||
// void addRowForTimedTransitions(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& enabledTimedTransitions, storm::gspn::Marking const& currentMarking, double const& accRate); |
|||
// |
|||
// /*! |
|||
// * Struct for comparing unsigned integer for maps |
|||
// */ |
|||
// struct cmpByIndex { |
|||
// bool operator()(const uint_fast64_t &a, const uint_fast64_t &b) const { |
|||
// return a < b; |
|||
// } |
|||
// }; |
|||
// |
|||
// /*! |
|||
// * This method insert the values from a map into the matrix |
|||
// * |
|||
// * @param values The values which are inserted |
|||
// */ |
|||
// void addValuesToBuilder(std::map<uint_fast64_t , double, storm::builder::ExplicitGspnModelBuilder<ValueType>::cmpByIndex> const& values); |
|||
// |
|||
// |
|||
// /*! |
|||
// * This method partitions all enabled immediate transitions w.r.t. a marking. |
|||
// * All enabled weighted immediate transitions are in one vector. Between these transitions |
|||
// * is chosen probabilistically by the weights. |
|||
// * |
|||
// * All other enabled non-weighted immediate transitions are in an singleton vector. |
|||
// * Between different vectors is chosen non-deterministically. |
|||
// * |
|||
// * @param marking The current marking which is considered. |
|||
// * @param enabledImmediateTransistions A vector of enabled immediate transitions. |
|||
// * @return The vector of vectors which is described above. |
|||
// */ |
|||
// std::vector<std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>>> partitonEnabledImmediateTransitions(storm::gspn::Marking const& marking, std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& enabledImmediateTransitions); |
|||
// |
|||
// /*! |
|||
// * Computes the accumulated weight of immediate transisions which are stored in a list. |
|||
// * |
|||
// * @param vector List of immediate transisitions. |
|||
// */ |
|||
// double getAccumulatedWeight(std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> const& vector) const; |
|||
// |
|||
// /*! |
|||
// * Compute the upper bound for the number of tokens in each place. |
|||
// * Also computes the number of bits which are used to store a marking. |
|||
// * |
|||
// * @param gspn The corresponding gspn. |
|||
// */ |
|||
// void computeCapacities(storm::gspn::GSPN const& gspn); |
|||
// |
|||
// /*! |
|||
// * Returns the vector of enabled timed transition with the highest priority. |
|||
// * |
|||
// * |
|||
// * @param marking The current marking which is considered. |
|||
// * @return The vector of enabled timed transitions. |
|||
// */ |
|||
// std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> getEnabledTimedTransition( |
|||
// storm::gspn::Marking const& marking); |
|||
// |
|||
// /*! |
|||
// * Returns the vector of active immediate transition with the highest priority. |
|||
// * |
|||
// * @param marking The current marking which is considered. |
|||
// * @return The vector of enabled immediate transitions. |
|||
// */ |
|||
// std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<double>>> getEnabledImmediateTransition( |
|||
// storm::gspn::Marking const& marking); |
|||
// |
|||
// /*! |
|||
// * Computes the accumulated rate of a vector of timed transitions. |
|||
// * |
|||
// * @param vector The vector of timed transitions. |
|||
// * @return The accumulated rate. |
|||
// */ |
|||
// double getAccumulatedRate(std::vector<std::shared_ptr<storm::gspn::TimedTransition<double>>> const& vector); |
|||
// |
|||
// // is only needed for debugging purposes |
|||
// // since markings is injective, we can determine the bitvector |
|||
// storm::storage::BitVector getBitvector(uint_fast64_t const& index); |
|||
// |
|||
// /*! |
|||
// * Adds the bitvector to the marking-map. |
|||
// * If the bitvector corresponds to a new marking the bitvector is added to the todo list. |
|||
// * |
|||
// * @return The rowGroup index for the bitvector. |
|||
// */ |
|||
// uint_fast64_t findOrAddBitvectorToMarkings(storm::storage::BitVector const& bitvector); |
|||
// |
|||
// /*! |
|||
// * Computes the state labeling and returns it. |
|||
// * Every state is labeled with its name. |
|||
// * |
|||
// * @return The computed state labeling. |
|||
// */ |
|||
// storm::models::sparse::StateLabeling getStateLabeling() const; |
|||
// |
|||
// |
|||
// // contains the number of bits which are used the store the number of tokens at each place |
|||
// std::map<uint_fast64_t, uint_fast64_t> numberOfBits; |
|||
// |
|||
// // contains the number of bits used to create markings |
|||
// uint_fast64_t numberOfTotalBits; |
|||
// |
|||
// // maps bitvectors (markings w.r.t. the capacity) to their rowgroup |
|||
// storm::storage::BitVectorHashMap<uint_fast64_t> markings = storm::storage::BitVectorHashMap<uint_fast64_t>(64, 1); |
|||
// |
|||
// // a list of markings for which the outgoing edges need to be computed |
|||
// std::deque<std::shared_ptr<storm::storage::BitVector>> todo; |
|||
// |
|||
// //the gspn which is transformed |
|||
// storm::gspn::GSPN gspn; |
|||
// |
|||
// // the next index for a new rowgroup |
|||
// uint_fast64_t nextRowGroupIndex = 0; |
|||
// |
|||
// // builder object which is used to create the probability matrix |
|||
// storm::storage::SparseMatrixBuilder<double> builder; |
|||
// |
|||
// // contains the current row index during the computation |
|||
// uint_fast64_t currentRowIndex; |
|||
// }; |
|||
// } |
|||
//} |
|||
// |
|||
//#endif //STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
@ -0,0 +1,343 @@ |
|||
#include "GreatSpnEditorProjectParser.h"
|
|||
|
|||
|
|||
#include <iostream>
|
|||
|
|||
#include "src/adapters/XercesAdapter.h"
|
|||
|
|||
#include "src/exceptions/UnexpectedException.h"
|
|||
#include "src/exceptions/WrongFormatException.h"
|
|||
#include "src/utility/macros.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
storm::gspn::GSPN* GreatSpnEditorProjectParser::parse(xercesc::DOMElement const* elementRoot) { |
|||
if (storm::adapters::XMLtoString(elementRoot->getTagName()) == "project") { |
|||
GreatSpnEditorProjectParser p; |
|||
return p.parse(elementRoot); |
|||
} else { |
|||
// If the top-level node is not a "pnml" or "" node, then throw an exception.
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Failed to identify the root element.\n"); |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseProjectElement(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("version") == 0 || |
|||
name.compare("name") == 0) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("gspn") == 0) { |
|||
traverseGspnElement(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseGspnElement(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("name") == 0) { |
|||
builder.setGspnName(storm::adapters::XMLtoString(attr->getNodeValue())); |
|||
} else if (name.compare("show-color-cmd") == 0 || |
|||
name.compare("show-fluid-cmd") == 0) { |
|||
// ignore node
|
|||
} else { |
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG( |
|||
"unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("nodes") == 0) { |
|||
traverseNodesElement(child); |
|||
} else if (name.compare("edges") == 0) { |
|||
traverseEdgesElement(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseNodesElement(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("place") == 0) { |
|||
traversePlaceElement(child); |
|||
} else if(name.compare("transition") == 0) { |
|||
traverseTransitionElement(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseEdgesElement(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
|
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
|
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("arc") == 0) { |
|||
traverseArcElement(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool ignorePlaceAttribute(std::string const& name) { |
|||
// TODO we should probably not ignore x-servers but check that it is 0.5.
|
|||
if ((name == "label-x") || (name == "label-y") || (name == "x") || (name == "y")) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
void GreatSpnEditorProjectParser::traversePlaceElement(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
std::string placeName; |
|||
uint64_t initialTokens = 0; |
|||
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("name") == 0) { |
|||
placeName = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("marking") == 0) { |
|||
initialTokens = std::stoull(storm::adapters::XMLtoString(attr->getNodeValue())); |
|||
} else if (ignorePlaceAttribute(name)) { |
|||
// ignore node
|
|||
} else { |
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG( |
|||
"unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
|
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
builder.addPlace(-1, initialTokens, placeName); |
|||
} |
|||
|
|||
bool ignoreTransitionAttribute(std::string const& name) { |
|||
// TODO we should probably not ignore x-servers but check that it is 0.5.
|
|||
if ((name == "label-x") || (name == "label-y") || (name == "x") || (name == "y") || (name == "nservers-x")) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseTransitionElement(xercesc::DOMNode const* const node) { |
|||
std::string transitionName; |
|||
bool immediateTransition; |
|||
double rate = 1.0; // The default rate in GreatSPN.
|
|||
|
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("name") == 0) { |
|||
transitionName = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("type") == 0) { |
|||
if (storm::adapters::XMLtoString(attr->getNodeValue()).compare("EXP") == 0) { |
|||
immediateTransition = false; |
|||
} else { |
|||
immediateTransition = true; |
|||
} |
|||
} else if(name.compare("delay") == 0) { |
|||
rate = std::stod(storm::adapters::XMLtoString(attr->getNodeValue())); |
|||
} else if (ignoreTransitionAttribute(name)) { |
|||
// ignore node
|
|||
} else { |
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG( |
|||
"unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
if (immediateTransition) { |
|||
builder.addImmediateTransition(0, 0, transitionName); |
|||
} else { |
|||
builder.addTimedTransition(0, rate, transitionName); |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool ignoreArcAttribute(std::string const& name) { |
|||
if ((name == "mult-x") || (name == "mult-y") || (name == "mult-k")) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool ignoreArcChild(std::string const& name) { |
|||
if (name == "point") { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
void GreatSpnEditorProjectParser::traverseArcElement(xercesc::DOMNode const* const node) { |
|||
std::string head = "____NOT_SET____"; |
|||
std::string tail = "____NOT_SET____"; |
|||
std::string kind = "____NOT_SET____"; |
|||
uint_fast64_t mult = 1; |
|||
|
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("head") == 0) { |
|||
head = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("tail") == 0) { |
|||
tail = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("kind") == 0) { |
|||
kind = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("mult") == 0) { |
|||
mult = std::stoull(storm::adapters::XMLtoString(attr->getNodeValue())); |
|||
} else if (ignoreArcAttribute(name)) { |
|||
// ignore node
|
|||
} else { |
|||
// Found node or attribute which is at the moment not handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG( |
|||
"unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
STORM_LOG_THROW(head.compare("____NOT_SET____") != 0, storm::exceptions::WrongFormatException, "Arc must have a head"); |
|||
STORM_LOG_THROW(tail.compare("____NOT_SET____") != 0, storm::exceptions::WrongFormatException, "Arc must have a tail"); |
|||
STORM_LOG_THROW(kind.compare("____NOT_SET____") != 0, storm::exceptions::WrongFormatException, "Arc must have a kind"); |
|||
|
|||
|
|||
if (kind.compare("INPUT") == 0) { |
|||
builder.addInputArc(head, tail, mult); |
|||
} else if (kind.compare("INHIBITOR") == 0) { |
|||
builder.addInhibitionArc(head, tail, mult); |
|||
} else if (kind.compare("OUTPUT") == 0) { |
|||
builder.addOutputArc(head, tail, mult); |
|||
} else { |
|||
// TODO error!
|
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else if(ignoreArcChild(name)) { |
|||
// ignore
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
@ -0,0 +1,42 @@ |
|||
#pragma once |
|||
|
|||
#include <string> |
|||
|
|||
#include <xercesc/parsers/XercesDOMParser.hpp> |
|||
#include <xercesc/util/XMLString.hpp> |
|||
|
|||
#include "src/storage/gspn/GSPN.h" |
|||
|
|||
#include "src/storage/gspn/GspnBuilder.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
class GreatSpnEditorProjectParser { |
|||
|
|||
public: |
|||
|
|||
/*! |
|||
* Parses the given file into the GSPN. |
|||
* |
|||
* @param filename The name of the file to parse. |
|||
* @return The resulting GSPN. |
|||
*/ |
|||
storm::gspn::GSPN* parse(xercesc::DOMElement const* elementRoot); |
|||
private: |
|||
void traverseProjectElement(xercesc::DOMNode const* const node); |
|||
|
|||
void traverseGspnElement(xercesc::DOMNode const* const node); |
|||
void traverseNodesElement(xercesc::DOMNode const* const node); |
|||
void traverseEdgesElement(xercesc::DOMNode const* const node); |
|||
|
|||
void traversePlaceElement(xercesc::DOMNode const* const node); |
|||
void traverseTransitionElement(xercesc::DOMNode const* const node); |
|||
void traverseArcElement(xercesc::DOMNode const* const node); |
|||
|
|||
|
|||
// the constructed gspn |
|||
storm::gspn::GspnBuilder builder; |
|||
|
|||
}; |
|||
} |
|||
} |
@ -1,177 +1,10 @@ |
|||
#ifndef STORM_PARSER_GSPNPARSER_H_ |
|||
#define STORM_PARSER_GSPNPARSER_H_ |
|||
|
|||
#include <string> |
|||
|
|||
#include <xercesc/parsers/XercesDOMParser.hpp> |
|||
#include <xercesc/util/XMLString.hpp> |
|||
|
|||
#include "src/storage/gspn/GSPN.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/* Parses a pnml-file to a gspn. |
|||
IMPORTANT: The names of places, transitions and arcs must differ from each other. |
|||
*/ |
|||
class GspnParser { |
|||
public: |
|||
|
|||
/*! |
|||
* Parses the given file into the GSPN. |
|||
* |
|||
* @param filename The name of the file to parse. |
|||
* @return The resulting GSPN. |
|||
*/ |
|||
storm::gspn::GSPN const& parse(std::string const& filename); |
|||
private: |
|||
|
|||
/*! |
|||
* Traverse the root element. |
|||
* |
|||
* @param element The root element of the DOM object. |
|||
*/ |
|||
void traversePnmlElement(xercesc::DOMElement const* const element); |
|||
|
|||
/*! |
|||
* Traverse a net or page node. |
|||
* |
|||
* @param node The net or page node. |
|||
*/ |
|||
void traverseNetOrPage(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a place node. |
|||
* |
|||
* @param node The place node. |
|||
*/ |
|||
void traversePlace(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a transition node. |
|||
* |
|||
* @param node The transition node. |
|||
*/ |
|||
void traverseTransition(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse an arc node. |
|||
* |
|||
* @param node The arc node. |
|||
*/ |
|||
void traverseArc(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse an initial marking node. |
|||
* |
|||
* @param node the initial marking node. |
|||
* @return The number of initial tokens. |
|||
*/ |
|||
uint_fast64_t traverseInitialMarking(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a capacity node. |
|||
* |
|||
* @param node The capacity node. |
|||
* @return The capacity for the place. |
|||
*/ |
|||
int_fast64_t traverseCapacity(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a inscription node. |
|||
* |
|||
* @param node The inscription node. |
|||
* @return The multiplicty for the arc. |
|||
*/ |
|||
uint_fast64_t traverseMultiplicity(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a rate node. |
|||
* |
|||
* @param node The rate node. |
|||
* @return The rate or weight of the transition. |
|||
*/ |
|||
std::string traverseTransitionValue(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a timed node. |
|||
* |
|||
* @param node The timed node. |
|||
* @return False if the tranisition is immediate |
|||
*/ |
|||
bool traverseTransitionType(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a type node. |
|||
* |
|||
* @param node The type node. |
|||
* @return Returns a string with the arc type. |
|||
*/ |
|||
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. |
|||
* |
|||
* @param node The node. |
|||
* @return The name of the node. |
|||
*/ |
|||
std::string getName(xercesc::DOMNode* node); |
|||
|
|||
/*! |
|||
* Transforms the given XML String to a std::string. |
|||
* |
|||
* @param xmlString The given String in the XML format |
|||
* @return The corresponding std::string. |
|||
*/ |
|||
static std::string XMLtoString(const XMLCh* xmlString); |
|||
|
|||
|
|||
void traverseProjectElement(xercesc::DOMNode const* const node); |
|||
|
|||
void traverseGspnElement(xercesc::DOMNode const* const node); |
|||
void traverseNodesElement(xercesc::DOMNode const* const node); |
|||
void traverseEdgesElement(xercesc::DOMNode const* const node); |
|||
|
|||
void traversePlaceElement(xercesc::DOMNode const* const node); |
|||
void traverseTransitionElement(xercesc::DOMNode const* const node); |
|||
void traverseArcElement(xercesc::DOMNode const* const node); |
|||
|
|||
|
|||
// the constructed gspn |
|||
storm::gspn::GSPN gspn; |
|||
|
|||
// contains the id for a new node |
|||
uint_fast64_t newNode = 0; |
|||
|
|||
// default value for initial tokens |
|||
uint_fast64_t defaultNumberOfInitialTokens = 0; |
|||
|
|||
// default value for capacities |
|||
int_fast64_t defaultCapacity = -1; |
|||
|
|||
// default value for the transition type (false == immediate transition) |
|||
bool defaultTransitionType = false; |
|||
|
|||
// default value for the transition weight or rate |
|||
std::string defaultTransitionValue = "1"; // TODO set to 0 |
|||
|
|||
// default value for the arc type |
|||
std::string defaultArcType = "normal"; |
|||
|
|||
// default multiplicity for arcs |
|||
uint_fast64_t defaultMultiplicity = 1; |
|||
|
|||
//default priority for transitions |
|||
uint_fast64_t defaultPriority = 0; |
|||
static storm::gspn::GSPN* parse(std::string const& filename); |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif //STORM_PARSER_GSPNPARSER_H_ |
@ -0,0 +1,446 @@ |
|||
#include "src/parser/PnmlParser.h"
|
|||
|
|||
#include <iostream>
|
|||
|
|||
#include "src/adapters/XercesAdapter.h"
|
|||
|
|||
#include "src/exceptions/UnexpectedException.h"
|
|||
#include "src/exceptions/WrongFormatException.h"
|
|||
#include "src/utility/macros.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
storm::gspn::GSPN * PnmlParser::parse(xercesc::DOMElement const* elementRoot ) { |
|||
if (storm::adapters::getName(elementRoot) == "pnml") { |
|||
traversePnmlElement(elementRoot); |
|||
} else { |
|||
// If the top-level node is not a "pnml" or "" node, then throw an exception.
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Failed to identify the root element.\n"); |
|||
} |
|||
return builder.buildGspn(); |
|||
} |
|||
|
|||
void PnmlParser::traversePnmlElement(xercesc::DOMElement const* const element) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < element->getAttributes()->getLength(); ++i) { |
|||
auto attr = element->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=pnml): " + name + "\n"); |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < element->getChildNodes()->getLength(); ++i) { |
|||
auto child = element->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("net") == 0) { |
|||
traverseNetOrPage(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=pnml): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PnmlParser::traverseNetOrPage(xercesc::DOMNode const* const node) { |
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("id") == 0) { |
|||
builder.setGspnName(storm::adapters::XMLtoString(attr->getNodeValue())); |
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("place") == 0) { |
|||
traversePlace(child); |
|||
} else if (name.compare("transition") == 0) { |
|||
traverseTransition(child); |
|||
} else if (name.compare("arc") == 0) { |
|||
traverseArc(child); |
|||
} else if (name.compare("page") == 0) { |
|||
// Some pnml files have a child named page.
|
|||
// The page node has the same children like the net node (e.g., place, transition, arc)
|
|||
traverseNetOrPage(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=" + storm::adapters::XMLtoString(node->getNodeName()) + "): " + name + "\n"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PnmlParser::traversePlace(xercesc::DOMNode const* const node) { |
|||
std::string placeName; |
|||
// the first entry is false if the corresponding information was not found in the pnml file
|
|||
std::pair<bool, uint_fast64_t> numberOfInitialTokens(false, defaultNumberOfInitialTokens); |
|||
std::pair<bool, int_fast64_t> capacity(false, defaultCapacity); |
|||
|
|||
// traverse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("id") == 0) { |
|||
placeName = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=place): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("initialMarking") == 0) { |
|||
numberOfInitialTokens.first = true; |
|||
numberOfInitialTokens.second = traverseInitialMarking(child); |
|||
} else if(name.compare("capacity") == 0) { |
|||
capacity.first = true; |
|||
capacity.second = traverseCapacity(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else if (name.compare("name") == 0 || |
|||
name.compare("graphics") == 0) { |
|||
// ignore these tags
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=place): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
if (!numberOfInitialTokens.first) { |
|||
// no information about the number of initial tokens is found
|
|||
// use the default number of initial tokens
|
|||
STORM_PRINT_AND_LOG("unknown numberOfInitialTokens (place=" + placeName + ")\n"); |
|||
} |
|||
if (!capacity.first) { |
|||
// no information about the capacity is found
|
|||
// use default capacity
|
|||
STORM_PRINT_AND_LOG("unknown capacity (place=" + placeName + ")\n"); |
|||
} |
|||
builder.addPlace(capacity.first ? capacity.second : -1, numberOfInitialTokens.first ? numberOfInitialTokens.second : 0, placeName); |
|||
} |
|||
|
|||
void PnmlParser::traverseTransition(xercesc::DOMNode const* const node) { |
|||
// the first entry is false if the corresponding information was not found in the pnml file
|
|||
std::pair<bool, bool> timed(false, defaultTransitionType); |
|||
std::pair<bool, std::string> value(false, ""); |
|||
std::string id; |
|||
uint_fast64_t priority = defaultPriority; |
|||
|
|||
// parse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("id") == 0) { |
|||
id = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=transition): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// traverse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
|
|||
if (name.compare("rate") == 0) { |
|||
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 || |
|||
name.compare("name") == 0 || |
|||
name.compare("orientation") == 0) { |
|||
// ignore these tags
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=transition): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// build transition and add it to the gspn
|
|||
if (!timed.first) { |
|||
// found unknown transition type
|
|||
// abort parsing
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "unknown transition type (transition=" + id + ")\n"); |
|||
return; |
|||
} |
|||
|
|||
if (timed.second) { |
|||
if (!value.first) { |
|||
// no information about the rate is found
|
|||
// abort the parsing
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException ,"unknown transition rate (transition=" + id + ")\n"); |
|||
} |
|||
builder.addTimedTransition(priority, std::stod(value.second), id); |
|||
} else { |
|||
if (!value.first) { |
|||
// no information about the weight is found
|
|||
// continue with the default weight
|
|||
STORM_PRINT_AND_LOG("unknown transition weight (transition=" + id + ")\n"); |
|||
} |
|||
builder.addImmediateTransition(priority, std::stod(value.second), id); |
|||
} |
|||
} |
|||
|
|||
void PnmlParser::traverseArc(xercesc::DOMNode const* const node) { |
|||
// the first entry is false if the corresponding information was not found in the pnml file
|
|||
std::pair<bool, std::string> source(false, ""); |
|||
std::pair<bool, std::string> target(false, ""); |
|||
std::pair<bool, std::string> type(false, defaultArcType); |
|||
std::pair<bool, uint_fast64_t> multiplicity(false, defaultMultiplicity); |
|||
std::string id; |
|||
|
|||
// parse attributes
|
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
|
|||
if (name.compare("source") == 0) { |
|||
source.first = true; |
|||
source.second = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("target") == 0) { |
|||
target.first = true; |
|||
target.second = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else if (name.compare("id") == 0) { |
|||
id = storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown attribute (node=arc): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// parse children
|
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("type") == 0) { |
|||
type.first = true; |
|||
type.second = traverseArcType(child); |
|||
} else if(name.compare("inscription") == 0) { |
|||
multiplicity.first = true; |
|||
multiplicity.second = traverseMultiplicity(child); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else if (name.compare("graphics") == 0 || |
|||
name.compare("arcpath") == 0 || |
|||
name.compare("tagged") == 0) { |
|||
// ignore these tags
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=arc): " + name + "\n"); |
|||
} |
|||
} |
|||
|
|||
// check if all necessary information where stored in the pnml file
|
|||
if (!source.first) { |
|||
// could not find start of the arc
|
|||
// abort parsing
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException ,"unknown arc source (arc=" + id + ")\n"); |
|||
} |
|||
if (!target.first) { |
|||
// could not find the target of the arc
|
|||
// abort parsing
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException ,"unknown arc target (arc=" + id + ")\n"); |
|||
} |
|||
if (!multiplicity.first) { |
|||
// no information about the multiplicity of the arc
|
|||
// continue and use the default multiplicity
|
|||
STORM_PRINT_AND_LOG("unknown multiplicity (node=arc): " + id + "\n"); |
|||
} |
|||
|
|||
STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "No arc type specified for arc '" + id + "'"); |
|||
if (type.second == "normal") { |
|||
builder.addNormalArc(source.second, target.second, multiplicity.second); |
|||
} else if (type.second == "inhibition") { |
|||
builder.addInhibitionArc(source.second, target.second, multiplicity.second); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Arc type '" << type.second << "' in arc '" << id << "' is unknown."); |
|||
} |
|||
} |
|||
|
|||
uint_fast64_t PnmlParser::traverseInitialMarking(xercesc::DOMNode const* const node) { |
|||
uint_fast64_t result = defaultNumberOfInitialTokens; |
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("text") == 0) { |
|||
result = std::stoull(storm::adapters::getName(child->getFirstChild())); |
|||
} else if (name.compare("value") == 0) { |
|||
auto value = storm::adapters::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 { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=initialMarking): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
int_fast64_t PnmlParser::traverseCapacity(xercesc::DOMNode const* const node) { |
|||
int_fast64_t result= defaultCapacity; |
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("value") == 0) { |
|||
auto value = storm::adapters::getName(child->getFirstChild()); |
|||
if (value.find("Default,") == 0) { |
|||
value = value.substr(std::string("Default,").length()); |
|||
} |
|||
result = std::stoull(value); |
|||
} else if (name.compare("graphics") == 0) { |
|||
// ignore these nodes
|
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=capacity): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
uint_fast64_t PnmlParser::traverseMultiplicity(xercesc::DOMNode const* const node) { |
|||
uint_fast64_t result = defaultMultiplicity; |
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("value") == 0) { |
|||
auto value = storm::adapters::getName(child->getFirstChild()); |
|||
if (value.find("Default,") == 0) { |
|||
value = value.substr(std::string("Default,").length()); |
|||
} |
|||
result = std::stoull(value); |
|||
} else if (name.compare("graphics") == 0) { |
|||
// ignore these nodes
|
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=inscription): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
std::string PnmlParser::traverseTransitionValue(xercesc::DOMNode const* const node) { |
|||
std::string result; |
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("value") == 0) { |
|||
result = storm::adapters::getName(child->getFirstChild()); |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=rate): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
bool PnmlParser::traverseTransitionType(xercesc::DOMNode const* const node) { |
|||
bool result; |
|||
for (uint_fast64_t i = 0; i < node->getChildNodes()->getLength(); ++i) { |
|||
auto child = node->getChildNodes()->item(i); |
|||
auto name = storm::adapters::getName(child); |
|||
if (name.compare("value") == 0) { |
|||
result = storm::adapters::getName(child->getFirstChild()).compare("true") == 0 ? true : false; |
|||
} else if (std::all_of(name.begin(), name.end(), isspace)) { |
|||
// ignore node (contains only whitespace)
|
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=timed): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
std::string PnmlParser::traverseArcType(xercesc::DOMNode const* const node) { |
|||
for (uint_fast64_t i = 0; i < node->getAttributes()->getLength(); ++i) { |
|||
auto attr = node->getAttributes()->item(i); |
|||
auto name = storm::adapters::getName(attr); |
|||
if (name.compare("value") == 0) { |
|||
return storm::adapters::XMLtoString(attr->getNodeValue()); |
|||
} else { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=type): " + name + "\n"); |
|||
} |
|||
} |
|||
return defaultArcType; |
|||
} |
|||
|
|||
uint_fast64_t PnmlParser::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 = storm::adapters::getName(child); |
|||
if (name.compare("text") == 0) { |
|||
result = std::stoull(storm::adapters::getName(child->getFirstChild())); |
|||
} else if (name.compare("value") == 0) { |
|||
auto value = storm::adapters::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 { |
|||
// Found node or attribute which is at the moment nod handled by this parser.
|
|||
// Notify the user and continue the parsing.
|
|||
STORM_PRINT_AND_LOG("unknown child (node=priority): " + name + "\n"); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,142 @@ |
|||
#pragma once |
|||
|
|||
#include <string> |
|||
|
|||
#include <xercesc/parsers/XercesDOMParser.hpp> |
|||
#include <xercesc/util/XMLString.hpp> |
|||
|
|||
#include "src/storage/gspn/GSPN.h" |
|||
|
|||
#include "src/storage/gspn/GspnBuilder.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/* Parses a pnml-file to a gspn. |
|||
IMPORTANT: The names of places, transitions and arcs must differ from each other. |
|||
*/ |
|||
class PnmlParser { |
|||
public: |
|||
|
|||
/*! |
|||
* Parses the given file into the GSPN. |
|||
* |
|||
* @param filename The name of the file to parse. |
|||
* @return The resulting GSPN. |
|||
*/ |
|||
storm::gspn::GSPN* parse(xercesc::DOMElement const* elementRoot); |
|||
private: |
|||
|
|||
/*! |
|||
* Traverse the root element. |
|||
* |
|||
* @param element The root element of the DOM object. |
|||
*/ |
|||
void traversePnmlElement(xercesc::DOMElement const* const element); |
|||
|
|||
/*! |
|||
* Traverse a net or page node. |
|||
* |
|||
* @param node The net or page node. |
|||
*/ |
|||
void traverseNetOrPage(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a place node. |
|||
* |
|||
* @param node The place node. |
|||
*/ |
|||
void traversePlace(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a transition node. |
|||
* |
|||
* @param node The transition node. |
|||
*/ |
|||
void traverseTransition(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse an arc node. |
|||
* |
|||
* @param node The arc node. |
|||
*/ |
|||
void traverseArc(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse an initial marking node. |
|||
* |
|||
* @param node the initial marking node. |
|||
* @return The number of initial tokens. |
|||
*/ |
|||
uint_fast64_t traverseInitialMarking(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a capacity node. |
|||
* |
|||
* @param node The capacity node. |
|||
* @return The capacity for the place. |
|||
*/ |
|||
int_fast64_t traverseCapacity(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a inscription node. |
|||
* |
|||
* @param node The inscription node. |
|||
* @return The multiplicty for the arc. |
|||
*/ |
|||
uint_fast64_t traverseMultiplicity(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a rate node. |
|||
* |
|||
* @param node The rate node. |
|||
* @return The rate or weight of the transition. |
|||
*/ |
|||
std::string traverseTransitionValue(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a timed node. |
|||
* |
|||
* @param node The timed node. |
|||
* @return False if the tranisition is immediate |
|||
*/ |
|||
bool traverseTransitionType(xercesc::DOMNode const* const node); |
|||
|
|||
/*! |
|||
* Traverse a type node. |
|||
* |
|||
* @param node The type node. |
|||
* @return Returns a string with the arc type. |
|||
*/ |
|||
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); |
|||
|
|||
// the constructed gspn |
|||
storm::gspn::GspnBuilder builder; |
|||
|
|||
// default value for initial tokens |
|||
uint_fast64_t defaultNumberOfInitialTokens = 0; |
|||
|
|||
// default value for capacities |
|||
int_fast64_t defaultCapacity = -1; |
|||
|
|||
// default value for the transition type (false == immediate transition) |
|||
bool defaultTransitionType = false; |
|||
|
|||
// default value for the arc type |
|||
std::string defaultArcType = "normal"; |
|||
|
|||
// default multiplicity for arcs |
|||
uint_fast64_t defaultMultiplicity = 1; |
|||
|
|||
//default priority for transitions |
|||
uint_fast64_t defaultPriority = 0; |
|||
}; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue