Browse Source

visualization of result :)

tempestpy_adaptions
TimQu 8 years ago
parent
commit
744126a380
  1. 58
      src/storm/modelchecker/parametric/ParameterLifting.cpp
  2. 2
      src/storm/modelchecker/parametric/ParameterLifting.h
  3. 12
      src/storm/utility/storm.h

58
src/storm/modelchecker/parametric/ParameterLifting.cpp

@ -1,3 +1,5 @@
#include <sstream>
#include "storm/modelchecker/parametric/ParameterLifting.h"
#include "storm/adapters/CarlAdapter.h"
@ -200,7 +202,7 @@ namespace storm {
currentFormula = checkTask.getFormula().asSharedPointer();
}
}
template <>
void ParameterLifting<storm::models::sparse::Mdp<storm::RationalFunction>, double>::simplifyParametricModel(CheckTask<logic::Formula, storm::RationalFunction> const& checkTask) {
storm::transformer::SparseParametricMdpSimplifier<storm::models::sparse::Mdp<storm::RationalFunction>> simplifier(parametricModel);
@ -213,6 +215,60 @@ namespace storm {
}
}
template <typename SparseModelType, typename ConstantType>
std::string ParameterLifting<SparseModelType, ConstantType>::visualizeResult(std::vector<std::pair<storm::storage::ParameterRegion<typename SparseModelType::ValueType>, RegionCheckResult>> const& result, storm::storage::ParameterRegion<typename SparseModelType::ValueType> const& parameterSpace, typename storm::storage::ParameterRegion<typename SparseModelType::ValueType>::VariableType const& x, typename storm::storage::ParameterRegion<typename SparseModelType::ValueType>::VariableType const& y) {
typedef typename storm::storage::ParameterRegion<typename SparseModelType::ValueType>::CoefficientType ValueType;
std::stringstream stream;
uint_fast64_t const size = 64;
stream << "Parameter lifting result (visualization):" << std::endl;
stream << " \t x-axis: " << x << " \t y-axis: " << y << " \t S=safe, [ ]=unsafe, -=ambiguous " << std::endl;
for (uint_fast64_t i = 0; i < 2*size+2; ++i) stream << "#"; stream << std::endl;
ValueType deltaX = (parameterSpace.getUpperBoundary(x) - parameterSpace.getLowerBoundary(x)) / storm::utility::convertNumber<ValueType>(size);
ValueType deltaY = (parameterSpace.getUpperBoundary(y) - parameterSpace.getLowerBoundary(y)) / storm::utility::convertNumber<ValueType>(size);
ValueType printedRegionArea = deltaX * deltaY;
for (ValueType yUpper = parameterSpace.getUpperBoundary(y); yUpper != parameterSpace.getLowerBoundary(y); yUpper -= deltaY) {
ValueType yLower = yUpper - deltaY;
stream << "#";
for (ValueType xLower = parameterSpace.getLowerBoundary(x); xLower != parameterSpace.getUpperBoundary(x); xLower += deltaX) {
ValueType xUpper = xLower + deltaX;
bool currRegionSafe = false;
bool currRegionUnSafe = false;
bool currRegionComplete = false;
ValueType coveredArea = storm::utility::zero<ValueType>();
for (auto const& r : result) {
ValueType instersectionArea = std::max(storm::utility::zero<ValueType>(), std::min(yUpper, r.first.getUpperBoundary(y)) - std::max(yLower, r.first.getLowerBoundary(y)));
instersectionArea *= std::max(storm::utility::zero<ValueType>(), std::min(xUpper, r.first.getUpperBoundary(x)) - std::max(xLower, r.first.getLowerBoundary(x)));
if(!storm::utility::isZero(instersectionArea)) {
currRegionSafe = currRegionSafe || r.second == RegionCheckResult::AllSat;
currRegionUnSafe = currRegionUnSafe || r.second == RegionCheckResult::AllViolated;
coveredArea += instersectionArea;
if(currRegionSafe && currRegionUnSafe) {
break;
}
if(coveredArea == printedRegionArea) {
currRegionComplete = true;
break;
}
}
}
if (currRegionComplete && currRegionSafe && !currRegionUnSafe) {
stream << "SS";
} else if (currRegionComplete && currRegionUnSafe && !currRegionSafe) {
stream << " ";
} else {
stream << "--";
}
}
stream << "#" << std::endl;
}
for (uint_fast64_t i = 0; i < 2*size+2; ++i) stream << "#"; stream << std::endl;
return stream.str();
}
#ifdef STORM_HAVE_CARL
template class ParameterLifting<storm::models::sparse::Dtmc<storm::RationalFunction>, double>;

