Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
HOAPathFormula.cpp
Go to the documentation of this file.
2
3#include <boost/any.hpp>
4#include <ostream>
5
10#include "storm/io/file.h"
13
14namespace storm {
15namespace logic {
16HOAPathFormula::HOAPathFormula(const std::string& automatonFile, FormulaContext context) : automatonFile(automatonFile), context(context) {
17 STORM_LOG_THROW(context == FormulaContext::Probability, storm::exceptions::InvalidPropertyException, "Invalid context for formula.");
18}
19
21 return context;
22}
23
24const std::string& HOAPathFormula::getAutomatonFile() const {
25 return automatonFile;
26}
27
29 return apToFormulaMap;
30}
31
32void HOAPathFormula::addAPMapping(const std::string& ap, const std::shared_ptr<Formula const>& formula) {
33 STORM_LOG_THROW(apToFormulaMap.find(ap) == apToFormulaMap.end(), storm::exceptions::IllegalArgumentException,
34 "HOA path formula: Mapping for atomic proposition \"" + ap + "\" already exists.");
35 apToFormulaMap[ap] = formula;
36}
37
39 return true;
40}
41
43 return true;
44}
45
47 return true;
48}
49
51 return false;
52}
53
54boost::any HOAPathFormula::accept(FormulaVisitor const& visitor, boost::any const& data) const {
55 return visitor.visit(*this, data);
56}
57
58void HOAPathFormula::gatherAtomicExpressionFormulas(std::vector<std::shared_ptr<AtomicExpressionFormula const>>& atomicExpressionFormulas) const {
59 for (auto& mapped : getAPMapping()) {
60 mapped.second->gatherAtomicExpressionFormulas(atomicExpressionFormulas);
61 }
62}
63
64void HOAPathFormula::gatherAtomicLabelFormulas(std::vector<std::shared_ptr<AtomicLabelFormula const>>& atomicLabelFormulas) const {
65 for (auto& mapped : getAPMapping()) {
66 mapped.second->gatherAtomicLabelFormulas(atomicLabelFormulas);
67 }
68}
69
70void HOAPathFormula::gatherReferencedRewardModels(std::set<std::string>& referencedRewardModels) const {
71 for (auto& mapped : getAPMapping()) {
72 mapped.second->gatherReferencedRewardModels(referencedRewardModels);
73 }
74}
75
77 std::ifstream in;
78 storm::io::openFile(automatonFile, in);
81 for (auto& ap : automaton->getAPSet().getAPs()) {
82 STORM_LOG_THROW(apToFormulaMap.find(ap) != apToFormulaMap.end(), storm::exceptions::ExpressionEvaluationException,
83 "For '" << automatonFile << "' HOA automaton, expression for atomic proposition '" << ap << "' is missing.");
84 }
85 return automaton;
86}
87
88std::ostream& HOAPathFormula::writeToStream(std::ostream& out, bool /* allowParentheses */) const {
89 // No parentheses necessary
90 out << "HOA: { ";
91 out << "\"" << automatonFile << "\"";
92 for (auto& mapping : apToFormulaMap) {
93 out << ", \"" << mapping.first << "\" -> ";
94 mapping.second->writeToStream(out);
95 }
96 out << " }";
97 return out;
98}
99} // namespace logic
100} // namespace storm
std::shared_ptr< DeterministicAutomaton > ptr
static DeterministicAutomaton::ptr parse(std::istream &in)
virtual boost::any visit(AtomicExpressionFormula const &f, boost::any const &data) const =0
virtual bool hasQuantitativeResult() const override
virtual std::ostream & writeToStream(std::ostream &out, bool allowParentheses=false) const override
Writes the forumla to the given output stream.
virtual boost::any accept(FormulaVisitor const &visitor, boost::any const &data) const override
virtual bool hasQualitativeResult() const override
virtual bool isHOAPathFormula() const override
virtual bool isProbabilityPathFormula() const override
virtual void gatherReferencedRewardModels(std::set< std::string > &referencedRewardModels) const override
const ap_to_formula_map & getAPMapping() const
virtual void gatherAtomicLabelFormulas(std::vector< std::shared_ptr< AtomicLabelFormula const > > &atomicLabelFormulas) const override
virtual void gatherAtomicExpressionFormulas(std::vector< std::shared_ptr< AtomicExpressionFormula const > > &atomicExpressionFormulas) const override
const std::string & getAutomatonFile() const
std::shared_ptr< storm::automata::DeterministicAutomaton > readAutomaton() const
void addAPMapping(const std::string &ap, const std::shared_ptr< Formula const > &formula)
FormulaContext const & getContext() const
HOAPathFormula(const std::string &automatonFile, FormulaContext context=FormulaContext::Probability)
std::map< std::string, std::shared_ptr< Formula const > > ap_to_formula_map
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
LabParser.cpp.
Definition cli.cpp:18