#include "storm/shields/OptimalShield.h" #include namespace tempest { namespace shields { template OptimalShield::OptimalShield(std::vector const& rowGroupIndices, std::vector const& choiceValues, std::shared_ptr const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional coalitionStates) : AbstractShield(rowGroupIndices, shieldingExpression, optimizationDirection, relevantStates, coalitionStates), choiceValues(choiceValues) { // Intentionally left empty. } template storm::storage::PostScheduler OptimalShield::construct() { if (this->getOptimizationDirection() == storm::OptimizationDirection::Minimize) { if(this->shieldingExpression->isRelative()) { return constructWithCompareType, true>(); } else { return constructWithCompareType, false>(); } } else { if(this->shieldingExpression->isRelative()) { return constructWithCompareType, true>(); } else { return constructWithCompareType, false>(); } } } template template storm::storage::PostScheduler OptimalShield::constructWithCompareType() { tempest::shields::utility::ChoiceFilter choiceFilter; storm::storage::PostScheduler shield(this->rowGroupIndices.size() - 1, this->computeRowGroupSizes()); auto choice_it = this->choiceValues.begin(); if(this->coalitionStates.is_initialized()) { this->relevantStates &= this->coalitionStates.get(); } for(uint state = 0; state < this->rowGroupIndices.size() - 1; state++) { uint rowGroupSize = this->rowGroupIndices[state + 1] - this->rowGroupIndices[state]; if(this->relevantStates.get(state)) { auto maxProbabilityIndex = std::max_element(choice_it, choice_it + rowGroupSize) - choice_it; ValueType maxProbability = *(choice_it + maxProbabilityIndex); if(!relative && !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::PostSchedulerChoice(), state, 0); choice_it += rowGroupSize; continue; } storm::storage::PostSchedulerChoice choiceMapping; for(uint choice = 0; choice < rowGroupSize; choice++, choice_it++) { if(choiceFilter(*choice_it, maxProbability, this->shieldingExpression->getValue())) { choiceMapping.addChoice(choice, choice); } else { choiceMapping.addChoice(choice, maxProbabilityIndex); } } shield.setChoice(choiceMapping, state, 0); } else { shield.setChoice(storm::storage::PostSchedulerChoice(), state, 0); choice_it += rowGroupSize; } } return shield; } // Explicitly instantiate appropriate classes template class OptimalShield::index_type>; #ifdef STORM_HAVE_CARL template class OptimalShield::index_type>; #endif } }