14 changed files with 1647 additions and 636 deletions
-
249src/builder/ExplicitGspnModelBuilder.cpp
-
158src/builder/ExplicitGspnModelBuilder.h
-
425src/parser/GspnParser.cpp
-
157src/parser/GspnParser.h
-
167src/storage/gspn/GSPN.cpp
-
133src/storage/gspn/GSPN.h
-
10src/storage/gspn/ImmediateTransition.h
-
111src/storage/gspn/Marking.cpp
-
70src/storage/gspn/Marking.h
-
41src/storage/gspn/Place.cpp
-
87src/storage/gspn/Place.h
-
10src/storage/gspn/TimedTransition.h
-
150src/storage/gspn/Transition.cpp
-
143src/storage/gspn/Transition.h
@ -0,0 +1,249 @@ |
|||||
|
#include "src/builder/ExplicitGspnModelBuilder.h"
|
||||
|
|
||||
|
#include "src/models/sparse/StandardRewardModel.h"
|
||||
|
|
||||
|
#include "src/utility/macros.h"
|
||||
|
#include "src/exceptions/NotImplementedException.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace builder { |
||||
|
|
||||
|
template<typename ValueType> |
||||
|
storm::models::sparse::MarkovAutomaton<ValueType> ExplicitGspnModelBuilder<ValueType>::translateGspn(storm::gspn::GSPN const& gspn) { |
||||
|
// 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, 0); |
||||
|
} |
||||
|
} |
||||
|
++currentRowIndex; |
||||
|
} |
||||
|
|
||||
|
auto matrix = builder.build(); |
||||
|
const storm::models::sparse::StateLabeling labeling; // TODO
|
||||
|
|
||||
|
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->getWeight() == 0) { |
||||
|
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; |
||||
|
|
||||
|
for (auto& trans_ptr : gspn.getTimedTransitions()) { |
||||
|
if (trans_ptr->isEnabled(marking)) { |
||||
|
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; |
||||
|
|
||||
|
for (auto& trans_ptr : gspn.getImmediateTransitions()) { |
||||
|
if (trans_ptr->isEnabled(marking)) { |
||||
|
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 class ExplicitGspnModelBuilder<double>; |
||||
|
} |
||||
|
} |
@ -1,11 +1,161 @@ |
|||||
#ifndef STORM_EXPLICITGSPNMODELBUILDER_H |
|
||||
#define STORM_EXPLICITGSPNMODELBUILDER_H |
|
||||
|
#ifndef STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
||||
|
#define STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
||||
|
|
||||
|
#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 storm { |
||||
namespace builder { |
namespace builder { |
||||
// Takes a GSPN, builds an MA. |
|
||||
|
|
||||
|
/*! |
||||
|
* 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); |
||||
|
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. |
||||
|
* |
||||
|
* @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 |
||||
|
* |
||||
|
* @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); |
||||
|
|
||||
|
|
||||
|
// 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_EXPLICITGSPNMODELBUILDER_H |
|
||||
|
#endif //STORM_BUILDER_EXPLICITGSPNMODELBUILDER_H_ |
@ -1,134 +1,155 @@ |
|||||
#ifndef STORM_GSPNPARSER_H |
|
||||
#define STORM_GSPNPARSER_H |
|
||||
|
#ifndef STORM_PARSER_GSPNPARSER_H_ |
||||
|
#define STORM_PARSER_GSPNPARSER_H_ |
||||
|
|
||||
#include <iostream> |
|
||||
#include <string> |
#include <string> |
||||
|
|
||||
#include <xercesc/parsers/XercesDOMParser.hpp> |
#include <xercesc/parsers/XercesDOMParser.hpp> |
||||
#include <xercesc/dom/DOM.hpp> |
|
||||
#include <xercesc/sax/HandlerBase.hpp> |
|
||||
#include <xercesc/util/XMLString.hpp> |
#include <xercesc/util/XMLString.hpp> |
||||
#include <xercesc/util/PlatformUtils.hpp> |
|
||||
|
|
||||
#include "src/storage/gspn/GSPN.h" |
#include "src/storage/gspn/GSPN.h" |
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace parser { |
namespace parser { |
||||
// Parses a GSPN in xml format |
|
||||
|
|
||||
|
/* Parses a pnml-file to a gspn. |
||||
|
IMPORTANT: The names of places, transitions and arcs must differ from each other. |
||||
|
*/ |
||||
class GspnParser { |
class GspnParser { |
||||
public: |
public: |
||||
/*! |
|
||||
* Parses the given file into the GSPN storage class assuming it complies with the PNML. |
|
||||
* |
|
||||
* @param filename The name of the file to parse |
|
||||
* @return The resulting GSPN. |
|
||||
*/ |
|
||||
storm::gspn::GSPN parse(std::string const& filename); |
|
||||
|
|
||||
/*! |
/*! |
||||
* Transforms the given XML String to a normal string. |
|
||||
|
* Parses the given file into the GSPN. |
||||
* |
* |
||||
* @param xmlString The given String in the XML format |
|
||||
* @return The corresponding standard string. |
|
||||
|
* @param filename The name of the file to parse. |
||||
|
* @return The resulting GSPN. |
||||
*/ |
*/ |
||||
static std::string XMLtoString(const XMLCh* xmlString); |
|
||||
|
storm::gspn::GSPN const& parse(std::string const& filename); |
||||
private: |
private: |
||||
// maps the original name of the state to its numerical representation |
|
||||
std::map<std::string,uint64_t> stringToState; |
|
||||
|
|
||||
// maps the transition id to a pointer to the transition |
|
||||
std::map<std::string,std::shared_ptr<storm::gspn::Transition>> stringToTransition; |
|
||||
|
|
||||
// the constructed gspn |
|
||||
storm::gspn::GSPN gspn; |
|
||||
|
|
||||
// has the new id for a new node |
|
||||
uint64_t newNode; |
|
||||
|
|
||||
/*! |
/*! |
||||
* Parses the root element. |
|
||||
|
* Traverse the root element. |
||||
* |
* |
||||
* @param element The root element. |
|
||||
|
* @param element The root element of the DOM object. |
||||
*/ |
*/ |
||||
void parsePNML(xercesc::DOMElement* element); |
|
||||
|
void traversePnmlElement(xercesc::DOMElement const* const element); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses a net node. |
|
||||
|
* Traverse a net or page node. |
||||
* |
* |
||||
* @param node The net node. |
|
||||
|
* @param node The net or page node. |
||||
*/ |
*/ |
||||
void parseNet(xercesc::DOMNode* node); |
|
||||
|
void traverseNetOrPage(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses a page node. |
|
||||
* |
|
||||
* @param node The page node. |
|
||||
a */ |
|
||||
void parsePage(xercesc::DOMNode* node); |
|
||||
|
|
||||
/*! |
|
||||
* Parses a place node. |
|
||||
|
* Traverse a place node. |
||||
* |
* |
||||
* @param node The place node. |
* @param node The place node. |
||||
*/ |
*/ |
||||
void parsePlace(xercesc::DOMNode* node); |
|
||||
|
void traversePlace(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses a transition node. |
|
||||
|
* Traverse a transition node. |
||||
* |
* |
||||
* @param node The transition node. |
* @param node The transition node. |
||||
*/ |
*/ |
||||
void parseTransition(xercesc::DOMNode* node); |
|
||||
|
void traverseTransition(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses an arc node. |
|
||||
|
* Traverse an arc node. |
||||
* |
* |
||||
* @param node The arc node. |
* @param node The arc node. |
||||
*/ |
*/ |
||||
void parseArc(xercesc::DOMNode* node); |
|
||||
|
void traverseArc(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses an initial marking node . |
|
||||
|
* Traverse an initial marking node. |
||||
* |
* |
||||
* @param node the initial marking node. |
* @param node the initial marking node. |
||||
* @return The number of tokens. |
|
||||
|
* @return The number of initial tokens. |
||||
*/ |
*/ |
||||
uint64_t parseInitialMarking(xercesc::DOMNode* node); |
|
||||
|
uint_fast64_t traverseInitialMarking(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Adds a new entry in the mapping from string to places. |
|
||||
|
* Traverse a capacity node. |
||||
* |
* |
||||
* @param id The string id for the new place |
|
||||
* @return The new place. |
|
||||
|
* @param node The capacity node. |
||||
|
* @return The capacity for the place. |
||||
*/ |
*/ |
||||
uint64_t addNewPlace(std::string id); |
|
||||
|
int_fast64_t traverseCapacity(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Gives the name of the current node. |
|
||||
* @param node Current node. |
|
||||
* @return The name. |
|
||||
|
* Traverse a inscription node. |
||||
|
* |
||||
|
* @param node The inscription node. |
||||
|
* @return The multiplicty for the arc. |
||||
*/ |
*/ |
||||
std::string getName(xercesc::DOMNode* node); |
|
||||
|
uint_fast64_t traverseMultiplicity(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parses a rate node. |
|
||||
|
* Traverse a rate node. |
||||
|
* |
||||
|
* @param node The rate node. |
||||
|
* @return The rate or weight of the transition. |
||||
*/ |
*/ |
||||
std::string parseRate(xercesc::DOMNode* node); |
|
||||
|
std::string traverseTransitionValue(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parse a timed node. |
|
||||
|
* Traverse a timed node. |
||||
|
* |
||||
|
* @param node The timed node. |
||||
|
* @return False if the tranisition is immediate |
||||
*/ |
*/ |
||||
bool parseTimed(xercesc::DOMNode* node); |
|
||||
|
bool traverseTransitionType(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parse a type node. |
|
||||
|
* Traverse a type node. |
||||
|
* |
||||
|
* @param node The type node. |
||||
|
* @return Returns a string with the arc type. |
||||
*/ |
*/ |
||||
std::string parseType(xercesc::DOMNode* node); |
|
||||
|
std::string traverseArcType(xercesc::DOMNode const* const node); |
||||
|
|
||||
/*! |
/*! |
||||
* Parse a capacity 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. |
||||
*/ |
*/ |
||||
uint64_t parseCapacity(xercesc::DOMNode* node); |
|
||||
|
static std::string XMLtoString(const XMLCh* xmlString); |
||||
|
|
||||
|
// 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; |
||||
}; |
}; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
#endif //STORM_GSPNPARSER_H |
|
||||
|
#endif //STORM_PARSER_GSPNPARSER_H_ |
@ -1,27 +1,168 @@ |
|||||
#include "src/storage/gspn/GSPN.h"
|
#include "src/storage/gspn/GSPN.h"
|
||||
|
|
||||
storm::gspn::GSPN::GSPN() : initialMarking(0, 0) { |
|
||||
|
namespace storm { |
||||
|
namespace gspn { |
||||
|
void GSPN::addImmediateTransition(storm::gspn::ImmediateTransition<WeightType> const& transition) { |
||||
|
this->immediateTransitions.push_back(std::make_shared<storm::gspn::ImmediateTransition<WeightType>>(transition)); |
||||
} |
} |
||||
|
|
||||
void storm::gspn::GSPN::setInitialTokens(uint64_t place, uint64_t token) { |
|
||||
if (initialMarking.getMaxNumberOfTokens() < token) { |
|
||||
initialMarking.setMaxNumberOfTokens(token); |
|
||||
|
void GSPN::addTimedTransition(storm::gspn::TimedTransition<RateType> const& transition) { |
||||
|
this->timedTransitions.push_back(std::make_shared<storm::gspn::TimedTransition<RateType>>(transition)); |
||||
} |
} |
||||
initialMarking.setNumberOfTokensAt(place, token); |
|
||||
|
|
||||
|
void GSPN::addPlace(Place const& place) { |
||||
|
//TODO check whether the name or id is already used by an place
|
||||
|
this->places.push_back(place); |
||||
|
} |
||||
|
|
||||
|
uint_fast64_t GSPN::getNumberOfPlaces() const { |
||||
|
return places.size(); |
||||
|
} |
||||
|
|
||||
|
std::vector<std::shared_ptr<storm::gspn::TimedTransition<GSPN::RateType>>> const& GSPN::getTimedTransitions() const { |
||||
|
return this->timedTransitions; |
||||
|
} |
||||
|
|
||||
|
std::vector<std::shared_ptr<storm::gspn::ImmediateTransition<GSPN::WeightType>>> const& GSPN::getImmediateTransitions() const { |
||||
|
return this->immediateTransitions; |
||||
} |
} |
||||
|
|
||||
void storm::gspn::GSPN::setNumberOfPlaces(uint64_t number) { |
|
||||
initialMarking.setNumberOfPlaces(number); |
|
||||
|
std::vector<storm::gspn::Place> const& GSPN::getPlaces() const { |
||||
|
return places; |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<storm::gspn::Marking> GSPN::getInitialMarking(std::map<uint_fast64_t, uint_fast64_t>& numberOfBits, uint_fast64_t const& numberOfTotalBits) const { |
||||
|
auto m = std::make_shared<storm::gspn::Marking>(getNumberOfPlaces(), numberOfBits, numberOfTotalBits); |
||||
|
for (auto& place : getPlaces()) { |
||||
|
m->setNumberOfTokensAt(place.getID(), place.getNumberOfInitialTokens()); |
||||
|
} |
||||
|
return m; |
||||
|
} |
||||
|
|
||||
|
std::pair<bool, storm::gspn::Place> GSPN::getPlace(std::string const& id) const { |
||||
|
for (auto& place : places) { |
||||
|
if (id.compare(place.getName()) == 0) { |
||||
|
return std::make_pair<bool, storm::gspn::Place const&>(true, place); |
||||
|
} |
||||
|
} |
||||
|
return std::make_pair<bool, storm::gspn::Place>(false, storm::gspn::Place()); |
||||
} |
} |
||||
|
|
||||
uint64_t storm::gspn::GSPN::getNumberOfPlaces() { |
|
||||
return initialMarking.getNumberOfPlaces(); |
|
||||
|
std::pair<bool, std::shared_ptr<storm::gspn::TimedTransition<GSPN::RateType>> const> GSPN::getTimedTransition(std::string const& id) const { |
||||
|
for (auto& trans : timedTransitions) { |
||||
|
if (id.compare(trans->getName()) == 0) { |
||||
|
return std::make_pair<bool, std::shared_ptr<storm::gspn::TimedTransition<GSPN::RateType>> const>(true, static_cast<std::shared_ptr<storm::gspn::TimedTransition<GSPN::RateType>> const>(trans)); |
||||
|
} |
||||
|
} |
||||
|
return std::make_pair<bool, std::shared_ptr<storm::gspn::TimedTransition<GSPN::RateType>> const>(false, nullptr); |
||||
|
} |
||||
|
|
||||
|
std::pair<bool, std::shared_ptr<storm::gspn::ImmediateTransition<GSPN::WeightType>> const> GSPN::getImmediateTransition(std::string id) const { |
||||
|
for (auto& trans : immediateTransitions) { |
||||
|
if (id.compare(trans->getName()) == 0) { |
||||
|
return std::make_pair<bool, std::shared_ptr<storm::gspn::ImmediateTransition<GSPN::WeightType>> const>(true, static_cast<std::shared_ptr<storm::gspn::ImmediateTransition<GSPN::WeightType>> const>(trans)); |
||||
|
} |
||||
|
} |
||||
|
return std::make_pair<bool, std::shared_ptr<storm::gspn::ImmediateTransition<GSPN::WeightType>> const>(false, nullptr); |
||||
|
} |
||||
|
|
||||
|
std::pair<bool, std::shared_ptr<storm::gspn::Transition> const> GSPN::getTransition(std::string const& id) const { |
||||
|
auto trans = getTimedTransition(id); |
||||
|
if (trans.first == true) { |
||||
|
return trans; |
||||
|
} |
||||
|
|
||||
|
return getImmediateTransition(id); |
||||
|
} |
||||
|
|
||||
|
void GSPN::writeDotToStream(std::ostream& outStream) { |
||||
|
outStream << "digraph " << this->getName() << " {" << std::endl; |
||||
|
|
||||
|
// print places with initial marking (not printed is the capacity)
|
||||
|
outStream << "\t" << "node [shape=ellipse]" << std::endl; |
||||
|
for (auto& place : this->getPlaces()) { |
||||
|
outStream << "\t" << place.getName() << " [label=\"" << place.getName() << "(" << place.getNumberOfInitialTokens(); |
||||
|
outStream << ")\"];" << std::endl; |
||||
} |
} |
||||
|
|
||||
void storm::gspn::GSPN::addImmediateTransition(std::shared_ptr<storm::gspn::ImmediateTransition<WeightType>> transition) { |
|
||||
this->immediateTransitions.push_back(transition); |
|
||||
|
// print transitions with weight/rate
|
||||
|
outStream << "\t" << "node [shape=box]" << std::endl; |
||||
|
for (auto& trans : this->getImmediateTransitions()) { |
||||
|
outStream << "\t" << trans->getName() << " [label=\"" << trans->getName(); |
||||
|
outStream << "(immediate:" << trans->getWeight() << ")\"];" << std::endl; |
||||
} |
} |
||||
|
|
||||
void storm::gspn::GSPN::addTimedTransition(std::shared_ptr<storm::gspn::TimedTransition<RateType>> transition) { |
|
||||
this->timedTransitions.push_back(transition); |
|
||||
|
for (auto& trans : this->getTimedTransitions()) { |
||||
|
outStream << "\t" << trans->getName() << " [label=\"" << trans->getName(); |
||||
|
outStream << "(timed:" << trans->getRate() << ")\"];" << std::endl; |
||||
} |
} |
||||
|
|
||||
|
// print arcs
|
||||
|
for (auto& trans : this->getImmediateTransitions()) { |
||||
|
auto it = trans->getInputPlacesCBegin(); |
||||
|
while (it != trans->getInputPlacesCEnd()) { |
||||
|
outStream << "\t" << (**it).getName() << " -> " << trans->getName() << "[label=\"normal:" << |
||||
|
trans->getInputArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
|
||||
|
++it; |
||||
|
} |
||||
|
|
||||
|
it = trans->getInhibitionPlacesCBegin(); |
||||
|
while (it != trans->getInhibitionPlacesCEnd()) { |
||||
|
outStream << "\t" << (**it).getName() << " -> " << trans->getName() << "[label=\"inhibition:" << |
||||
|
trans->getInhibitionArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
++it; |
||||
|
} |
||||
|
|
||||
|
it = trans->getOutputPlacesCBegin(); |
||||
|
while (it != trans->getOutputPlacesCEnd()) { |
||||
|
outStream << "\t" << trans->getName() << " -> " << (**it).getName() << "[label=\"" << |
||||
|
trans->getOutputArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
++it; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
for (auto& trans : this->getTimedTransitions()) { |
||||
|
auto it = trans->getInputPlacesCBegin(); |
||||
|
while (it != trans->getInputPlacesCEnd()) { |
||||
|
outStream << "\t" << (**it).getName() << " -> " << trans->getName() << "[label=\"normal:" << |
||||
|
trans->getInputArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
++it; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
it = trans->getInhibitionPlacesCBegin(); |
||||
|
while (it != trans->getInhibitionPlacesCEnd()) { |
||||
|
outStream << "\t" << (**it).getName() << " -> " << trans->getName() << "[label=\"inhibition:" << |
||||
|
trans->getInhibitionArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
++it; |
||||
|
} |
||||
|
|
||||
|
it = trans->getOutputPlacesCBegin(); |
||||
|
while (it != trans->getOutputPlacesCEnd()) { |
||||
|
outStream << "\t" << trans->getName() << " -> " << (**it).getName() << "[label=\"" << |
||||
|
trans->getOutputArcMultiplicity(**it); |
||||
|
outStream << "\"];" << std::endl; |
||||
|
++it; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
outStream << "}" << std::endl; |
||||
|
} |
||||
|
|
||||
|
void GSPN::setName(std::string const& name) { |
||||
|
this->name = name; |
||||
|
} |
||||
|
|
||||
|
std::string const& GSPN::getName() const { |
||||
|
return this->name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -1,110 +1,59 @@ |
|||||
|
#include <stdint.h>
|
||||
#include "src/storage/gspn/Marking.h"
|
#include "src/storage/gspn/Marking.h"
|
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace gspn { |
namespace gspn { |
||||
Marking::Marking(uint_fast64_t numberOfPlaces, uint_fast64_t maxNumberOfTokens) { |
|
||||
|
Marking::Marking(uint_fast64_t const& numberOfPlaces, std::map<uint_fast64_t, uint_fast64_t> const& numberOfBits, uint_fast64_t const& numberOfTotalBits) { |
||||
this->numberOfPlaces = numberOfPlaces; |
this->numberOfPlaces = numberOfPlaces; |
||||
this->maxNumberOfTokens = maxNumberOfTokens; |
|
||||
|
|
||||
this->numberOfBits = calculateNumberOfBits(maxNumberOfTokens); |
|
||||
this->marking = storm::storage::BitVector(numberOfBits * numberOfPlaces); |
|
||||
|
this->numberOfBits = numberOfBits; |
||||
|
this->marking = storm::storage::BitVector(numberOfTotalBits); |
||||
} |
} |
||||
|
|
||||
uint_fast64_t Marking::getNumberOfPlaces() { |
|
||||
return this->numberOfPlaces; |
|
||||
|
Marking::Marking(uint_fast64_t const& numberOfPlaces, std::map<uint_fast64_t, uint_fast64_t> const& numberOfBits, storm::storage::BitVector const& bitvector) { |
||||
|
this->numberOfPlaces = numberOfPlaces; |
||||
|
this->numberOfBits = numberOfBits; |
||||
|
this->marking = bitvector; |
||||
} |
} |
||||
|
|
||||
uint_fast64_t Marking::getMaxNumberOfTokens() { |
|
||||
return this->maxNumberOfTokens; |
|
||||
|
uint_fast64_t Marking::getNumberOfPlaces() const { |
||||
|
return this->numberOfPlaces; |
||||
} |
} |
||||
|
|
||||
void Marking::setNumberOfTokensAt(uint_fast64_t place, uint_fast64_t numberOfTokens) { |
|
||||
// TODO check range (place < getNumberOfPlaces(), numberOfTokens < getMaxNumberOfTokens())
|
|
||||
for (uint_fast64_t i = place * numberOfBits; i <(place * numberOfBits) + numberOfBits; ++i) { |
|
||||
if (numberOfTokens % 2 == 0) { |
|
||||
marking.set(i, false); |
|
||||
} else { |
|
||||
marking.set(i, true); |
|
||||
} |
|
||||
numberOfTokens /= 2; |
|
||||
|
void Marking::setNumberOfTokensAt(uint_fast64_t const& place, uint_fast64_t const& numberOfTokens) { |
||||
|
uint_fast64_t index = 0; |
||||
|
for (uint_fast64_t i=0; i < place; ++i) { |
||||
|
index += numberOfBits[i]; |
||||
} |
} |
||||
|
marking.setFromInt(index, numberOfBits[place], numberOfTokens); |
||||
} |
} |
||||
|
|
||||
uint_fast64_t Marking::getNumberOfTokensAt(uint_fast64_t place) { |
|
||||
uint_fast64_t tokens = 0; |
|
||||
for (uint_fast64_t i = place * numberOfBits, mult = 0; i < (place * numberOfBits) + numberOfBits; ++i, ++mult) { |
|
||||
if (marking.get(i)) { |
|
||||
tokens += std::pow(2, mult); |
|
||||
} |
|
||||
|
uint_fast64_t Marking::getNumberOfTokensAt(uint_fast64_t const& place) const { |
||||
|
uint_fast64_t index = 0; |
||||
|
for (uint_fast64_t i=0; i < place; ++i) { |
||||
|
index += numberOfBits.at(i); |
||||
} |
} |
||||
return tokens; |
|
||||
|
return marking.getAsInt(index, numberOfBits.at(place)); |
||||
} |
} |
||||
|
|
||||
bool Marking::setNumberOfPlaces(uint_fast64_t numberOfPlaces) { |
|
||||
if (numberOfPlaces == this->numberOfPlaces) { |
|
||||
return true; |
|
||||
} |
|
||||
if (numberOfPlaces > this->numberOfPlaces) { |
|
||||
marking.resize(numberOfPlaces * numberOfBits); |
|
||||
this->numberOfPlaces = numberOfPlaces; |
|
||||
return true; |
|
||||
} else { |
|
||||
auto diff = this->numberOfPlaces - numberOfPlaces; |
|
||||
for (uint64_t i = 0; i < diff; ++i) { |
|
||||
if (getNumberOfTokensAt(numberOfPlaces-1-i) != 0) { |
|
||||
// TODO error
|
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
marking.resize(numberOfPlaces * numberOfBits); |
|
||||
this->numberOfPlaces = numberOfPlaces; |
|
||||
return true; |
|
||||
} |
|
||||
|
std::shared_ptr<storm::storage::BitVector> Marking::getBitVector() const { |
||||
|
auto result = std::make_shared<storm::storage::BitVector>(); |
||||
|
*result = storm::storage::BitVector(marking); |
||||
|
return result; |
||||
} |
} |
||||
|
|
||||
bool Marking::setMaxNumberOfTokens(uint_fast64_t maxNumberOfTokens) { |
|
||||
for (uint64_t i = 0; i < getNumberOfPlaces(); ++i) { |
|
||||
if (getNumberOfTokensAt(i) > maxNumberOfTokens) { |
|
||||
|
bool Marking::operator==(const Marking& other) const { |
||||
|
if (getNumberOfPlaces() != other.getNumberOfPlaces()) { |
||||
return false; |
return false; |
||||
} |
} |
||||
|
if (&numberOfBits == &other.numberOfBits) { |
||||
|
return marking == other.marking; |
||||
} |
} |
||||
|
|
||||
if (maxNumberOfTokens == getMaxNumberOfTokens()) { |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
uint_fast64_t newNumberOfBits = calculateNumberOfBits(maxNumberOfTokens); |
|
||||
if (maxNumberOfTokens < getMaxNumberOfTokens()) { |
|
||||
for (uint_fast64_t i=0; i < getNumberOfPlaces(); ++i) { |
for (uint_fast64_t i=0; i < getNumberOfPlaces(); ++i) { |
||||
for (uint_fast64_t j = 0; j < numberOfBits; ++j) { |
|
||||
marking.set(i*newNumberOfBits + j , marking.get(i*numberOfBits + j)); |
|
||||
} |
|
||||
} |
|
||||
marking.resize(getNumberOfPlaces() * newNumberOfBits); |
|
||||
} else { |
|
||||
marking.resize(getNumberOfPlaces() * newNumberOfBits); |
|
||||
for (int_fast64_t i = getNumberOfPlaces()-1; i >= 0; --i) { |
|
||||
for (int_fast64_t j = numberOfBits-1; j >= 0; --j) { |
|
||||
for (uint_fast64_t diff = 0; diff < newNumberOfBits-numberOfBits; ++diff) { |
|
||||
marking.set(i*newNumberOfBits+j+diff+1, 0); |
|
||||
} |
|
||||
marking.set(i*newNumberOfBits+j, marking.get(i*numberOfBits+j)); |
|
||||
} |
|
||||
|
if (getNumberOfTokensAt(i) != other.getNumberOfTokensAt(i)) { |
||||
|
return false; |
||||
} |
} |
||||
} |
} |
||||
numberOfBits = newNumberOfBits; |
|
||||
return true; |
return true; |
||||
} |
} |
||||
|
|
||||
void Marking::incNumberOfPlaces() { |
|
||||
setNumberOfPlaces(getNumberOfPlaces()+1); |
|
||||
} |
|
||||
|
|
||||
uint_fast64_t Marking::calculateNumberOfBits(uint_fast64_t maxNumber) { |
|
||||
if (maxNumber == 0) { |
|
||||
return 1; |
|
||||
} |
|
||||
return std::floor(std::log2(maxNumber)) + 1; |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
@ -0,0 +1,41 @@ |
|||||
|
#include "Place.h"
|
||||
|
|
||||
|
#include "src/exceptions/IllegalArgumentValueException.h"
|
||||
|
#include "src/utility/macros.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace gspn { |
||||
|
void Place::setName(std::string const& name) { |
||||
|
this->name = name; |
||||
|
} |
||||
|
|
||||
|
std::string Place::getName() const { |
||||
|
return this->name; |
||||
|
} |
||||
|
|
||||
|
void Place::setID(uint_fast64_t const& id) { |
||||
|
this->id = id; |
||||
|
} |
||||
|
|
||||
|
uint_fast64_t Place::getID() const { |
||||
|
return this->id; |
||||
|
} |
||||
|
|
||||
|
void Place::setNumberOfInitialTokens(uint_fast64_t const& tokens) { |
||||
|
this->numberOfInitialTokens = tokens; |
||||
|
} |
||||
|
|
||||
|
uint_fast64_t Place::getNumberOfInitialTokens() const { |
||||
|
return this->numberOfInitialTokens; |
||||
|
} |
||||
|
|
||||
|
void Place::setCapacity(int_fast64_t const& capacity) { |
||||
|
STORM_LOG_THROW(capacity >= -1, storm::exceptions::IllegalArgumentValueException, "The capacity cannot be less than -1."); |
||||
|
this->capacity = capacity; |
||||
|
} |
||||
|
|
||||
|
int_fast64_t Place::getCapacity() const { |
||||
|
return this->capacity; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,87 @@ |
|||||
|
#ifndef STORM_STORAGE_GSPN_PLACE_H_ |
||||
|
#define STORM_STORAGE_GSPN_PLACE_H_ |
||||
|
|
||||
|
#include <string> |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace gspn { |
||||
|
/*! |
||||
|
* This class provides methods to store and retrieve data for a place in a gspn. |
||||
|
*/ |
||||
|
class Place { |
||||
|
public: |
||||
|
/*! |
||||
|
* Sets the name of this place. The name must be unique for a gspn. |
||||
|
* |
||||
|
* @param name The new name for the place. |
||||
|
*/ |
||||
|
void setName(std::string const& name); |
||||
|
|
||||
|
/*! |
||||
|
* Returns the name of this place. |
||||
|
* |
||||
|
* @return The name of this place. |
||||
|
*/ |
||||
|
std::string getName() const; |
||||
|
|
||||
|
/*! |
||||
|
* Sets the id of this place. The id must be unique for a gspn. |
||||
|
* |
||||
|
* @param id The new id of this place. |
||||
|
*/ |
||||
|
void setID(uint_fast64_t const& id); |
||||
|
|
||||
|
/*! |
||||
|
* Returns the id of this place. |
||||
|
* |
||||
|
* @return The id of this place. |
||||
|
*/ |
||||
|
uint_fast64_t getID() const; |
||||
|
|
||||
|
/*! |
||||
|
* Sets the number of initial tokens of this place. |
||||
|
* |
||||
|
* @param tokens The number of initial tokens. |
||||
|
*/ |
||||
|
void setNumberOfInitialTokens(uint_fast64_t const& tokens); |
||||
|
|
||||
|
/*! |
||||
|
* Returns the number of initial tokens of this place. |
||||
|
* |
||||
|
* @return The number of initial tokens of this place. |
||||
|
*/ |
||||
|
uint_fast64_t getNumberOfInitialTokens() const; |
||||
|
|
||||
|
/*! |
||||
|
* Sets the capacity of tokens of this place. |
||||
|
* |
||||
|
* @param capacity The capacity of this place. A non-negative number represents the capacity. |
||||
|
* The value -1 indicates that the capacity is not set. |
||||
|
*/ |
||||
|
void setCapacity(int_fast64_t const& capacity); |
||||
|
|
||||
|
/*! |
||||
|
* Returns the capacity of tokens of this place. |
||||
|
* |
||||
|
* @return The capacity of the place. The value -1 indicates that the capacity is not set. |
||||
|
*/ |
||||
|
int_fast64_t getCapacity() const; |
||||
|
private: |
||||
|
// contains the number of initial tokens of this place |
||||
|
uint_fast64_t numberOfInitialTokens; |
||||
|
|
||||
|
// unique id (is used to refer to a specific place in a bitvector) |
||||
|
uint_fast64_t id; |
||||
|
|
||||
|
// name which is used in pnml file |
||||
|
std::string name; |
||||
|
|
||||
|
// capacity of this place |
||||
|
// -1 indicates that the capacity is not set |
||||
|
// other non-negative values represents the capacity |
||||
|
int_fast64_t capacity; |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endif //STORM_STORAGE_GSPN_PLACE_H_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue