1#include "storm-config.h"
27std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> buildParametricDtmc(std::string
const& programFile, std::string
const& formulaAsString) {
30 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
32 EXPECT_EQ(1ul, formulas.size());
41 std::vector<std::string> result;
42 for (
auto const& entry : constraints) {
43 result.push_back(entry.toString());
54 auto result = asStringsInDiscoveryOrder(constraints);
55 std::sort(result.begin(), result.end());
65 GTEST_SKIP() <<
"Z3 not available.";
76 auto dtmc = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/only_p.pm",
"P=? [F s=1]");
81 std::vector<storm::RationalFunctionVariable> variables(collector.
getVariables().begin(), collector.
getVariables().end());
82 ASSERT_EQ(1ul, variables.size());
83 EXPECT_EQ(
"p", variables.front().name());
92 std::vector<std::string> expectedWellformed{
"((-1 + p) <= 0)",
"(-(p) <= 0)"};
96 std::vector<std::string> expectedGraphPreserving{
"((1 - p) != 0)",
"(p != 0)"};
101 auto dtmc = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/only_rational_denominator.pm",
"P=? [F s=2]");
105 std::vector<storm::RationalFunctionVariable> variables(collector.
getVariables().begin(), collector.
getVariables().end());
106 ASSERT_EQ(2ul, variables.size());
111 std::vector<std::string> expectedWellformed{
"((((-1 + p) - q) < 0) ? ((-1 + p) <= 0) : ((1 - p) <= 0))",
"((((-1 + p) - q) < 0) ? (-(q) <= 0) : (q <= 0))",
112 "(((1 - p) + q) != 0)"};
115 std::vector<std::string> expectedGraphPreserving{
"((1 - p) != 0)",
"(q != 0)"};
120 auto dtmc = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/only_p.pm",
"P=? [F s=1]");
126 auto dtmcWithManyTransitions = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/parametric_die_2.pm",
"P=? [F s=7]");
131 std::set<std::string> distinct(constraints.begin(), constraints.end());
132 EXPECT_EQ(constraints.size(), distinct.size());
137 auto dtmc = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/only_p.pm",
"P=? [F s=1]");
149 std::vector<std::string> expectedWellformed{
"(-(p) <= 0)",
"((-1 + p) <= 0)"};
150 std::vector<std::string> expectedGraphPreserving{
"(p != 0)",
"((1 - p) != 0)"};
158 EXPECT_NE(expectedWellformed, sortedWellformed);
162 auto dtmc = buildParametricDtmc(STORM_TEST_RESOURCES_DIR
"/pdtmc/only_rational_denominator.pm",
"P=? [F s=2]");
168 for (
auto const& entry : dtmc->getTransitionMatrix()) {
170 resultValue = entry.getValue();
175 std::string temporaryFile =
"graph-conditions-export.txt";
178 std::ifstream input(temporaryFile);
179 ASSERT_TRUE(input.good());
180 std::stringstream buffer;
181 buffer << input.rdbuf();
182 std::string content = buffer.str();
186 EXPECT_NE(std::string::npos, content.find(
"$Parameters: p; q; \n"));
187 EXPECT_NE(std::string::npos, content.find(
"$Result: "));
188 EXPECT_NE(std::string::npos, content.find(
"$Well-formed Constraints: \n"));
189 EXPECT_NE(std::string::npos, content.find(
"$Graph-preserving Constraints: \n"));
193 std::vector<std::string> wellformedLines;
194 std::string currentSection;
195 std::istringstream contentStream(content);
197 while (std::getline(contentStream, line)) {
198 if (line ==
"$Well-formed Constraints: ") {
199 currentSection =
"wellformed";
200 }
else if (line ==
"$Graph-preserving Constraints: ") {
201 currentSection =
"graphPreserving";
202 }
else if (!line.empty() && currentSection ==
"wellformed") {
203 wellformedLines.push_back(line);
206 std::sort(wellformedLines.begin(), wellformedLines.end());
209 std::remove(temporaryFile.c_str());
TEST_F(GraphConditionsTest, PolynomialDenominators)
Class to collect constraints on parametric Markov chains.
ConstraintSet const & getGraphPreservingConstraints() const
Returns the set of graph-preserving constraints.
std::set< storm::RationalFunctionVariable > const & getVariables() const
Returns the set of variables in the model.
ConstraintSet const & getWellformedConstraints() const
Returns the set of wellformed-ness constraints.
std::vector< storm::expressions::Expression > ConstraintSet
The type of the collected constraints.
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > build()
Convert the program given at construction time to an abstract model.
This class represents a discrete-time Markov chain.
void checkValidity(Program::ValidityCheckLevel lvl=Program::ValidityCheckLevel::READYFORPROCESSING) const
Checks the validity of the program.
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
storm::prism::Program parseProgram(std::string const &filename, bool prismCompatibility, bool simplify)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
storm::builder::BuilderOptions NextStateGeneratorOptions
void closeFile(std::ofstream &stream)
Close the given file after writing.
void exportParametricResultToFile(std::optional< storm::RationalFunction > result, storm::OptionalRef< storm::analysis::ConstraintCollector const > const &constraintCollector, std::string const &path)
bool isConstant(ValueType const &)
carl::RationalFunction< Polynomial, true > RationalFunction
void clearRFVariablePool()
Clears the global pool of rational-function variables.