Browse Source

reworked getUniqueRewardModel a little

Former-commit-id: b0a3677c1a [formerly a2124b3363]
Former-commit-id: c76a56a168
tempestpy_adaptions
dehnert 8 years ago
parent
commit
29f0f66689
  1. 10
      src/modelchecker/region/ApproximationModel.cpp
  2. 4
      src/modelchecker/region/SamplingModel.cpp
  3. 4
      src/modelchecker/region/SparseDtmcRegionModelChecker.cpp
  4. 10
      src/models/sparse/Model.cpp
  5. 8
      src/models/sparse/Model.h
  6. 14
      src/models/symbolic/Model.cpp
  7. 11
      src/models/symbolic/Model.h
  8. 2
      src/parser/ExpressionParser.cpp
  9. 4
      src/storage/bisimulation/BisimulationDecomposition.cpp
  10. 6
      src/storage/bisimulation/DeterministicModelBisimulationDecomposition.cpp
  11. 8
      src/storage/bisimulation/NondeterministicModelBisimulationDecomposition.cpp

10
src/modelchecker/region/ApproximationModel.cpp

@ -33,7 +33,7 @@ namespace storm {
this->computeRewards=true;
STORM_LOG_THROW(this->typeOfParametricModel==storm::models::ModelType::Dtmc, storm::exceptions::InvalidArgumentException, "Approximation with rewards is only implemented for Dtmcs");
STORM_LOG_THROW(parametricModel.hasUniqueRewardModel(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the approximation model should be unique");
STORM_LOG_THROW(parametricModel.getUniqueRewardModel()->second.hasOnlyStateRewards(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the approximation model should have state rewards only");
STORM_LOG_THROW(parametricModel.getUniqueRewardModel().hasOnlyStateRewards(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the approximation model should have state rewards only");
} else {
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Invalid formula: " << formula << ". Approximation model only supports eventually or reachability reward formulae.");
}
@ -211,8 +211,8 @@ namespace storm {
ConstantType dummyNonZeroValue = storm::utility::one<ConstantType>();
auto vectorIt = this->vectorData.vector.begin();
for(auto oldState : this->maybeStates){
if(storm::utility::isConstant(parametricModel.getUniqueRewardModel()->second.getStateRewardVector()[oldState])){
ConstantType reward = storm::utility::region::convertNumber<ConstantType>(storm::utility::region::getConstantPart(parametricModel.getUniqueRewardModel()->second.getStateRewardVector()[oldState]));
if(storm::utility::isConstant(parametricModel.getUniqueRewardModel().getStateRewardVector()[oldState])){
ConstantType reward = storm::utility::region::convertNumber<ConstantType>(storm::utility::region::getConstantPart(parametricModel.getUniqueRewardModel().getStateRewardVector()[oldState]));
//Add one of these entries for every row in the row group of oldState
for(auto matrixRow=this->matrixData.matrix.getRowGroupIndices()[oldState]; matrixRow<this->matrixData.matrix.getRowGroupIndices()[oldState+1]; ++matrixRow){
*vectorIt = reward;
@ -220,7 +220,7 @@ namespace storm {
}
} else {
std::set<VariableType> occurringRewVariables;
storm::utility::region::gatherOccurringVariables(parametricModel.getUniqueRewardModel()->second.getStateRewardVector()[oldState], occurringRewVariables);
storm::utility::region::gatherOccurringVariables(parametricModel.getUniqueRewardModel().getStateRewardVector()[oldState], occurringRewVariables);
// For each row in the row group of oldState, we get the corresponding substitution and insert the FunctionSubstitution
for(auto matrixRow=this->matrixData.matrix.getRowGroupIndices()[oldState]; matrixRow<this->matrixData.matrix.getRowGroupIndices()[oldState+1]; ++matrixRow){
//Extend the substitution for the probabilities with the reward parameters
@ -230,7 +230,7 @@ namespace storm {
substitution.insert(typename std::map<VariableType, RegionBoundary>::value_type(rewardVar, RegionBoundary::UNSPECIFIED));
}
// insert the FunctionSubstitution
auto functionsIt = this->funcSubData.functions.insert(FunctionEntry(FunctionSubstitution(parametricModel.getUniqueRewardModel()->second.getStateRewardVector()[oldState], this->matrixData.rowSubstitutions[matrixRow]), dummyNonZeroValue)).first;
auto functionsIt = this->funcSubData.functions.insert(FunctionEntry(FunctionSubstitution(parametricModel.getUniqueRewardModel().getStateRewardVector()[oldState], this->matrixData.rowSubstitutions[matrixRow]), dummyNonZeroValue)).first;
//insert assignment and dummy data
this->vectorData.assignment.emplace_back(vectorIt, functionsIt->second);
*vectorIt = dummyNonZeroValue;

4
src/modelchecker/region/SamplingModel.cpp

@ -43,7 +43,7 @@ namespace storm {
this->computeRewards=true;
STORM_LOG_THROW(this->typeOfParametricModel==storm::models::ModelType::Dtmc, storm::exceptions::InvalidArgumentException, "Sampling with rewards is only implemented for Dtmcs");
STORM_LOG_THROW(parametricModel.hasUniqueRewardModel(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the sampling model should be unique");
STORM_LOG_THROW(parametricModel.getUniqueRewardModel()->second.hasOnlyStateRewards(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the sampling model should have state rewards only");
STORM_LOG_THROW(parametricModel.getUniqueRewardModel().hasOnlyStateRewards(), storm::exceptions::InvalidArgumentException, "The rewardmodel of the sampling model should have state rewards only");
STORM_LOG_THROW(formula->getSubformula().isEventuallyFormula(), storm::exceptions::InvalidArgumentException, "The subformula should be a reachabilityreward formula");
STORM_LOG_THROW(formula->getSubformula().asEventuallyFormula().getSubformula().isInFragment(storm::logic::propositional()), storm::exceptions::InvalidArgumentException, "The subsubformula should be a propositional formula");
} else {
@ -131,7 +131,7 @@ namespace storm {
std::vector<ConstantType> b;
if(this->computeRewards){
b.resize(submatrix.getRowCount());
storm::utility::vector::selectVectorValues(b, this->maybeStates, instantiatedModel.getUniqueRewardModel()->second.getStateRewardVector());
storm::utility::vector::selectVectorValues(b, this->maybeStates, instantiatedModel.getUniqueRewardModel().getStateRewardVector());
} else {
b = instantiatedModel.getTransitionMatrix().getConstrainedRowSumVector(this->maybeStates, this->targetStates);
}

4
src/modelchecker/region/SparseDtmcRegionModelChecker.cpp

@ -317,7 +317,7 @@ namespace storm {
} else {
STORM_LOG_THROW(this->getModel()->hasRewardModel(), storm::exceptions::InvalidArgumentException, "No reward model specified");
STORM_LOG_THROW(this->getModel()->hasUniqueRewardModel(), storm::exceptions::InvalidArgumentException, "Ambiguous reward model. Specify it in the formula!");
rewardModel=&(this->getModel()->getUniqueRewardModel()->second);
rewardModel=&(this->getModel()->getUniqueRewardModel());
}
//Get target states
storm::modelchecker::SparsePropositionalModelChecker<ParametricSparseModelType> modelChecker(*(this->getModel()));
@ -416,7 +416,7 @@ namespace storm {
storm::storage::BitVector phiStates(simpleModel.getNumberOfStates(), true);
std::vector<ParametricType> values;
if(this->isComputeRewards()){
values = simpleModel.getUniqueRewardModel()->second.getTotalRewardVector(maybeStates.getNumberOfSetBits(), simpleModel.getTransitionMatrix(), maybeStates);
values = simpleModel.getUniqueRewardModel().getTotalRewardVector(maybeStates.getNumberOfSetBits(), simpleModel.getTransitionMatrix(), maybeStates);
} else {
values = oneStepProbabilities;
}

10
src/models/sparse/Model.cpp

@ -101,7 +101,7 @@ namespace storm {
if (it == this->rewardModels.end()) {
if (rewardModelName.empty()) {
if (this->hasUniqueRewardModel()) {
return this->getUniqueRewardModel()->second;
return this->getUniqueRewardModel();
} else {
STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unable to refer to default reward model, because there is no default model or it is not unique.");
}
@ -142,15 +142,15 @@ namespace storm {
}
template<typename ValueType, typename RewardModelType>
typename std::unordered_map<std::string, RewardModelType>::const_iterator Model<ValueType, RewardModelType>::getUniqueRewardModel() const {
RewardModelType const& Model<ValueType, RewardModelType>::getUniqueRewardModel() const {
STORM_LOG_THROW(this->getNumberOfRewardModels() == 1, storm::exceptions::IllegalFunctionCallException, "The reward model is not unique.");
return this->rewardModels.cbegin();
return this->rewardModels.cbegin()->second;
}
template<typename ValueType, typename RewardModelType>
typename std::unordered_map<std::string, RewardModelType>::iterator Model<ValueType, RewardModelType>::getUniqueRewardModel() {
RewardModelType& Model<ValueType, RewardModelType>::getUniqueRewardModel() {
STORM_LOG_THROW(this->getNumberOfRewardModels() == 1, storm::exceptions::IllegalFunctionCallException, "The reward model is not unique.");
return this->rewardModels.begin();
return this->rewardModels.begin()->second;
}
template<typename ValueType, typename RewardModelType>

8
src/models/sparse/Model.h

@ -180,16 +180,16 @@ namespace storm {
/*!
* Retrieves the unique reward model, if there exists exactly one. Otherwise, an exception is thrown.
*
* @return An iterator to the name and the reward model.
* @return The requested reward model.
*/
typename std::unordered_map<std::string, RewardModelType>::const_iterator getUniqueRewardModel() const;
RewardModelType const& getUniqueRewardModel() const;
/*!
* Retrieves the unique reward model, if there exists exactly one. Otherwise, an exception is thrown.
*
* @return An iterator to the name and the reward model.
* @return The requested reward model.
*/
typename std::unordered_map<std::string, RewardModelType>::iterator getUniqueRewardModel();
RewardModelType& getUniqueRewardModel();
/*!
* Retrieves whether the model has a unique reward model.

14
src/models/symbolic/Model.cpp

@ -156,7 +156,7 @@ namespace storm {
if (it == this->rewardModels.end()) {
if (rewardModelName.empty()) {
if (this->hasUniqueRewardModel()) {
return this->getUniqueRewardModel()->second;
return this->getUniqueRewardModel();
} else {
STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unable to refer to default reward model, because there is no default model or it is not unique.");
}
@ -168,11 +168,17 @@ namespace storm {
}
template<storm::dd::DdType Type, typename ValueType>
typename std::unordered_map<std::string, typename Model<Type, ValueType>::RewardModelType>::const_iterator Model<Type, ValueType>::getUniqueRewardModel() const {
typename Model<Type, ValueType>::RewardModelType const& Model<Type, ValueType>::getUniqueRewardModel() const {
STORM_LOG_THROW(this->hasUniqueRewardModel(), storm::exceptions::InvalidOperationException, "Cannot retrieve unique reward model, because there is no unique one.");
return this->rewardModels.begin();
return this->rewardModels.cbegin()->second;
}
template<storm::dd::DdType Type, typename ValueType>
typename Model<Type, ValueType>::RewardModelType& Model<Type, ValueType>::getUniqueRewardModel() {
STORM_LOG_THROW(this->hasUniqueRewardModel(), storm::exceptions::InvalidOperationException, "Cannot retrieve unique reward model, because there is no unique one.");
return this->rewardModels.begin()->second;
}
template<storm::dd::DdType Type, typename ValueType>
bool Model<Type, ValueType>::hasUniqueRewardModel() const {
return this->rewardModels.size() == 1;

11
src/models/symbolic/Model.h

@ -207,9 +207,16 @@ namespace storm {
/*!
* Retrieves the unique reward model, if there exists exactly one. Otherwise, an exception is thrown.
*
* @return An iterator to the name and the reward model.
* @return The requested reward model.
*/
typename std::unordered_map<std::string, RewardModelType>::const_iterator getUniqueRewardModel() const;
RewardModelType const& getUniqueRewardModel() const;
/*!
* Retrieves the unique reward model, if there exists exactly one. Otherwise, an exception is thrown.
*
* @return The requested reward model.
*/
RewardModelType& getUniqueRewardModel();
/*!
* Retrieves whether the model has a unique reward model.

2
src/parser/ExpressionParser.cpp

@ -379,8 +379,6 @@ namespace storm {
STORM_LOG_THROW(this->identifiers_ != nullptr, storm::exceptions::WrongFormatException, "Unable to substitute identifier expressions without given mapping.");
storm::expressions::Expression const* expression = this->identifiers_->find(identifier);
if (expression == nullptr) {
std::cout << "didn't find " << identifier << std::endl;
identifiers_->for_each([] (std::string const& name, storm::expressions::Expression const& expr) { std::cout << "name: " << name << ", " << expr << std::endl; });
pass = false;
return manager->boolean(false);
}

4
src/storage/bisimulation/BisimulationDecomposition.cpp

@ -168,7 +168,7 @@ namespace storm {
template<typename ModelType, typename BlockDataType>
BisimulationDecomposition<ModelType, BlockDataType>::BisimulationDecomposition(ModelType const& model, storm::storage::SparseMatrix<ValueType> const& backwardTransitions, Options const& options) : model(model), backwardTransitions(backwardTransitions), options(options), partition(), comparator(), quotient(nullptr) {
STORM_LOG_THROW(!options.getKeepRewards() || !model.hasRewardModel() || model.hasUniqueRewardModel(), storm::exceptions::IllegalFunctionCallException, "Bisimulation currently only supports models with at most one reward model.");
STORM_LOG_THROW(!options.getKeepRewards() || !model.hasRewardModel() || model.getUniqueRewardModel()->second.hasOnlyStateRewards(), storm::exceptions::IllegalFunctionCallException, "Bisimulation is currently supported for models with state rewards only. Consider converting the transition rewards to state rewards (via suitable function calls).");
STORM_LOG_THROW(!options.getKeepRewards() || !model.hasRewardModel() || model.getUniqueRewardModel().hasOnlyStateRewards(), storm::exceptions::IllegalFunctionCallException, "Bisimulation is currently supported for models with state rewards only. Consider converting the transition rewards to state rewards (via suitable function calls).");
STORM_LOG_THROW(options.getType() != BisimulationType::Weak || !options.getBounded(), storm::exceptions::IllegalFunctionCallException, "Weak bisimulation cannot preserve bounded properties.");
// Fix the respected atomic propositions if they were not explicitly given.
@ -260,7 +260,7 @@ namespace storm {
template<typename ModelType, typename BlockDataType>
void BisimulationDecomposition<ModelType, BlockDataType>::splitInitialPartitionBasedOnStateRewards() {
std::vector<ValueType> const& stateRewardVector = model.getUniqueRewardModel()->second.getStateRewardVector();
std::vector<ValueType> const& stateRewardVector = model.getUniqueRewardModel().getStateRewardVector();
partition.split([&stateRewardVector] (storm::storage::sparse::state_type const& a, storm::storage::sparse::state_type const& b) { return stateRewardVector[a] < stateRewardVector[b]; });
}

6
src/storage/bisimulation/DeterministicModelBisimulationDecomposition.cpp

@ -627,8 +627,7 @@ namespace storm {
// If the model has state rewards, we simply copy the state reward of the representative state, because
// all states in a block are guaranteed to have the same state reward.
if (this->options.getKeepRewards() && this->model.hasRewardModel()) {
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getUniqueRewardModel();
stateRewards.get()[blockIndex] = nameRewardModelPair->second.getStateRewardVector()[representativeState];
stateRewards.get()[blockIndex] = this->model.getUniqueRewardModel().getStateRewardVector()[representativeState];
}
}
@ -641,7 +640,8 @@ namespace storm {
// Construct the reward model mapping.
std::unordered_map<std::string, typename ModelType::RewardModelType> rewardModels;
if (this->options.getKeepRewards() && this->model.hasRewardModel()) {
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getUniqueRewardModel();
STORM_LOG_THROW(this->model.hasUniqueRewardModel(), storm::exceptions::IllegalFunctionCallException, "Cannot preserve more than one reward model.");
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getRewardModels().begin();
rewardModels.insert(std::make_pair(nameRewardModelPair->first, typename ModelType::RewardModelType(stateRewards)));
}

8
src/storage/bisimulation/NondeterministicModelBisimulationDecomposition.cpp

@ -170,8 +170,7 @@ namespace storm {
// If the model has state rewards, we simply copy the state reward of the representative state, because
// all states in a block are guaranteed to have the same state reward.
if (this->options.getKeepRewards() && this->model.hasRewardModel()) {
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getUniqueRewardModel();
stateRewards.get()[blockIndex] = nameRewardModelPair->second.getStateRewardVector()[representativeState];
stateRewards.get()[blockIndex] = this->model.getUniqueRewardModel().getStateRewardVector()[representativeState];
}
}
@ -184,12 +183,13 @@ namespace storm {
// Construct the reward model mapping.
std::unordered_map<std::string, typename ModelType::RewardModelType> rewardModels;
if (this->options.getKeepRewards() && this->model.hasRewardModel()) {
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getUniqueRewardModel();
STORM_LOG_THROW(this->model.hasUniqueRewardModel(), storm::exceptions::IllegalFunctionCallException, "Cannot preserve more than one reward model.");
typename std::unordered_map<std::string, typename ModelType::RewardModelType>::const_iterator nameRewardModelPair = this->model.getRewardModels().begin();
rewardModels.insert(std::make_pair(nameRewardModelPair->first, typename ModelType::RewardModelType(stateRewards)));
}
// Finally construct the quotient model.
this->quotient = std::shared_ptr<ModelType>(new ModelType(builder.build(), std::move(newLabeling), std::move(rewardModels)));
this->quotient = std::make_shared<ModelType>(builder.build(), std::move(newLabeling), std::move(rewardModels));
}
template<typename ModelType>
Loading…
Cancel
Save