Browse Source

less searches for epoch solutions

tempestpy_adaptions
TimQu 7 years ago
parent
commit
4cadc61f19
  1. 20
      src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.cpp
  2. 3
      src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.h

20
src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.cpp

@ -331,21 +331,22 @@ namespace storm {
} }
// compute the solution for the stepChoices // compute the solution for the stepChoices
// For optimization purposes, we distinguish the case where the memory state does not have to be transformed // For optimization purposes, we distinguish the case where the memory state does not have to be transformed
EpochSolution const& successorEpochSolution = getEpochSolution(subSolutions, successorEpoch);
SolutionType choiceSolution; SolutionType choiceSolution;
bool firstSuccessor = true; bool firstSuccessor = true;
if (!containsLowerBoundedObjective && epochManager.compareEpochClass(epoch, successorEpoch)) { if (!containsLowerBoundedObjective && epochManager.compareEpochClass(epoch, successorEpoch)) {
for (auto const& successor : productModel->getProduct().getTransitionMatrix().getRow(productChoice)) { for (auto const& successor : productModel->getProduct().getTransitionMatrix().getRow(productChoice)) {
if (firstSuccessor) { if (firstSuccessor) {
choiceSolution = getScaledSolution(getStateSolution(subSolutions, successorEpoch, successor.getColumn()), successor.getValue());
choiceSolution = getScaledSolution(getStateSolution(successorEpochSolution, successor.getColumn()), successor.getValue());
firstSuccessor = false; firstSuccessor = false;
} else { } else {
addScaledSolution(choiceSolution, getStateSolution(subSolutions, successorEpoch, successor.getColumn()), successor.getValue());
addScaledSolution(choiceSolution, getStateSolution(successorEpochSolution, successor.getColumn()), successor.getValue());
} }
} }
} else { } else {
for (auto const& successor : productModel->getProduct().getTransitionMatrix().getRow(productChoice)) { for (auto const& successor : productModel->getProduct().getTransitionMatrix().getRow(productChoice)) {
uint64_t successorProductState = productModel->transformProductState(successor.getColumn(), successorEpochClass, memoryState); uint64_t successorProductState = productModel->transformProductState(successor.getColumn(), successorEpochClass, memoryState);
SolutionType const& successorSolution = getStateSolution(subSolutions, successorEpoch, successorProductState);
SolutionType const& successorSolution = getStateSolution(successorEpochSolution, successorProductState);
if (firstSuccessor) { if (firstSuccessor) {
choiceSolution = getScaledSolution(successorSolution, successor.getValue()); choiceSolution = getScaledSolution(successorSolution, successor.getValue());
firstSuccessor = false; firstSuccessor = false;
@ -580,14 +581,17 @@ namespace storm {
STORM_LOG_ASSERT((*epochSolution.productStateToSolutionVectorMap)[productState] < epochSolution.solutions.size(), "Requested solution for epoch " << epochManager.toString(epoch) << " at a state for which no solution was stored."); STORM_LOG_ASSERT((*epochSolution.productStateToSolutionVectorMap)[productState] < epochSolution.solutions.size(), "Requested solution for epoch " << epochManager.toString(epoch) << " at a state for which no solution was stored.");
return epochSolution.solutions[(*epochSolution.productStateToSolutionVectorMap)[productState]]; return epochSolution.solutions[(*epochSolution.productStateToSolutionVectorMap)[productState]];
} }
template<typename ValueType, bool SingleObjectiveMode> template<typename ValueType, bool SingleObjectiveMode>
typename MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::SolutionType const& MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::getStateSolution(std::map<Epoch, EpochSolution const*> const& solutions, Epoch const& epoch, uint64_t const& productState) {
typename MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::EpochSolution const& MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::getEpochSolution(std::map<Epoch, EpochSolution const*> const& solutions, Epoch const& epoch) {
auto epochSolutionIt = solutions.find(epoch); auto epochSolutionIt = solutions.find(epoch);
STORM_LOG_ASSERT(epochSolutionIt != solutions.end(), "Requested unexisting solution for epoch " << epochManager.toString(epoch) << "."); STORM_LOG_ASSERT(epochSolutionIt != solutions.end(), "Requested unexisting solution for epoch " << epochManager.toString(epoch) << ".");
auto const& epochSolution = *epochSolutionIt->second;
STORM_LOG_ASSERT(productState < epochSolution.productStateToSolutionVectorMap->size(), "Requested solution for epoch " << epochManager.toString(epoch) << " at an unexisting product state.");
STORM_LOG_ASSERT((*epochSolution.productStateToSolutionVectorMap)[productState] < epochSolution.solutions.size(), "Requested solution for epoch " << epochManager.toString(epoch) << " at a state for which no solution was stored.");
return *epochSolutionIt->second;
}
template<typename ValueType, bool SingleObjectiveMode>
typename MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::SolutionType const& MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::getStateSolution(EpochSolution const& epochSolution, uint64_t const& productState) {
STORM_LOG_ASSERT(productState < epochSolution.productStateToSolutionVectorMap->size(), "Requested solution at an unexisting product state.");
STORM_LOG_ASSERT((*epochSolution.productStateToSolutionVectorMap)[productState] < epochSolution.solutions.size(), "Requested solution for epoch at a state for which no solution was stored.");
return epochSolution.solutions[(*epochSolution.productStateToSolutionVectorMap)[productState]]; return epochSolution.solutions[(*epochSolution.productStateToSolutionVectorMap)[productState]];
} }

3
src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.h

@ -105,7 +105,8 @@ namespace storm {
std::vector<SolutionType> solutions; std::vector<SolutionType> solutions;
}; };
std::map<Epoch, EpochSolution> epochSolutions; std::map<Epoch, EpochSolution> epochSolutions;
SolutionType const& getStateSolution(std::map<Epoch, EpochSolution const*> const& solutions, Epoch const& epoch, uint64_t const& productState);
EpochSolution const& getEpochSolution(std::map<Epoch, EpochSolution const*> const& solutions, Epoch const& epoch);
SolutionType const& getStateSolution(EpochSolution const& epochSolution, uint64_t const& productState);
storm::models::sparse::Mdp<ValueType> const& model; storm::models::sparse::Mdp<ValueType> const& model;
std::vector<storm::modelchecker::multiobjective::Objective<ValueType>> objectives; std::vector<storm::modelchecker::multiobjective::Objective<ValueType>> objectives;

Loading…
Cancel
Save