Browse Source

Refactored and fixed bugs in explicit model adapter. Added support for labeling of choices of a model. The explicit model adapter uses that functionality to label each choice with the involved PRISM commands.

Former-commit-id: 818431d6e9
tempestpy_adaptions
dehnert 11 years ago
parent
commit
947581dd25
  1. 2
      examples/mdp/asynchronous_leader/leader3.nm
  2. BIN
      resources/3rdparty/gtest-1.6.0/libgtest.a
  3. BIN
      resources/3rdparty/gtest-1.6.0/libgtest_main.a
  4. 1085
      src/adapters/ExplicitModelAdapter.cpp
  5. 492
      src/adapters/ExplicitModelAdapter.h
  6. 12
      src/ir/Command.cpp
  7. 16
      src/ir/Command.h
  8. 3
      src/ir/Module.cpp
  9. 11
      src/models/AbstractDeterministicModel.h
  10. 28
      src/models/AbstractModel.h
  11. 13
      src/models/AbstractNondeterministicModel.h
  12. 11
      src/models/Ctmc.h
  13. 12
      src/models/Ctmdp.h
  14. 11
      src/models/Dtmc.h
  15. 27
      src/models/Mdp.h
  16. 4
      src/parser/DeterministicModelParser.cpp
  17. 4
      src/parser/NondeterministicModelParser.cpp
  18. 7
      src/parser/prismparser/PrismGrammar.cpp
  19. 10
      src/parser/prismparser/PrismGrammar.h
  20. 7
      src/parser/prismparser/VariableState.cpp
  21. 12
      src/parser/prismparser/VariableState.h

2
examples/mdp/asynchronous_leader/leader3.nm

@ -4,7 +4,7 @@
mdp
const N= 3; // number of processes
const int N = 3; // number of processes
//----------------------------------------------------------------------------------------------------------------------------
module process1

BIN
resources/3rdparty/gtest-1.6.0/libgtest.a

BIN
resources/3rdparty/gtest-1.6.0/libgtest_main.a

1085
src/adapters/ExplicitModelAdapter.cpp
File diff suppressed because it is too large
View File

492
src/adapters/ExplicitModelAdapter.h

