24template<
typename ValueType>
26 std::vector<ValueType> stateActionRewardVector, std::string targetLabel,
27 std::string rewardModelName)
29 targetStates(
std::move(targetStates)),
30 stateActionRewardVector(
std::move(stateActionRewardVector)),
31 targetLabel(targetLabel),
32 rewardModelName(rewardModelName),
35template<
typename ValueType>
38 STORM_LOG_WARN(
"Certificate invalid because the given model is not sparse.");
51 STORM_LOG_WARN(
"Certificate invalid because the given model is of unsupported type.");
55template<
typename ValueType, OptimizationDirection Dir>
58 std::vector<RankingType>
const& ranks) {
59 for (uint64_t state = 0; state < targetStates.
size(); ++state) {
61 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" has negative infinity as value.");
66 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" has infinite rank but finite value " << values[state] <<
".");
69 if (targetStates.
get(state)) {
72 STORM_LOG_WARN(
"Certificate invalid because target state " << state <<
" has negative upper bound " << values[state]);
87 auto const currentChoiceValue = transitionProbabilityMatrix.
multiplyRowWithVector(choice, values, stateActionRewardVector[choice]);
88 stateValue =
storm::solver::maximize(Dir) ? std::max(stateValue, currentChoiceValue) : std::min(stateValue, currentChoiceValue);
92 for (
auto const& entry : transitionProbabilityMatrix.
getRow(choice)) {
96 choiceRank &= ranks[entry.getColumn()];
99 "Ranking operator failed to compute rank for state " << state <<
" since the row " << choice <<
" is empty.");
100 stateRankMinusOne &= *choiceRank;
103 if (values[state] < stateValue) {
105 STORM_LOG_WARN(
"Certificate invalid because upper bound is not inductive. At state " << state <<
" the Bellman operator yields " << stateValue
106 <<
" but the certificate has smaller value " << values[state]
107 <<
". Approx. diff is " << approxDiff <<
".");
110 if (stateRankMinusOne.
empty()) {
111 STORM_LOG_WARN(
"Certificate invalid because there is no valid (i.e. decreasing) action at state " << state <<
", where the certificate has rank "
112 << ranks[state] <<
".");
116 if (stateRank > ranks[state]) {
117 STORM_LOG_WARN(
"Certificate invalid because ranks for upper bound is not inductive. At state "
118 << state <<
" the rank operator yields " << stateRank <<
" but the certificate has smaller rank " << ranks[state] <<
".");
125template<
typename ValueType, OptimizationDirection Dir>
128 std::vector<RankingType>
const& ranks) {
129 for (uint64_t state = 0; state < targetStates.
size(); ++state) {
131 if (targetStates.
get(state)) {
133 STORM_LOG_WARN(
"Certificate invalid because target state " << state <<
" has non-zero lower bound " << values[state] <<
".");
137 STORM_LOG_WARN(
"Certificate invalid because target state " << state <<
" has finite rank" << ranks[state] <<
".");
143 STORM_LOG_WARN(
"Certificate invalid because state " << state <<
" has infinite rank and value.");
154 auto const currentChoiceValue = transitionProbabilityMatrix.
multiplyRowWithVector(choice, values, stateActionRewardVector[choice]);
155 stateValue =
storm::solver::maximize(Dir) ? std::max(stateValue, currentChoiceValue) : std::min(stateValue, currentChoiceValue);
158 bool allSuccessorsEqual =
true;
159 for (
auto const& entry : transitionProbabilityMatrix.
getRow(choice)) {
163 if (!minSuccessorRank.
empty() && ranks[entry.getColumn()] != *minSuccessorRank) {
164 allSuccessorsEqual =
false;
166 minSuccessorRank &= ranks[entry.getColumn()];
169 "Ranking operator failed to compute rank for state " << state <<
" since the row " << choice <<
" is empty.");
170 auto choiceRank = *minSuccessorRank;
171 if (choiceRank !=
InfRank && !allSuccessorsEqual) {
174 stateRank &= choiceRank;
177 if (stateValue < values[state]) {
179 STORM_LOG_WARN(
"Certificate invalid because lower bound is not inductive. At state " << state <<
" the Bellman operator yields " << stateValue
180 <<
" but the certificate has larger value " << values[state]
181 <<
". Approx. diff is " << approxDiff <<
".");
184 STORM_LOG_ASSERT(!stateRank.empty(),
"Failed to compute ranks for state " << state <<
" since the row group is empty.");
185 if (*stateRank > ranks[state]) {
186 STORM_LOG_WARN(
"Certificate invalid because ranks for lower bound is not inductive. At state "
187 << state <<
" the rank operator yields " << *stateRank <<
" but the certificate has smaller rank " << ranks[state] <<
".");
194template<
typename ValueType>
197 STORM_LOG_WARN(
"Certificate invalid because Matrix has non-trivial row grouping but no optimization direction given.");
200 if (transitionProbabilityMatrix.
getRowGroupCount() != targetStates.size() || transitionProbabilityMatrix.
getColumnCount() != targetStates.size()) {
201 STORM_LOG_WARN(
"Certificate invalid because Matrix has invalid dimensions (target states).");
204 if (transitionProbabilityMatrix.
getRowCount() != stateActionRewardVector.size()) {
205 STORM_LOG_WARN(
"Certificate invalid because Matrix has invalid dimensions (reward vector).");
210 return checkValidityInternal<storm::OptimizationDirection::Maximize>(transitionProbabilityMatrix);
212 return checkValidityInternal<storm::OptimizationDirection::Minimize>(transitionProbabilityMatrix);
216template<
typename ValueType>
217template<storm::OptimizationDirection Dir>
220 upperBoundsCertificate.values, upperBoundsCertificate.ranks)) {
221 STORM_LOG_WARN(
"Certificate invalid because upper bound certificate is violated.");
225 lowerBoundsCertificate.values, lowerBoundsCertificate.ranks)) {
226 STORM_LOG_WARN(
"Certificate invalid because lower bound certificate is violated.");
232template<
typename ValueType>
235 result[
"kind"] =
"reachability-reward";
236 if (dir.has_value()) {
239 result[
"reward-model"] = rewardModelName;
253template<
typename ValueType>
255 std::stringstream ss;
257 STORM_LOG_THROW(numStates > 0, storm::exceptions::InvalidOperationException,
258 "Tried to summarize reachability reward certificate but no state is relevant.");
260 auto getLowerUpperBound = [
this](uint64_t state) -> std::pair<ExtendedValueType, ExtendedValueType> {
264 auto const [lowerBound, upperBound] = getLowerUpperBound(relevantStates.
getNextSetIndex(0));
265 ss <<
"Certified reachability reward: [" << lowerBound <<
", " << upperBound <<
"]";
270 ss <<
" (only showing first of " << numStates <<
" relevant states)";
274 for (
auto const state : relevantStates) {
275 auto const [lower, upper] = getLowerUpperBound(state);
278 if (absDiff == zero) {
286 maxAbsDiff = std::max(maxAbsDiff, absDiff);
287 maxRelDiff = std::max(maxRelDiff, relDiff);
289 auto printIntervalWidth([&](
auto const& value,
auto const& name) {
290 ss <<
"\n\t" << name <<
" interval width: " << value;
295 ss <<
" (showing maximum over " << numStates <<
" relevant states)";
298 printIntervalWidth(maxAbsDiff,
"Absolute");
299 printIntervalWidth(maxRelDiff,
"Relative");
303template<
typename ValueType>
305 auto cloned = std::make_unique<ReachabilityRewardCertificate<ValueType>>(dir, targetStates, stateActionRewardVector, targetLabel, rewardModelName);
307 auto v = lowerBoundsCertificate.values;
308 auto r = lowerBoundsCertificate.ranks;
309 cloned->setLowerBoundsCertificate(std::move(v), std::move(r));
312 auto v = upperBoundsCertificate.values;
313 auto r = upperBoundsCertificate.ranks;
314 cloned->setUpperBoundsCertificate(std::move(v), std::move(r));
319template<
typename ValueType>
321 STORM_LOG_ASSERT(
values.size() == targetStates.size(),
"Values for lower bound certificate have incorrect dimension.");
322 STORM_LOG_ASSERT(
ranks.size() == targetStates.size(),
"Ranks for lower bound certificate have incorrect dimension.");
323 lowerBoundsCertificate.values = std::move(
values);
324 lowerBoundsCertificate.ranks = std::move(
ranks);
327template<
typename ValueType>
329 STORM_LOG_ASSERT(
values.size() == targetStates.size(),
"Values for upper bound certificate have incorrect dimension.");
330 STORM_LOG_ASSERT(
ranks.size() == targetStates.size(),
"Ranks for lower bound certificate have incorrect dimension.");
331 upperBoundsCertificate.values = std::move(
values);
332 upperBoundsCertificate.ranks = std::move(
ranks);
335template<
typename ValueType>
337 return !lowerBoundsCertificate.values.empty();
340template<
typename ValueType>
342 return !upperBoundsCertificate.values.empty();
Certificate(CertificateKind kind)
bool hasUpperBoundsCertificate() const
virtual bool checkValidity(storm::models::Model< ValueType > const &model) const override
virtual storm::json< ValueType > toJson() const override
void setLowerBoundsCertificate(std::vector< ExtendedValueType > &&values, std::vector< RankingType > &&ranks)
virtual std::string summaryString(storm::storage::BitVector const &relevantStates) const override
virtual std::unique_ptr< Certificate< ValueType > > clone() const override
storm::utility::ExtendedValueType< ValueType > ExtendedValueType
ReachabilityRewardCertificate(std::optional< storm::OptimizationDirection > dir, storm::storage::BitVector targetStates, std::vector< ValueType > stateActionRewardVector, std::string targetLabel="goal", std::string rewardModelName="")
bool hasLowerBoundsCertificate() const
void setUpperBoundsCertificate(std::vector< ExtendedValueType > &&values, std::vector< RankingType > &&ranks)
std::vector< RankingType > ranks
std::vector< ExtendedValueType > values
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.
index_type getRowCount() const
Returns the number of rows of the 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
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)
ExtendedValueType< ValueType > positiveInfinity()
Extremum< storm::OptimizationDirection::Minimize, ValueType > Minimum
bool isFinite(ExtendedNumber< ValueType > const &value)
ExtendedValueType< ValueType > negativeInfinity()
bool isNegativeInfinity(ExtendedNumber< ValueType > const &number)
bool isZero(ValueType const &a)
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
bool isInfinity(ValueType const &a)
ValueType const & getFinite(ExtendedNumber< ValueType > const &value)
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