#include "storm/shields/PreShield.h" #include namespace tempest { namespace shields { template PreShield::PreShield(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::PreScheduler PreShield::construct() { if constexpr (std::is_same_v) { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "todo"); } 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::PreScheduler PreShield::constructWithCompareType() { tempest::shields::utility::ChoiceFilter choiceFilter; storm::storage::PreScheduler shield(this->rowGroupIndices.size() - 1); 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(true){ //if(this->relevantStates.get(state)) { storm::storage::PreSchedulerChoice enabledChoices; ValueType optProbability; if(std::is_same>::value) { optProbability = *std::max_element(choice_it, choice_it + rowGroupSize); } else { optProbability = *std::min_element(choice_it, choice_it + rowGroupSize); } if(!relative && !choiceFilter(optProbability, optProbability, this->shieldingExpression->getValue())) { //STORM_LOG_WARN("No shielding action possible with absolute comparison for state with index " << state); shield.setChoice(storm::storage::PreSchedulerChoice(), state, 0); choice_it += rowGroupSize; continue; } for(uint choice = 0; choice < rowGroupSize; choice++, choice_it++) { if(choiceFilter(*choice_it, optProbability, this->shieldingExpression->getValue())) { enabledChoices.addChoice(choice, *choice_it); } } shield.setChoice(enabledChoices, state, 0); } else { shield.setChoice(storm::storage::PreSchedulerChoice(), state, 0); choice_it += rowGroupSize; } } preScheduler = std::make_shared>(shield); return shield; } template std::shared_ptr> PreShield::getScheduler() const { return preScheduler; } template bool PreShield::isPreShield() const { return true; } template void PreShield::printJsonToStream(std::ostream& out, std::shared_ptr> const& model) { preScheduler->printJsonToStream(out, model); } template void PreShield::printToStream(std::ostream& out, std::shared_ptr> const& model) { preScheduler->printToStream(out, this->shieldingExpression, model); } // Explicitly instantiate appropriate classes template class PreShield::index_type>; #ifdef STORM_HAVE_CARL template class PreShield::index_type>; template class PreShield::index_type>; #endif } }