Browse Source

Added actionsToCommandIndexMap, initialization and getter.

This map maps an action name to the set of Commands labelled with this action name.
tempestpy_adaptions
gereon 12 years ago
parent
commit
00ce70d411
  1. 22
      src/ir/Module.cpp
  2. 13
      src/ir/Module.h

22
src/ir/Module.cpp

@ -17,7 +17,7 @@ namespace ir {
// Initializes all members with their default constructors.
Module::Module() : moduleName(), booleanVariables(), integerVariables(), booleanVariablesToIndexMap(),
integerVariablesToIndexMap(), commands() {
integerVariablesToIndexMap(), commands(), actionsToCommandIndexMap() {
// Nothing to do here.
}
@ -29,8 +29,14 @@ Module::Module(std::string moduleName, std::vector<storm::ir::BooleanVariable> b
std::vector<storm::ir::Command> commands)
: moduleName(moduleName), booleanVariables(booleanVariables), integerVariables(integerVariables),
booleanVariablesToIndexMap(booleanVariableToIndexMap),
integerVariablesToIndexMap(integerVariableToIndexMap), commands(commands) {
// Nothing to do here.
integerVariablesToIndexMap(integerVariableToIndexMap), commands(commands), actionsToCommandIndexMap() {
// Build actionsToCommandIndexMap
for (unsigned int id = 0; id < this->commands.size(); id++) {
std::string action = this->commands[id].getActionName();
if (action != "") {
this->actionsToCommandIndexMap[action]->insert(id);
}
}
}
// Return the number of boolean variables.
@ -100,6 +106,16 @@ std::string Module::toString() const {
return result.str();
}
// Return Commands with given action.
std::shared_ptr<std::set<uint_fast64_t>> const Module::getCommandsByAction(std::string const& action) const {
auto res = this->actionsToCommandIndexMap.find(action);
if (res == this->actionsToCommandIndexMap.end()) {
return std::shared_ptr<std::set<uint_fast64_t>>(new std::set<uint_fast64_t>());
} else {
return res->second;
}
}
} // namespace ir
} // namespace storm

13
src/ir/Module.h

@ -13,8 +13,10 @@
#include "Command.h"
#include <map>
#include <set>
#include <string>
#include <vector>
#include <memory>
namespace storm {
@ -98,6 +100,14 @@ public:
* @returns a string representation of this variable.
*/
std::string toString() const;
/*!
* Retrieves the indices of all Commands within this module that are labelled
* by the given action.
* @param action Name of the action
* @returns Indices of all matching Commands.
*/
std::shared_ptr<std::set<uint_fast64_t>> const getCommandsByAction(std::string const& action) const;
private:
// The name of the module.
@ -117,6 +127,9 @@ private:
// The commands associated with the module.
std::vector<storm::ir::Command> commands;
// A map of actions to the set of commands labelled with this action.
std::map<std::string, std::shared_ptr<std::set<uint_fast64_t>>> actionsToCommandIndexMap;
};
} // namespace ir

Loading…
Cancel
Save