|
@ -120,7 +120,7 @@ namespace storm { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
template <typename ValueType, typename RewardModelType, typename StateType> |
|
|
void ExplicitModelBuilder<ValueType, RewardModelType, StateType>::buildMatrices(storm::storage::SparseMatrixBuilder<ValueType>& transitionMatrixBuilder, std::vector<RewardModelBuilder<typename RewardModelType::ValueType>>& rewardModelBuilders, ChoiceInformationBuilder& choiceInformationBuilder, boost::optional<storm::storage::BitVector>& markovianStates, boost::optional<storm::storage::sparse::StateValuationsBuilder>& stateValuationsBuilder) { |
|
|
|
|
|
|
|
|
void ExplicitModelBuilder<ValueType, RewardModelType, StateType>::buildMatrices(storm::storage::SparseMatrixBuilder<ValueType>& transitionMatrixBuilder, std::vector<RewardModelBuilder<typename RewardModelType::ValueType>>& rewardModelBuilders, ChoiceInformationBuilder& choiceInformationBuilder, boost::optional<storm::storage::BitVector>& markovianStates, boost::optional<std::vector<uint_fast32_t>> playerActionIndices, boost::optional<storm::storage::sparse::StateValuationsBuilder>& stateValuationsBuilder) { |
|
|
|
|
|
|
|
|
// Create markovian states bit vector, if required.
|
|
|
// Create markovian states bit vector, if required.
|
|
|
if (generator->getModelType() == storm::generator::ModelType::MA) { |
|
|
if (generator->getModelType() == storm::generator::ModelType::MA) { |
|
@ -128,6 +128,12 @@ namespace storm { |
|
|
markovianStates = storm::storage::BitVector(1000); |
|
|
markovianStates = storm::storage::BitVector(1000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create the player indices vector, if required.
|
|
|
|
|
|
if (generator->getModelType() == storm::generator::ModelType::SMG) { |
|
|
|
|
|
playerActionIndices = std::vector<uint_fast32_t>{}; |
|
|
|
|
|
playerActionIndices.get().reserve(1000); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Create a callback for the next-state generator to enable it to request the index of states.
|
|
|
// Create a callback for the next-state generator to enable it to request the index of states.
|
|
|
std::function<StateType (CompressedState const&)> stateToIdCallback = std::bind(&ExplicitModelBuilder<ValueType, RewardModelType, StateType>::getOrAddStateIndex, this, std::placeholders::_1); |
|
|
std::function<StateType (CompressedState const&)> stateToIdCallback = std::bind(&ExplicitModelBuilder<ValueType, RewardModelType, StateType>::getOrAddStateIndex, this, std::placeholders::_1); |
|
|
|
|
|
|
|
@ -203,6 +209,11 @@ namespace storm { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (playerActionIndices) { |
|
|
|
|
|
// TODO change this to storm::utility::infinity<ValueType>() ?
|
|
|
|
|
|
playerActionIndices.get().push_back(-1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
++currentRow; |
|
|
++currentRow; |
|
|
++currentRowGroup; |
|
|
++currentRowGroup; |
|
|
} else { |
|
|
} else { |
|
@ -257,6 +268,10 @@ namespace storm { |
|
|
} |
|
|
} |
|
|
++currentRow; |
|
|
++currentRow; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (playerActionIndices) { |
|
|
|
|
|
playerActionIndices.get().push_back(behavior.getChoices().at(0).getPlayerIndex()); |
|
|
|
|
|
} |
|
|
++currentRowGroup; |
|
|
++currentRowGroup; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -288,6 +303,10 @@ namespace storm { |
|
|
markovianStates->resize(currentRowGroup, false); |
|
|
markovianStates->resize(currentRowGroup, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (playerActionIndices) { |
|
|
|
|
|
playerActionIndices.get().shrink_to_fit(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// If the exploration order was not breadth-first, we need to fix the entries in the matrix according to
|
|
|
// If the exploration order was not breadth-first, we need to fix the entries in the matrix according to
|
|
|
// (reversed) mapping of row groups to indices.
|
|
|
// (reversed) mapping of row groups to indices.
|
|
|
if (options.explorationOrder != ExplorationOrder::Bfs) { |
|
|
if (options.explorationOrder != ExplorationOrder::Bfs) { |
|
@ -331,6 +350,7 @@ namespace storm { |
|
|
} |
|
|
} |
|
|
ChoiceInformationBuilder choiceInformationBuilder; |
|
|
ChoiceInformationBuilder choiceInformationBuilder; |
|
|
boost::optional<storm::storage::BitVector> markovianStates; |
|
|
boost::optional<storm::storage::BitVector> markovianStates; |
|
|
|
|
|
boost::optional<std::vector<uint_fast32_t>> playerActionIndices; |
|
|
|
|
|
|
|
|
// If we need to build state valuations, initialize them now.
|
|
|
// If we need to build state valuations, initialize them now.
|
|
|
boost::optional<storm::storage::sparse::StateValuationsBuilder> stateValuationsBuilder; |
|
|
boost::optional<storm::storage::sparse::StateValuationsBuilder> stateValuationsBuilder; |
|
@ -338,10 +358,10 @@ namespace storm { |
|
|
stateValuationsBuilder = generator->initializeStateValuationsBuilder(); |
|
|
stateValuationsBuilder = generator->initializeStateValuationsBuilder(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
buildMatrices(transitionMatrixBuilder, rewardModelBuilders, choiceInformationBuilder, markovianStates, stateValuationsBuilder); |
|
|
|
|
|
|
|
|
buildMatrices(transitionMatrixBuilder, rewardModelBuilders, choiceInformationBuilder, markovianStates, playerActionIndices, stateValuationsBuilder); |
|
|
|
|
|
|
|
|
// Initialize the model components with the obtained information.
|
|
|
// Initialize the model components with the obtained information.
|
|
|
storm::storage::sparse::ModelComponents<ValueType, RewardModelType> modelComponents(transitionMatrixBuilder.build(0, transitionMatrixBuilder.getCurrentRowGroupCount()), buildStateLabeling(), std::unordered_map<std::string, RewardModelType>(), !generator->isDiscreteTimeModel(), std::move(markovianStates)); |
|
|
|
|
|
|
|
|
storm::storage::sparse::ModelComponents<ValueType, RewardModelType> modelComponents(transitionMatrixBuilder.build(0, transitionMatrixBuilder.getCurrentRowGroupCount()), buildStateLabeling(), std::unordered_map<std::string, RewardModelType>(), !generator->isDiscreteTimeModel(), std::move(markovianStates), /* player1Matrix = */ boost::none, std::move(playerActionIndices)); |
|
|
|
|
|
|
|
|
// Now finalize all reward models.
|
|
|
// Now finalize all reward models.
|
|
|
for (auto& rewardModelBuilder : rewardModelBuilders) { |
|
|
for (auto& rewardModelBuilder : rewardModelBuilders) { |
|
|