Browse Source

Added actionMap to Program, added set of actions to Module and Program.

tempestpy_adaptions
gereon 12 years ago
parent
commit
845af3f12e
  1. 12
      src/ir/Module.cpp
  2. 15
      src/ir/Module.h
  3. 27
      src/ir/Program.cpp
  4. 23
      src/ir/Program.h

12
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(), actionsToCommandIndexMap() {
integerVariablesToIndexMap(), commands(), actions(), actionsToCommandIndexMap() {
// Nothing to do here.
}
@ -29,12 +29,13 @@ 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), actionsToCommandIndexMap() {
integerVariablesToIndexMap(integerVariableToIndexMap), commands(commands), actions(), 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);
this->actions.insert(action);
}
}
}
@ -106,7 +107,12 @@ std::string Module::toString() const {
return result.str();
}
// Return Commands with given action.
// Return set of actions.
std::set<std::string> const& Module::getActions() const {
return this->actions;
}
// 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()) {

15
src/ir/Module.h

@ -102,10 +102,16 @@ public:
std::string toString() const;
/*!
* Retrieves the indices of all Commands within this module that are labelled
* Retrieves the set of actions present in this module.
* @returns the set of actions present in this module.
*/
std::set<std::string> const& getActions() 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.
* @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;
@ -128,6 +134,9 @@ private:
// The commands associated with the module.
std::vector<storm::ir::Command> commands;
// The set of actions present in this module.
std::set<std::string> actions;
// 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;
};

27
src/ir/Program.cpp

@ -14,14 +14,20 @@ namespace storm {
namespace ir {
// Initializes all members with their default constructors.
Program::Program() : modelType(UNDEFINED), booleanUndefinedConstantExpressions(), integerUndefinedConstantExpressions(), doubleUndefinedConstantExpressions(), modules(), rewards() {
Program::Program() : modelType(UNDEFINED), booleanUndefinedConstantExpressions(), integerUndefinedConstantExpressions(), doubleUndefinedConstantExpressions(), modules(), rewards(), actions(), actionsToModuleIndexMap() {
// Nothing to do here.
}
// Initializes all members according to the given values.
Program::Program(ModelType modelType, std::map<std::string, std::shared_ptr<storm::ir::expressions::BooleanConstantExpression>> booleanUndefinedConstantExpressions, std::map<std::string, std::shared_ptr<storm::ir::expressions::IntegerConstantExpression>> integerUndefinedConstantExpressions, std::map<std::string, std::shared_ptr<storm::ir::expressions::DoubleConstantExpression>> doubleUndefinedConstantExpressions, std::vector<storm::ir::Module> modules, std::map<std::string, storm::ir::RewardModel> rewards, std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels)
: modelType(modelType), booleanUndefinedConstantExpressions(booleanUndefinedConstantExpressions), integerUndefinedConstantExpressions(integerUndefinedConstantExpressions), doubleUndefinedConstantExpressions(doubleUndefinedConstantExpressions), modules(modules), rewards(rewards), labels(labels) {
// Nothing to do here.
: modelType(modelType), booleanUndefinedConstantExpressions(booleanUndefinedConstantExpressions), integerUndefinedConstantExpressions(integerUndefinedConstantExpressions), doubleUndefinedConstantExpressions(doubleUndefinedConstantExpressions), modules(modules), rewards(rewards), labels(labels), actionsToModuleIndexMap() {
// Build actionsToModuleIndexMap
for (unsigned int id = 0; id < this->modules.size(); id++) {
for (auto action : this->modules[id].getActions()) {
this->actionsToModuleIndexMap[action]->insert(id);
this->actions.insert(action);
}
}
}
Program::ModelType Program::getModelType() const {
@ -74,6 +80,21 @@ storm::ir::Module const& Program::getModule(uint_fast64_t index) const {
return this->modules[index];
}
// Return set of actions.
std::set<std::string> const& Program::getActions() const {
return this->actions;
}
// Return modules with given action.
std::shared_ptr<std::set<uint_fast64_t>> const Program::getModulesByAction(std::string const& action) const {
auto res = this->actionsToModuleIndexMap.find(action);
if (res == this->actionsToModuleIndexMap.end()) {
return std::shared_ptr<std::set<uint_fast64_t>>(new std::set<uint_fast64_t>());
} else {
return res->second;
}
}
} // namespace ir

23
src/ir/Program.h

@ -18,6 +18,7 @@
#include <map>
#include <vector>
#include <memory>
#include <set>
namespace storm {
@ -78,6 +79,20 @@ public:
*/
std::string toString() const;
/*!
* Retrieves the set of actions present in this module.
* @returns the set of actions present in this module.
*/
std::set<std::string> const& getActions() const;
/*!
* Retrieved the indices of all Modules within this program that contain
* commands that are labelled with the given action.
* @param action Name of the action.
* @returns Indices of all matching modules.
*/
std::shared_ptr<std::set<uint_fast64_t>> const getModulesByAction(std::string const& action) const;
private:
// The type of the model.
ModelType modelType;
@ -88,7 +103,7 @@ private:
// A map of undefined integer constants to their expressions nodes.
std::map<std::string, std::shared_ptr<storm::ir::expressions::IntegerConstantExpression>> integerUndefinedConstantExpressions;
// A mpa of undefined double constants to their expressions nodes.
// A map of undefined double constants to their expressions nodes.
std::map<std::string, std::shared_ptr<storm::ir::expressions::DoubleConstantExpression>> doubleUndefinedConstantExpressions;
// The modules associated with the program.
@ -99,6 +114,12 @@ private:
// The labels that are defined for this model.
std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> labels;
// The set of actions present in this program.
std::set<std::string> actions;
// A map of actions to the set of modules containing commands labelled with this action.
std::map<std::string, std::shared_ptr<std::set<uint_fast64_t>>> actionsToModuleIndexMap;
};
} // namespace ir

Loading…
Cancel
Save