Browse Source

fixed several minor bugs regarding the choicelabeling

tempestpy_adaptions
TimQu 8 years ago
parent
commit
e7bc5fdef9
  1. 6
      src/storm/builder/ChoiceInformationBuilder.cpp
  2. 2
      src/storm/builder/ChoiceInformationBuilder.h
  3. 8
      src/storm/builder/ExplicitModelBuilder.cpp
  4. 2
      src/storm/builder/ExplicitModelBuilder.h
  5. 2
      src/storm/cli/entrypoints.h
  6. 2
      src/storm/models/sparse/ItemLabeling.cpp
  7. 4
      src/storm/models/sparse/Model.cpp
  8. 8
      src/storm/models/sparse/StateLabeling.cpp
  9. 4
      src/storm/storage/BitVector.cpp

6
src/storm/builder/ChoiceInformationBuilder.cpp

@ -16,7 +16,10 @@ namespace storm {
dataOfOrigins.push_back(originData); dataOfOrigins.push_back(originData);
} }
storm::models::sparse::ChoiceLabeling ChoiceInformationBuilder::buildChoiceLabeling(uint_fast64_t totalNumberOfChoices) {
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); storm::models::sparse::ChoiceLabeling result(totalNumberOfChoices);
for (auto& label : labels) { for (auto& label : labels) {
label.second.resize(totalNumberOfChoices, false); label.second.resize(totalNumberOfChoices, false);
@ -24,6 +27,7 @@ namespace storm {
} }
return result; return result;
} }
}
std::vector<boost::any> ChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) { std::vector<boost::any> ChoiceInformationBuilder::buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices) {
dataOfOrigins.resize(totalNumberOfChoices); dataOfOrigins.resize(totalNumberOfChoices);

2
src/storm/builder/ChoiceInformationBuilder.h

@ -27,7 +27,7 @@ namespace storm {
void addOriginData(boost::any const& originData, uint_fast64_t choiceIndex); void addOriginData(boost::any const& originData, uint_fast64_t choiceIndex);
storm::models::sparse::ChoiceLabeling buildChoiceLabeling(uint_fast64_t totalNumberOfChoices);
boost::optional<storm::models::sparse::ChoiceLabeling> buildChoiceLabeling(uint_fast64_t totalNumberOfChoices);
std::vector<boost::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices); std::vector<boost::any> buildDataOfChoiceOrigins(uint_fast64_t totalNumberOfChoices);

8
src/storm/builder/ExplicitModelBuilder.cpp

@ -74,16 +74,16 @@ namespace storm {
std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>> resultModel; std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>> resultModel;
switch (generator->getModelType()) { switch (generator->getModelType()) {
case storm::generator::ModelType::DTMC: case storm::generator::ModelType::DTMC:
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Dtmc<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels) )); //, std::move(modelComponents.choiceLabeling)));
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Dtmc<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels), std::move(modelComponents.choiceLabeling)));
break; break;
case storm::generator::ModelType::CTMC: case storm::generator::ModelType::CTMC:
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Ctmc<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels) )); //, std::move(modelComponents.choiceLabeling)));
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Ctmc<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels), std::move(modelComponents.choiceLabeling)));
break; break;
case storm::generator::ModelType::MDP: case storm::generator::ModelType::MDP:
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Mdp<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels) )); //, std::move(modelComponents.choiceLabeling)));
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Mdp<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.rewardModels), std::move(modelComponents.choiceLabeling)));
break; break;
case storm::generator::ModelType::MA: case storm::generator::ModelType::MA:
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::MarkovAutomaton<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), *std::move(modelComponents.markovianStates), std::move(modelComponents.rewardModels) )); //, std::move(modelComponents.choiceLabeling)));
resultModel = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::MarkovAutomaton<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), *std::move(modelComponents.markovianStates), std::move(modelComponents.rewardModels), std::move(modelComponents.choiceLabeling)));
break; break;
default: default:
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Error while creating model: cannot handle this model type."); STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Error while creating model: cannot handle this model type.");

2
src/storm/builder/ExplicitModelBuilder.h

