Browse Source
WIP (HOA-path) logic: HOAPathFormula
WIP (HOA-path) logic: HOAPathFormula
Note: syntax of the HOA path formula will change! We have added checks for boundedGloballyFormulae hence the conflicts Conflicts: src/storm/logic/CloneVisitor.cpp src/storm/logic/Formula.cpp src/storm/logic/Formula.h src/storm/logic/FragmentSpecification.cpp src/storm/logic/FragmentSpecification.h src/storm/logic/LiftableTransitionRewardsVisitor.cpp src/storm/storage/jani/JSONExporter.cpptempestpy_adaptions
Joachim Klein
4 years ago
committed by
Stefan Pranger
21 changed files with 262 additions and 38 deletions
-
8src/storm/logic/CloneVisitor.cpp
-
1src/storm/logic/CloneVisitor.h
-
12src/storm/logic/Formula.cpp
-
79src/storm/logic/Formula.h
-
8src/storm/logic/FormulaInformationVisitor.cpp
-
1src/storm/logic/FormulaInformationVisitor.h
-
1src/storm/logic/FormulaVisitor.h
-
1src/storm/logic/Formulas.h
-
1src/storm/logic/FormulasForwardDeclarations.h
-
10src/storm/logic/FragmentChecker.cpp
-
1src/storm/logic/FragmentChecker.h
-
10src/storm/logic/FragmentSpecification.cpp
-
4src/storm/logic/FragmentSpecification.h
-
90src/storm/logic/HOAPathFormula.cpp
-
54src/storm/logic/HOAPathFormula.h
-
9src/storm/logic/LiftableTransitionRewardsVisitor.cpp
-
1src/storm/logic/LiftableTransitionRewardsVisitor.h
-
3src/storm/logic/ToExpressionVisitor.cpp
-
1src/storm/logic/ToExpressionVisitor.h
-
4src/storm/storage/jani/JSONExporter.cpp
-
1src/storm/storage/jani/JSONExporter.h
@ -0,0 +1,90 @@ |
|||||
|
#include "storm/logic/HOAPathFormula.h"
|
||||
|
#include "storm/logic/FormulaVisitor.h"
|
||||
|
|
||||
|
#include "storm/utility/macros.h"
|
||||
|
#include "storm/automata/DeterministicAutomaton.h"
|
||||
|
#include "storm/exceptions/ExpressionEvaluationException.h"
|
||||
|
#include "storm/exceptions/IllegalArgumentException.h"
|
||||
|
#include "storm/exceptions/InvalidPropertyException.h"
|
||||
|
#include "storm/exceptions/FileIoException.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace logic { |
||||
|
HOAPathFormula::HOAPathFormula(const std::string& automatonFile, FormulaContext context) : automatonFile(automatonFile), context(context) { |
||||
|
STORM_LOG_THROW(context == FormulaContext::Probability, storm::exceptions::InvalidPropertyException, "Invalid context for formula."); |
||||
|
} |
||||
|
|
||||
|
FormulaContext const& HOAPathFormula::getContext() const { |
||||
|
return context; |
||||
|
} |
||||
|
|
||||
|
const std::string& HOAPathFormula::getAutomatonFile() const { |
||||
|
return automatonFile; |
||||
|
} |
||||
|
|
||||
|
const HOAPathFormula::ap_to_formula_map &HOAPathFormula::getAPMapping() const { |
||||
|
return apToFormulaMap; |
||||
|
} |
||||
|
|
||||
|
void HOAPathFormula::addAPMapping(const std::string& ap, const std::shared_ptr<Formula const>& formula) { |
||||
|
STORM_LOG_THROW(apToFormulaMap.find(ap) == apToFormulaMap.end(), storm::exceptions::IllegalArgumentException, "HOA path formula: Mapping for atomic proposition \"" + ap + "\" already exists."); |
||||
|
apToFormulaMap[ap] = formula; |
||||
|
} |
||||
|
|
||||
|
bool HOAPathFormula::isProbabilityPathFormula() const { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool HOAPathFormula::isHOAPathFormula() const { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool HOAPathFormula::hasQuantitativeResult() const { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
boost::any HOAPathFormula::accept(FormulaVisitor const& visitor, boost::any const& data) const { |
||||
|
return visitor.visit(*this, data); |
||||
|
} |
||||
|
|
||||
|
void HOAPathFormula::gatherAtomicExpressionFormulas(std::vector<std::shared_ptr<AtomicExpressionFormula const>>& atomicExpressionFormulas) const { |
||||
|
for (auto& mapped : getAPMapping()) { |
||||
|
mapped.second->gatherAtomicExpressionFormulas(atomicExpressionFormulas); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void HOAPathFormula::gatherAtomicLabelFormulas(std::vector<std::shared_ptr<AtomicLabelFormula const>>& atomicLabelFormulas) const { |
||||
|
for (auto& mapped : getAPMapping()) { |
||||
|
mapped.second->gatherAtomicLabelFormulas(atomicLabelFormulas); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void HOAPathFormula::gatherReferencedRewardModels(std::set<std::string>& referencedRewardModels) const { |
||||
|
for (auto& mapped : getAPMapping()) { |
||||
|
mapped.second->gatherReferencedRewardModels(referencedRewardModels); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
storm::automata::DeterministicAutomaton::ptr HOAPathFormula::readAutomaton() const { |
||||
|
std::ifstream in(automatonFile); |
||||
|
STORM_LOG_THROW(in.good(), storm::exceptions::FileIoException, "Can not open '" << automatonFile << "' for reading."); |
||||
|
storm::automata::DeterministicAutomaton::ptr automaton = storm::automata::DeterministicAutomaton::parse(in); |
||||
|
for (auto& ap : automaton->getAPSet().getAPs()) { |
||||
|
STORM_LOG_THROW(apToFormulaMap.find(ap) != apToFormulaMap.end(), storm::exceptions::ExpressionEvaluationException, "For '" << automatonFile << "' HOA automaton, expression for atomic proposition '" << ap << "' is missing."); |
||||
|
} |
||||
|
return automaton; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
std::ostream& HOAPathFormula::writeToStream(std::ostream& out) const { |
||||
|
out << "HOA: { "; |
||||
|
out << "\"" << automatonFile << "\""; |
||||
|
for (auto& mapping : apToFormulaMap) { |
||||
|
out << ", \"" << mapping.first << "\" -> "; |
||||
|
mapping.second->writeToStream(out); |
||||
|
} |
||||
|
out << " }"; |
||||
|
return out; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,54 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "storm/logic/PathFormula.h" |
||||
|
#include "storm/logic/FormulaContext.h" |
||||
|
|
||||
|
#include <map> |
||||
|
#include <memory> |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace automata { |
||||
|
// fwd |
||||
|
class DeterministicAutomaton; |
||||
|
} |
||||
|
|
||||
|
namespace logic { |
||||
|
class HOAPathFormula : public PathFormula { |
||||
|
public: |
||||
|
typedef std::map<std::string, std::shared_ptr<Formula const>> ap_to_formula_map; |
||||
|
|
||||
|
HOAPathFormula(const std::string& automatonFile, FormulaContext context = FormulaContext::Probability); |
||||
|
|
||||
|
virtual ~HOAPathFormula() { |
||||
|
// Intentionally left empty. |
||||
|
} |
||||
|
|
||||
|
FormulaContext const& getContext() const; |
||||
|
const std::string& getAutomatonFile() const; |
||||
|
const ap_to_formula_map &getAPMapping() const; |
||||
|
|
||||
|
void addAPMapping(const std::string& ap, const std::shared_ptr<Formula const>& formula); |
||||
|
|
||||
|
virtual bool isHOAPathFormula() const override; |
||||
|
virtual bool isProbabilityPathFormula() const override; |
||||
|
virtual bool hasQuantitativeResult() const override; |
||||
|
|
||||
|
virtual boost::any accept(FormulaVisitor const& visitor, boost::any const& data) const override; |
||||
|
|
||||
|
virtual void gatherAtomicExpressionFormulas(std::vector<std::shared_ptr<AtomicExpressionFormula const>>& atomicExpressionFormulas) const override; |
||||
|
virtual void gatherAtomicLabelFormulas(std::vector<std::shared_ptr<AtomicLabelFormula const>>& atomicLabelFormulas) const override; |
||||
|
virtual void gatherReferencedRewardModels(std::set<std::string>& referencedRewardModels) const override; |
||||
|
|
||||
|
virtual std::ostream& writeToStream(std::ostream& out) const override; |
||||
|
|
||||
|
std::shared_ptr<storm::automata::DeterministicAutomaton> readAutomaton() const; |
||||
|
|
||||
|
private: |
||||
|
std::string automatonFile; |
||||
|
ap_to_formula_map apToFormulaMap; |
||||
|
|
||||
|
FormulaContext context; |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue