Browse Source

renamed BoundType to CoefficientType, better region.getVariables

Former-commit-id: 68459c4396
tempestpy_adaptions
TimQu 10 years ago
parent
commit
777942f5d3
  1. 64
      src/modelchecker/reachability/SparseDtmcRegionModelChecker.cpp
  2. 33
      src/modelchecker/reachability/SparseDtmcRegionModelChecker.h
  3. 20
      src/utility/regions.cpp
  4. 16
      src/utility/regions.h

64
src/modelchecker/reachability/SparseDtmcRegionModelChecker.cpp

@ -27,27 +27,35 @@ namespace storm {
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::ParameterRegion(std::map<VariableType, BoundType> lowerBounds, std::map<VariableType, BoundType> upperBounds) : lowerBounds(lowerBounds), upperBounds(upperBounds), checkResult(RegionCheckResult::UNKNOWN) {
//todo: check whether both mappings map the same variables
SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::ParameterRegion(std::map<VariableType, CoefficientType> lowerBounds, std::map<VariableType, CoefficientType> upperBounds) : lowerBounds(lowerBounds), upperBounds(upperBounds), checkResult(RegionCheckResult::UNKNOWN) {
//check whether both mappings map the same variables and precompute the set of variables
for(auto const& variableWithBound : lowerBounds) {
STORM_LOG_THROW((upperBounds.find(variableWithBound.first)!=upperBounds.end()), storm::exceptions::InvalidArgumentException, "Couldn't create region. No upper bound specified for Variable " << variableWithBound.first);
this->variables.insert(variableWithBound.first);
}
for(auto const& variableWithBound : upperBounds){
STORM_LOG_THROW((this->variables.find(variableWithBound.first)!=this->variables.end()), storm::exceptions::InvalidArgumentException, "Couldn't create region. No lower bound specified for Variable " << variableWithBound.first);
}
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::setViolatedPoint(std::map<VariableType, BoundType> const& violatedPoint) {
void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::setViolatedPoint(std::map<VariableType, CoefficientType> const& violatedPoint) {
this->violatedPoint = violatedPoint; this->violatedPoint = violatedPoint;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getViolatedPoint() const {
std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getViolatedPoint() const {
return violatedPoint; return violatedPoint;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::setSatPoint(std::map<VariableType, BoundType> const& satPoint) {
void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::setSatPoint(std::map<VariableType, CoefficientType> const& satPoint) {
this->satPoint = satPoint; this->satPoint = satPoint;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getSatPoint() const {
std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getSatPoint() const {
return satPoint; return satPoint;
} }
@ -75,42 +83,38 @@ namespace storm {
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
std::set<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getVariables() const{ std::set<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getVariables() const{
std::set<VariableType> result;
for(auto const& variableWithBound : lowerBounds) {
result.insert(variableWithBound.first);
}
return result;
return this->variables;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType const& SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getLowerBound(VariableType const& variable) const{
typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType const& SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getLowerBound(VariableType const& variable) const{
auto const& result = lowerBounds.find(variable); auto const& result = lowerBounds.find(variable);
STORM_LOG_THROW(result!=lowerBounds.end(), storm::exceptions::IllegalArgumentException, "tried to find a lower bound of a variable that is not specified by this region"); STORM_LOG_THROW(result!=lowerBounds.end(), storm::exceptions::IllegalArgumentException, "tried to find a lower bound of a variable that is not specified by this region");
return (*result).second; return (*result).second;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType const& SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getUpperBound(VariableType const& variable) const{
typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType const& SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getUpperBound(VariableType const& variable) const{
auto const& result = upperBounds.find(variable); auto const& result = upperBounds.find(variable);
STORM_LOG_THROW(result!=upperBounds.end(), storm::exceptions::IllegalArgumentException, "tried to find an upper bound of a variable that is not specified by this region"); STORM_LOG_THROW(result!=upperBounds.end(), storm::exceptions::IllegalArgumentException, "tried to find an upper bound of a variable that is not specified by this region");
return (*result).second; return (*result).second;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
const std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getUpperBounds() const {
const std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getUpperBounds() const {
return upperBounds; return upperBounds;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
const std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getLowerBounds() const {
const std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getLowerBounds() const {
return lowerBounds; return lowerBounds;
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
std::vector<std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType>> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getVerticesOfRegion(std::set<VariableType> const& consideredVariables) const{
std::vector<std::map<typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::VariableType, typename SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType>> SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::getVerticesOfRegion(std::set<VariableType> const& consideredVariables) const{
std::size_t const numOfVariables=consideredVariables.size(); std::size_t const numOfVariables=consideredVariables.size();
std::size_t const numOfVertices=std::pow(2,numOfVariables); std::size_t const numOfVertices=std::pow(2,numOfVariables);
std::vector<std::map<VariableType, BoundType>> resultingVector(numOfVertices,std::map<VariableType, BoundType>());
std::vector<std::map<VariableType, CoefficientType>> resultingVector(numOfVertices,std::map<VariableType, CoefficientType>());
if(numOfVertices==1){ if(numOfVertices==1){
//no variables are given, the returned vector should still contain an empty map //no variables are given, the returned vector should still contain an empty map
return resultingVector; return resultingVector;
@ -123,10 +127,10 @@ namespace storm {
std::size_t variableIndex=0; std::size_t variableIndex=0;
for(auto const& variable : consideredVariables){ for(auto const& variable : consideredVariables){
if( (vertexId>>variableIndex)%2==0 ){ if( (vertexId>>variableIndex)%2==0 ){
resultingVector[vertexId].insert(std::pair<VariableType, BoundType>(variable, getLowerBound(variable)));
resultingVector[vertexId].insert(std::pair<VariableType, CoefficientType>(variable, getLowerBound(variable)));
} }
else{ else{
resultingVector[vertexId].insert(std::pair<VariableType, BoundType>(variable, getUpperBound(variable)));
resultingVector[vertexId].insert(std::pair<VariableType, CoefficientType>(variable, getUpperBound(variable)));
} }
++variableIndex; ++variableIndex;
} }
@ -158,11 +162,11 @@ namespace storm {
std::string SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::toString() const { std::string SparseDtmcRegionModelChecker<ParametricType, ConstantType>::ParameterRegion::toString() const {
std::stringstream regionstringstream; std::stringstream regionstringstream;
for(auto var : this->getVariables()){ for(auto var : this->getVariables()){
regionstringstream << storm::utility::regions::convertNumber<SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType,double>(this->getLowerBound(var));
regionstringstream << storm::utility::regions::convertNumber<SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType,double>(this->getLowerBound(var));
regionstringstream << "<="; regionstringstream << "<=";
regionstringstream << storm::utility::regions::getVariableName(var); regionstringstream << storm::utility::regions::getVariableName(var);
regionstringstream << "<="; regionstringstream << "<=";
regionstringstream << storm::utility::regions::convertNumber<SparseDtmcRegionModelChecker<ParametricType, ConstantType>::BoundType,double>(this->getUpperBound(var));
regionstringstream << storm::utility::regions::convertNumber<SparseDtmcRegionModelChecker<ParametricType, ConstantType>::CoefficientType,double>(this->getUpperBound(var));
regionstringstream << ","; regionstringstream << ",";
} }
std::string regionstring = regionstringstream.str(); std::string regionstring = regionstringstream.str();
@ -364,7 +368,7 @@ namespace storm {
storm::storage::sparse::state_type currentMdpRow=0; storm::storage::sparse::state_type currentMdpRow=0;
//go through rows: //go through rows:
for(storm::storage::sparse::state_type oldStateIndex : subsys){ for(storm::storage::sparse::state_type oldStateIndex : subsys){
ParametricType valueToSinkState=storm::utility::regions::getNewFunction<ParametricType, BoundType>(storm::utility::one<BoundType>());
ParametricType valueToSinkState=storm::utility::regions::getNewFunction<ParametricType, CoefficientType>(storm::utility::one<CoefficientType>());
// the dtmc and the mdp rows need to sum up to one, therefore the first entry that we add has value one. // the dtmc and the mdp rows need to sum up to one, therefore the first entry that we add has value one.
ConstantType dummyEntry=storm::utility::one<ConstantType>(); ConstantType dummyEntry=storm::utility::one<ConstantType>();
// store the columns and values that we have added because we need the same information for the next rows in the mdp // store the columns and values that we have added because we need the same information for the next rows in the mdp
@ -760,7 +764,7 @@ namespace storm {
} }
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
bool SparseDtmcRegionModelChecker<ParametricType, ConstantType>::checkPoint(ParameterRegion& region, std::map<VariableType, BoundType>const& point, bool viaReachProbFunction) {
bool SparseDtmcRegionModelChecker<ParametricType, ConstantType>::checkPoint(ParameterRegion& region, std::map<VariableType, CoefficientType>const& point, bool viaReachProbFunction) {
// check whether the property is satisfied or not at the given point // check whether the property is satisfied or not at the given point
bool valueInBoundOfFormula; bool valueInBoundOfFormula;
if(viaReachProbFunction){ if(viaReachProbFunction){
@ -769,7 +773,7 @@ namespace storm {
else{ else{
//put the values into the dtmc matrix //put the values into the dtmc matrix
for( std::pair<ParametricType, typename storm::storage::MatrixEntry<storm::storage::sparse::state_type, ConstantType>&>& mappingPair : this->sampleDtmcMapping){ for( std::pair<ParametricType, typename storm::storage::MatrixEntry<storm::storage::sparse::state_type, ConstantType>&>& mappingPair : this->sampleDtmcMapping){
mappingPair.second.setValue(storm::utility::regions::convertNumber<BoundType,ConstantType>(
mappingPair.second.setValue(storm::utility::regions::convertNumber<CoefficientType,ConstantType>(
storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(mappingPair.first, point) storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(mappingPair.first, point)
) )
); );
@ -782,7 +786,7 @@ namespace storm {
//Delete from here //Delete from here
// ConstantType result=resultPtr->asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()[*this->sampleDtmc->getInitialStates().begin()]; // ConstantType result=resultPtr->asExplicitQuantitativeCheckResult<ConstantType>().getValueVector()[*this->sampleDtmc->getInitialStates().begin()];
// ConstantType otherresult=storm::utility::regions::convertNumber<BoundType, ConstantType>(storm::utility::regions::evaluateFunction<ParametricType, ConstantType>(this->reachProbFunction, point));
// ConstantType otherresult=storm::utility::regions::convertNumber<CoefficientType, ConstantType>(storm::utility::regions::evaluateFunction<ParametricType, ConstantType>(this->reachProbFunction, point));
// STORM_LOG_THROW((std::abs(result - otherresult) <= 0.01),storm::exceptions::UnexpectedException, "The results of new DTMC algorithm does not match: " << result << " vs. " << otherresult); // STORM_LOG_THROW((std::abs(result - otherresult) <= 0.01),storm::exceptions::UnexpectedException, "The results of new DTMC algorithm does not match: " << result << " vs. " << otherresult);
//To here //To here
@ -927,7 +931,7 @@ namespace storm {
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::buildMdpForApproximation(const ParameterRegion& region) { void SparseDtmcRegionModelChecker<ParametricType, ConstantType>::buildMdpForApproximation(const ParameterRegion& region) {
//instantiate the substitutions for the given region //instantiate the substitutions for the given region
std::vector<std::map<VariableType, BoundType>> substitutions(this->approxMdpSubstitutions.size());
std::vector<std::map<VariableType, CoefficientType>> substitutions(this->approxMdpSubstitutions.size());
for(uint_fast64_t substitutionIndex=0; substitutionIndex<this->approxMdpSubstitutions.size(); ++substitutionIndex){ for(uint_fast64_t substitutionIndex=0; substitutionIndex<this->approxMdpSubstitutions.size(); ++substitutionIndex){
for(std::pair<VariableType, TypeOfBound> const& sub : this->approxMdpSubstitutions[substitutionIndex]){ for(std::pair<VariableType, TypeOfBound> const& sub : this->approxMdpSubstitutions[substitutionIndex]){
switch(sub.second){ switch(sub.second){
@ -945,7 +949,7 @@ namespace storm {
//now put the values into the mdp matrix //now put the values into the mdp matrix
for( std::tuple<ParametricType, typename storm::storage::MatrixEntry<storm::storage::sparse::state_type, ConstantType>&, size_t>& mappingTriple : this->approxMdpMapping){ for( std::tuple<ParametricType, typename storm::storage::MatrixEntry<storm::storage::sparse::state_type, ConstantType>&, size_t>& mappingTriple : this->approxMdpMapping){
std::get<1>(mappingTriple).setValue(storm::utility::regions::convertNumber<BoundType,ConstantType>(
std::get<1>(mappingTriple).setValue(storm::utility::regions::convertNumber<CoefficientType,ConstantType>(
storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(std::get<0>(mappingTriple),substitutions[std::get<2>(mappingTriple)]) storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(std::get<0>(mappingTriple),substitutions[std::get<2>(mappingTriple)])
) )
); );
@ -1008,7 +1012,7 @@ namespace storm {
selfloopIndex=numStates; // --> selfloop will never be inserted again selfloopIndex=numStates; // --> selfloop will never be inserted again
} }
for(auto const& entry : this->sparseTransitions.getRow(oldStateIndex)){ for(auto const& entry : this->sparseTransitions.getRow(oldStateIndex)){
ConstantType value = storm::utility::regions::convertNumber<BoundType,ConstantType>(
ConstantType value = storm::utility::regions::convertNumber<CoefficientType,ConstantType>(
storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(entry.getValue(),substitutions[substitutionIndex]) storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(entry.getValue(),substitutions[substitutionIndex])
); );
missingProbability-=value; missingProbability-=value;
@ -1022,7 +1026,7 @@ namespace storm {
} }
if(!this->parametricTypeComparator.isZero(this->oneStepProbabilities[oldStateIndex])){ //transition to target state if(!this->parametricTypeComparator.isZero(this->oneStepProbabilities[oldStateIndex])){ //transition to target state
ConstantType value = storm::utility::regions::convertNumber<BoundType,ConstantType>(
ConstantType value = storm::utility::regions::convertNumber<CoefficientType,ConstantType>(
storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(this->oneStepProbabilities[oldStateIndex],substitutions[substitutionIndex]) storm::utility::regions::evaluateFunction<ParametricType,ConstantType>(this->oneStepProbabilities[oldStateIndex],substitutions[substitutionIndex])
); );
missingProbability-=value; missingProbability-=value;
@ -1716,7 +1720,7 @@ namespace storm {
#ifdef STORM_HAVE_CARL #ifdef STORM_HAVE_CARL
template class SparseDtmcRegionModelChecker<storm::RationalFunction, double>; template class SparseDtmcRegionModelChecker<storm::RationalFunction, double>;
#endif #endif
//note: for other template instantiations, add a rule for the typedefs of VariableType and BoundType
//note: for other template instantiations, add a rule for the typedefs of VariableType and CoefficientType
} // namespace modelchecker } // namespace modelchecker
} // namespace storm } // namespace storm

33
src/modelchecker/reachability/SparseDtmcRegionModelChecker.h

@ -20,7 +20,7 @@ namespace storm {
//The type of variables and bounds depends on the template arguments //The type of variables and bounds depends on the template arguments
typedef typename std::conditional<(std::is_same<ParametricType,storm::RationalFunction>::value), storm::Variable,std::nullptr_t>::type VariableType; typedef typename std::conditional<(std::is_same<ParametricType,storm::RationalFunction>::value), storm::Variable,std::nullptr_t>::type VariableType;
typedef typename std::conditional<(std::is_same<ParametricType,storm::RationalFunction>::value), storm::Coefficient,std::nullptr_t>::type BoundType;
typedef typename std::conditional<(std::is_same<ParametricType,storm::RationalFunction>::value), storm::Coefficient,std::nullptr_t>::type CoefficientType;
/*! /*!
* The possible results for a single region * The possible results for a single region
@ -37,15 +37,15 @@ namespace storm {
class ParameterRegion{ class ParameterRegion{
public: public:
ParameterRegion(std::map<VariableType, BoundType> lowerBounds, std::map<VariableType, BoundType> upperBounds);
ParameterRegion(std::map<VariableType, CoefficientType> lowerBounds, std::map<VariableType, CoefficientType> upperBounds);
std::set<VariableType> getVariables() const; std::set<VariableType> getVariables() const;
BoundType const& getLowerBound(VariableType const& variable) const;
BoundType const& getUpperBound(VariableType const& variable) const;
const std::map<VariableType, BoundType> getUpperBounds() const;
const std::map<VariableType, BoundType> getLowerBounds() const;
CoefficientType const& getLowerBound(VariableType const& variable) const;
CoefficientType const& getUpperBound(VariableType const& variable) const;
const std::map<VariableType, CoefficientType> getUpperBounds() const;
const std::map<VariableType, CoefficientType> getLowerBounds() const;
/* /*
* Returns a vector of all possible combinations of lower and upper bounds of the given variables. * Returns a vector of all possible combinations of lower and upper bounds of the given variables.
@ -56,7 +56,7 @@ namespace storm {
* *
* If the given set of variables is empty, the returned vector will contain an empty map * If the given set of variables is empty, the returned vector will contain an empty map
*/ */
std::vector<std::map<VariableType, BoundType>> getVerticesOfRegion(std::set<VariableType> const& consideredVariables) const;
std::vector<std::map<VariableType, CoefficientType>> getVerticesOfRegion(std::set<VariableType> const& consideredVariables) const;
//returns the currently set check result as a string //returns the currently set check result as a string
std::string checkResultToString() const; std::string checkResultToString() const;
@ -70,33 +70,34 @@ namespace storm {
/*! /*!
* Sets a point in the region for which the considered property is not satisfied. * Sets a point in the region for which the considered property is not satisfied.
*/ */
void setViolatedPoint(std::map<VariableType, BoundType> const& violatedPoint);
void setViolatedPoint(std::map<VariableType, CoefficientType> const& violatedPoint);
/*! /*!
* Retrieves a point in the region for which is considered property is not satisfied. * Retrieves a point in the region for which is considered property is not satisfied.
* If such a point is not known, the returned map is empty. * If such a point is not known, the returned map is empty.
*/ */
std::map<VariableType, BoundType> getViolatedPoint() const;
std::map<VariableType, CoefficientType> getViolatedPoint() const;
/*! /*!
* Sets a point in the region for which the considered property is satisfied. * Sets a point in the region for which the considered property is satisfied.
*/ */
void setSatPoint(std::map<VariableType, BoundType> const& satPoint);
void setSatPoint(std::map<VariableType, CoefficientType> const& satPoint);
/*! /*!
* Retrieves a point in the region for which is considered property is satisfied. * Retrieves a point in the region for which is considered property is satisfied.
* If such a point is not known, the returned map is empty. * If such a point is not known, the returned map is empty.
*/ */
std::map<VariableType, BoundType> getSatPoint() const;
std::map<VariableType, CoefficientType> getSatPoint() const;
private: private:
std::map<VariableType, BoundType> const lowerBounds;
std::map<VariableType, BoundType> const upperBounds;
std::map<VariableType, CoefficientType> const lowerBounds;
std::map<VariableType, CoefficientType> const upperBounds;
std::set<VariableType> variables;
RegionCheckResult checkResult; RegionCheckResult checkResult;
std::map<VariableType, BoundType> satPoint;
std::map<VariableType, BoundType> violatedPoint;
std::map<VariableType, CoefficientType> satPoint;
std::map<VariableType, CoefficientType> violatedPoint;
}; };
@ -281,7 +282,7 @@ namespace storm {
* *
* @return true if an violated point as well as a sat point has been found, i.e., the check result is changed to EXISTSOTH * @return true if an violated point as well as a sat point has been found, i.e., the check result is changed to EXISTSOTH
*/ */
bool checkPoint(ParameterRegion& region, std::map<VariableType, BoundType>const& point, bool viaReachProbFunction=false);
bool checkPoint(ParameterRegion& region, std::map<VariableType, CoefficientType>const& point, bool viaReachProbFunction=false);
/*! /*!
* Builds an MDP that is used to compute bounds on the maximal/minimal reachability probability, * Builds an MDP that is used to compute bounds on the maximal/minimal reachability probability,

20
src/utility/regions.cpp

@ -20,8 +20,8 @@ namespace storm {
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
void RegionParser<ParametricType, ConstantType>::parseParameterBounds( void RegionParser<ParametricType, ConstantType>::parseParameterBounds(
std::map<VariableType, BoundType>& lowerBounds,
std::map<VariableType, BoundType>& upperBounds,
std::map<VariableType, CoefficientType>& lowerBounds,
std::map<VariableType, CoefficientType>& upperBounds,
std::string const& parameterBoundsString, std::string const& parameterBoundsString,
double const precision){ double const precision){
double actualPrecision = (precision==0.0 ? storm::settings::generalSettings().getPrecision() : precision); double actualPrecision = (precision==0.0 ? storm::settings::generalSettings().getPrecision() : precision);
@ -46,10 +46,10 @@ namespace storm {
} }
VariableType var = getVariableFromString<VariableType>(parameter); VariableType var = getVariableFromString<VariableType>(parameter);
BoundType lb = convertNumber<double, BoundType>(lowerBound, true, actualPrecision);
STORM_LOG_WARN_COND((lowerBound==convertNumber<BoundType, double>(lb, true, actualPrecision)), "The lower bound of '"<< parameterBoundsString << "' could not be parsed accurately. Increase precision?");
BoundType ub = convertNumber<double, BoundType>(upperBound, false, actualPrecision);
STORM_LOG_WARN_COND((upperBound==convertNumber<BoundType, double>(ub, true, actualPrecision)), "The upper bound of '"<< parameterBoundsString << "' could not be parsed accurately. Increase precision?");
CoefficientType lb = convertNumber<double, CoefficientType>(lowerBound, true, actualPrecision);
STORM_LOG_WARN_COND((lowerBound==convertNumber<CoefficientType, double>(lb, true, actualPrecision)), "The lower bound of '"<< parameterBoundsString << "' could not be parsed accurately. Increase precision?");
CoefficientType ub = convertNumber<double, CoefficientType>(upperBound, false, actualPrecision);
STORM_LOG_WARN_COND((upperBound==convertNumber<CoefficientType, double>(ub, true, actualPrecision)), "The upper bound of '"<< parameterBoundsString << "' could not be parsed accurately. Increase precision?");
lowerBounds.emplace(std::make_pair(var, lb)); lowerBounds.emplace(std::make_pair(var, lb));
upperBounds.emplace(std::make_pair(var, ub)); upperBounds.emplace(std::make_pair(var, ub));
// std::cout << "parsed bounds " << parameterBoundsString << ": lb=" << lowerBound << " ub=" << upperBound << " param='" << parameter << "' precision=" << actualPrecision << std::endl; // std::cout << "parsed bounds " << parameterBoundsString << ": lb=" << lowerBound << " ub=" << upperBound << " param='" << parameter << "' precision=" << actualPrecision << std::endl;
@ -58,8 +58,8 @@ namespace storm {
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
typename RegionParser<ParametricType, ConstantType>::ParameterRegion RegionParser<ParametricType, ConstantType>::parseRegion(std::string const& regionString, double precision){ typename RegionParser<ParametricType, ConstantType>::ParameterRegion RegionParser<ParametricType, ConstantType>::parseRegion(std::string const& regionString, double precision){
double actualPrecision = (precision==0.0 ? storm::settings::generalSettings().getPrecision() : precision); double actualPrecision = (precision==0.0 ? storm::settings::generalSettings().getPrecision() : precision);
std::map<VariableType, BoundType> lowerBounds;
std::map<VariableType, BoundType> upperBounds;
std::map<VariableType, CoefficientType> lowerBounds;
std::map<VariableType, CoefficientType> upperBounds;
std::vector<std::string> parameterBounds; std::vector<std::string> parameterBounds;
boost::split(parameterBounds, regionString, boost::is_any_of(",")); boost::split(parameterBounds, regionString, boost::is_any_of(","));
for(auto const& parameterBound : parameterBounds){ for(auto const& parameterBound : parameterBounds){
@ -177,10 +177,10 @@ namespace storm {
} }
template<> template<>
typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::BoundType evaluateFunction<storm::RationalFunction, double>(
typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::CoefficientType evaluateFunction<storm::RationalFunction, double>(
storm::RationalFunction const& function, storm::RationalFunction const& function,
std::map<typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::VariableType, std::map<typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::VariableType,
typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::BoundType> const& point){
typename storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction,double>::CoefficientType> const& point){
return function.evaluate(point); return function.evaluate(point);
} }

16
src/utility/regions.h

@ -31,26 +31,26 @@ namespace storm {
public: public:
typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::ParameterRegion ParameterRegion; typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::ParameterRegion ParameterRegion;
typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::VariableType VariableType; typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::VariableType VariableType;
typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::BoundType BoundType;
typedef typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::CoefficientType CoefficientType;
/* /*
* Can be used to parse a single parameter with its bounds from a string of the form "0.3<=p<=0.5". * Can be used to parse a single parameter with its bounds from a string of the form "0.3<=p<=0.5".
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::Boundtype.
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::CoefficientType.
* According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up. * According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up.
* If no precision is given, the one from the settings is used. * If no precision is given, the one from the settings is used.
* The results will be inserted in the given maps * The results will be inserted in the given maps
* *
*/ */
static void parseParameterBounds( static void parseParameterBounds(
std::map<VariableType, BoundType>& lowerBounds,
std::map<VariableType, BoundType>& upperBounds,
std::map<VariableType, CoefficientType>& lowerBounds,
std::map<VariableType, CoefficientType>& upperBounds,
std::string const& parameterBoundsString, std::string const& parameterBoundsString,
double const precision=0.0 double const precision=0.0
); );
/* /*
* Can be used to parse a single region from a string of the form "0.3<=p<=0.5,0.4<=q<=0.7". * Can be used to parse a single region from a string of the form "0.3<=p<=0.5,0.4<=q<=0.7".
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::Boundtype.
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::CoefficientType.
* According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up. * According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up.
* If no precision is given, the one from the settings is used. * If no precision is given, the one from the settings is used.
* *
@ -61,7 +61,7 @@ namespace storm {
/* /*
* Can be used to parse a vector of region from a string of the form "0.3<=p<=0.5,0.4<=q<=0.7;0.1<=p<=0.3,0.2<=q<=0.4". * Can be used to parse a vector of region from a string of the form "0.3<=p<=0.5,0.4<=q<=0.7;0.1<=p<=0.3,0.2<=q<=0.4".
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::Boundtype.
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::CoefficientType.
* According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up. * According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up.
* If no precision is given, the one from the settings is used. * If no precision is given, the one from the settings is used.
* *
@ -73,7 +73,7 @@ namespace storm {
/* /*
* Retrieves the regions that are specified in the settings. * Retrieves the regions that are specified in the settings.
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::Boundtype.
* The numbers are parsed as doubles and then converted to SparseDtmcRegionModelChecker::CoefficientType.
* According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up. * According to the given precision, the lower bound may be rounded down and the upper bound may be rounded up.
* If no precision is given, the one from the settings is used. * If no precision is given, the one from the settings is used.
* *
@ -115,7 +115,7 @@ namespace storm {
std::string getVariableName(VariableType variable); std::string getVariableName(VariableType variable);
template<typename ParametricType, typename ConstantType> template<typename ParametricType, typename ConstantType>
typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::BoundType evaluateFunction(ParametricType const& function, std::map<typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::VariableType, typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::BoundType> const& point);
typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::CoefficientType evaluateFunction(ParametricType const& function, std::map<typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::VariableType, typename storm::modelchecker::SparseDtmcRegionModelChecker<ParametricType,ConstantType>::CoefficientType> const& point);
/*! /*!
* Returns true if the function is rational. Note that the function might be simplified. * Returns true if the function is rational. Note that the function might be simplified.

Loading…
Cancel
Save