10namespace modelchecker {
24 boost::get<map_type>(truthValues)[state] = value;
44 return std::make_unique<ExplicitQualitativeCheckResult>(this->truthValues);
49 "Cannot perform logical 'and' on check results of incompatible type.");
51 "Cannot perform logical 'and' on check results of incompatible type.");
55 boost::get<vector_type>(first.truthValues) &= boost::get<vector_type>(secondCheckResult.truthValues);
57 boost::get<vector_type>(first.truthValues) |= boost::get<vector_type>(secondCheckResult.truthValues);
60 std::function<bool(
bool,
bool)> function = logicalAnd ? std::function<bool(bool, bool)>([](
bool a,
bool b) {
return a && b; })
61 :
std::function<bool(bool, bool)>([](bool a, bool b) {
return a || b; });
63 map_type& map1 = boost::get<map_type>(first.truthValues);
64 map_type
const& map2 = boost::get<map_type>(secondCheckResult.truthValues);
65 for (
auto& element1 : map1) {
66 auto const& keyValuePair = map2.find(element1.first);
67 STORM_LOG_THROW(keyValuePair != map2.end(), storm::exceptions::InvalidOperationException,
68 "Cannot perform logical 'and' on check results of incompatible type.");
69 element1.second = function(element1.second, keyValuePair->second);
73 for (
auto const& element2 : map2) {
74 auto const& keyValuePair = map1.find(element2.first);
75 STORM_LOG_THROW(keyValuePair != map1.end(), storm::exceptions::InvalidOperationException,
76 "Cannot perform logical 'and' on check results of incompatible type.");
82 performLogicalOperation(*
this, other,
true);
87 performLogicalOperation(*
this, other,
false);
91bool ExplicitQualitativeCheckResult::existsTrue()
const {
92 if (this->isResultForAllStates()) {
93 return !boost::get<vector_type>(truthValues).empty();
95 for (
auto& element : boost::get<map_type>(truthValues)) {
103bool ExplicitQualitativeCheckResult::forallTrue()
const {
104 if (this->isResultForAllStates()) {
105 return boost::get<vector_type>(truthValues).full();
107 for (
auto& element : boost::get<map_type>(truthValues)) {
108 if (!element.second) {
116uint64_t ExplicitQualitativeCheckResult::count()
const {
117 if (this->isResultForAllStates()) {
118 return boost::get<vector_type>(truthValues).getNumberOfSetBits();
121 for (
auto& element : boost::get<map_type>(truthValues)) {
122 if (element.second) {
131 if (this->isResultForAllStates()) {
132 return boost::get<vector_type>(truthValues).get(state);
134 map_type const& map = boost::get<map_type>(truthValues);
135 auto const& keyValuePair = map.find(state);
136 STORM_LOG_THROW(keyValuePair != map.end(), storm::exceptions::InvalidOperationException,
"Unknown key '" << state <<
"'.");
137 return keyValuePair->second;
142 return boost::get<vector_type>(truthValues);
146 return boost::get<map_type>(truthValues);
149void ExplicitQualitativeCheckResult::complement() {
150 if (this->isResultForAllStates()) {
151 boost::get<vector_type>(truthValues).complement();
153 for (
auto& element : boost::get<map_type>(truthValues)) {
154 element.second = !element.second;
159bool ExplicitQualitativeCheckResult::isExplicit()
const {
163bool ExplicitQualitativeCheckResult::isResultForAllStates()
const {
164 return truthValues.which() == 0;
167bool ExplicitQualitativeCheckResult::isExplicitQualitativeCheckResult()
const {
171std::ostream& ExplicitQualitativeCheckResult::writeToStream(std::ostream& out)
const {
172 if (this->isResultForAllStates()) {
173 vector_type const& vector = boost::get<vector_type>(truthValues);
174 bool allTrue = vector.
full();
175 bool allFalse = !allTrue && vector.
empty();
178 }
else if (allFalse) {
181 out <<
"{true, false}";
184 std::ios::fmtflags oldflags(std::cout.flags());
185 out << std::boolalpha;
187 map_type const& map = boost::get<map_type>(truthValues);
188 if (map.size() == 1) {
189 out << map.begin()->second;
192 bool allFalse =
true;
193 for (
auto const& entry : map) {
202 }
else if (allFalse) {
205 out <<
"{true, false}";
209 std::cout.flags(oldflags);
215 STORM_LOG_THROW(filter.isExplicitQualitativeCheckResult(), storm::exceptions::InvalidOperationException,
216 "Cannot filter explicit check result with non-explicit filter.");
217 STORM_LOG_THROW(filter.isResultForAllStates(), storm::exceptions::InvalidOperationException,
"Cannot filter check result with non-complete filter.");
221 if (this->isResultForAllStates()) {
223 for (
auto element : filterTruthValues) {
224 newMap.emplace(element, this->getTruthValuesVector().get(element));
226 this->truthValues = newMap;
228 map_type const& map = boost::get<map_type>(truthValues);
231 for (
auto const& element : map) {
232 if (filterTruthValues.
get(element.first)) {
233 newMap.insert(element);
238 "The check result fails to contain some results referred to by the filter.");
240 this->truthValues = newMap;
244template<
typename JsonRationalType>
246 std::optional<storm::storage::sparse::StateValuations>
const& stateValuations = std::nullopt,
247 std::optional<storm::models::sparse::StateLabeling>
const& stateLabels = std::nullopt) {
249 if (stateValuations) {
250 entry[
"s"] = stateValuations->template toJson<JsonRationalType>(
id);
256 auto labs = stateLabels->getLabelsOfState(
id);
259 json.push_back(std::move(entry));
262template<
typename JsonRationalType>
264 std::optional<storm::models::sparse::StateLabeling>
const& stateLabels)
const {
266 if (this->isResultForAllStates()) {
267 vector_type const& valuesAsVector = boost::get<vector_type>(truthValues);
268 for (uint64_t state = 0; state < valuesAsVector.
size(); ++state) {
269 insertJsonEntry(result, state, valuesAsVector.
get(state), stateValuations, stateLabels);
272 map_type const& valuesAsMap = boost::get<map_type>(truthValues);
273 for (
auto const& stateValue : valuesAsMap) {
274 insertJsonEntry(result, stateValue.first, stateValue.second, stateValuations, stateLabels);
280template storm::json<double> ExplicitQualitativeCheckResult::toJson<double>(std::optional<storm::storage::sparse::StateValuations>
const&,
281 std::optional<storm::models::sparse::StateLabeling>
const&)
const;
283 std::optional<storm::storage::sparse::StateValuations>
const&, std::optional<storm::models::sparse::StateLabeling>
const&)
const;
virtual bool isResultForAllStates() const
virtual bool isExplicitQualitativeCheckResult() const
virtual std::unique_ptr< CheckResult > clone() const override
std::map< storm::storage::sparse::state_type, bool > map_type
vector_type const & getTruthValuesVector() const
virtual bool isResultForAllStates() const override
ExplicitQualitativeCheckResult()
A bit vector that is internally represented as a vector of 64-bit values.
bool full() const
Retrieves whether all bits are set in this bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_THROW(cond, exception, message)
void insertJsonEntry(storm::json< JsonRationalType > &json, uint64_t const &id, bool value, std::optional< storm::storage::sparse::StateValuations > const &stateValuations=std::nullopt, std::optional< storm::models::sparse::StateLabeling > const &stateLabels=std::nullopt)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json