2
src/storm/modelchecker/parametric/ParameterLifting.h

@ -43,6 +43,8 @@ namespace storm {
SparseParameterLiftingModelChecker<SparseModelType, ConstantType> const& getParameterLiftingChecker() const;
SparseInstantiationModelChecker<SparseModelType, ConstantType> const& getInstantiationChecker() const;
static std::string visualizeResult(std::vector<std::pair<storm::storage::ParameterRegion<typename SparseModelType::ValueType>, RegionCheckResult>> const& result, storm::storage::ParameterRegion<typename SparseModelType::ValueType> const& parameterSpace, typename storm::storage::ParameterRegion<typename SparseModelType::ValueType>::VariableType const& x, typename storm::storage::ParameterRegion<typename SparseModelType::ValueType>::VariableType const& y);
private:
SparseModelType const& getConsideredParametricModel() const;

12
src/storm/utility/storm.h

@ -330,15 +330,24 @@ namespace storm {
STORM_PRINT_AND_LOG("Performing parameter lifting for property " << *formula << " with parameter space " << parameterSpace.toString(true) << " and refinement threshold " << storm::utility::convertNumber<double>(refinementThreshold) << " ..." << std::endl);
storm::modelchecker::CheckTask<storm::logic::Formula, storm::RationalFunction> task(*formula, true);
std::string resultVisualization;
if (markovModel->isOfType(storm::models::ModelType::Dtmc)) {
storm::modelchecker::parametric::ParameterLifting <storm::models::sparse::Dtmc<storm::RationalFunction>, double> parameterLiftingContext(*markovModel->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>());
parameterLiftingContext.specifyFormula(task);
result = parameterLiftingContext.performRegionRefinement(parameterSpace, refinementThreshold);
parameterLiftingStopWatch.stop();
if (modelParameters.size() == 2) {
resultVisualization = parameterLiftingContext.visualizeResult(result, parameterSpace, *modelParameters.begin(), *(modelParameters.rbegin()));
}
} else if (markovModel->isOfType(storm::models::ModelType::Mdp)) {
storm::modelchecker::parametric::ParameterLifting<storm::models::sparse::Mdp<storm::RationalFunction>, double> parameterLiftingContext(*markovModel->template as<storm::models::sparse::Mdp<storm::RationalFunction>>());
parameterLiftingContext.specifyFormula(task);
result = parameterLiftingContext.performRegionRefinement(parameterSpace, refinementThreshold);
parameterLiftingStopWatch.stop();
if (modelParameters.size() == 2) {
resultVisualization = parameterLiftingContext.visualizeResult(result, parameterSpace, *modelParameters.begin(), *(modelParameters.rbegin()));
}
} else {
STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "Unable to perform parameterLifting on the provided model type.");
}
@ -363,13 +372,12 @@ namespace storm {
break;
}
}
STORM_PRINT_AND_LOG("Done! Found " << numOfSatRegions << " safe regions and "
<< numOfUnsatRegions << " unsafe regions." << std::endl);
STORM_PRINT_AND_LOG(storm::utility::convertNumber<double>(satArea / parameterSpace.area()) * 100 << "% of the parameter space is safe, and "
<< storm::utility::convertNumber<double>(unsatArea / parameterSpace.area()) * 100 << "% of the parameter space is unsafe." << std::endl);
parameterLiftingStopWatch.stop();
STORM_PRINT_AND_LOG("Model checking with parameter lifting took " << parameterLiftingStopWatch << " seconds." << std::endl);
STORM_PRINT_AND_LOG(resultVisualization);
if (storm::settings::getModule<storm::settings::modules::ParametricSettings>().exportResultToFile()) {
std::string path = storm::settings::getModule<storm::settings::modules::ParametricSettings>().exportResultPath();

Loading…
Cancel
Save