Browse Source

refactored preSafetyShield to use ChoiceFilter

tempestpy_adaptions
Stefan Pranger 4 years ago
parent
commit
4801173505
  1. 26
      src/storm/shields/PreSafetyShield.cpp
  2. 5
      src/storm/shields/PreSafetyShield.h

26
src/storm/shields/PreSafetyShield.cpp

@ -12,6 +12,27 @@ namespace tempest {
template<typename ValueType, typename IndexType>
storm::storage::Scheduler<ValueType> PreSafetyShield<ValueType, IndexType>::construct() {
STORM_LOG_DEBUG("PreSafetyShield::construct called");
if (this->getOptimizationDirection() == storm::OptimizationDirection::Minimize) {
if(this->shieldingExpression->isRelative()) {
return constructWithCompareType<tempest::shields::utility::ChoiceFilter<ValueType, storm::utility::ElementLessEqual<ValueType>, true>>();
} else {
return constructWithCompareType<tempest::shields::utility::ChoiceFilter<ValueType, storm::utility::ElementLessEqual<ValueType>, false>>();
}
} else {
if(this->shieldingExpression->isRelative()) {
return constructWithCompareType<tempest::shields::utility::ChoiceFilter<ValueType, storm::utility::ElementGreaterEqual<ValueType>, true>>();
} else {
return constructWithCompareType<tempest::shields::utility::ChoiceFilter<ValueType, storm::utility::ElementGreaterEqual<ValueType>, false>>();
}
}
}
template<typename ValueType, typename IndexType>
template<typename ChoiceFilter>
storm::storage::Scheduler<ValueType> PreSafetyShield<ValueType, IndexType>::constructWithCompareType() {
STORM_LOG_DEBUG("PreSafetyShield::constructWithCompareType called");
ChoiceFilter choiceFilter;
storm::storage::Scheduler<ValueType> shield(this->rowGroupIndices.size() - 1);
auto choice_it = this->choiceValues.begin();
if(this->coalitionStates.is_initialized()) {
@ -22,13 +43,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(!this->allowedValue(maxProbability, maxProbability, this->shieldingExpression)) {
if(!choiceFilter(maxProbability, maxProbability, this->shieldingExpression->getValue())) {
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(this->allowedValue(maxProbability, *choice_it, this->shieldingExpression)) {
if(choiceFilter(*choice_it, maxProbability, this->shieldingExpression->getValue())) {
actionDistribution.addProbability(choice, *choice_it);
}
}
@ -39,6 +60,7 @@ namespace tempest {
shield.setChoice(storm::storage::Distribution<ValueType, IndexType>(), state);
}
}
STORM_LOG_DEBUG("PreSafetyShield::constructWithCompareType done");
return shield;
}
// Explicitly instantiate appropriate

5
src/storm/shields/PreSafetyShield.h

@ -8,8 +8,11 @@ namespace tempest {
template<typename ValueType, typename IndexType>
class PreSafetyShield : public AbstractShield<ValueType, IndexType> {
public:
PreSafetyShield(std::vector<IndexType> const& rowGroupIndices, std::vector<ValueType> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates);
PreSafetyShield(std::vector<IndexType> const& rowGroupIndices, std::vector<ValueType> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates);
storm::storage::Scheduler<ValueType> construct();
template<typename ChoiceFilter>
storm::storage::Scheduler<ValueType> constructWithCompareType();
};
}
}
Loading…
Cancel
Save