14template<
typename ParametricType>
19template<
typename ParametricType>
21 : lowerBoundaries(lowerBoundaries), upperBoundaries(upperBoundaries) {
25template<
typename ParametricType>
27 : lowerBoundaries(lowerBoundaries), upperBoundaries(upperBoundaries) {
31template<
typename ParametricType>
34 for (
auto const& variableWithLowerBoundary : this->lowerBoundaries) {
35 auto variableWithUpperBoundary = this->upperBoundaries.find(variableWithLowerBoundary.first);
36 STORM_LOG_THROW((variableWithUpperBoundary != upperBoundaries.end()), storm::exceptions::InvalidArgumentException,
37 "Could not create region. No upper boundary specified for Variable " << variableWithLowerBoundary.first);
38 STORM_LOG_THROW((variableWithLowerBoundary.second <= variableWithUpperBoundary->second), storm::exceptions::InvalidArgumentException,
39 "Could not create region. The lower boundary for " << variableWithLowerBoundary.first <<
" is larger then the upper boundary");
40 this->variables.insert(variableWithLowerBoundary.first);
41 this->sortedOnDifference.insert({variableWithLowerBoundary.second - variableWithUpperBoundary->second, variableWithLowerBoundary.first});
43 for (
auto const& variableWithBoundary : this->upperBoundaries) {
44 STORM_LOG_THROW((this->variables.find(variableWithBoundary.first) != this->variables.end()), storm::exceptions::InvalidArgumentException,
45 "Could not create region. No lower boundary specified for Variable " << variableWithBoundary.first);
47 this->splitThreshold = variables.size();
50template<
typename ParametricType>
52 return this->variables;
55template<
typename ParametricType>
58 return this->sortedOnDifference;
61template<
typename ParametricType>
63 auto const& result = lowerBoundaries.find(variable);
64 STORM_LOG_THROW(result != lowerBoundaries.end(), storm::exceptions::InvalidArgumentException,
65 "Tried to find a lower boundary for variable " << variable <<
" which is not specified by this region");
66 return (*result).second;
69template<
typename ParametricType>
71 for (
auto itr = lowerBoundaries.begin(); itr != lowerBoundaries.end(); ++itr) {
72 if (itr->first.name().compare(varName) == 0) {
77 "Tried to find a lower boundary for variableName " << varName <<
" which is not specified by this region");
80template<
typename ParametricType>
82 auto const& result = upperBoundaries.find(variable);
83 STORM_LOG_THROW(result != upperBoundaries.end(), storm::exceptions::InvalidArgumentException,
84 "Tried to find an upper boundary for variable " << variable <<
" which is not specified by this region");
85 return (*result).second;
88template<
typename ParametricType>
90 for (
auto itr = upperBoundaries.begin(); itr != upperBoundaries.end(); ++itr) {
91 if (itr->first.name().compare(varName) == 0) {
96 "Tried to find an upper boundary for variableName " << varName <<
" which is not specified by this region");
99template<
typename ParametricType>
101 return getUpperBoundary(variable) - getLowerBoundary(variable);
104template<
typename ParametricType>
106 return getUpperBoundary(varName) - getLowerBoundary(varName);
109template<
typename ParametricType>
111 return (getLowerBoundary(variable) + getUpperBoundary(variable)) / 2;
114template<
typename ParametricType>
116 return (getLowerBoundary(varName) + getUpperBoundary(varName)) / 2;
119template<
typename ParametricType>
121 return upperBoundaries;
124template<
typename ParametricType>
126 return lowerBoundaries;
129template<
typename ParametricType>
131 std::set<VariableType>
const& consideredVariables)
const {
132 std::size_t
const numOfVariables = consideredVariables.size();
133 STORM_LOG_THROW(numOfVariables <= std::numeric_limits<std::size_t>::digits, storm::exceptions::OutOfRangeException,
134 "Number of variables " << numOfVariables <<
" is too high.");
135 std::size_t
const numOfVertices = std::pow(2, numOfVariables);
136 std::vector<Valuation> resultingVector(numOfVertices);
138 for (uint_fast64_t vertexId = 0; vertexId < numOfVertices; ++vertexId) {
142 uint_fast64_t variableIndex = 0;
144 for (
auto variable : consideredVariables) {
145 if ((vertexId >> variableIndex) % 2 == 0) {
146 resultingVector[vertexId].insert(std::pair<VariableType, CoefficientType>(variable, getLowerBoundary(variable)));
148 resultingVector[vertexId].insert(std::pair<VariableType, CoefficientType>(variable, getUpperBoundary(variable)));
153 return resultingVector;
156template<
typename ParametricType>
158 return this->getLowerBoundaries();
161template<
typename ParametricType>
164 for (
auto const& variable : this->variables) {
165 result.emplace(variable, getCenter(variable));
170template<
typename ParametricType>
173 for (
auto const& variable : this->variables) {
174 if (this->getUpperBoundary(variable) != this->getLowerBoundary(variable)) {
175 result *= (this->getUpperBoundary(variable) - this->getLowerBoundary(variable));
180 result /= utility::convertNumber<CoefficientType>(2);
186template<
typename ParametricType>
188 for (
auto const& variable : this->variables) {
190 "Tried to check if a point is in a region, but the point does not contain a value for variable " << variable);
191 auto pointEntry = point.find(variable)->second;
192 if (pointEntry < this->getLowerBoundary(variable) || pointEntry > this->getUpperBoundary(variable)) {
199template<
typename ParametricType>
201 return split(splittingPoint, regionVector, variables, {});
204template<
typename ParametricType>
206 const std::set<VariableType>& consideredVariables,
const std::set<VariableType>& discreteVariables)
const {
207 std::set<VariableType> vertexVariables = consideredVariables;
210 for (
auto const& var : discreteVariables) {
211 if (this->getDifference(var) == storm::utility::zero<CoefficientType>()) {
212 vertexVariables.erase(var);
216 auto vertices = getVerticesOfRegion(vertexVariables);
218 for (
auto const& vertex : vertices) {
220 Valuation subLower, subUpper;
221 for (
auto variableBound : this->lowerBoundaries) {
222 VariableType variable = variableBound.first;
223 auto vertexEntry = vertex.find(variable);
224 if (vertexEntry != vertex.end()) {
225 if (discreteVariables.find(variable) != discreteVariables.end()) {
229 subLower.insert(
typename Valuation::value_type(variable, vertexEntry->second));
230 subUpper.insert(
typename Valuation::value_type(variable, vertexEntry->second));
232 auto splittingPointEntry = splittingPoint.find(variable);
233 subLower.insert(
typename Valuation::value_type(variable, std::min(vertexEntry->second, splittingPointEntry->second)));
234 subUpper.insert(
typename Valuation::value_type(variable, std::max(vertexEntry->second, splittingPointEntry->second)));
237 subLower.insert(
typename Valuation::value_type(variable, getLowerBoundary(variable)));
238 subUpper.insert(
typename Valuation::value_type(variable, getUpperBoundary(variable)));
242 ParameterRegion<ParametricType> subRegion(std::move(subLower), std::move(subUpper));
245 regionVector.push_back(std::move(subRegion));
250template<
typename ParametricType>
252 std::stringstream regionstringstream;
253 if (boundariesAsDouble) {
255 regionstringstream << storm::utility::convertNumber<double>(this->getLowerBoundary(var));
256 regionstringstream <<
"<=";
257 regionstringstream << var;
258 regionstringstream <<
"<=";
259 regionstringstream << storm::utility::convertNumber<double>(this->getUpperBoundary(var));
260 regionstringstream <<
",";
264 regionstringstream << this->getLowerBoundary(var);
265 regionstringstream <<
"<=";
266 regionstringstream << var;
267 regionstringstream <<
"<=";
268 regionstringstream << this->getUpperBoundary(var);
269 regionstringstream <<
",";
272 std::string regionstring = regionstringstream.str();
274 regionstring = regionstring.substr(0, regionstring.length() - 1) +
";";
278template<
typename ParametricType>
282 for (
auto var : varsRegion) {
283 if (std::find(varsSubRegion.begin(), varsSubRegion.end(), var) != varsSubRegion.end()) {
284 if (getLowerBoundary(var) > subRegion.
getLowerBoundary(var) || getUpperBoundary(var) < getUpperBoundary(var)) {
294template<
typename ParametricType>
297 auto val = this->getCenterPoint();
301 val[monResEntry.first] =
storm::solver::minimize(dir) ? getLowerBoundary(monResEntry.first) : getUpperBoundary(monResEntry.first);
303 val[monResEntry.first] =
storm::solver::maximize(dir) ? getLowerBoundary(monResEntry.first) : getUpperBoundary(monResEntry.first);
310template<
typename ParametricType>
312 std::set<VariableType>
const& monIncrParameters,
313 std::set<VariableType>
const& monDecrParameters)
const {
314 auto val = this->getCenterPoint();
315 for (
auto var : monIncrParameters) {
318 for (
auto var : monDecrParameters) {
325template<
typename ParametricType>
330template<
typename ParametricType>
335template<
typename ParametricType>
341#ifdef STORM_HAVE_CARL
342template class ParameterRegion<storm::RationalFunction>;
343template std::ostream& operator<<(std::ostream& out, ParameterRegion<storm::RationalFunction>
const& region);
std::map< VariableType, Monotonicity > const & getMonotonicityResult() const
Returns the results so far.
bool isDoneForVar(VariableType) const
storm::utility::parametric::CoefficientType< ParametricType >::type CoefficientType
std::set< VariableType > const & getVariables() const
Valuation getCenterPoint() const
Returns the center point of this region.
CoefficientType area() const
Returns the area of this region.
void setBoundParent(CoefficientType bound)
std::string toString(bool boundariesAsDouble=false) const
storm::utility::parametric::Valuation< ParametricType > Valuation
Valuation const & getLowerBoundaries() const
CoefficientType getDifference(const std::string varName) const
storm::utility::parametric::VariableType< ParametricType >::type VariableType
Valuation getPoint(storm::solver::OptimizationDirection dir, storm::analysis::MonotonicityResult< VariableType > &monRes) const
bool contains(Valuation const &point) const
Returns whether the given point is in this region.
CoefficientType const & getLowerBoundary(VariableType const &variable) const
CoefficientType getBoundParent()
void split(Valuation const &splittingPoint, std::vector< ParameterRegion< ParametricType > > ®ionVector) const
Splits the region at the given point and inserts the resulting subregions at the end of the given vec...
bool isSubRegion(ParameterRegion< ParametricType > region)
CoefficientType const & getUpperBoundary(VariableType const &variable) const
Valuation getSomePoint() const
Returns some point that lies within this region.
CoefficientType getCenter(const std::string varName) const
Valuation const & getUpperBoundaries() const
std::multimap< CoefficientType, VariableType > const & getVariablesSorted() const
std::vector< Valuation > getVerticesOfRegion(std::set< VariableType > const &consideredVariables) const
Returns a vector of all possible combinations of lower and upper bounds of the given variables.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
std::set< storm::RationalFunctionVariable > getVariables(SparseMatrix< storm::RationalFunction > const &matrix)
bool isZero(ValueType const &a)