@ -65,7 +65,7 @@ namespace storm {
std::unordered_map<std::string, storm::models::sparse::StandardRewardModel<typename RewardModelType::ValueType>> rewardModels; std::unordered_map<std::string, storm::models::sparse::StandardRewardModel<typename RewardModelType::ValueType>> rewardModels;
// A vector that stores a labeling for each choice. // A vector that stores a labeling for each choice.
storm::models::sparse::ChoiceLabeling choiceLabeling;
boost::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
// A vector that stores which states are markovian. // A vector that stores which states are markovian.
boost::optional<storm::storage::BitVector> markovianStates; boost::optional<storm::storage::BitVector> markovianStates;

2
src/storm/cli/entrypoints.h

@ -325,7 +325,7 @@ namespace storm {
markovModel->printModelInformationToStream(std::cout); markovModel->printModelInformationToStream(std::cout);
// Preprocess the model. // Preprocess the model.
STORM_LOG_WARN_COND(builderResult.hasStateValuations() || builderResult.hasChoiceOrigins(), "state valuations and choice origins might be invalidated if the model is preprocessed..."); // TODO: check this more carefully.
STORM_LOG_WARN_COND(!builderResult.hasStateValuations() && !builderResult.hasChoiceOrigins(), "State valuations and Choice origins might be invalidated if the model is preprocessed..."); // TODO: check this more carefully.
BRANCH_ON_SPARSE_MODELTYPE(markovModel, markovModel, ValueType, preprocessModel, formulas); BRANCH_ON_SPARSE_MODELTYPE(markovModel, markovModel, ValueType, preprocessModel, formulas);
std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel = markovModel->template as<storm::models::sparse::Model<ValueType>>(); std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel = markovModel->template as<storm::models::sparse::Model<ValueType>>();

2
src/storm/models/sparse/ItemLabeling.cpp

@ -121,7 +121,7 @@ namespace storm {
} }
void ItemLabeling::printLabelingInformationToStream(std::ostream& out) const { void ItemLabeling::printLabelingInformationToStream(std::ostream& out) const {
out << "Labels: \t" << this->getNumberOfLabels() << std::endl;
out << this->getNumberOfLabels() << " labels" << std::endl;
for (auto const& labelIndexPair : this->nameToLabelingIndexMap) { for (auto const& labelIndexPair : this->nameToLabelingIndexMap) {
out << " * " << labelIndexPair.first << " -> " << this->labelings[labelIndexPair.second].getNumberOfSetBits() << " item(s)" << std::endl; out << " * " << labelIndexPair.first << " -> " << this->labelings[labelIndexPair.second].getNumberOfSetBits() << " item(s)" << std::endl;
} }

4
src/storm/models/sparse/Model.cpp

@ -206,11 +206,13 @@ namespace storm {
template<typename ValueType, typename RewardModelType> template<typename ValueType, typename RewardModelType>
void Model<ValueType, RewardModelType>::printModelInformationFooterToStream(std::ostream& out) const { void Model<ValueType, RewardModelType>::printModelInformationFooterToStream(std::ostream& out) const {
this->printRewardModelsInformationToStream(out); this->printRewardModelsInformationToStream(out);
out << "State Labels: \t";
this->getStateLabeling().printLabelingInformationToStream(out); this->getStateLabeling().printLabelingInformationToStream(out);
out << "Choice Labels: \t";
if (this->hasChoiceLabeling()) { if (this->hasChoiceLabeling()) {
this->getChoiceLabeling().printLabelingInformationToStream(out); this->getChoiceLabeling().printLabelingInformationToStream(out);
} else { } else {
out << "Choice Labels: \tnone";
out << "none" << std::endl;
} }
out << "-------------------------------------------------------------- " << std::endl; out << "-------------------------------------------------------------- " << std::endl;
} }

8
src/storm/models/sparse/StateLabeling.cpp

@ -19,7 +19,6 @@ namespace storm {
// Intentionally left empty. // Intentionally left empty.
} }
bool StateLabeling::operator==(StateLabeling const& other) const { bool StateLabeling::operator==(StateLabeling const& other) const {
if (itemCount != other.itemCount) { if (itemCount != other.itemCount) {
return false; return false;
@ -38,19 +37,14 @@ namespace storm {
return true; return true;
} }
StateLabeling StateLabeling::getSubLabeling(storm::storage::BitVector const& states) const { StateLabeling StateLabeling::getSubLabeling(storm::storage::BitVector const& states) const {
return StateLabeling(ItemLabeling::getSubLabeling(states)); return StateLabeling(ItemLabeling::getSubLabeling(states));
} }
std::set<std::string> StateLabeling::getLabelsOfState(storm::storage::sparse::state_type state) const { std::set<std::string> StateLabeling::getLabelsOfState(storm::storage::sparse::state_type state) const {
return ItemLabeling::getLabelsOfItem(state); return ItemLabeling::getLabelsOfItem(state);
} }
void StateLabeling::addLabelToState(std::string const& label, storm::storage::sparse::state_type state) { void StateLabeling::addLabelToState(std::string const& label, storm::storage::sparse::state_type state) {
return ItemLabeling::addLabelToItem(label, state); return ItemLabeling::addLabelToItem(label, state);
} }
@ -59,7 +53,6 @@ namespace storm {
return ItemLabeling::getItemHasLabel(label, state); return ItemLabeling::getItemHasLabel(label, state);
} }
storm::storage::BitVector const& StateLabeling::getStates(std::string const& label) const { storm::storage::BitVector const& StateLabeling::getStates(std::string const& label) const {
return ItemLabeling::getItems(label); return ItemLabeling::getItems(label);
} }
@ -74,7 +67,6 @@ namespace storm {
std::ostream& operator<<(std::ostream& out, StateLabeling const& labeling) { std::ostream& operator<<(std::ostream& out, StateLabeling const& labeling) {
out << "State ";
labeling.printLabelingInformationToStream(out); labeling.printLabelingInformationToStream(out);
return out; return out;
} }

4
src/storm/storage/BitVector.cpp

@ -254,7 +254,9 @@ namespace storm {
void BitVector::grow(uint_fast64_t minimumLength, bool init) { void BitVector::grow(uint_fast64_t minimumLength, bool init) {
if (minimumLength > bitCount) { if (minimumLength > bitCount) {
uint_fast64_t newLength = bitCount;
// We double the bitcount as long as it is less then the minimum length.
uint_fast64_t newLength = std::max(64ull, bitCount);
// Note that newLength has to be initialized with a non-zero number.
while (newLength < minimumLength) { while (newLength < minimumLength) {
newLength = newLength << 1; newLength = newLength << 1;
} }

Loading…
Cancel
Save