Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PrismChoiceOrigins.cpp
Go to the documentation of this file.
2
4
7
10
11namespace storm {
12namespace storage {
13namespace sparse {
14
15PrismChoiceOrigins::PrismChoiceOrigins(std::shared_ptr<storm::prism::Program const> const& prismProgram,
16 std::vector<uint_fast64_t> const& indexToIdentifierMapping, std::vector<CommandSet> const& identifierToCommandSetMapping)
17 : ChoiceOrigins(indexToIdentifierMapping), program(prismProgram), identifierToCommandSet(identifierToCommandSetMapping) {
18 STORM_LOG_THROW(identifierToCommandSet[this->getIdentifierForChoicesWithNoOrigin()].empty(), storm::exceptions::InvalidArgumentException,
19 "The given command set for the choices without origin is non-empty");
20}
21
22PrismChoiceOrigins::PrismChoiceOrigins(std::shared_ptr<storm::prism::Program const> const& prismProgram, std::vector<uint_fast64_t>&& indexToIdentifierMapping,
23 std::vector<CommandSet>&& identifierToCommandSetMapping)
24 : ChoiceOrigins(std::move(indexToIdentifierMapping)), program(prismProgram), identifierToCommandSet(std::move(identifierToCommandSetMapping)) {
25 STORM_LOG_THROW(identifierToCommandSet[this->getIdentifierForChoicesWithNoOrigin()].empty(), storm::exceptions::InvalidArgumentException,
26 "The given command set for the choices without origin is non-empty");
27}
28
30 return true;
31}
32
34 return identifierToCommandSet.size();
35}
36
40
42 return identifierToCommandSet[this->getIdentifier(choiceIndex)];
43}
44
45std::shared_ptr<ChoiceOrigins> PrismChoiceOrigins::cloneWithNewIndexToIdentifierMapping(std::vector<uint_fast64_t>&& indexToIdentifierMapping) const {
46 auto result = std::make_shared<PrismChoiceOrigins>(this->program, std::move(indexToIdentifierMapping), std::move(this->identifierToCommandSet));
47 result->identifierToInfo = this->identifierToInfo;
48 return result;
49}
50
52 this->identifierToInfo.clear();
53 this->identifierToInfo.reserve(this->getNumberOfIdentifiers());
54 for (CommandSet const& set : identifierToCommandSet) {
55 // Get a string representation of this command set.
56 std::stringstream setName;
57 if (set.empty()) {
58 setName << "No origin";
59 } else {
60 // process the first command in the set
61 auto commandIndexIt = set.begin();
62 auto moduleCommandPair = program->getModuleCommandIndexByGlobalCommandIndex(*commandIndexIt);
63 storm::prism::Module const& firstModule = program->getModule(moduleCommandPair.first);
64 storm::prism::Command const& firstCommand = firstModule.getCommand(moduleCommandPair.second);
65
66 std::string actionName = firstCommand.getActionName();
67 setName << actionName;
68
69 // If the commands are labeled, it is clear which modules induced the current choice.
70 // In this case, we only need to print more information if there are multiple commands in a module with the same label.
71 bool setNameNeedsAllModuleNames = !firstCommand.isLabeled();
72 bool actionNameIsUniqueInModule = firstCommand.isLabeled() && firstModule.getCommandIndicesByActionIndex(firstCommand.getActionIndex()).size() == 1;
73
74 bool setNameHasModuleDetails = false;
75 if (!actionNameIsUniqueInModule || setNameNeedsAllModuleNames) {
76 setNameHasModuleDetails = true;
77 if (!actionName.empty()) {
78 setName << " ";
79 }
80 setName << "(" << firstModule.getName();
81 if (!actionNameIsUniqueInModule) {
82 setName << ": " << firstCommand;
83 }
84 }
85
86 // now process the remaining commands
87 for (++commandIndexIt; commandIndexIt != set.end(); ++commandIndexIt) {
88 moduleCommandPair = program->getModuleCommandIndexByGlobalCommandIndex(*commandIndexIt);
89 storm::prism::Module const& module = program->getModule(moduleCommandPair.first);
90 storm::prism::Command const& command = module.getCommand(moduleCommandPair.second);
91 STORM_LOG_THROW(command.getActionName() == actionName, storm::exceptions::UnexpectedException, "Inconsistent action names for choice origin");
92
93 actionNameIsUniqueInModule = firstCommand.isLabeled() && module.getCommandIndicesByActionIndex(command.getActionIndex()).size() == 1;
94 if (!actionNameIsUniqueInModule || setNameNeedsAllModuleNames) {
95 if (setNameHasModuleDetails) {
96 setName << " || ";
97 } else {
98 setNameHasModuleDetails = true;
99 if (!actionName.empty()) {
100 setName << " ";
101 }
102 setName << "(";
103 }
104 setName << module.getName();
105 if (!actionNameIsUniqueInModule) {
106 setName << ": " << command;
107 }
108 }
109 }
110 if (setNameHasModuleDetails) {
111 setName << ")";
112 }
113 }
114 this->identifierToInfo.push_back(setName.str());
115 }
116 STORM_LOG_DEBUG("Generated the following names for the choice origins: " << storm::utility::vector::toString(this->identifierToInfo));
117 STORM_LOG_ASSERT(storm::utility::vector::isUnique(this->identifierToInfo), "The generated names for the prism choice origins are not unique.");
118}
119
121 this->identifierToJson.clear();
122 this->identifierToJson.reserve(this->getNumberOfIdentifiers());
123 for (CommandSet const& set : identifierToCommandSet) {
124 // Get a string representation of this command set.
125 Json setJson;
126 if (set.empty()) {
127 setJson = "No origin";
128 } else {
129 bool first = true;
130 std::vector<Json> commandsJson;
131 for (auto const& commandIndex : set) {
132 Json commandJson;
133 auto moduleCommandPair = program->getModuleCommandIndexByGlobalCommandIndex(commandIndex);
134 storm::prism::Module const& module = program->getModule(moduleCommandPair.first);
135 storm::prism::Command const& command = module.getCommand(moduleCommandPair.second);
136 if (first) {
137 setJson["action-label"] = command.getActionName();
138 first = false;
139 }
140 commandJson["module"] = module.getName();
141 commandJson["guard"] = command.getGuardExpression().toString();
142 std::vector<Json> updatesJson;
143 for (auto const& update : command.getUpdates()) {
144 Json updateJson;
145 updateJson["prob"] = update.getLikelihoodExpression().toString();
146 std::stringstream assignmentsString;
147 bool firstAssignment = true;
148 for (auto const& a : update.getAssignments()) {
149 if (firstAssignment) {
150 firstAssignment = false;
151 } else {
152 assignmentsString << " & ";
153 }
154 assignmentsString << a;
155 }
156 updateJson["result"] = assignmentsString.str();
157 updatesJson.push_back(std::move(updateJson));
158 }
159 commandJson["updates"] = updatesJson;
160 commandsJson.push_back(std::move(commandJson));
161 }
162 setJson["transitions"] = commandsJson;
163 }
164 this->identifierToJson.push_back(std::move(setJson));
165 }
166}
167
168std::size_t PrismChoiceOrigins::hash() const {
169 return 0;
170}
171} // namespace sparse
172} // namespace storage
173} // namespace storm
bool isLabeled() const
Retrieves whether the command possesses a synchronization label.
Definition Command.cpp:82
std::string const & getActionName() const
Retrieves the action name of this command.
Definition Command.cpp:31
uint_fast64_t getActionIndex() const
Retrieves the action index of this command.
Definition Command.cpp:19
storm::prism::Command const & getCommand(uint_fast64_t index) const
Retrieves a reference to the command with the given index.
Definition Module.cpp:129
std::set< uint_fast64_t > const & getCommandIndicesByActionIndex(uint_fast64_t actionIndex) const
Retrieves the indices of all commands within this module that are labelled by the given action.
Definition Module.cpp:179
std::string const & getName() const
Retrieves the name of the module.
Definition Module.cpp:141
This class represents the origin of the choices of a model in terms of the input model specification ...
uint_fast64_t getIdentifier(uint_fast64_t choiceIndex) const
std::vector< std::string > identifierToInfo
static uint_fast64_t getIdentifierForChoicesWithNoOrigin()
storm::json< storm::RationalNumber > Json
virtual void computeIdentifierInfos() const override
virtual uint_fast64_t getNumberOfIdentifiers() const override
PrismChoiceOrigins(std::shared_ptr< storm::prism::Program const > const &prismProgram, std::vector< uint_fast64_t > const &indexToIdentifierMapping, std::vector< CommandSet > const &identifierToCommandSetMapping)
Creates a new representation of the choice indices to their origin in the prism program.
virtual void computeIdentifierJson() const override
CommandSet const & getCommandSet(uint_fast64_t choiceIndex) const
virtual bool isPrismChoiceOrigins() const override
storm::prism::Program const & getProgram() const
virtual std::shared_ptr< ChoiceOrigins > cloneWithNewIndexToIdentifierMapping(std::vector< uint_fast64_t > &&indexToIdentifierMapping) const override
std::shared_ptr< storm::prism::Program const > program
storm::storage::FlatSet< uint_fast64_t > CommandSet
#define STORM_LOG_DEBUG(message)
Definition logging.h:23
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool isUnique(std::vector< T > const &v)
Returns true iff every element in the given vector is unique, i.e., there are no i,...
Definition vector.h:159
std::string toString(std::vector< ValueType > const &vector)
Output vector as string.
Definition vector.h:1298
LabParser.cpp.
Definition cli.cpp:18