From 81b4fa6b9bd74202673065c6d32d92419821bce2 Mon Sep 17 00:00:00 2001 From: dehnert Date: Tue, 17 May 2016 13:08:13 +0200 Subject: [PATCH] added composition specification to PRISM program Former-commit-id: 2c032f5d7e55dfdf00f62188f84989f4e6244064 --- src/builder/DdPrismModelBuilder.cpp | 2 +- src/parser/PrismParser.cpp | 2 +- .../GmmxxMinMaxLinearEquationSolver.cpp | 4 +- src/storage/prism/Assignment.cpp | 6 --- src/storage/prism/Assignment.h | 2 +- src/storage/prism/Composition.cpp | 12 +++++ src/storage/prism/Composition.h | 23 ++++++++++ src/storage/prism/CompositionVisitor.h | 22 +++++++++ src/storage/prism/ModuleComposition.cpp | 14 ++++++ src/storage/prism/ModuleComposition.h | 24 ++++++++++ src/storage/prism/ParallelComposition.cpp | 17 +++++++ src/storage/prism/ParallelComposition.h | 26 +++++++++++ src/storage/prism/Program.cpp | 42 ++++++++++++----- src/storage/prism/Program.h | 45 +++++++++++++++---- src/storage/prism/RenamingComposition.cpp | 28 ++++++++++++ src/storage/prism/RenamingComposition.h | 28 ++++++++++++ 16 files changed, 267 insertions(+), 30 deletions(-) create mode 100644 src/storage/prism/Composition.cpp create mode 100644 src/storage/prism/Composition.h create mode 100644 src/storage/prism/CompositionVisitor.h create mode 100644 src/storage/prism/ModuleComposition.cpp create mode 100644 src/storage/prism/ModuleComposition.h create mode 100644 src/storage/prism/ParallelComposition.cpp create mode 100644 src/storage/prism/ParallelComposition.h create mode 100644 src/storage/prism/RenamingComposition.cpp create mode 100644 src/storage/prism/RenamingComposition.h diff --git a/src/builder/DdPrismModelBuilder.cpp b/src/builder/DdPrismModelBuilder.cpp index e265f70c5..6bf7284b2 100644 --- a/src/builder/DdPrismModelBuilder.cpp +++ b/src/builder/DdPrismModelBuilder.cpp @@ -799,7 +799,7 @@ namespace storm { STORM_LOG_TRACE("Translating (first) module '" << generationInfo.program.getModule(0).getName() << "'."); ModuleDecisionDiagram system = createModuleDecisionDiagram(generationInfo, generationInfo.program.getModule(0), synchronizingActionToOffsetMap); - // No translate module by module and combine it with the system created thus far. + // Now translate module by module and combine it with the system created thus far. for (uint_fast64_t i = 1; i < generationInfo.program.getNumberOfModules(); ++i) { storm::prism::Module const& currentModule = generationInfo.program.getModule(i); STORM_LOG_TRACE("Translating module '" << currentModule.getName() << "'."); diff --git a/src/parser/PrismParser.cpp b/src/parser/PrismParser.cpp index b2a153f99..9944d8abd 100644 --- a/src/parser/PrismParser.cpp +++ b/src/parser/PrismParser.cpp @@ -570,7 +570,7 @@ namespace storm { } storm::prism::Program PrismParser::createProgram(GlobalProgramInformation const& globalProgramInformation) const { - return storm::prism::Program(manager, globalProgramInformation.modelType, globalProgramInformation.constants, globalProgramInformation.globalBooleanVariables, globalProgramInformation.globalIntegerVariables, globalProgramInformation.formulas, globalProgramInformation.modules, globalProgramInformation.actionIndices, globalProgramInformation.rewardModels, this->secondRun && !globalProgramInformation.hasInitialConstruct, globalProgramInformation.initialConstruct, globalProgramInformation.labels, this->getFilename(), 1, this->secondRun); + return storm::prism::Program(manager, globalProgramInformation.modelType, globalProgramInformation.constants, globalProgramInformation.globalBooleanVariables, globalProgramInformation.globalIntegerVariables, globalProgramInformation.formulas, globalProgramInformation.modules, globalProgramInformation.actionIndices, globalProgramInformation.rewardModels, globalProgramInformation.labels, secondRun && !globalProgramInformation.hasInitialConstruct ? boost::none : boost::optional(storm::prism::InitialConstruct(manager->boolean(false))), boost::none, this->getFilename(), 1, this->secondRun); } } // namespace parser } // namespace storm diff --git a/src/solver/GmmxxMinMaxLinearEquationSolver.cpp b/src/solver/GmmxxMinMaxLinearEquationSolver.cpp index eed6fb258..922d162a2 100644 --- a/src/solver/GmmxxMinMaxLinearEquationSolver.cpp +++ b/src/solver/GmmxxMinMaxLinearEquationSolver.cpp @@ -51,7 +51,7 @@ namespace storm { // Proceed with the iterations as long as the method did not converge or reach the user-specified maximum number // of iterations. - while (!converged && iterations < this->maximalNumberOfIterations && !(this->hasCustomTerminationCondition() && this->getTerminationCondition().terminateNow(*currentX))) { + while (!converged && iterations < this->maximalNumberOfIterations) { // Compute x' = A*x + b. gmm::mult(*gmmxxMatrix, *currentX, *multiplyResult); gmm::add(b, *multiplyResult); @@ -60,7 +60,7 @@ namespace storm { storm::utility::vector::reduceVectorMinOrMax(dir, *multiplyResult, *newX, rowGroupIndices); // Determine whether the method converged. - converged = storm::utility::vector::equalModuloPrecision(*currentX, *newX, this->precision, this->relative); + converged = storm::utility::vector::equalModuloPrecision(*currentX, *newX, this->precision, this->relative) || (this->hasCustomTerminationCondition() && this->getTerminationCondition().terminateNow(*newX)); // Update environment variables. std::swap(currentX, newX); diff --git a/src/storage/prism/Assignment.cpp b/src/storage/prism/Assignment.cpp index a6c8b4456..40b37d4a9 100644 --- a/src/storage/prism/Assignment.cpp +++ b/src/storage/prism/Assignment.cpp @@ -26,12 +26,6 @@ namespace storm { bool Assignment::isIdentity() const { if(this->expression.isVariable()) { assert(this->expression.getVariables().size() == 1); - //if( variable == *(this->expression.getVariables().begin())) { - // std::cout << variable.getName() << " == " << (this->expression.getVariables().begin())->getName() << std::endl; - //} - //else { - // std::cout << "********" << variable.getName() << " != " << (this->expression.getVariables().begin())->getName() << std::endl; - //} return variable == *(this->expression.getVariables().begin()); } return false; diff --git a/src/storage/prism/Assignment.h b/src/storage/prism/Assignment.h index 1c45a2b78..c3318346a 100644 --- a/src/storage/prism/Assignment.h +++ b/src/storage/prism/Assignment.h @@ -61,7 +61,7 @@ namespace storm { Assignment substitute(std::map const& substitution) const; /*! - * Checks whether the assignment is an identity (lhs equals rhs) + * Checks whether the assignment is an identity (lhs equals rhs) * * @return true iff the assignment is of the form a' = a. */ diff --git a/src/storage/prism/Composition.cpp b/src/storage/prism/Composition.cpp new file mode 100644 index 000000000..0e9d688db --- /dev/null +++ b/src/storage/prism/Composition.cpp @@ -0,0 +1,12 @@ +#include "src/storage/prism/Composition.h" + +namespace storm { + namespace prism { + + std::ostream& operator<<(std::ostream& stream, Composition const& composition) { + composition.writeToStream(stream); + return stream; + } + + } +} diff --git a/src/storage/prism/Composition.h b/src/storage/prism/Composition.h new file mode 100644 index 000000000..6fd3a6a63 --- /dev/null +++ b/src/storage/prism/Composition.h @@ -0,0 +1,23 @@ +#ifndef STORM_STORAGE_PRISM_COMPOSITION_H_ +#define STORM_STORAGE_PRISM_COMPOSITION_H_ + +#include + +namespace storm { + namespace prism { + class Composition { + public: + Composition() = default; + + friend std::ostream& operator<<(std::ostream& stream, Composition const& composition); + + protected: + virtual void writeToStream(std::ostream& stream) const = 0; + + private: + + }; + } +} + +#endif /* STORM_STORAGE_PRISM_COMPOSITION_H_ */ diff --git a/src/storage/prism/CompositionVisitor.h b/src/storage/prism/CompositionVisitor.h new file mode 100644 index 000000000..5d782d026 --- /dev/null +++ b/src/storage/prism/CompositionVisitor.h @@ -0,0 +1,22 @@ +#ifndef STORM_STORAGE_PRISM_COMPOSITIONVISITOR_H_ +#define STORM_STORAGE_PRISM_COMPOSITIONVISITOR_H_ + +#include + +namespace storm { + namespace prism { + + class ModuleComposition; + class RenamingComposition; + class ParallelComposition; + + class CompositionVisitor { + public: + virtual boost::any visit(ModuleComposition const& composition) = 0; + virtual boost::any visit(RenamingComposition const& composition) = 0; + virtual boost::any visit(ParallelComposition const& composition) = 0; + }; + } +} + +#endif /* STORM_STORAGE_PRISM_COMPOSITIONVISITOR_H_ */ \ No newline at end of file diff --git a/src/storage/prism/ModuleComposition.cpp b/src/storage/prism/ModuleComposition.cpp new file mode 100644 index 000000000..9b72e80f3 --- /dev/null +++ b/src/storage/prism/ModuleComposition.cpp @@ -0,0 +1,14 @@ +#include "src/storage/prism/ModuleComposition.h" + +namespace storm { + namespace prism { + + ModuleComposition::ModuleComposition(std::string const& moduleName) : moduleName(moduleName) { + // Intentionally left empty. + } + + void ModuleComposition::writeToStream(std::ostream& stream) const { + stream << moduleName; + } + } +} \ No newline at end of file diff --git a/src/storage/prism/ModuleComposition.h b/src/storage/prism/ModuleComposition.h new file mode 100644 index 000000000..9056f5617 --- /dev/null +++ b/src/storage/prism/ModuleComposition.h @@ -0,0 +1,24 @@ +#ifndef STORM_STORAGE_PRISM_MODULECOMPOSITION_H_ +#define STORM_STORAGE_PRISM_MODULECOMPOSITION_H_ + +#include + +#include "src/storage/prism/Composition.h" + +namespace storm { + namespace prism { + class ModuleComposition : Composition { + public: + ModuleComposition(std::string const& moduleName); + + protected: + virtual void writeToStream(std::ostream& stream) const override; + + private: + // The name of the module to compose. + std::string moduleName; + }; + } +} + +#endif /* STORM_STORAGE_PRISM_MODULECOMPOSITION_H_ */ diff --git a/src/storage/prism/ParallelComposition.cpp b/src/storage/prism/ParallelComposition.cpp new file mode 100644 index 000000000..633f2c42e --- /dev/null +++ b/src/storage/prism/ParallelComposition.cpp @@ -0,0 +1,17 @@ +#include "src/storage/prism/ParallelComposition.h" + +#include + +namespace storm { + namespace prism { + + ParallelComposition::ParallelComposition(std::shared_ptr const& left, std::set const& synchronizingActions, std::shared_ptr const& right) : left(left), synchronizingActions(synchronizingActions), right(right) { + // Intentionally left empty. + } + + void ParallelComposition::writeToStream(std::ostream& stream) const { + stream << "(" << *left << " |[" << boost::algorithm::join(synchronizingActions, ", ") << "]| " << *right << ")"; + } + + } +} \ No newline at end of file diff --git a/src/storage/prism/ParallelComposition.h b/src/storage/prism/ParallelComposition.h new file mode 100644 index 000000000..cc7b49fb9 --- /dev/null +++ b/src/storage/prism/ParallelComposition.h @@ -0,0 +1,26 @@ +#ifndef STORM_STORAGE_PRISM_PARALLELCOMPOSITION_H_ +#define STORM_STORAGE_PRISM_PARALLELCOMPOSITION_H_ + +#include +#include + +#include "src/storage/prism/Composition.h" + +namespace storm { + namespace prism { + class ParallelComposition : Composition { + public: + ParallelComposition(std::shared_ptr const& left, std::set const& synchronizingActions, std::shared_ptr const& right); + + protected: + virtual void writeToStream(std::ostream& stream) const override; + + private: + std::shared_ptr left; + std::set synchronizingActions; + std::shared_ptr right; + }; + } +} + +#endif /* STORM_STORAGE_PRISM_PARALLELCOMPOSITION_H_ */ diff --git a/src/storage/prism/Program.cpp b/src/storage/prism/Program.cpp index b94f288c0..b78b6e97a 100644 --- a/src/storage/prism/Program.cpp +++ b/src/storage/prism/Program.cpp @@ -17,13 +17,13 @@ namespace storm { namespace prism { - Program::Program(std::shared_ptr manager, ModelType modelType, std::vector const& constants, std::vector const& globalBooleanVariables, std::vector const& globalIntegerVariables, std::vector const& formulas, std::vector const& modules, std::map const& actionToIndexMap, std::vector const& rewardModels, bool fixInitialConstruct, storm::prism::InitialConstruct const& initialConstruct, std::vector