Browse Source
Polished ExplicitModelBuilder:
Polished ExplicitModelBuilder:
* ChoiceInformationBuilder renamed to StateAndChoiceInformationBuilder, now also keeping track of state-based information (StateValuations, MarkovianStates, statePlayerIndications) * ModelComponents now consider statePlayerIndications and PlayerNamesToIndices separatelymain
12 changed files with 282 additions and 163 deletions
-
38src/storm/builder/ChoiceInformationBuilder.cpp
-
40src/storm/builder/ChoiceInformationBuilder.h
-
125src/storm/builder/ExplicitModelBuilder.cpp
-
8src/storm/builder/ExplicitModelBuilder.h
-
121src/storm/builder/StateAndChoiceInformationBuilder.cpp
-
75src/storm/builder/StateAndChoiceInformationBuilder.h
-
1src/storm/generator/Choice.cpp
-
5src/storm/generator/NextStateGenerator.cpp
-
3src/storm/generator/NextStateGenerator.h
-
5src/storm/generator/PrismNextStateGenerator.cpp
-
4src/storm/generator/PrismNextStateGenerator.h
-
20src/storm/storage/sparse/ModelComponents.h
@ -1,38 +0,0 @@ |
|||
#include "storm/builder/ChoiceInformationBuilder.h"
|
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
void ChoiceInformationBuilder::addLabel(std::string const& label, uint_fast64_t choiceIndex) { |
|||
storm::storage::BitVector& labeledChoices = labels[label]; |
|||
labeledChoices.grow(choiceIndex + 1); |
|||
labeledChoices.set(choiceIndex, true); |
|||
} |
|||
|
|||
void ChoiceInformationBuilder::addOriginData(boost::any const& originData, uint_fast64_t choiceIndex) { |
|||
if (dataOfOrigins.size() != choiceIndex) { |
|||
dataOfOrigins.resize(choiceIndex); |
|||
} |
|||
dataOfOrigins.push_back(originData); |
|||
} |
|||
|
|||
boost::optional<storm::models::sparse::ChoiceLabeling> ChoiceInformationBuilder::buildChoiceLabeling(uint_fast64_t totalNumberOfChoices) { |
|||
if (labels.empty()) { |
|||
return boost::none; |
|||
} else { |
|||
storm::models::sparse::ChoiceLabeling result(totalNumberOfChoices); |
|||
for (auto& label : labels) { |
|||
label.second.resize(totalNumberOfChoices, false); |
|||
result.addLabel(label.first, std::move(label.second)); |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
std::vector<boost::any> ChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) { |
|||
dataOfOrigins.resize(totalNumberOfChoices); |
|||
return std::move(dataOfOrigins); |
|||
} |
|||
|
|||
} |
|||
} |
@ -1,40 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <memory> |
|||
#include <string> |
|||
#include <unordered_map> |
|||
#include <vector> |
|||
#include <boost/any.hpp> |
|||
|
|||
#include "storm/models/sparse/ChoiceLabeling.h" |
|||
#include "storm/storage/BitVector.h" |
|||
#include "storm/storage/sparse/PrismChoiceOrigins.h" |
|||
#include "storm/storage/prism/Program.h" |
|||
|
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
/*! |
|||
* This class collects information regarding the choices |
|||
*/ |
|||
class ChoiceInformationBuilder { |
|||
public: |
|||
|
|||
ChoiceInformationBuilder() = default; |
|||
|
|||
void addLabel(std::string const& label, uint_fast64_t choiceIndex); |
|||
|
|||
void addOriginData(boost::any const& originData, uint_fast64_t choiceIndex); |
|||
|
|||
boost::optional<storm::models::sparse::ChoiceLabeling> buildChoiceLabeling(uint_fast64_t totalNumberOfChoices); |
|||
|
|||
std::vector<boost::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices); |
|||
|
|||
private: |
|||
std::unordered_map<std::string, storm::storage::BitVector> labels; |
|||
std::vector<boost::any> dataOfOrigins; |
|||
}; |
|||
} |
|||
} |
|||
|
@ -0,0 +1,121 @@ |
|||
#include "storm/builder/StateAndChoiceInformationBuilder.h"
|
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
StateAndChoiceInformationBuilder::StateAndChoiceInformationBuilder() : _buildChoiceLabels(false), _buildChoiceOrigins(false), _buildStatePlayerIndications(false), _buildMarkovianStates(false), _buildStateValuations(false) { |
|||
// Intentionally left empty
|
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::setBuildChoiceLabels(bool value) { |
|||
_buildChoiceLabels = value; |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::isBuildChoiceLabels() const { |
|||
return _buildChoiceLabels; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::addChoiceLabel(std::string const& label, uint_fast64_t choiceIndex) { |
|||
STORM_LOG_ASSERT(_buildChoiceLabels, "Building ChoiceLabels was not enabled."); |
|||
storm::storage::BitVector& labeledChoices = _choiceLabels[label]; |
|||
labeledChoices.grow(choiceIndex + 1, false); |
|||
labeledChoices.set(choiceIndex, true); |
|||
} |
|||
|
|||
storm::models::sparse::ChoiceLabeling StateAndChoiceInformationBuilder::buildChoiceLabeling(uint_fast64_t totalNumberOfChoices) { |
|||
storm::models::sparse::ChoiceLabeling result(totalNumberOfChoices); |
|||
for (auto& label : _choiceLabels) { |
|||
label.second.resize(totalNumberOfChoices, false); |
|||
result.addLabel(label.first, std::move(label.second)); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::setBuildChoiceOrigins(bool value) { |
|||
_buildChoiceOrigins = value; |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::isBuildChoiceOrigins() const { |
|||
return _buildChoiceOrigins; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::addChoiceOriginData(boost::any const& originData, uint_fast64_t choiceIndex) { |
|||
STORM_LOG_ASSERT(_buildChoiceOrigins, "Building ChoiceOrigins was not enabled."); |
|||
STORM_LOG_ASSERT(_dataOfChoiceOrigins.size() <= choiceIndex, "Unexpected choice index. Apparently, the choice indices are provided in an incorrect order."); |
|||
if (_dataOfChoiceOrigins.size() != choiceIndex) { |
|||
_dataOfChoiceOrigins.resize(choiceIndex); |
|||
} |
|||
_dataOfChoiceOrigins.push_back(originData); |
|||
} |
|||
|
|||
std::vector<boost::any> StateAndChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) { |
|||
STORM_LOG_ASSERT(_buildChoiceOrigins, "Building ChoiceOrigins was not enabled."); |
|||
_dataOfChoiceOrigins.resize(totalNumberOfChoices); |
|||
_dataOfChoiceOrigins.shrink_to_fit(); |
|||
return std::move(_dataOfChoiceOrigins); |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::setBuildStatePlayerIndications(bool value) { |
|||
_buildStatePlayerIndications = value; |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::isBuildStatePlayerIndications() const { |
|||
return _buildStatePlayerIndications; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::addStatePlayerIndication(storm::storage::PlayerIndex player, uint_fast64_t stateIndex) { |
|||
STORM_LOG_ASSERT(_buildStatePlayerIndications, "Building StatePlayerIndications was not enabled."); |
|||
STORM_LOG_ASSERT(_statePlayerIndications.size() <= stateIndex, "Unexpected choice index. Apparently, the choice indices are provided in an incorrect order."); |
|||
if (_statePlayerIndications.size() != stateIndex) { |
|||
_statePlayerIndications.resize(stateIndex, storm::storage::INVALID_PLAYER_INDEX); |
|||
} |
|||
_statePlayerIndications.push_back(player); |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::hasStatePlayerIndicationBeenSet(storm::storage::PlayerIndex expectedPlayer, uint_fast64_t stateIndex) const { |
|||
STORM_LOG_ASSERT(_buildStatePlayerIndications, "Building StatePlayerIndications was not enabled."); |
|||
return (stateIndex < _statePlayerIndications.size()) && (_statePlayerIndications[stateIndex] == expectedPlayer); |
|||
} |
|||
|
|||
std::vector<storm::storage::PlayerIndex> StateAndChoiceInformationBuilder::buildStatePlayerIndications(uint_fast64_t totalNumberOfStates) { |
|||
STORM_LOG_ASSERT(_buildStatePlayerIndications, "Building StatePlayerIndications was not enabled."); |
|||
_statePlayerIndications.resize(totalNumberOfStates, storm::storage::INVALID_PLAYER_INDEX); |
|||
_statePlayerIndications.shrink_to_fit(); |
|||
return std::move(_statePlayerIndications); |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::setBuildMarkovianStates(bool value) { |
|||
_buildMarkovianStates = value; |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::isBuildMarkovianStates() const { |
|||
return _buildMarkovianStates; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::addMarkovianState(uint_fast64_t markovianStateIndex) { |
|||
STORM_LOG_ASSERT(_buildMarkovianStates, "Building MarkovianStates was not enabled."); |
|||
_markovianStates.grow(markovianStateIndex + 1, false); |
|||
_markovianStates.set(markovianStateIndex, true); |
|||
} |
|||
|
|||
storm::storage::BitVector StateAndChoiceInformationBuilder::buildMarkovianStates(uint_fast64_t totalNumberOfStates) { |
|||
STORM_LOG_ASSERT(_buildMarkovianStates, "Building MarkovianStates was not enabled."); |
|||
_markovianStates.resize(totalNumberOfStates, false); |
|||
return _markovianStates; |
|||
} |
|||
|
|||
void StateAndChoiceInformationBuilder::setBuildStateValuations(bool value) { |
|||
_buildStateValuations = value; |
|||
} |
|||
|
|||
bool StateAndChoiceInformationBuilder::isBuildStateValuations() const { |
|||
return _buildStateValuations; |
|||
} |
|||
|
|||
storm::storage::sparse::StateValuationsBuilder& StateAndChoiceInformationBuilder::stateValuationsBuilder() { |
|||
STORM_LOG_ASSERT(_buildStateValuations, "Building StateValuations was not enabled."); |
|||
return _stateValuationsBuilder; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
#pragma once |
|||
|
|||
#include <memory> |
|||
#include <string> |
|||
#include <unordered_map> |
|||
#include <vector> |
|||
#include <boost/any.hpp> |
|||
|
|||
#include "storm/models/sparse/ChoiceLabeling.h" |
|||
#include "storm/storage/BitVector.h" |
|||
#include "storm/storage/PlayerIndex.h" |
|||
#include "storm/storage/sparse/PrismChoiceOrigins.h" |
|||
#include "storm/storage/prism/Program.h" |
|||
#include "storm/storage/sparse/StateValuations.h" |
|||
|
|||
|
|||
namespace storm { |
|||
namespace builder { |
|||
|
|||
/*! |
|||
* This class collects information regarding the states and choices during model building. |
|||
* It is expected that the provided indices are in ascending order |
|||
*/ |
|||
class StateAndChoiceInformationBuilder { |
|||
public: |
|||
|
|||
StateAndChoiceInformationBuilder(); |
|||
|
|||
void setBuildChoiceLabels(bool value); |
|||
bool isBuildChoiceLabels() const; |
|||
void addChoiceLabel(std::string const& label, uint_fast64_t choiceIndex); |
|||
storm::models::sparse::ChoiceLabeling buildChoiceLabeling(uint_fast64_t totalNumberOfChoices); |
|||
|
|||
void setBuildChoiceOrigins(bool value); |
|||
bool isBuildChoiceOrigins() const; |
|||
void addChoiceOriginData(boost::any const& originData, uint_fast64_t choiceIndex); |
|||
std::vector<boost::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices); |
|||
|
|||
void setBuildStatePlayerIndications(bool value); |
|||
bool isBuildStatePlayerIndications() const; |
|||
/*! |
|||
* @note: skipped choiceIndices get assigned the invalid player index. |
|||
*/ |
|||
void addStatePlayerIndication(storm::storage::PlayerIndex player, uint_fast64_t stateIndex); |
|||
bool hasStatePlayerIndicationBeenSet(storm::storage::PlayerIndex expectedPlayer, uint_fast64_t stateIndex) const; |
|||
std::vector<storm::storage::PlayerIndex> buildStatePlayerIndications(uint_fast64_t totalNumberOfStates); |
|||
|
|||
void setBuildMarkovianStates(bool value); |
|||
bool isBuildMarkovianStates() const; |
|||
void addMarkovianState(uint_fast64_t markovianStateIndex); |
|||
storm::storage::BitVector buildMarkovianStates(uint_fast64_t totalNumberOfStates); |
|||
|
|||
void setBuildStateValuations(bool value); |
|||
bool isBuildStateValuations() const; |
|||
storm::storage::sparse::StateValuationsBuilder& stateValuationsBuilder(); |
|||
|
|||
private: |
|||
bool _buildChoiceLabels; |
|||
std::unordered_map<std::string, storm::storage::BitVector> _choiceLabels; |
|||
|
|||
bool _buildChoiceOrigins; |
|||
std::vector<boost::any> _dataOfChoiceOrigins; |
|||
|
|||
bool _buildStatePlayerIndications; |
|||
std::vector<storm::storage::PlayerIndex> _statePlayerIndications; |
|||
|
|||
bool _buildMarkovianStates; |
|||
storm::storage::BitVector _markovianStates; |
|||
|
|||
bool _buildStateValuations; |
|||
storm::storage::sparse::StateValuationsBuilder _stateValuationsBuilder; |
|||
}; |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue