Browse Source

refactored allowedValue method

tempestpy_adaptions
Stefan Pranger 4 years ago
parent
commit
514dfb8ce6
  1. 5
      src/storm/shields/AbstractShield.cpp
  2. 11
      src/storm/shields/AbstractShield.h
  3. 4
      src/storm/shields/PostSafetyShield.cpp
  4. 4
      src/storm/shields/PreSafetyShield.cpp

5
src/storm/shields/AbstractShield.cpp

@ -24,6 +24,11 @@ namespace tempest {
return rowGroupSizes;
}
template<typename ValueType, typename IndexType>
bool AbstractShield<ValueType, IndexType>::allowedValue(ValueType const& max, ValueType const& v, std::shared_ptr<storm::logic::ShieldExpression const> const shieldExpression) {
return shieldExpression->isRelative() ? v >= shieldExpression->getValue() * max : v >= shieldExpression->getValue();
}
template<typename ValueType, typename IndexType>
std::string AbstractShield<ValueType, IndexType>::getClassName() const {
return std::string(boost::core::demangled_name(BOOST_CORE_TYPEID(*this)));

11
src/storm/shields/AbstractShield.h

@ -26,9 +26,13 @@ namespace tempest {
/*!
* TODO
*/
//virtual storm::storage::Scheduler<ValueType>* construct() = 0;
std::vector<IndexType> computeRowGroupSizes();
/*!
* TODO
*/
bool allowedValue(ValueType const& max, ValueType const& v, std::shared_ptr<storm::logic::ShieldExpression const> const shieldExpression);
/*!
* TODO
*/
@ -46,10 +50,5 @@ namespace tempest {
boost::optional<storm::storage::BitVector> coalitionStates;
};
template<typename ValueType, typename IndexType>
bool allowedValue(ValueType const& max, ValueType const& v, std::shared_ptr<storm::logic::ShieldExpression const> const shieldExpression) {
return shieldExpression->isRelative() ? v >= shieldExpression->getValue() * max : v >= shieldExpression->getValue();
}
}
}

4
src/storm/shields/PostSafetyShield.cpp

@ -22,14 +22,14 @@ namespace tempest {
uint rowGroupSize = this->rowGroupIndices[state + 1] - this->rowGroupIndices[state];
auto maxProbabilityIndex = std::max_element(choice_it, choice_it + rowGroupSize) - choice_it;
ValueType maxProbability = *(choice_it + maxProbabilityIndex);
if(!allowedValue<ValueType, IndexType>(maxProbability, maxProbability, this->shieldingExpression)) {
if(!this->allowedValue(maxProbability, maxProbability, this->shieldingExpression)) {
STORM_LOG_WARN("No shielding action possible with absolute comparison for state with index " << state);
shield.setChoice(0, storm::storage::Distribution<ValueType, IndexType>(), state);
continue;
}
for(uint choice = 0; choice < rowGroupSize; choice++, choice_it++) {
storm::storage::Distribution<ValueType, IndexType> actionDistribution;
if(allowedValue<ValueType, IndexType>(maxProbability, *choice_it, this->shieldingExpression)) {
if(this->allowedValue(maxProbability, *choice_it, this->shieldingExpression)) {
actionDistribution.addProbability(choice, 1);
} else {
actionDistribution.addProbability(maxProbabilityIndex, 1);

4
src/storm/shields/PreSafetyShield.cpp

@ -22,13 +22,13 @@ namespace tempest {
uint rowGroupSize = this->rowGroupIndices[state + 1] - this->rowGroupIndices[state];
storm::storage::Distribution<ValueType, IndexType> actionDistribution;
ValueType maxProbability = *std::max_element(choice_it, choice_it + rowGroupSize);
if(!allowedValue<ValueType, IndexType>(maxProbability, maxProbability, this->shieldingExpression)) {
if(!this->allowedValue(maxProbability, maxProbability, this->shieldingExpression)) {
STORM_LOG_WARN("No shielding action possible with absolute comparison for state with index " << state);
shield.setChoice(storm::storage::Distribution<ValueType, IndexType>(), state);
continue;
}
for(uint choice = 0; choice < rowGroupSize; choice++, choice_it++) {
if(allowedValue<ValueType, IndexType>(maxProbability, *choice_it, this->shieldingExpression)) {
if(this->allowedValue(maxProbability, *choice_it, this->shieldingExpression)) {
actionDistribution.addProbability(choice, *choice_it);
}
}

Loading…
Cancel
Save