Browse Source

add GspnBuilder class

Former-commit-id: e6e91366cc
tempestpy_adaptions
ThomasH 8 years ago
parent
commit
8ba12791ff
  1. 89
      src/storage/gspn/GspnBuilder.cpp
  2. 89
      src/storage/gspn/GspnBuilder.h

89
src/storage/gspn/GspnBuilder.cpp

@ -0,0 +1,89 @@
#include <src/exceptions/IllegalFunctionCallException.h>
#include "GspnBuilder.h"
#include "src/utility/macros.h"
#include "src/exceptions/IllegalFunctionCallException.h"
#include "Place.h"
namespace storm {
namespace gspn {
void GspnBuilder::addPlace(uint_fast64_t const& id, int_fast64_t const& capacity, uint_fast64_t const& initialTokens) {
addPlace(id, "place_" + std::to_string(id), capacity, initialTokens);
}
void GspnBuilder::addPlace(uint_fast64_t const& id, std::string const& name, int_fast64_t const& capacity, uint_fast64_t const& initialTokens) {
auto place = storm::gspn::Place();
place.setCapacity(capacity);
place.setID(id);
place.setName(name);
place.setNumberOfInitialTokens(initialTokens);
idToPlaceName.insert(std::pair<uint_fast64_t const, std::string const>(id, name));
gspn.addPlace(place);
}
void GspnBuilder::addImmediateTransition(std::string const& name, uint_fast64_t const& priority, double const& weight) {
auto trans = storm::gspn::ImmediateTransition<double>();
trans.setName(name);
trans.setPriority(priority);
trans.setWeight(weight);
gspn.addImmediateTransition(trans);
}
void GspnBuilder::addTimedTransition(std::string const& name, uint_fast64_t const& priority, double const& rate) {
auto trans = storm::gspn::TimedTransition<double>();
trans.setName(name);
trans.setPriority(priority);
trans.setRate(rate);
gspn.addTimedTransition(trans);
}
void GspnBuilder::addInputArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity) {
auto transPair = gspn.getTransition(to);
if (!std::get<0>(transPair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The transition with the name \"" + to + "\" does not exist.");
}
auto placePair = gspn.getPlace(idToPlaceName.at(from));
if (!std::get<0>(placePair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The place with the id \"" + std::to_string(from) + "\" does not exist.");
}
std::get<1>(transPair)->setInputArcMultiplicity(std::get<1>(placePair), multiplicity);
}
void GspnBuilder::addInhibitionArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity) {
auto transPair = gspn.getTransition(to);
if (!std::get<0>(transPair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The transition with the name \"" + to + "\" does not exist.");
}
auto placePair = gspn.getPlace(idToPlaceName.at(from));
if (!std::get<0>(placePair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The place with the id \"" + std::to_string(from) + "\" does not exist.");
}
std::get<1>(transPair)->setInhibitionArcMultiplicity(std::get<1>(placePair), multiplicity);
}
void GspnBuilder::addOutputArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity) {
auto transPair = gspn.getTransition(to);
if (!std::get<0>(transPair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The transition with the name \"" + to + "\" does not exist.");
}
auto placePair = gspn.getPlace(idToPlaceName.at(from));
if (!std::get<0>(placePair)) {
STORM_LOG_THROW(false, storm::exceptions::IllegalFunctionCallException, "The place with the id \"" + std::to_string(from) + "\" does not exist.");
}
std::get<1>(transPair)->setOutputArcMultiplicity(std::get<1>(placePair), multiplicity);
}
storm::gspn::GSPN const& GspnBuilder::buildGspn() const {
return gspn;
}
}
}

89
src/storage/gspn/GspnBuilder.h

@ -0,0 +1,89 @@
#ifndef STORM_STORAGE_GSPN_GSPNBUILDER_H
#define STORM_STORAGE_GSPN_GSPNBUILDER_H
#include <map>
#include <string>
#include <vector>
#include "GSPN.h"
namespace storm {
namespace gspn {
class GspnBuilder {
public:
/**
* Add a place to the gspn.
* @param id The id must be unique for the gspn.
* @param capacity The capacity is the limit of tokens in the place.
* A capacity of -1 indicates an unbounded place.
* @param initialTokens The number of inital tokens in the place.
*/
void addPlace(uint_fast64_t const& id, int_fast64_t const& capacity = 1, uint_fast64_t const& initialTokens = 0);
/**
* Add a place to the gspn.
* @param id The id must be unique for the gspn.
* @param name The name must be unique for the gspn.
* @param capacity The capacity is the limit of tokens in the place.
* A capacity of -1 indicates an unbounded place.
* @param initialTokens The number of inital tokens in the place.
*/
void addPlace(uint_fast64_t const& id, std::string const& name, int_fast64_t const& capacity = 1, uint_fast64_t const& initialTokens = 0);
/**
* Adds an immediate transition to the gspn.
* @param name The name must be unique for the gspn.
* @param priority The priority for the transtion.
* @param weight The weight for the transition.
*/
void addImmediateTransition(std::string const& name, uint_fast64_t const& priority = 0, double const& weight = 0);
/**
* Adds an timed transition to the gspn.
* @param name The name must be unique for the gspn.
* @param priority The priority for the transtion.
* @param weight The weight for the transition.
*/
void addTimedTransition(std::string const& name, uint_fast64_t const& priority = 0, double const& rate = 0);
/**
* Adds an new input arc from a place to an transition.
* @param from The place from which the arc is originating.
* @param to The transtion to which the arc goes to.
* @param multiplicity The multiplicity of the arc.
*/
void addInputArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity = 1);
/**
* Adds an new input arc from a place to an transition.
* @param from The place from which the arc is originating.
* @param to The transtion to which the arc goes to.
* @param multiplicity The multiplicity of the arc.
*/
void addInhibitionArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity = 1);
/**
* Adds an new input arc from a place to an transition.
* @param from The place from which the arc is originating.
* @param to The transtion to which the arc goes to.
* @param multiplicity The multiplicity of the arc.
*/
void addOutputArc(uint_fast64_t const& from, std::string const& to, uint_fast64_t const& multiplicity = 1);
/**
*
* @return The gspn which is constructed by the builder.
*/
storm::gspn::GSPN const& buildGspn() const;
private:
// gspn which is returned
storm::gspn::GSPN gspn;
// map from ids to names (for places)
std::map<uint_fast64_t const, std::string const> idToPlaceName;
};
}
}
#endif //STORM_STORAGE_GSPN_GSPNBUILDER_H
Loading…
Cancel
Save