22template<
typename ValueType>
27template<
typename ValueType>
31 std::string constraintLabel)
33 targetStates(
std::move(targetStates)),
34 constraintStates(
std::move(constraintStates)),
35 targetLabel(targetLabel),
36 constraintLabel(
std::move(constraintLabel)),
38 STORM_LOG_ASSERT(this->constraintStates->
size() == this->targetStates.size(),
"Constraint set and target set consider a different state count.");
41template<
typename ValueType>
44 STORM_LOG_WARN(
"Certificate invalid because the given model is not sparse.");
57 STORM_LOG_WARN(
"Certificate invalid because the given model is of unsupported type.");
61template<
typename ValueType, OptimizationDirection Dir>
64 for (uint64_t state = 0; state < targetStates.
size(); ++state) {
65 if (targetStates.
get(state)) {
68 STORM_LOG_WARN(
"Certificate invalid because target state " << state <<
" has upper bound " << values[state] <<
" < 1.");
75 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" has upper bound " << values[state] <<
" < 0.");
79 if (constraintStates && !constraintStates->get(state)) {
87 STORM_LOG_ASSERT(!stateValue.
empty(),
"Bellman operator failed to compute value for state " << state <<
" since the row group is empty.");
88 if (*stateValue > values[state]) {
90 STORM_LOG_WARN(
"Certificate invalid because upper bound is not inductive. At state " << state <<
" the Bellman operator yields " << *stateValue
91 <<
" but the certificate has smaller value " << values[state]
92 <<
". Approx. diff is " << approxDiff <<
".");
99template<
typename ValueType, OptimizationDirection Dir>
102 std::vector<RankingType>
const& ranks) {
103 for (uint64_t state = 0; state < targetStates.
size(); ++state) {
105 if (targetStates.
get(state)) {
107 STORM_LOG_WARN(
"Certificate invalid because target state " << state <<
" has lower bound " << values[state] <<
" > 1.");
113 if (constraintStates && !constraintStates->get(state)) {
115 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" is not in the constraint set but has lower bound " << values[state]
120 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" is not in the constraint set but has finite rank " << ranks[state] <<
".");
127 STORM_LOG_WARN(
"Certificate invalid because infinite rank is assigned to a state " << state <<
" with non-zero lower bound " << values[state]
138 stateValue &= currentChoiceValue;
142 for (
auto const& entry : transitionProbabilityMatrix.
getRow(choice)) {
146 choiceRank &= ranks[entry.getColumn()];
149 "Ranking operator failed to compute rank for state " << state <<
" since the row " << choice <<
" is empty.");
150 stateRankMinusOne &= *choiceRank;
153 STORM_LOG_ASSERT(!stateValue.
empty(),
"Bellman operator failed to compute value for state " << state <<
" since the row group is empty.");
154 if (*stateValue < values[state]) {
156 STORM_LOG_WARN(
"Certificate invalid because lower bound is not inductive. At state " << state <<
" the Bellman operator yields " << *stateValue
157 <<
" but the certificate has larger value " << values[state]
158 <<
". Approx. diff is " << approxDiff <<
".");
161 if (stateRankMinusOne.empty()) {
162 STORM_LOG_WARN(
"Certificate invalid because there is no valid (i.e. inductive) action at state " << state <<
", where the certificate has rank "
163 << ranks[state] <<
".");
166 STORM_LOG_ASSERT(!stateRankMinusOne.empty(),
"Ranking operator failed to compute rank for state " << state <<
".");
168 if (stateRank > ranks[state]) {
169 STORM_LOG_WARN(
"Certificate invalid because ranks for lower bound is not inductive. At state "
170 << state <<
" the rank operator yields " << stateRank <<
" but the certificate has smaller rank " << ranks[state] <<
".");
177template<
typename ValueType>
180 STORM_LOG_WARN(
"Certificate invalid because Matrix has non-trivial row grouping but no optimization direction given.");
183 if (transitionProbabilityMatrix.
getRowGroupCount() != targetStates.size() || transitionProbabilityMatrix.
getColumnCount() != targetStates.size()) {
184 STORM_LOG_WARN(
"Certificate invalid because Matrix has invalid dimensions.");
188 return checkValidityInternal<storm::OptimizationDirection::Maximize>(transitionProbabilityMatrix);
190 return checkValidityInternal<storm::OptimizationDirection::Minimize>(transitionProbabilityMatrix);
194template<
typename ValueType>
195template<storm::OptimizationDirection Dir>
198 if (hasConstraintStates()) {
199 constraintStatesRef.
reset(*constraintStates);
201 if (hasUpperBoundsCertificate() &&
203 STORM_LOG_WARN(
"Certificate invalid because upper bound certificate is violated.");
207 lowerBoundsCertificate.values, lowerBoundsCertificate.ranks)) {
208 STORM_LOG_WARN(
"Certificate invalid because lower bound certificate is violated.");
214template<
typename ValueType>
217 result[
"kind"] =
"reachability-probability";
218 if (dir.has_value()) {
222 if (hasConstraintStates()) {
235template<
typename ValueType>
237 std::stringstream ss;
239 STORM_LOG_THROW(numStates > 0, storm::exceptions::InvalidOperationException,
240 "Tried to summarize reachability probability certificate but no state is relevant.");
242 auto getLowerUpperBound = [
this](uint64_t state) -> std::pair<ValueType, ValueType> {
246 auto const [lowerBound, upperBound] = getLowerUpperBound(relevantStates.
getNextSetIndex(0));
247 ss <<
"Certified reachability probability: [" << lowerBound <<
", " << upperBound <<
"]";
252 ss <<
" (only showing first of " << numStates <<
" relevant states)";
255 for (
auto const state : relevantStates) {
256 auto const [lower, upper] = getLowerUpperBound(state);
257 ValueType absDiff = upper - lower;
262 relDiff = absDiff / lower;
264 maxAbsDiff &= absDiff;
265 maxRelDiff &= relDiff;
267 auto printIntervalWidth([&](
auto const& value,
auto const& name) {
268 ss <<
"\n\t" << name <<
" interval width: " << value;
273 ss <<
" (showing maximum over " << numStates <<
" relevant states)";
276 printIntervalWidth(*maxAbsDiff,
"Absolute");
277 printIntervalWidth(*maxRelDiff,
"Relative");
281template<
typename ValueType>
283 auto cloned = hasConstraintStates()
284 ? std::make_unique<ReachabilityProbabilityCertificate<ValueType>>(dir, targetStates, *constraintStates, targetLabel, constraintLabel)
285 : std::make_unique<ReachabilityProbabilityCertificate<ValueType>>(dir, targetStates, targetLabel);
287 auto v = lowerBoundsCertificate.values;
288 auto r = lowerBoundsCertificate.ranks;
289 cloned->setLowerBoundsCertificate(std::move(v), std::move(r));
292 auto v = upperBoundsCertificate.values;
293 cloned->setUpperBoundsCertificate(std::move(v));
298template<
typename ValueType>
300 STORM_LOG_ASSERT(
values.size() == targetStates.size(),
"Values for lower bound certificate have incorrect dimension.");
301 STORM_LOG_ASSERT(
ranks.size() == targetStates.size(),
"Ranks for lower bound certificate have incorrect dimension.");
302 lowerBoundsCertificate.values = std::move(
values);
303 lowerBoundsCertificate.ranks = std::move(
ranks);
306template<
typename ValueType>
308 STORM_LOG_ASSERT(
values.size() == targetStates.size(),
"Values for upper bound certificate have incorrect dimension.");
309 upperBoundsCertificate.values = std::move(
values);
312template<
typename ValueType>
314 return !lowerBoundsCertificate.values.empty();
317template<
typename ValueType>
319 return !upperBoundsCertificate.values.empty();
322template<
typename ValueType>
323bool ReachabilityProbabilityCertificate<ValueType>::hasConstraintStates()
const {
324 return constraintStates.has_value();
327template class ReachabilityProbabilityCertificate<double>;
328template class ReachabilityProbabilityCertificate<storm::RationalNumber>;
Helper class that optionally holds a reference to an object of type T.
void reset()
Unsets the reference.
Certificate(CertificateKind kind)
virtual std::string summaryString(storm::storage::BitVector const &relevantStates) const override
bool hasUpperBoundsCertificate() const
void setUpperBoundsCertificate(std::vector< ValueType > &&values)
virtual std::unique_ptr< Certificate< ValueType > > clone() const override
virtual bool checkValidity(storm::models::Model< ValueType > const &model) const override
void setLowerBoundsCertificate(std::vector< ValueType > &&values, std::vector< RankingType > &&ranks)
std::vector< ValueType > values
bool hasLowerBoundsCertificate() const
virtual storm::json< ValueType > toJson() const override
std::vector< RankingType > ranks
ReachabilityProbabilityCertificate(std::optional< storm::OptimizationDirection > dir, storm::storage::BitVector targetStates, std::string targetLabel="goal")
virtual bool isSparseModel() const
Checks whether the model is a sparse model.
bool isOfType(storm::models::ModelType const &modelType) const
Checks whether the model is of the given type.
This class represents a continuous-time Markov chain.
Base class for all sparse models.
A bit vector that is internally represented as a vector of 64-bit values.
uint64_t getNextSetIndex(uint64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
ValueType multiplyRowWithVector(index_type row, std::vector< ValueType > const &vector, ValueType offset=storm::utility::zero< ValueType >()) const
Multiplies a single row of the matrix with the given vector and adds the given offset to the result.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
index_type getColumnCount() const
Returns the number of columns of the matrix.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
Stores and manages an extremal (maximal or minimal) value.
#define STORM_LOG_WARN(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::json< ValueType > ranksToJson(std::vector< RankingType > const &ranks)
Converts the given ranks to a json array.
storm::json< ValueType > valuesToJson(std::vector< ElementType > const &values)
Converts the given values to a json array.
storm::json< ValueType > stateSetToJson(std::string const &label, storm::storage::BitVector const &states)
Converts the given set of states to a json object of the form {"label": <label>, "states": [<state in...
bool checkUpperBoundCertificate(storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector const &targetStates, storm::OptionalRef< storm::storage::BitVector const > constraintStates, std::vector< ValueType > const &values)
static RankingType const InfRank
@ ReachabilityProbability
bool checkLowerBoundCertificate(storm::storage::SparseMatrix< ValueType > const &transitionProbabilityMatrix, storm::storage::BitVector const &targetStates, storm::OptionalRef< storm::storage::BitVector const > constraintStates, std::vector< ValueType > const &values, std::vector< RankingType > const &ranks)
bool constexpr maximize(OptimizationDirection d)
OptimizationDirection constexpr invert(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
Extremum< storm::OptimizationDirection::Maximize, ValueType > Maximum
Extremum< storm::OptimizationDirection::Minimize, ValueType > Minimum
bool isZero(ValueType const &a)
TargetType convertNumber(SourceType const &number)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
static const bool IsExact