Browse Source
created storage class for JANI assignments that guarantees ordering
created storage class for JANI assignments that guarantees ordering
Former-commit-id:tempestpy_adaptions6cc43016a2
[formerlyaaa7b8a213
] Former-commit-id:8eb1c8d54d
dehnert
9 years ago
17 changed files with 403 additions and 784 deletions
-
46src/adapters/DereferenceIteratorAdapter.h
-
10src/generator/JaniNextStateGenerator.cpp
-
3src/generator/PrismNextStateGenerator.cpp
-
31src/storage/jani/Assignment.cpp
-
22src/storage/jani/Assignment.h
-
14src/storage/jani/Edge.cpp
-
23src/storage/jani/Edge.h
-
100src/storage/jani/EdgeDestination.cpp
-
61src/storage/jani/EdgeDestination.h
-
438src/storage/jani/Exporter.cpp
-
48src/storage/jani/Exporter.h
-
14src/storage/jani/Location.cpp
-
8src/storage/jani/Location.h
-
116src/storage/jani/OrderedAssignments.cpp
-
91src/storage/jani/OrderedAssignments.h
-
90src/storage/jani/VariableSet.cpp
-
72src/storage/jani/VariableSet.h
@ -0,0 +1,46 @@ |
|||
#pragma once |
|||
|
|||
#include <type_traits> |
|||
|
|||
#include <boost/iterator/transform_iterator.hpp> |
|||
|
|||
namespace storm { |
|||
namespace adapters { |
|||
|
|||
template<typename T> |
|||
struct Dereferencer { |
|||
decltype((*std::declval<T>())) operator()(T const& t) const { |
|||
return *t; |
|||
} |
|||
}; |
|||
|
|||
template<typename ContainerType> |
|||
class DereferenceIteratorAdapter { |
|||
public: |
|||
typedef typename ContainerType::value_type value_type; |
|||
typedef typename std::conditional<std::is_const<ContainerType>::value, typename ContainerType::const_iterator, typename ContainerType::iterator>::type input_iterator; |
|||
typedef typename boost::transform_iterator<Dereferencer<value_type>, input_iterator> iterator; |
|||
|
|||
DereferenceIteratorAdapter(input_iterator it, input_iterator ite) : it(it), ite(ite) { |
|||
// Intentionally left empty. |
|||
} |
|||
|
|||
iterator begin() { |
|||
return boost::make_transform_iterator(it, Dereferencer<value_type>()); |
|||
} |
|||
|
|||
iterator end() { |
|||
return boost::make_transform_iterator(ite, Dereferencer<value_type>()); |
|||
} |
|||
|
|||
static iterator make_iterator(input_iterator it) { |
|||
return boost::make_transform_iterator(it, Dereferencer<value_type>()); |
|||
} |
|||
|
|||
private: |
|||
input_iterator it; |
|||
input_iterator ite; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -1,438 +0,0 @@ |
|||
#include "src/storage/jani/Exporter.h"
|
|||
|
|||
#include <iostream>
|
|||
|
|||
namespace storm { |
|||
namespace jani { |
|||
|
|||
void appendIndent(std::stringstream& out, uint64_t indent) { |
|||
for (uint64_t i = 0; i < indent; ++i) { |
|||
out << "\t"; |
|||
} |
|||
} |
|||
|
|||
void appendField(std::stringstream& out, std::string const& name) { |
|||
out << "\"" << name << "\": "; |
|||
} |
|||
|
|||
void appendValue(std::stringstream& out, std::string const& value) { |
|||
out << "\"" << value << "\""; |
|||
} |
|||
|
|||
void clearLine(std::stringstream& out) { |
|||
out << std::endl; |
|||
} |
|||
|
|||
std::string expressionToString(storm::expressions::Expression const& expression) { |
|||
std::stringstream s; |
|||
s << expression; |
|||
return s.str(); |
|||
} |
|||
|
|||
void Exporter::appendVersion(std::stringstream& out, uint64_t janiVersion, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "jani-version"); |
|||
} |
|||
|
|||
void Exporter::appendModelName(std::stringstream& out, std::string const& name, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "name"); |
|||
appendValue(out, name); |
|||
} |
|||
|
|||
void Exporter::appendModelType(std::stringstream& out, storm::jani::ModelType const& modelType, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "type"); |
|||
} |
|||
|
|||
void Exporter::appendAction(std::stringstream& out, storm::jani::Action const& action, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{" << std::endl; |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, action.getName()); |
|||
clearLine(out); |
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendActions(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "actions"); |
|||
out << " [" << std::endl; |
|||
|
|||
for (uint64_t index = 0; index < model.actions.size(); ++index) { |
|||
appendAction(out, model.actions[index], indent + 1); |
|||
if (index < model.actions.size() - 1) { |
|||
out << ","; |
|||
} |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendIndent(out, indent); |
|||
out << "]"; |
|||
} |
|||
|
|||
void Exporter::appendVariable(std::stringstream& out, storm::jani::BooleanVariable const& variable, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, variable.getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "type"); |
|||
appendValue(out, "bool"); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendBoundedIntegerVariableType(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const { |
|||
out << " {"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
appendField(out, "kind"); |
|||
appendValue(out, "bounded"); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
appendField(out, "base"); |
|||
appendValue(out, "int"); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
appendField(out, "lower-bound"); |
|||
appendValue(out, expressionToString(variable.getLowerBound())); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
appendField(out, "upper-bound"); |
|||
appendValue(out, expressionToString(variable.getLowerBound())); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent - 1); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendVariable(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, variable.getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "type"); |
|||
appendBoundedIntegerVariableType(out, variable, indent + 2); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendVariable(std::stringstream& out, storm::jani::UnboundedIntegerVariable const& variable, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, variable.getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "type"); |
|||
appendValue(out, "int"); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendVariables(std::stringstream& out, storm::jani::VariableSet const& variables, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "variables"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (auto const& variable : variables.getBooleanVariables()) { |
|||
appendVariable(out, variable, indent + 1); |
|||
clearLine(out); |
|||
} |
|||
for (auto const& variable : variables.getBoundedIntegerVariables()) { |
|||
appendVariable(out, variable, indent + 1); |
|||
clearLine(out); |
|||
} |
|||
for (auto const& variable : variables.getUnboundedIntegerVariables()) { |
|||
appendVariable(out, variable, indent + 1); |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendIndent(out, indent); |
|||
out << "]"; |
|||
} |
|||
|
|||
void Exporter::appendLocation(std::stringstream& out, storm::jani::Location const& location, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, location.getName()); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendLocations(std::stringstream& out, storm::jani::Automaton const& automaton, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "locations"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (auto const& location : automaton.getLocations()) { |
|||
appendLocation(out, location, indent + 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendIndent(out, indent); |
|||
out << "]"; |
|||
} |
|||
|
|||
void Exporter::appendAssignment(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Assignment const& assignment, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "ref"); |
|||
storm::jani::Variable const& variable = model.getGlobalVariables().hasVariable(assignment.getExpressionVariable()) ? model.getGlobalVariables().getVariable(assignment.getExpressionVariable()) : automaton.getVariables().getVariable(assignment.getExpressionVariable()); |
|||
appendValue(out, variable.getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "value"); |
|||
appendValue(out, expressionToString(assignment.getAssignedExpression())); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendEdgeDestination(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::EdgeDestination const& destination, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "probability"); |
|||
appendValue(out, expressionToString(destination.getProbability())); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "location"); |
|||
appendValue(out, automaton.getLocation(destination.getLocationIndex()).getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "assignments"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (uint64_t index = 0; index < destination.getAssignments().size(); ++index) { |
|||
appendAssignment(out, model, automaton, destination.getAssignments()[index], indent + 2); |
|||
if (index < destination.getAssignments().size() - 1) { |
|||
out << ","; |
|||
} |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendIndent(out, indent + 1); |
|||
out << "]"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
clearLine(out); |
|||
} |
|||
|
|||
void Exporter::appendEdge(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Edge const& edge, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "location"); |
|||
appendValue(out, automaton.getLocation(edge.getSourceLocationIndex()).getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "action"); |
|||
appendValue(out, model.getAction(edge.getActionIndex()).getName()); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "guard"); |
|||
appendValue(out, expressionToString(edge.getGuard())); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "destinations"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (auto const& destination : edge.getDestinations()) { |
|||
appendEdgeDestination(out, model, automaton, destination, indent + 2); |
|||
} |
|||
|
|||
appendIndent(out, indent + 1); |
|||
out << "]"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendEdges(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "edges"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (uint64_t location = 0; location < automaton.getNumberOfLocations(); ++location) { |
|||
for (auto const& edge : automaton.getEdgesFromLocation(location)) { |
|||
appendEdge(out, model, automaton, edge, indent + 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
} |
|||
} |
|||
|
|||
appendIndent(out, indent); |
|||
out << "]"; |
|||
clearLine(out); |
|||
} |
|||
|
|||
void Exporter::appendAutomaton(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
out << "{"; |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "name"); |
|||
appendValue(out, automaton.getName()); |
|||
clearLine(out); |
|||
appendVariables(out, automaton.getVariables(), indent + 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
|
|||
appendLocations(out, automaton, indent + 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "initial-locations"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
for (auto const& index : automaton.getInitialLocationIndices()) { |
|||
appendIndent(out, indent + 2); |
|||
appendValue(out, automaton.getLocation(index).getName()); |
|||
clearLine(out); |
|||
} |
|||
appendIndent(out, indent + 1); |
|||
out << "]"; |
|||
clearLine(out); |
|||
if (automaton.hasInitialStatesRestriction()) { |
|||
appendIndent(out, indent + 1); |
|||
appendField(out, "initial-states"); |
|||
clearLine(out); |
|||
appendIndent(out, indent + 2); |
|||
out << "{"; |
|||
clearLine(out); |
|||
appendIndent(out, indent + 3); |
|||
appendField(out, "exp"); |
|||
appendValue(out, expressionToString(automaton.getInitialStatesExpression())); |
|||
clearLine(out); |
|||
appendIndent(out, indent + 2); |
|||
out << "}"; |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendEdges(out, model, automaton, indent + 1); |
|||
|
|||
appendIndent(out, indent); |
|||
out << "}"; |
|||
} |
|||
|
|||
void Exporter::appendAutomata(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const { |
|||
appendIndent(out, indent); |
|||
appendField(out, "automata"); |
|||
out << " ["; |
|||
clearLine(out); |
|||
|
|||
for (uint64_t index = 0; index < model.automata.size(); ++index) { |
|||
appendAutomaton(out, model, model.automata[index], indent + 1); |
|||
if (index < model.automata.size() - 1) { |
|||
out << ","; |
|||
} |
|||
clearLine(out); |
|||
} |
|||
|
|||
appendIndent(out, indent); |
|||
out << "]"; |
|||
} |
|||
|
|||
std::string Exporter::toJaniString(storm::jani::Model const& model) const { |
|||
std::stringstream out; |
|||
|
|||
out << "{" << std::endl; |
|||
appendVersion(out, model.getJaniVersion(), 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendModelName(out, model.getName(), 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendModelType(out, model.getModelType(), 1); |
|||
out << ","; |
|||
clearLine(out); |
|||
appendActions(out, model, 1); |
|||
clearLine(out); |
|||
appendVariables(out, model.getGlobalVariables(), 1); |
|||
clearLine(out); |
|||
|
|||
appendIndent(out, 1); |
|||
appendField(out, "initial-states"); |
|||
clearLine(out); |
|||
appendIndent(out, 2); |
|||
out << "{"; |
|||
clearLine(out); |
|||
appendIndent(out, 3); |
|||
appendField(out, "exp"); |
|||
appendValue(out, expressionToString(model.getInitialStatesRestriction())); |
|||
clearLine(out); |
|||
appendIndent(out, 2); |
|||
out << "}"; |
|||
clearLine(out); |
|||
|
|||
appendAutomata(out, model, 1); |
|||
clearLine(out); |
|||
out << "}" << std::endl; |
|||
|
|||
return out.str(); |
|||
} |
|||
|
|||
} |
|||
} |
@ -1,48 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <sstream> |
|||
#include <cstdint> |
|||
|
|||
#include "src/storage/jani/Model.h" |
|||
|
|||
namespace storm { |
|||
namespace jani { |
|||
|
|||
class Exporter { |
|||
public: |
|||
Exporter() = default; |
|||
|
|||
std::string toJaniString(storm::jani::Model const& model) const; |
|||
|
|||
private: |
|||
void appendVersion(std::stringstream& out, uint64_t janiVersion, uint64_t indent) const; |
|||
|
|||
void appendModelName(std::stringstream& out, std::string const& name, uint64_t indent) const; |
|||
|
|||
void appendModelType(std::stringstream& out, storm::jani::ModelType const& modelType, uint64_t indent) const; |
|||
|
|||
void appendAction(std::stringstream& out, storm::jani::Action const& action, uint64_t indent) const; |
|||
|
|||
void appendActions(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const; |
|||
|
|||
void appendVariables(std::stringstream& out, storm::jani::VariableSet const& variables, uint64_t indent) const; |
|||
|
|||
void appendVariable(std::stringstream& out, storm::jani::BooleanVariable const& variable, uint64_t indent) const; |
|||
void appendVariable(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const; |
|||
void appendBoundedIntegerVariableType(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const; |
|||
void appendVariable(std::stringstream& out, storm::jani::UnboundedIntegerVariable const& variable, uint64_t indent) const; |
|||
|
|||
void appendAutomata(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const; |
|||
void appendAutomaton(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const; |
|||
|
|||
void appendLocation(std::stringstream& out, storm::jani::Location const& location, uint64_t indent) const; |
|||
void appendLocations(std::stringstream& out, storm::jani::Automaton const& automaton, uint64_t indent) const; |
|||
|
|||
void appendAssignment(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Assignment const& assignment, uint64_t indent) const; |
|||
void appendEdgeDestination(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::EdgeDestination const& destination, uint64_t indent) const; |
|||
void appendEdge(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Edge const& edge, uint64_t indent) const; |
|||
void appendEdges(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,116 @@ |
|||
#include "src/storage/jani/OrderedAssignments.h"
|
|||
|
|||
#include "src/utility/macros.h"
|
|||
#include "src/exceptions/InvalidArgumentException.h"
|
|||
|
|||
namespace storm { |
|||
namespace jani { |
|||
|
|||
OrderedAssignments::OrderedAssignments(std::vector<Assignment> const& assignments) { |
|||
for (auto const& assignment : assignments) { |
|||
add(assignment); |
|||
} |
|||
} |
|||
|
|||
bool OrderedAssignments::add(Assignment const& assignment) { |
|||
// If the element is contained in this set of assignment, nothing needs to be added.
|
|||
if (this->contains(assignment)) { |
|||
return false; |
|||
} |
|||
|
|||
// Otherwise, we find the spot to insert it.
|
|||
auto it = lowerBound(assignment, allAssignments); |
|||
|
|||
if (it != allAssignments.end()) { |
|||
STORM_LOG_THROW(assignment.getExpressionVariable() != (*it)->getExpressionVariable(), storm::exceptions::InvalidArgumentException, "Cannot add assignment as an assignment to this variable already exists."); |
|||
} |
|||
|
|||
// Finally, insert the new element in the correct vectors.
|
|||
auto elementToInsert = std::make_shared<Assignment>(assignment); |
|||
allAssignments.emplace(it, elementToInsert); |
|||
if (assignment.isTransient()) { |
|||
auto transientIt = lowerBound(assignment, transientAssignments); |
|||
transientAssignments.emplace(transientIt, elementToInsert); |
|||
} else { |
|||
auto nonTransientIt = lowerBound(assignment, nonTransientAssignments); |
|||
nonTransientAssignments.emplace(nonTransientIt, elementToInsert); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
bool OrderedAssignments::remove(Assignment const& assignment) { |
|||
// If the element is contained in this set of assignment, nothing needs to be removed.
|
|||
if (!this->contains(assignment)) { |
|||
return false; |
|||
} |
|||
|
|||
// Otherwise, we find the element to delete.
|
|||
auto it = lowerBound(assignment, allAssignments); |
|||
STORM_LOG_ASSERT(it != allAssignments.end(), "Invalid iterator, expected existing element."); |
|||
STORM_LOG_ASSERT(assignment == **it, "Wrong iterator position."); |
|||
allAssignments.erase(it); |
|||
|
|||
if (assignment.isTransient()) { |
|||
auto transientIt = lowerBound(assignment, transientAssignments); |
|||
STORM_LOG_ASSERT(transientIt != transientAssignments.end(), "Invalid iterator, expected existing element."); |
|||
STORM_LOG_ASSERT(assignment == **transientIt, "Wrong iterator position."); |
|||
transientAssignments.erase(transientIt); |
|||
} else { |
|||
auto nonTransientIt = lowerBound(assignment, nonTransientAssignments); |
|||
STORM_LOG_ASSERT(nonTransientIt != nonTransientAssignments.end(), "Invalid iterator, expected existing element."); |
|||
STORM_LOG_ASSERT(assignment == **nonTransientIt, "Wrong iterator position."); |
|||
nonTransientAssignments.erase(nonTransientIt); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool OrderedAssignments::contains(Assignment const& assignment) const { |
|||
auto it = lowerBound(assignment, allAssignments); |
|||
if (it != allAssignments.end() && assignment == **it) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
detail::ConstAssignments OrderedAssignments::getAllAssignments() const { |
|||
return detail::ConstAssignments(allAssignments.begin(), allAssignments.end()); |
|||
} |
|||
|
|||
detail::ConstAssignments OrderedAssignments::getTransientAssignments() const { |
|||
return detail::ConstAssignments(transientAssignments.begin(), transientAssignments.end()); |
|||
} |
|||
|
|||
detail::ConstAssignments OrderedAssignments::getNonTransientAssignments() const { |
|||
return detail::ConstAssignments(nonTransientAssignments.begin(), nonTransientAssignments.end()); |
|||
} |
|||
|
|||
detail::Assignments::iterator OrderedAssignments::begin() { |
|||
return detail::Assignments::make_iterator(allAssignments.begin()); |
|||
} |
|||
|
|||
detail::ConstAssignments::iterator OrderedAssignments::begin() const { |
|||
return detail::ConstAssignments::make_iterator(allAssignments.begin()); |
|||
} |
|||
|
|||
detail::Assignments::iterator OrderedAssignments::end() { |
|||
return detail::Assignments::make_iterator(allAssignments.end()); |
|||
} |
|||
|
|||
detail::ConstAssignments::iterator OrderedAssignments::end() const { |
|||
return detail::ConstAssignments::make_iterator(allAssignments.end()); |
|||
} |
|||
|
|||
void OrderedAssignments::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution) { |
|||
for (auto& assignment : allAssignments) { |
|||
assignment->substitute(substitution); |
|||
} |
|||
} |
|||
|
|||
std::vector<std::shared_ptr<Assignment>>::const_iterator OrderedAssignments::lowerBound(Assignment const& assignment, std::vector<std::shared_ptr<Assignment>> const& assignments) { |
|||
return std::lower_bound(assignments.begin(), assignments.end(), assignment, storm::jani::AssignmentPartialOrderByVariable()); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,91 @@ |
|||
#pragma once |
|||
|
|||
#include "src/adapters/DereferenceIteratorAdapter.h" |
|||
|
|||
#include "src/storage/jani/Assignment.h" |
|||
|
|||
namespace storm { |
|||
namespace jani { |
|||
|
|||
namespace detail { |
|||
using Assignments = storm::adapters::DereferenceIteratorAdapter<std::vector<std::shared_ptr<Assignment>>>; |
|||
using ConstAssignments = storm::adapters::DereferenceIteratorAdapter<std::vector<std::shared_ptr<Assignment>> const>; |
|||
} |
|||
|
|||
class OrderedAssignments { |
|||
public: |
|||
/*! |
|||
* Creates an ordered set of assignments. |
|||
*/ |
|||
OrderedAssignments(std::vector<Assignment> const& assignments = std::vector<Assignment>()); |
|||
|
|||
/*! |
|||
* Adds the given assignment to the set of assignments. |
|||
* |
|||
* @return True iff the assignment was added. |
|||
*/ |
|||
bool add(Assignment const& assignment); |
|||
|
|||
/*! |
|||
* Removes the given assignment from this set of assignments. |
|||
* |
|||
* @return True if the assignment was found and removed. |
|||
*/ |
|||
bool remove(Assignment const& assignment); |
|||
|
|||
/*! |
|||
* Retrieves whether the given assignment is contained in this set of assignments. |
|||
*/ |
|||
bool contains(Assignment const& assignment) const; |
|||
|
|||
/*! |
|||
* Returns all assignments in this set of assignments. |
|||
*/ |
|||
detail::ConstAssignments getAllAssignments() const; |
|||
|
|||
/*! |
|||
* Returns all transient assignments in this set of assignments. |
|||
*/ |
|||
detail::ConstAssignments getTransientAssignments() const; |
|||
|
|||
/*! |
|||
* Returns all non-transient assignments in this set of assignments. |
|||
*/ |
|||
detail::ConstAssignments getNonTransientAssignments() const; |
|||
|
|||
/*! |
|||
* Returns an iterator to the assignments. |
|||
*/ |
|||
detail::Assignments::iterator begin(); |
|||
|
|||
/*! |
|||
* Returns an iterator to the assignments. |
|||
*/ |
|||
detail::ConstAssignments::iterator begin() const; |
|||
|
|||
/*! |
|||
* Returns an iterator past the end of the assignments. |
|||
*/ |
|||
detail::Assignments::iterator end(); |
|||
|
|||
/*! |
|||
* Returns an iterator past the end of the assignments. |
|||
*/ |
|||
detail::ConstAssignments::iterator end() const; |
|||
|
|||
/*! |
|||
* Substitutes all variables in all expressions according to the given substitution. |
|||
*/ |
|||
void substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution); |
|||
|
|||
private: |
|||
static std::vector<std::shared_ptr<Assignment>>::const_iterator lowerBound(Assignment const& assignment, std::vector<std::shared_ptr<Assignment>> const& assignments); |
|||
|
|||
// The vectors to store the assignments. These need to be ordered at all times. |
|||
std::vector<std::shared_ptr<Assignment>> allAssignments; |
|||
std::vector<std::shared_ptr<Assignment>> transientAssignments; |
|||
std::vector<std::shared_ptr<Assignment>> nonTransientAssignments; |
|||
}; |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue