2#include <boost/format.hpp>
3#include <boost/graph/adjacency_list.hpp>
9namespace elimination_actions {
11 this->automatonName = automatonName;
12 this->locationName = locationName;
16 return (boost::format(
"EliminateAction (Automaton %s, Location %s)") % automatonName % locationName).str();
20 STORM_LOG_THROW(!session.
hasLoops(automatonName, locationName), storm::exceptions::InvalidArgumentException,
"Locations with loops cannot be eliminated");
37 uint64_t edgeIndex = 0;
38 uint64_t stepsWithoutChange = 0;
39 std::vector<Edge>& edges = automaton.
getEdges();
40 while (stepsWithoutChange <= edges.size()) {
41 Edge edge = edges[edgeIndex];
45 for (uint64_t j = 0; j < destCount; j++) {
49 eliminateDestination(session, automaton, edges[edgeIndex], j, outgoingEdges);
53 stepsWithoutChange = 0;
61 if (edgeIndex >= edges.size()) {
62 edgeIndex -= edges.size();
69 if (!edge.getGuard().containsVariables() && !edge.getGuard().evaluateAsBool())
72 if (dest.getLocationIndex() == locIndex) {
73 STORM_LOG_THROW(
false, storm::exceptions::IllegalArgumentException,
"Could not eliminate location");
88 for (
Edge& outEdge : outgoing) {
89 if (!outEdge.getGuard().containsVariables() && !outEdge.getGuard().evaluateAsBool())
93 std::shared_ptr<storm::jani::TemplateEdge> templateEdge = std::make_shared<storm::jani::TemplateEdge>(newGuard);
94 std::vector<std::pair<uint64_t, storm::expressions::Expression>> destinationLocationsAndProbabilities;
100 templateEdge->addDestination(templateEdgeDestination);
102 destinationLocationsAndProbabilities.emplace_back(outDest.getLocationIndex(), probability);
107 for (uint64_t i = 0; i < destCount; i++) {
113 templateEdge->addDestination(templateEdgeDestination);
117 STORM_LOG_THROW(!edge.
hasRate() && !outEdge.hasRate(), storm::exceptions::NotImplementedException,
"Edge Rates are not implemented");
118 newEdges.emplace_back(Edge(sourceIndex, actionIndex, boost::none, templateEdge, destinationLocationsAndProbabilities));
123 for (
const Edge& newEdge : newEdges) {
bool evaluateAsBool(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
bool containsVariables() const
Retrieves whether the expression contains a variable.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Expression boolean(bool value) const
Creates an expression that characterizes the given boolean literal.
void addEdge(Edge const &edge)
Adds an edge to the automaton.
Edges getEdgesFromLocation(std::string const &name)
Retrieves the edges of the location with the given name.
std::vector< Edge > & getEdges()
Retrieves the edges of the automaton.
uint64_t getLocationIndex(std::string const &name) const
storm::expressions::Expression const & getProbability() const
Retrieves the probability of choosing this destination.
OrderedAssignments const & getOrderedAssignments() const
Retrieves the assignments to make when choosing this destination.
uint64_t getLocationIndex() const
Retrieves the id of the destination location.
uint64_t getActionIndex() const
Retrieves the id of the action with which this edge is labeled.
bool hasRate() const
Retrieves whether this edge has an associated rate.
uint64_t getSourceLocationIndex() const
Retrieves the index of the source location.
std::size_t getNumberOfDestinations() const
Retrieves the number of destinations of this edge.
void setGuard(storm::expressions::Expression const &guard)
Sets a new guard for this edge.
storm::expressions::Expression const & getGuard() const
Retrieves the guard of this edge.
EdgeDestination const & getDestination(uint64_t index) const
Retrieves the destination with the given index.
expressions::Expression getNewGuard(const Edge &edge, const EdgeDestination &dest, const Edge &outgoing)
bool hasLoops(const std::string &automatonName, std::string const &locationName)
expressions::Expression getProbability(const EdgeDestination &first, const EdgeDestination &then)
std::set< std::string > rewardModels
OrderedAssignments executeInSequence(const EdgeDestination &first, const EdgeDestination &then, std::set< std::string > &rewardVariables)
Automaton & getAutomaton(std::string const &name)
Retrieves the automaton with the given name.
OrderedAssignments clone() const
EliminateAction(const std::string &automatonName, const std::string &locationName)
std::string getDescription() override
void doAction(JaniLocalEliminator::Session &session) override
#define STORM_LOG_THROW(cond, exception, message)