16namespace modelchecker {
17namespace multiobjective {
19template<
class SparseModelType,
typename GeometryValueType>
22 :
SparsePcaaQuery<SparseModelType, GeometryValueType>(preprocessorResult) {
24 "Invalid query Type");
26 for (uint_fast64_t objIndex = 0; objIndex < this->
objectives.size(); ++objIndex) {
27 if (!this->
objectives[objIndex].formula->hasBound()) {
28 indexOfOptimizingObjective = objIndex;
32 initializeThresholdData();
35 this->
weightVectorChecker->setWeightedPrecision(storm::utility::convertNumber<typename SparseModelType::ValueType>(0.1));
38template<
class SparseModelType,
typename GeometryValueType>
40 thresholds.reserve(this->objectives.size());
42 std::vector<storm::storage::geometry::Halfspace<GeometryValueType>> thresholdConstraints;
43 thresholdConstraints.reserve(this->objectives.size() - 1);
44 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
45 auto const& formula = *this->objectives[objIndex].formula;
47 if (formula.hasBound()) {
48 thresholds.push_back(formula.template getThresholdAs<GeometryValueType>());
53 thresholds.back() *= -storm::utility::one<GeometryValueType>();
56 WeightVector normalVector(this->objectives.size(), storm::utility::zero<GeometryValueType>());
57 normalVector[objIndex] = -storm::utility::one<GeometryValueType>();
58 thresholdConstraints.emplace_back(std::move(normalVector), -thresholds.back());
60 thresholds.push_back(storm::utility::zero<GeometryValueType>());
67template<
class SparseModelType,
typename GeometryValueType>
70 if (this->checkAchievability(env)) {
72 GeometryValueType result = this->improveSolution(env);
75 auto const& obj = this->objectives[indexOfOptimizingObjective];
77 if (obj.considersComplementaryEvent) {
78 result = storm::utility::one<GeometryValueType>() - result;
81 if (obj.considersComplementaryEvent) {
82 result = storm::utility::one<GeometryValueType>() + result;
84 result *= -storm::utility::one<GeometryValueType>();
87 auto resultForOriginalModel = storm::utility::convertNumber<typename SparseModelType::ValueType>(result);
90 this->originalModel.getInitialStates().getNextSetIndex(0), resultForOriginalModel));
96template<
class SparseModelType,
typename GeometryValueType>
98 if (this->objectives.size() > 1) {
100 this->diracWeightVectorsToBeChecked.set(indexOfOptimizingObjective,
false);
103 WeightVector separatingVector = this->findSeparatingVector(thresholds);
104 this->updateWeightedPrecisionInAchievabilityPhase(separatingVector);
105 this->performRefinementStep(env, std::move(separatingVector));
107 thresholds[indexOfOptimizingObjective] =
108 std::min(thresholds[indexOfOptimizingObjective], this->refinementSteps.back().lowerBoundPoint[indexOfOptimizingObjective]);
109 if (!checkIfThresholdsAreSatisfied(this->overApproximation)) {
112 if (checkIfThresholdsAreSatisfied(this->underApproximation)) {
120 STORM_LOG_ERROR(
"Could not check whether thresholds are achievable: Termination requested or maximum number of refinement steps exceeded.");
124template<
class SparseModelType,
typename GeometryValueType>
125void SparsePcaaQuantitativeQuery<SparseModelType, GeometryValueType>::updateWeightedPrecisionInAchievabilityPhase(WeightVector
const& weights) {
127 std::pair<Point, bool> optimizationResOverApprox = this->overApproximation->optimize(weights);
128 if (optimizationResOverApprox.second) {
129 std::pair<Point, bool> optimizationResUnderApprox = this->underApproximation->optimize(weights);
130 if (optimizationResUnderApprox.second) {
133 STORM_LOG_ASSERT(distance >= storm::utility::zero<GeometryValueType>(),
"Negative distance between under- and over approximation was not expected");
136 distance /= GeometryValueType(2);
137 this->weightVectorChecker->setWeightedPrecision(storm::utility::convertNumber<typename SparseModelType::ValueType>(distance));
143template<
class SparseModelType,
typename GeometryValueType>
144GeometryValueType SparsePcaaQuantitativeQuery<SparseModelType, GeometryValueType>::improveSolution(Environment
const& env) {
146 storm::exceptions::IllegalArgumentException,
"Unhandled multiobjective precision type.");
147 this->diracWeightVectorsToBeChecked.clear();
149 WeightVector directionOfOptimizingObjective(this->objectives.size(), storm::utility::zero<GeometryValueType>());
150 directionOfOptimizingObjective[indexOfOptimizingObjective] = storm::utility::one<GeometryValueType>();
156 GeometryValueType result = storm::utility::zero<GeometryValueType>();
158 if (this->refinementSteps.empty()) {
160 this->weightVectorChecker->setWeightedPrecision(
161 storm::utility::convertNumber<typename SparseModelType::ValueType>(env.modelchecker().multi().getPrecision()));
162 WeightVector separatingVector = directionOfOptimizingObjective;
163 this->performRefinementStep(env, std::move(separatingVector));
165 std::pair<Point, bool> optimizationRes = this->underApproximation->intersection(thresholdsAsPolytope)->optimize(directionOfOptimizingObjective);
166 STORM_LOG_THROW(optimizationRes.second, storm::exceptions::UnexpectedException,
"The underapproximation is either unbounded or empty.");
167 result = optimizationRes.first[indexOfOptimizingObjective];
168 STORM_LOG_DEBUG(
"Best solution found so far is ~" << storm::utility::convertNumber<double>(result) <<
".");
170 optimizationRes = this->overApproximation->intersection(thresholdsAsPolytope)->optimize(directionOfOptimizingObjective);
171 if (optimizationRes.second) {
172 GeometryValueType precisionOfResult = optimizationRes.first[indexOfOptimizingObjective] - result;
173 if (precisionOfResult < storm::utility::convertNumber<GeometryValueType>(env.modelchecker().multi().getPrecision())) {
177 STORM_LOG_DEBUG(
"Solution can be improved by at most " << storm::utility::convertNumber<double>(precisionOfResult));
178 thresholds[indexOfOptimizingObjective] = optimizationRes.first[indexOfOptimizingObjective];
181 thresholds[indexOfOptimizingObjective] = result + storm::utility::one<GeometryValueType>();
183 WeightVector separatingVector = this->findSeparatingVector(thresholds);
184 this->updateWeightedPrecisionInImprovingPhase(env, separatingVector);
185 this->performRefinementStep(env, std::move(separatingVector));
187 STORM_LOG_ERROR(
"Could not reach the desired precision: Termination requested or maximum number of refinement steps exceeded.");
191template<
class SparseModelType,
typename GeometryValueType>
192void SparsePcaaQuantitativeQuery<SparseModelType, GeometryValueType>::updateWeightedPrecisionInImprovingPhase(Environment
const& env,
193 WeightVector
const& weights) {
195 "The chosen weight-vector gives zero weight for the objective that is to be optimized.");
197 storm::exceptions::IllegalArgumentException,
"Unhandled multiobjective precision type.");
201 GeometryValueType weightedPrecision =
202 weights[this->indexOfOptimizingObjective] * storm::utility::convertNumber<GeometryValueType>(env.modelchecker().multi().getPrecision());
205 weightedPrecision *= storm::utility::convertNumber<GeometryValueType>(0.9);
207 this->weightVectorChecker->setWeightedPrecision(storm::utility::convertNumber<typename SparseModelType::ValueType>(weightedPrecision));
210template<
class SparseModelType,
typename GeometryValueType>
211bool SparsePcaaQuantitativeQuery<SparseModelType, GeometryValueType>::checkIfThresholdsAreSatisfied(
213 std::vector<storm::storage::geometry::Halfspace<GeometryValueType>> halfspaces = polytope->getHalfspaces();
214 for (
auto const& h : halfspaces) {
217 if (h.isPointOnBoundary(thresholds)) {
218 for (
auto strictThreshold : strictThresholds) {
219 if (h.normalVector()[strictThreshold] > storm::utility::zero<GeometryValueType>()) {
231#ifdef STORM_HAVE_CARL
232template class SparsePcaaQuantitativeQuery<storm::models::sparse::Mdp<double>, storm::RationalNumber>;
233template class SparsePcaaQuantitativeQuery<storm::models::sparse::MarkovAutomaton<double>, storm::RationalNumber>;
235template class SparsePcaaQuantitativeQuery<storm::models::sparse::Mdp<storm::RationalNumber>, storm::RationalNumber>;
236template class SparsePcaaQuantitativeQuery<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>, storm::RationalNumber>;
SparsePcaaQuantitativeQuery(preprocessing::SparseMultiObjectivePreprocessorResult< SparseModelType > &preprocessorResult)
virtual std::unique_ptr< CheckResult > check(Environment const &env) override
std::unique_ptr< PcaaWeightVectorChecker< SparseModelType > > weightVectorChecker
std::vector< Objective< typename SparseModelType::ValueType > > objectives
A bit vector that is internally represented as a vector of 64-bit values.
static std::shared_ptr< Polytope< ValueType > > create(std::vector< Halfspace< ValueType > > const &halfspaces)
Creates a polytope from the given halfspaces.
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_ERROR(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
bool isLowerBound(ComparisonType t)
bool isStrict(ComparisonType t)
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
bool isZero(ValueType const &a)
ValueType sqrt(ValueType const &number)