Browse Source

added layout info to gspn - dft to gspn builds some layout in be and and

tempestpy_adaptions
Sebastian Junges 8 years ago
parent
commit
49537a83d3
  1. 15
      src/storm-dft/transformations/DftToGspnTransformator.cpp
  2. 43
      src/storm-gspn/storage/gspn/GSPN.cpp
  3. 13
      src/storm-gspn/storage/gspn/GSPN.h
  4. 14
      src/storm-gspn/storage/gspn/GspnBuilder.cpp
  5. 14
      src/storm-gspn/storage/gspn/GspnBuilder.h
  6. 17
      src/storm-gspn/storage/gspn/PlacementInfo.h
  7. 3
      src/storm-gspn/storage/gspn/Transition.h

15
src/storm-dft/transformations/DftToGspnTransformator.cpp

@ -90,11 +90,13 @@ namespace storm {
template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawBE(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBE, bool isRepresentative) {
double xcenter = 10.0;
double ycenter = 10.0;
uint64_t beActive = builder.addPlace(defaultCapacity, isBEActive(dftBE) ? 1 : 0, dftBE->name() + STR_ACTIVATED);
activeNodes.emplace(dftBE->id(), beActive);
uint64_t beFailed = builder.addPlace(defaultCapacity, 0, dftBE->name() + STR_FAILED);
uint64_t unavailableNode = 0;
if (isRepresentative) {
unavailableNode = addUnavailableNode(dftBE);
@ -116,10 +118,18 @@ namespace storm {
builder.addOutputArc(tActive, unavailableNode);
builder.addOutputArc(tPassive, unavailableNode);
}
builder.setPlaceLayoutInfo(beActive, storm::gspn::LayoutInfo(xcenter - 3.0, ycenter));
builder.setPlaceLayoutInfo(beFailed, storm::gspn::LayoutInfo(xcenter + 3.0, ycenter));
builder.setTransitionLayoutInfo(tActive, storm::gspn::LayoutInfo(xcenter, ycenter + 3.0));
builder.setTransitionLayoutInfo(tPassive, storm::gspn::LayoutInfo(xcenter, ycenter - 3.0));
}
template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawAND(std::shared_ptr<storm::storage::DFTAnd<ValueType> const> dftAnd, bool isRepresentative) {
double xcenter = 10.0;
double ycenter = 20.0;
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftAnd->name() + STR_FAILED);
assert(failedNodes.size() == dftAnd->id());
failedNodes.push_back(nodeFailed);
@ -142,6 +152,9 @@ namespace storm {
builder.addOutputArc(tAndFailed, failedNodes[child->id()]);
}
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
builder.setTransitionLayoutInfo(tAndFailed, storm::gspn::LayoutInfo(xcenter, ycenter+3.0));
}
template <typename ValueType>

43
src/storm-gspn/storage/gspn/GSPN.cpp

@ -376,6 +376,20 @@ namespace storm {
return result;
}
void GSPN::setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layout) const {
placeLayout[placeId] = layout;
}
void GSPN::setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const& layout) const {
transitionLayout[transitionId] = layout;
}
void GSPN::setPlaceLayoutInfo(std::map<uint64_t, LayoutInfo> const& placeLayout) const {
this->placeLayout = placeLayout;
}
void GSPN::setTransitionLayoutInfo(std::map<uint64_t, LayoutInfo> const& transitionLayout) const {
this->transitionLayout = transitionLayout;
}
void GSPN::toPnpro(std::ostream &stream) const {
auto space = " ";
@ -390,8 +404,14 @@ namespace storm {
for (auto& place : places) {
stream << space3 << "<place marking=\"" << place.getNumberOfInitialTokens() <<"\" ";
stream << "name =\"" << place.getName() << "\" ";
stream << "x=\"" << x << "\" ";
stream << "y=\"1\" ";
if (placeLayout.count(place.getID()) > 0) {
stream << "x=\"" << placeLayout.at(place.getID()).x << "\" ";
stream << "y=\"" << placeLayout.at(place.getID()).y << "\" ";
} else {
stream << "x=\"" << x << "\" ";
stream << "y=\"1\" ";
}
stream << "/>" << std::endl;
x = x + 3;
}
@ -400,8 +420,14 @@ namespace storm {
stream << space3 << "<transition name=\"" << trans.getName() << "\" ";
stream << "type=\"EXP\" ";
stream << "nservers-x=\"" << trans.getRate() << "\" ";
stream << "x=\"" << x << "\" ";
stream << "y=\"4\" ";
if (transitionLayout.count(trans.getID()) > 0) {
stream << "x=\"" << transitionLayout.at(trans.getID()).x << "\" ";
stream << "y=\"" << transitionLayout.at(trans.getID()).y << "\" ";
} else {
stream << "x=\"" << x << "\" ";
stream << "y=\"4\" ";
}
stream << "/>" << std::endl;
x = x + 3;
}
@ -409,8 +435,13 @@ namespace storm {
stream << space3 << "<transition name=\"" << trans.getName() << "\" ";
stream << "type=\"IMM\" ";
stream << "priority=\"" << trans.getPriority() << "\" ";
stream << "x=\"" << x << "\" ";
stream << "y=\"4\" ";
if (transitionLayout.count(trans.getID()) > 0) {
stream << "x=\"" << transitionLayout.at(trans.getID()).x << "\" ";
stream << "y=\"" << transitionLayout.at(trans.getID()).y << "\" ";
} else {
stream << "x=\"" << x << "\" ";
stream << "y=\"4\" ";
}
stream << "/>" << std::endl;
x = x + 3;
}

13
src/storm-gspn/storage/gspn/GSPN.h

@ -11,6 +11,7 @@
#include "storm-gspn/storage/gspn/Place.h"
#include "storm-gspn/storage/gspn/TimedTransition.h"
#include "storm-gspn/storage/gspn/TransitionPartition.h"
#include "storm-gspn/storage/gspn/PlacementInfo.h"
namespace storm {
namespace gspn {
@ -140,7 +141,13 @@ namespace storm {
* Set Capacities according to name->capacity map.
*/
void setCapacities(std::unordered_map<std::string, uint64_t> const& mapping);
void setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layout) const;
void setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const& layout) const;
void setPlaceLayoutInfo(std::map<uint64_t, LayoutInfo> const& placeLayout) const;
void setTransitionLayoutInfo(std::map<uint64_t, LayoutInfo> const& transitionLayout) const;
/*!
* Performe some checks
* - testPlaces()
@ -191,6 +198,10 @@ namespace storm {
std::vector<storm::gspn::TransitionPartition> partitions;
mutable std::map<uint64_t, LayoutInfo> placeLayout;
mutable std::map<uint64_t, LayoutInfo> transitionLayout;
};
}
}

14
src/storm-gspn/storage/gspn/GspnBuilder.cpp

@ -23,6 +23,15 @@ namespace storm {
places.push_back(place);
return newId;
}
void GspnBuilder::setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layoutInfo) {
placeLayout[placeId] = layoutInfo;
}
void GspnBuilder::setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const& layoutInfo) {
transitionLayout[transitionId] = layoutInfo;
}
uint_fast64_t GspnBuilder::addImmediateTransition(uint_fast64_t const& priority, double const& weight, std::string const& name) {
auto trans = storm::gspn::ImmediateTransition<double>();
@ -164,7 +173,10 @@ namespace storm {
}
std::reverse(orderedPartitions.begin(), orderedPartitions.end());
return new GSPN(gspnName, places, immediateTransitions, timedTransitions, orderedPartitions);
GSPN* result = new GSPN(gspnName, places, immediateTransitions, timedTransitions, orderedPartitions);
result->setTransitionLayoutInfo(transitionLayout);
result->setPlaceLayoutInfo(placeLayout);
return result;
}
}
}

14
src/storm-gspn/storage/gspn/GspnBuilder.h

@ -20,29 +20,32 @@ namespace storm {
/**
* 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.
*/
uint_fast64_t addPlace(int_fast64_t const& capacity = 1, uint_fast64_t const& initialTokens = 0, std::string const& name = "");
void setPlaceLayoutInfo(uint64_t placeId, LayoutInfo const& layoutInfo);
/**
* Adds an immediate transition to the gspn.
* @param id The id must be unique for the gspn.
* @param priority The priority for the transtion.
* @param weight The weight for the transition.
*/
uint_fast64_t addImmediateTransition(uint_fast64_t const& priority = 0, WeightType const& weight = 0, std::string const& name = "");
/**
* Adds an timed transition to the gspn.
* @param id The name id be unique for the gspn.
* @param priority The priority for the transtion.
* @param weight The weight for the transition.
*/
uint_fast64_t addTimedTransition(uint_fast64_t const &priority, RateType const& rate, std::string const& name = "");
void setTransitionLayoutInfo(uint64_t transitionId, LayoutInfo const& layoutInfo);
/**
* Adds an new input arc from a place to an transition.
@ -112,6 +115,9 @@ namespace storm {
// set containing all places
std::vector<storm::gspn::Place> places;
std::map<uint64_t, LayoutInfo> placeLayout;
std::map<uint64_t, LayoutInfo> transitionLayout;
};
}
}

17
src/storm-gspn/storage/gspn/PlacementInfo.h

@ -0,0 +1,17 @@
#pragma once
namespace storm {
namespace gspn {
struct LayoutInfo {
LayoutInfo() {};
LayoutInfo(double x, double y, double rotation = 0.0) : x(x), y(y), rotation(rotation) {};
// x location
double x = 0.0;
// y location
double y = 0.0;
// degrees
double rotation = 0.0;
};
}
}

3
src/storm-gspn/storage/gspn/Transition.h

@ -168,6 +168,9 @@ namespace storm {
void setID(uint64_t const& id) {
this->id = id;
}
uint64_t getID() const { return id; }
private:
// maps place ids connected to this transition with an input arc to the corresponding multiplicity

Loading…
Cancel
Save