Browse Source

SolutionType is now a single vector instead of a struct

tempestpy_adaptions
TimQu 7 years ago
parent
commit
9735ff98d0
  1. 16
      src/storm/modelchecker/multiobjective/pcaa/SparseMdpRewardBoundedPcaaWeightVectorChecker.cpp
  2. 15
      src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.cpp
  3. 7
      src/storm/modelchecker/multiobjective/rewardbounded/MultiDimensionalRewardUnfolding.h

16
src/storm/modelchecker/multiobjective/pcaa/SparseMdpRewardBoundedPcaaWeightVectorChecker.cpp

@ -37,8 +37,10 @@ namespace storm {
auto solution = rewardUnfolding.getInitialStateResult(initEpoch);
// Todo: we currently assume precise results...
underApproxResult = solution.objectiveValues;
overApproxResult = solution.objectiveValues;
auto solutionIt = solution.begin();
++solutionIt;
underApproxResult = std::vector<ValueType>(solutionIt, solution.end());
overApproxResult = underApproxResult;
}
@ -62,7 +64,7 @@ namespace storm {
}
auto stepSolutionIt = epochModel.stepSolutions.begin();
for (auto const& choice : epochModel.stepChoices) {
b[choice] += stepSolutionIt->weightedValue;
b[choice] += stepSolutionIt->front();
++stepSolutionIt;
}
@ -79,8 +81,10 @@ namespace storm {
swMinMaxSolving.stop();
swEqBuilding.start();
auto resultIt = result.begin();
uint64_t solSize = this->objectives.size() + 1;
for (auto const& state : epochModel.inStates) {
resultIt->weightedValue = x[state];
resultIt->reserve(solSize);
resultIt->push_back(x[state]);
++resultIt;
}
@ -103,7 +107,7 @@ namespace storm {
b[state] = storm::utility::zero<ValueType>();
}
if (epochModel.stepChoices.get(choice)) {
b[state] += epochModel.stepSolutions[epochModel.stepChoices.getNumberOfSetBitsBeforeIndex(choice)].objectiveValues[objIndex];
b[state] += epochModel.stepSolutions[epochModel.stepChoices.getNumberOfSetBitsBeforeIndex(choice)][objIndex + 1];
}
}
swEqBuilding.stop();
@ -113,7 +117,7 @@ namespace storm {
swEqBuilding.start();
auto resultIt = result.begin();
for (auto const& state : epochModel.inStates) {
resultIt->objectiveValues.push_back(x[state]);
resultIt->push_back(x[state]);
++resultIt;
}
}

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

@ -28,6 +28,7 @@ namespace storm {
template<typename ValueType, bool SingleObjectiveMode>
void MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::initialize() {
swInit.start();
STORM_LOG_ASSERT(!SingleObjectiveMode || (this->objectives.size() == 1), "Enabled single objective mode but there are multiple objectives.");
std::vector<std::vector<uint64_t>> epochSteps;
initializeObjectives(epochSteps);
initializePossibleEpochSteps(epochSteps);
@ -415,17 +416,16 @@ namespace storm {
template<typename ValueType, bool SingleObjectiveMode>
template<bool SO, typename std::enable_if<SO, int>::type>
typename MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::SolutionType MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::getScaledSolution(SolutionType const& solution, ValueType const& scalingFactor) const {
//return solution * scalingFactor;
return solution * scalingFactor;
}
template<typename ValueType, bool SingleObjectiveMode>
template<bool SO, typename std::enable_if<!SO, int>::type>
typename MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::SolutionType MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::getScaledSolution(SolutionType const& solution, ValueType const& scalingFactor) const {
SolutionType res;
res.weightedValue = solution.weightedValue * scalingFactor;
res.objectiveValues.reserve(solution.objectiveValues.size());
for (auto const& sol : solution.objectiveValues) {
res.objectiveValues.push_back(sol * scalingFactor);
res.reserve(solution.size());
for (auto const& sol : solution) {
res.push_back(sol * scalingFactor);
}
return res;
}
@ -433,14 +433,13 @@ namespace storm {
template<typename ValueType, bool SingleObjectiveMode>
template<bool SO, typename std::enable_if<SO, int>::type>
void MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::addScaledSolution(SolutionType& solution, SolutionType const& solutionToAdd, ValueType const& scalingFactor) const {
// solution += solutionToAdd * scalingFactor;
solution += solutionToAdd * scalingFactor;
}
template<typename ValueType, bool SingleObjectiveMode>
template<bool SO, typename std::enable_if<!SO, int>::type>
void MultiDimensionalRewardUnfolding<ValueType, SingleObjectiveMode>::addScaledSolution(SolutionType& solution, SolutionType const& solutionToAdd, ValueType const& scalingFactor) const {
solution.weightedValue += solutionToAdd.weightedValue * scalingFactor;
storm::utility::vector::addScaledVector(solution.objectiveValues, solutionToAdd.objectiveValues, scalingFactor);
storm::utility::vector::addScaledVector(solution, solutionToAdd, scalingFactor);
}
template<typename ValueType, bool SingleObjectiveMode>

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

@ -25,12 +25,7 @@ namespace storm {
typedef std::vector<int64_t> Epoch; // The number of reward steps that are "left" for each dimension
typedef uint64_t EpochClass; // Collection of epochs that consider the same epoch model
// typedef typename std::conditional<singleObjectiveMode, ValueType, std::vector<ValueType>>::type; SolutionType
struct SolutionType {
ValueType weightedValue;
std::vector<ValueType> objectiveValues;
};
typedef typename std::conditional<SingleObjectiveMode, ValueType, std::vector<ValueType>>::type SolutionType;
struct EpochModel {
storm::storage::SparseMatrix<ValueType> epochMatrix;

Loading…
Cancel
Save