@ -5,8 +5,8 @@
* Created on March 15, 2013, 11:42 AM
*/
#ifndef EXPLICITMODELADAPTER_H
#define EXPLICITMODELADAPTER_H
#ifndef STORM_ADAPTERS_EXPLICITMODELADAPTER_H
#define STORM_ADAPTERS_EXPLICITMODELADAPTER_H
#include <memory>
#include <unordered_map>
@ -23,226 +23,272 @@
#include "src/storage/SparseMatrix.h"
namespace storm {
namespace adapters {
/*!
* Model state, represented by the values of all variables.
*/
typedef std::pair<std::vector<bool>, std::vector<int_fast64_t>> StateType;
class StateHash {
public:
std::size_t operator()(StateType* state) const {
size_t seed = 0;
for (auto it : state->first) {
boost::hash_combine<bool>(seed, it);
}
for (auto it : state->second) {
boost::hash_combine<int_fast64_t>(seed, it);
}
return seed;
}
};
class StateCompare {
public:
bool operator()(StateType* state1, StateType* state2) const {
return *state1 == *state2;
}
};
class ExplicitModelAdapter {
public:
/*!
* Initialize adapter with given program.
*/
ExplicitModelAdapter(storm::ir::Program program);
~ExplicitModelAdapter();
/*!
* Convert program to an AbstractModel.
* The model will be of the type specified in the program.
* The model will contain rewards that are specified by the given reward model.
* @param rewardModelName Name of reward model to be added to the model.
* @return Model resulting from the program.
*/
std::shared_ptr<storm::models::AbstractModel<double>> getModel(std::string const & rewardModelName = "");
private:
// Copying/Moving is disabled for this class
ExplicitModelAdapter(ExplicitModelAdapter const& other) {}
ExplicitModelAdapter(ExplicitModelAdapter && other) {}
double precision;
/*!
* Set some boolean variable in the given state object.
* @param state State to be changed.
* @param index Index of boolean variable.
* @param value New value.
*/
static void setValue(StateType* const state, uint_fast64_t const index, bool const value);
/*!
* Set some integer variable in the given state object.
* @param state State to be changed.
* @param index Index of integer variable.
* @param value New value.
*/
static void setValue(StateType* const state, uint_fast64_t const index, int_fast64_t const value);
/*!
* Transforms a state into a somewhat readable string.
* @param state State.
* @return String representation of the state.
*/
static std::string toString(StateType const * const state);
/*!
* Apply an update to the given state and return the resulting new state object.
* This methods creates a copy of the given state.
* @params state Current state.
* @params update Update to be applied.
* @return Resulting state.
*/
StateType* applyUpdate(StateType const * const state, storm::ir::Update const& update) const;
/*!
* Apply an update to a given state and return the resulting new state object.
* Updates are done using the variable values from a given baseState.
* @params state State to be updated.
* @params baseState State used for update variables.
* @params update Update to be applied.
* @return Resulting state.
*/
StateType* applyUpdate(StateType const * const state, StateType const * const baseState, storm::ir::Update const& update) const;
/*!
* Reads and combines variables from all program modules and stores them.
* Also creates a map to obtain a variable index from a variable map efficiently.
*/
void initializeVariables();
/*!
* Calculate state reward for every reachable state based on given reward models.
* @param rewards List of state reward models.
* @return Reward for every state.
*/
std::vector<double> getStateRewards(std::vector<storm::ir::StateReward> const & rewards);
/*!
* Determines the labels for every reachable state, based on a list of available labels.
* @param labels Mapping from label names to boolean expressions.
* @returns The resulting labeling.
*/
storm::models::AtomicPropositionsLabeling getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels);
/*!
* Retrieves all active command labeled by some label, ordered by modules.
*
* This function will iterate over all modules and retrieve all commands that are labeled with the given action and active for the current state.
* The result will be a list of lists of commands.
*
* For each module that has appropriately labeled commands, there will be a list.
* If none of these commands is active, this list is empty.
* Note the difference between *no list* and *empty list*: Modules that produce no list are not relevant for this action while an empty list means, that it is not possible to do anything with this label.
* @param state Current state.
* @param action Action label.
* @return Active commands.
*/
std::unique_ptr<std::list<std::list<storm::ir::Command>>> getActiveCommandsByAction(StateType const * state, std::string& action);
/*!
* Generates the initial state.
*
* @return The initial state.
*/
StateType* getInitialState();
/*!
* Retrieves the state id of the given state.
* If the state has not been hit yet, it will be added to allStates and given a new id.
* In this case, the pointer must not be deleted, as it is used within allStates.
* If the state is already known, the pointer is deleted and the old state id is returned.
* Hence, the given state pointer should not be used afterwards.
* @param state Pointer to state, shall not be used afterwards.
* @returns State id of given state.
*/
uint_fast64_t getOrAddStateId(StateType * state);
/*!
* Expands all unlabeled transitions for a given state and adds them to the given list of results.
* @params state State to be explored.
* @params res Intermediate transition map.
*/
void addUnlabeledTransitions(const uint_fast64_t stateID, std::list<std::pair<std::string, std::map<uint_fast64_t, double>>>& res);
/*!
* Explores reachable state from given state by using labeled transitions.
* Found transitions are stored in given map.
* @param stateID State to be explored.
* @param res Intermediate transition map.
*/
void addLabeledTransitions(const uint_fast64_t stateID, std::list<std::pair<std::string, std::map<uint_fast64_t, double>>>& res);
/*!
* Create matrix from intermediate mapping, assuming it is a dtmc model.
* @param intermediate Intermediate representation of transition mapping.
* @return result matrix.
*/
storm::storage::SparseMatrix<double> buildDeterministicMatrix();
/*!
* Create matrix from intermediate mapping, assuming it is a mdp model.
* @param intermediate Intermediate representation of transition mapping.
* @param choices Overall number of choices for all nodes.
* @return result matrix.
*/
storm::storage::SparseMatrix<double> buildNondeterministicMatrix();
/*!
* Generate internal transition map from given model.
* Starts with all initial states and explores the reachable state space.
*/
void buildTransitionMap();
/*!
* Clear all members that are initialized during the computation.
*/
void clearInternalState();
// Program that should be converted.
storm::ir::Program program;
// List of all boolean variables.
std::vector<storm::ir::BooleanVariable> booleanVariables;
// List of all integer variables.
std::vector<storm::ir::IntegerVariable> integerVariables;
// Maps boolean variable names to their index.
std::map<std::string, uint_fast64_t> booleanVariableToIndexMap;
// Maps integer variable names to their index.
std::map<std::string, uint_fast64_t> integerVariableToIndexMap;
//// Members that are filled during the conversion.
// Selected reward model.
std::unique_ptr<storm::ir::RewardModel> rewardModel;
// List of all reachable states.
std::vector<StateType*> allStates;
// Maps states to their index (within allStates).
std::unordered_map<StateType*, uint_fast64_t, StateHash, StateCompare> stateToIndexMap;
// Number of transitions.
uint_fast64_t numberOfTransitions;
// Number of choices. (Is number of rows in matrix of nondeterministic model.)
uint_fast64_t numberOfChoices;
// Number of choices for each state.
std::vector<uint_fast64_t> choiceIndices;
// Rewards for transitions.
boost::optional<storm::storage::SparseMatrix<double>> transitionRewards;
/*!
* Maps a source node to a list of probability distributions over target nodes.
* Each such distribution corresponds to an unlabeled command or a feasible combination of labeled commands.
* Therefore, each distribution is represented by a label and a mapping from target nodes to their probabilities.
*/
std::map<uint_fast64_t, std::list<std::pair<std::string, std::map<uint_fast64_t, double>>>> transitionMap;
};
} // namespace adapters
namespace adapters {
/*!
* A state of the model, i.e. a valuation of all variables.
*/
typedef std::pair<std::vector<bool>, std::vector<int_fast64_t>> StateType;
/*!
* A helper class that provides the functionality to compute a hash value for states of the model.
*/
class StateHash {
public:
std::size_t operator()(StateType* state) const {
size_t seed = 0;
for (auto it : state->first) {
boost::hash_combine<bool>(seed, it);
}
for (auto it : state->second) {
boost::hash_combine<int_fast64_t>(seed, it);
}
return seed;
}
};
/*!
* A helper class that provides the functionality to compare states of the model.
*/
class StateCompare {
public:
bool operator()(StateType* state1, StateType* state2) const {
return *state1 == *state2;
}
};
class ExplicitModelAdapter {
public:
/*!
* Initializes the adapter with the given program.
*
* @param program The program from which to build the explicit model.
*/
ExplicitModelAdapter(storm::ir::Program program);
/*!
* Destroys the adapter.
*/
~ExplicitModelAdapter();
/*!
* Convert the program given at construction time to an abstract model. The type of the model is the one
* specified in the program. The given reward model name selects the rewards that the model will contain.
*
* @param rewardModelName The name of reward model to be added to the model. This must be either a reward
* model of the program or the empty string. In the latter case, the constructed model will contain no
* rewards.
* @return The explicit model that was given by the probabilistic program.
*/
std::shared_ptr<storm::models::AbstractModel<double>> getModel(std::string const& rewardModelName = "");
private:
// Copying/Moving is disabled for this class
ExplicitModelAdapter(ExplicitModelAdapter const& other) { }
ExplicitModelAdapter(ExplicitModelAdapter && other) { }
/*!
* The precision that is to be used for sanity checks internally.
*/
double precision;
/*!
* Sets some boolean variable in the given state object.
*
* @param state The state to modify.
* @param index The index of the boolean variable to modify.
* @param value The new value of the variable.
*/
static void setValue(StateType* state, uint_fast64_t index, bool value);
/*!
* Set some integer variable in the given state object.
*
* @param state The state to modify.
* @param index index of the integer variable to modify.
* @param value The new value of the variable.
*/
static void setValue(StateType* state, uint_fast64_t index, int_fast64_t value);
/*!
* Transforms a state into a somewhat readable string.
*
* @param state The state to transform into a string.
* @return A string representation of the state.
*/
static std::string toString(StateType const* state);
/*!
* Applies an update to the given state and returns the resulting new state object. This methods does not
* modify the given state but returns a new one.
*
* @params state The state to which to apply the update.
* @params update The update to apply.
* @return The resulting state.
*/
StateType* applyUpdate(StateType const* state, storm::ir::Update const& update) const;
/*!
* Applies an update to the given state and returns the resulting new state object. The update is evaluated
* over the variable values of the given base state. This methods does not modify the given state but
* returns a new one.
*
* @params state The state to which to apply the update.
* @params baseState The state used for evaluating the update.
* @params update The update to apply.
* @return The resulting state.
*/
StateType* applyUpdate(StateType const* state, StateType const* baseState, storm::ir::Update const& update) const;
/*!
* Prepares internal data structures associated with the variables in the program that are used during the
* translation.
*/
void initializeVariables();
/*!
* Retrieves the state rewards for every reachable state based on the given state rewards.
*
* @param rewards The rewards to use.
* @return The reward values for every (reachable) state.
*/
std::vector<double> getStateRewards(std::vector<storm::ir::StateReward> const& rewards);
/*!
* Computes the labels for every reachable state based on a list of available labels.
*
* @param labels A mapping from label names to boolean expressions to use for the labeling.
* @return The resulting labeling.
*/
storm::models::AtomicPropositionsLabeling getStateLabeling(std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels);
/*!
* Retrieves all commands that are labeled with the given label and enabled in the given state, grouped by
* modules.
*
* This function will iterate over all modules and retrieve all commands that are labeled with the given
* action and active (i.e. enabled) in the current state. The result is a list of lists of commands in which
* the inner lists contain all commands of exactly one module. If a module does not have *any* (including
* disabled) commands, there will not be a list of commands of that module in the result. If, however, the
* module has a command with a relevant label, but no enabled one, nothing is returned to indicate that there
* is no legal transition possible.
*
* @param state The current state.
* @param action The action label to select.
* @return A list of lists of active commands or nothing.
*/
boost::optional<std::vector<std::list<storm::ir::Command>>> getActiveCommandsByAction(StateType const* state, std::string const& action);
/*!
* Generates the initial state.
*
* @return The initial state.
*/
StateType* getInitialState();
/*!
* Retrieves the state id of the given state. If the state has not been encountered yet, it will be added to
* the lists of all states with a new id. If the state was already known, the object that is pointed to by
* the given state pointer is deleted and the old state id is returned. Note that the pointer should not be
* used after invoking this method.
*
* @param state A pointer to a state for which to retrieve the index. This must not be used after the call.
* @return The state id of the given state.
*/
uint_fast64_t getOrAddStateIndex(StateType* state);
/*!
* Expands all unlabeled (i.e. independent) transitions of the given state and adds them to the transition list.
*
* @param stateIndex The state to expand.
* @params transitionList The current list of transitions for this state.
*/
void addUnlabeledTransitions(uint_fast64_t stateIndex, std::list<std::pair<std::pair<std::string, std::list<uint_fast64_t>>, std::map<uint_fast64_t, double>>>& transitionList);
/*!
* Expands all labeled (i.e. synchronizing) transitions of the given state and adds them to the transition list.
*
* @param stateIndex The index of the state to expand.
* @param transitionList The current list of transitions for this state.
*/
void addLabeledTransitions(uint_fast64_t stateIndex, std::list<std::pair<std::pair<std::string, std::list<uint_fast64_t>>, std::map<uint_fast64_t, double>>>& transitionList);
/*!
* Builds the transition matrix of a deterministic model from the current list of transitions.
*
* @return The transition matrix.
*/
storm::storage::SparseMatrix<double> buildDeterministicMatrix();
/*!
* Builds the transition matrix of a nondeterministic model from the current list of transitions.
*
* @return result The transition matrix.
*/
storm::storage::SparseMatrix<double> buildNondeterministicMatrix();
/*!
* Generate the (internal) list of all transitions of the model.
*/
void buildTransitionMap();
/*!
* Clear all members that are initialized during the computation.
*/
void clearInternalState();
// Program that is to be converted.
storm::ir::Program program;
// List of all boolean variables.
std::vector<storm::ir::BooleanVariable> booleanVariables;
// List of all integer variables.
std::vector<storm::ir::IntegerVariable> integerVariables;
// A mapping of boolean variable names to their indices.
std::map<std::string, uint_fast64_t> booleanVariableToIndexMap;
// A mapping of integer variable names to their indices.
std::map<std::string, uint_fast64_t> integerVariableToIndexMap;
//// Members that are filled during the conversion.
// The selected reward model.
std::unique_ptr<storm::ir::RewardModel> rewardModel;
// A list of all reachable states.
std::vector<StateType*> allStates;
// A mapping of states to their indices (within the list of all states).
std::unordered_map<StateType*, uint_fast64_t, StateHash, StateCompare> stateToIndexMap;
// The number of transitions.
uint_fast64_t numberOfTransitions;
// The number of choices in a nondeterminstic model. (This corresponds to the number of rows of the matrix
// used to represent the nondeterministic model.)
uint_fast64_t numberOfChoices;
// The number of choices for each state of a nondeterministic model.
std::vector<uint_fast64_t> choiceIndices;
// The result of the translation of transition rewards to a sparse matrix (if any).
boost::optional<storm::storage::SparseMatrix<double>> transitionRewards;
// A labeling for the choices of each state.
std::vector<std::list<uint_fast64_t>> choiceLabeling;
/*!
* Maps a source state to a list of probability distributions over target states. Each distribution
* corresponds to an unlabeled command or a feasible combination of labeled commands. Therefore, each
* distribution is represented by a structure that contains the label of the participating commands, a list
* of labels associated with that particular command combination and a mapping from target states to their
* probabilities.
*/
std::map<uint_fast64_t, std::list<std::pair<std::pair<std::string, std::list<uint_fast64_t>>, std::map<uint_fast64_t, double>>>> transitionMap;
};
} // namespace adapters
} // namespace storm
#endif /* EXPLICITMODELADAPTER_H */
#endif /* STORM_ADAPTERS_EXPLICITMODELADAPTER_H */

12
src/ir/Command.cpp

@ -18,13 +18,13 @@ namespace storm {
// Nothing to do here.
}
Command::Command(std::string const& actionName, std::shared_ptr<storm::ir::expressions::BaseExpression> guardExpression, std::vector<storm::ir::Update> const& updates)
: actionName(actionName), guardExpression(guardExpression), updates(updates) {
Command::Command(uint_fast64_t globalIndex, std::string const& actionName, std::shared_ptr<storm::ir::expressions::BaseExpression> guardExpression, std::vector<storm::ir::Update> const& updates)
: actionName(actionName), guardExpression(guardExpression), updates(updates), globalIndex(globalIndex) {
// Nothing to do here.
}
Command::Command(Command const& oldCommand, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState const& variableState)
: actionName(oldCommand.getActionName()), guardExpression(oldCommand.guardExpression->clone(renaming, variableState)) {
Command::Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState const& variableState)
: actionName(oldCommand.getActionName()), guardExpression(oldCommand.guardExpression->clone(renaming, variableState)), globalIndex(newGlobalIndex) {
auto renamingPair = renaming.find(this->actionName);
if (renamingPair != renaming.end()) {
this->actionName = renamingPair->first;
@ -51,6 +51,10 @@ namespace storm {
return this->updates[index];
}
uint_fast64_t Command::getGlobalIndex() const {
return this->globalIndex;
}
std::string Command::toString() const {
std::stringstream result;
result << "[" << actionName << "] " << guardExpression->toString() << " -> ";

16
src/ir/Command.h

@ -38,21 +38,23 @@ namespace storm {
/*!
* Creates a command with the given name, guard and updates.
*
* @param globalIndex The global index of the command.
* @param actionName The action name of the command.
* @param guardExpression the expression that defines the guard of the command.
* @param updates A list of updates that is associated with this command.
*/
Command(std::string const& actionName, std::shared_ptr<storm::ir::expressions::BaseExpression> guardExpression, std::vector<storm::ir::Update> const& updates);
Command(uint_fast64_t globalIndex, std::string const& actionName, std::shared_ptr<storm::ir::expressions::BaseExpression> guardExpression, std::vector<storm::ir::Update> const& updates);
/*!
* Creates a copy of the given command and performs the provided renaming.
*
* @param oldCommand The command to copy.
* @param newGlobalIndex The global index of the copy of the command.
* @param renaming A mapping from names that are to be renamed to the names they are to be
* replaced with.
* @param variableState An object knowing about the variables in the system.
*/
Command(Command const& oldCommand, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState const& variableState);
Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState const& variableState);
/*!
* Retrieves the action name of this command.
@ -82,6 +84,13 @@ namespace storm {
*/
storm::ir::Update const& getUpdate(uint_fast64_t index) const;
/*!
* Retrieves the global index of the command, that is, a unique index over all modules.
*
* @return The global index of the command.
*/
uint_fast64_t getGlobalIndex() const;
/*!
* Retrieves a string representation of this command.
*
@ -98,6 +107,9 @@ namespace storm {
// The list of updates of the command.
std::vector<storm::ir::Update> updates;
// The global index of the command.
uint_fast64_t globalIndex;
};
} // namespace ir

3
src/ir/Module.cpp

@ -72,7 +72,8 @@ namespace storm {
// Now we are ready to clone all commands and rename them if requested.
this->commands.reserve(oldModule.getNumberOfCommands());
for (Command const& command : oldModule.commands) {
this->commands.emplace_back(command, renaming, variableState);
this->commands.emplace_back(command, variableState.getNextGlobalCommandIndex(), renaming, variableState);
variableState.nextGlobalCommandIndex++;
}
this->collectActions();

11
src/models/AbstractDeterministicModel.h

@ -28,8 +28,9 @@ class AbstractDeterministicModel: public AbstractModel<T> {
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
AbstractDeterministicModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix, optionalChoiceLabeling) {
}
/*! Constructs an abstract determinstic model from the given parameters.
@ -41,9 +42,11 @@ class AbstractDeterministicModel: public AbstractModel<T> {
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
AbstractDeterministicModel(storm::storage::SparseMatrix<T>&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) {
: AbstractModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)) {
// Intentionally left empty.
}

28
src/models/AbstractModel.h

@ -18,7 +18,7 @@ namespace models {
* @brief Enumeration of all supported types of models.
*/
enum ModelType {
Unknown, DTMC, CTMC, MDP, CTMDP
Unknown, DTMC, CTMC, MDP, UPDATE_LABELED_MDP, CTMDP
};
/*!
@ -44,7 +44,8 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
: transitionMatrix(other.transitionMatrix),
stateLabeling(other.stateLabeling),
stateRewardVector(other.stateRewardVector),
transitionRewardMatrix(other.transitionRewardMatrix) {
transitionRewardMatrix(other.transitionRewardMatrix),
choiceLabeling(other.choiceLabeling) {
// Intentionally left empty.
}
@ -56,7 +57,8 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
: transitionMatrix(std::move(other.transitionMatrix)),
stateLabeling(std::move(other.stateLabeling)),
stateRewardVector(std::move(other.stateRewardVector)),
transitionRewardMatrix(std::move(other.transitionRewardMatrix)) {
transitionRewardMatrix(std::move(other.transitionRewardMatrix)),
choiceLabeling(std::move(other.choiceLabeling)) {
// Intentionally left empty.
}
@ -67,17 +69,22 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* propositions to each state.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
AbstractModel(storm::storage::SparseMatrix<T> const& transitionMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: transitionMatrix(transitionMatrix), stateLabeling(stateLabeling) {
if (optionalStateRewardVector) { // Boost::Optional
if (optionalStateRewardVector) {
this->stateRewardVector.reset(optionalStateRewardVector.get());
}
if (optionalTransitionRewardMatrix) { // Boost::Optional
if (optionalTransitionRewardMatrix) {
this->transitionRewardMatrix.reset(optionalTransitionRewardMatrix.get());
}
if (optionalChoiceLabeling) {
this->choiceLabeling.reset(optionalChoiceLabeling.get());
}
}
/*! Constructs an abstract model from the given transition matrix and
@ -89,9 +96,11 @@ class AbstractModel: public std::enable_shared_from_this<AbstractModel<T>> {
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
AbstractModel(storm::storage::SparseMatrix<T>&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix) :
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling) :
transitionMatrix(std::move(transitionMatrix)), stateLabeling(std::move(stateLabeling)),
stateRewardVector(std::move(optionalStateRewardVector)), transitionRewardMatrix(std::move(optionalTransitionRewardMatrix)) { }
stateRewardVector(std::move(optionalStateRewardVector)), transitionRewardMatrix(std::move(optionalTransitionRewardMatrix)),
choiceLabeling(std::move(optionalChoiceLabeling)) { }
/*!
* Destructor.
@ -507,6 +516,9 @@ private:
/*! The transition-based rewards of the model. */
boost::optional<storm::storage::SparseMatrix<T>> transitionRewardMatrix;
/*! The labeling that is associated with the choices for each state. */
boost::optional<std::vector<std::list<uint_fast64_t>>> choiceLabeling;
};
} // namespace models

13
src/models/AbstractNondeterministicModel.h

@ -26,14 +26,16 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
* @param choiceIndices A mapping from states to rows in the transition matrix.
* @param stateRewardVector The reward values associated with the states.
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
* @param optionalChoiceLabeling A vector that represents the labels associated with the choices of each state.
*/
AbstractNondeterministicModel(
storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractModel<T>(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix, optionalChoiceLabeling) {
this->nondeterministicChoiceIndices = nondeterministicChoiceIndices;
}
@ -51,10 +53,11 @@ class AbstractNondeterministicModel: public AbstractModel<T> {
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)),
nondeterministicChoiceIndices(std::move(nondeterministicChoiceIndices)) {
: AbstractModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)), nondeterministicChoiceIndices(std::move(nondeterministicChoiceIndices)) {
// Intentionally left empty.
}

11
src/models/Ctmc.h

@ -36,8 +36,9 @@ public:
* propositions to each state.
*/
Ctmc(storm::storage::SparseMatrix<T> const& rateMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractDeterministicModel<T>(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix, optionalChoiceLabeling) {
// Intentionally left empty.
}
@ -50,9 +51,11 @@ public:
* propositions to each state.
*/
Ctmc(storm::storage::SparseMatrix<T>&& rateMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractDeterministicModel<T>(std::move(rateMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) {
: AbstractDeterministicModel<T>(std::move(rateMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)) {
// Intentionally left empty.
}

12
src/models/Ctmdp.h

@ -41,8 +41,10 @@ public:
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractNondeterministicModel<T>(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix,
optionalChoiceLabeling) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -62,9 +64,11 @@ public:
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractNondeterministicModel<T>(std::move(probabilityMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) {
: AbstractNondeterministicModel<T>(std::move(probabilityMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";

11
src/models/Dtmc.h

@ -42,8 +42,9 @@ public:
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
Dtmc(storm::storage::SparseMatrix<T> const& probabilityMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling,
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<std::vector<T>> const& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractDeterministicModel<T>(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix, optionalChoiceLabeling) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -67,9 +68,11 @@ public:
* @param transitionRewardMatrix The reward values associated with the transitions of the model.
*/
Dtmc(storm::storage::SparseMatrix<T>&& probabilityMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling,
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<std::vector<T>>&& optionalStateRewardVector, boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractDeterministicModel<T>(std::move(probabilityMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) {
: AbstractDeterministicModel<T>(std::move(probabilityMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";

27
src/models/Mdp.h

@ -31,20 +31,25 @@ class Mdp : public storm::models::AbstractNondeterministicModel<T> {
public:
/*!
* Constructs a MDP object from the given transition probability matrix and
* the given labeling of the states.
* Constructs a MDP object from the given transition probability matrix and the given labeling of the states.
* All values are copied.
* @param probabilityMatrix The transition probability relation of the
* MDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic
* propositions to each state.
*
* @param probabilityMatrix The transition probability relation of the MDP given by a matrix.
* @param stateLabeling The labeling that assigns a set of atomic propositions to each state.
* @param nondeterministicChoiceIndices The row indices in the sparse matrix at which the nondeterministic
* choices of a given state begin.
* @param optionalStateRewardVector A vector assigning rewards to states.
* @param optionalTransitionRewardVector A sparse matrix that represents an assignment of rewards to the transitions.
* @param optionalChoiceLabeling A vector that represents the labels associated with each nondeterministic choice of
* a state.
*/
Mdp(storm::storage::SparseMatrix<T> const& transitionMatrix,
storm::models::AtomicPropositionsLabeling const& stateLabeling,
std::vector<uint_fast64_t> const& nondeterministicChoiceIndices,
boost::optional<std::vector<T>> const& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix)
: AbstractNondeterministicModel<T>(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) {
boost::optional<storm::storage::SparseMatrix<T>> const& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>> const& optionalChoiceLabeling)
: AbstractNondeterministicModel<T>(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix, optionalChoiceLabeling) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";
@ -64,9 +69,11 @@ public:
storm::models::AtomicPropositionsLabeling&& stateLabeling,
std::vector<uint_fast64_t>&& nondeterministicChoiceIndices,
boost::optional<std::vector<T>>&& optionalStateRewardVector,
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix)
boost::optional<storm::storage::SparseMatrix<T>>&& optionalTransitionRewardMatrix,
boost::optional<std::vector<std::list<uint_fast64_t>>>&& optionalChoiceLabeling)
// The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class
: AbstractNondeterministicModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) {
: AbstractNondeterministicModel<T>(std::move(transitionMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix),
std::move(optionalChoiceLabeling)) {
if (!this->checkValidityOfProbabilityMatrix()) {
LOG4CPLUS_ERROR(logger, "Probability matrix is invalid.");
throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid.";

4
src/parser/DeterministicModelParser.cpp

@ -58,7 +58,7 @@ DeterministicModelParserResultContainer<double> parseDeterministicModel(std::str
storm::models::Dtmc<double> DeterministicModelParserAsDtmc(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile) {
DeterministicModelParserResultContainer<double> parserResult(std::move(parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)));
return storm::models::Dtmc<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards));
return storm::models::Dtmc<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards), boost::optional<std::vector<std::list<uint_fast64_t>>>());
}
/*!
@ -69,7 +69,7 @@ storm::models::Dtmc<double> DeterministicModelParserAsDtmc(std::string const & t
storm::models::Ctmc<double> DeterministicModelParserAsCtmc(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile) {
DeterministicModelParserResultContainer<double> parserResult(std::move(parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)));
return storm::models::Ctmc<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards));
return storm::models::Ctmc<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards), boost::optional<std::vector<std::list<uint_fast64_t>>>());
}
} /* namespace parser */

4
src/parser/NondeterministicModelParser.cpp

@ -58,7 +58,7 @@ NondeterministicModelParserResultContainer<double> parseNondeterministicModel(st
storm::models::Mdp<double> NondeterministicModelParserAsMdp(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile) {
NondeterministicModelParserResultContainer<double> parserResult = parseNondeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile);
return storm::models::Mdp<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards));
return storm::models::Mdp<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards), boost::optional<std::vector<std::list<uint_fast64_t>>>());
}
/*!
@ -69,7 +69,7 @@ storm::models::Mdp<double> NondeterministicModelParserAsMdp(std::string const &
storm::models::Ctmdp<double> NondeterministicModelParserAsCtmdp(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile) {
NondeterministicModelParserResultContainer<double> parserResult = parseNondeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile);
return storm::models::Ctmdp<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards));
return storm::models::Ctmdp<double>(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards), boost::optional<std::vector<std::list<uint_fast64_t>>>());
}
} /* namespace parser */

7
src/parser/prismparser/PrismGrammar.cpp

@ -108,8 +108,9 @@ void createRewardModel(std::string name, std::vector<StateReward>& stateRewards,
Update createUpdate(std::shared_ptr<BaseExpression> likelihood, std::map<std::string, Assignment>& bools, std::map<std::string, Assignment> ints) {
return Update(likelihood, bools, ints);
}
Command createCommand(std::string& label, std::shared_ptr<BaseExpression> guard, std::vector<Update>& updates) {
return Command(label, guard, updates);
Command PrismGrammar::createCommand(std::string const& label, std::shared_ptr<BaseExpression> guard, std::vector<Update> const& updates) {
this->state->nextGlobalCommandIndex++;
return Command(this->state->getNextGlobalCommandIndex() - 1, label, guard, updates);
}
Program createProgram(
Program::ModelType modelType,
@ -164,7 +165,7 @@ PrismGrammar::PrismGrammar() : PrismGrammar::base_type(start), state(new Variabl
qi::lit("[") > -(
(FreeIdentifierGrammar::instance(this->state)[phoenix::bind(this->state->commandNames_.add, qi::_1, qi::_1)] | commandName)[qi::_a = qi::_1]
) > qi::lit("]") > BooleanExpressionGrammar::instance(this->state) > qi::lit("->") > updateListDefinition > qi::lit(";")
)[qi::_val = phoenix::bind(&createCommand, qi::_a, qi::_2, qi::_3)];
)[qi::_val = phoenix::bind(&PrismGrammar::createCommand, this, qi::_a, qi::_2, qi::_3)];
commandDefinition.name("command");
// This block defines all entities that are needed for parsing variable definitions.

10
src/parser/prismparser/PrismGrammar.h

@ -215,6 +215,16 @@ private:
* @param booleanVariableToGlobalIndexMap A mapping of boolean variables to global indices.
*/
void createBooleanVariable(std::string const& name, std::shared_ptr<BaseExpression> const& init, std::vector<BooleanVariable>& booleanVariables, std::map<std::string, uint_fast64_t>& booleanVariableToGlobalIndexMap);
/*!
* Creates a command with the given label, guard and updates.
*
* @param label The label of the command.
* @param guard The guard of the command.
* @param updates The updates associated with the command.
*/
Command createCommand(std::string const& label, std::shared_ptr<BaseExpression> guard, std::vector<Update> const& updates);
};

7
src/parser/prismparser/VariableState.cpp

@ -31,7 +31,7 @@ std::ostream& operator<<(std::ostream& out, VariableState::variableNamesStruct&
}
VariableState::VariableState(bool firstRun) : firstRun(firstRun), keywords(), nextLocalBooleanVariableIndex(0), nextLocalIntegerVariableIndex(0), nextGlobalBooleanVariableIndex(0), nextGlobalIntegerVariableIndex(0) {
VariableState::VariableState(bool firstRun) : firstRun(firstRun), keywords(), nextLocalBooleanVariableIndex(0), nextLocalIntegerVariableIndex(0), nextGlobalBooleanVariableIndex(0), nextGlobalIntegerVariableIndex(0), nextGlobalCommandIndex(0) {
// Nothing to do here.
}
@ -51,6 +51,10 @@ uint_fast64_t VariableState::getNextGlobalIntegerVariableIndex() const {
return this->nextGlobalIntegerVariableIndex;
}
uint_fast64_t VariableState::getNextGlobalCommandIndex() const {
return this->nextGlobalCommandIndex;
}
uint_fast64_t VariableState::addBooleanVariable(std::string const& name) {
if (firstRun) {
LOG4CPLUS_TRACE(logger, "Adding boolean variable " << name << " with new id " << this->nextGlobalBooleanVariableIndex << ".");
@ -161,6 +165,7 @@ void VariableState::prepareForSecondRun() {
doubleConstants_.clear();
allConstantNames_.clear();
this->firstRun = false;
nextGlobalCommandIndex = 0;
}
} // namespace prism

12
src/parser/prismparser/VariableState.h

@ -99,6 +99,18 @@ public:
*/
uint_fast64_t getNextGlobalIntegerVariableIndex() const;
/*!
* Internal counter for the index of the next command.
*/
uint_fast64_t nextGlobalCommandIndex;
/*!
* Retrieves the next free global index for a command.
*
* @return The next free global index for a command.
*/
uint_fast64_t getNextGlobalCommandIndex() const;
// Structures mapping variable and constant names to the corresponding expression nodes of
// the intermediate representation.
struct qi::symbols<char, std::shared_ptr<VariableExpression>> integerVariables_, booleanVariables_;

Loading…
Cancel
Save