26 std::stringstream valuationStr;
28 for (
auto const& v : valueValuationPair.second) {
34 valuationStr << v.first <<
"=" << v.second;
37 STORM_PRINT_AND_LOG(
"Result at initial state: " << valueValuationPair.first <<
" ( approx. "
48 STORM_LOG_THROW(formula->isRewardOperatorFormula() || formula->isProbabilityOperatorFormula(), storm::exceptions::NotSupportedException,
49 "We only support reward- and probability operator formulas.");
50 STORM_LOG_THROW(regions.size() <= 1, storm::exceptions::NotSupportedException,
"Storm only supports one or zero regions.");
52 std::shared_ptr<storm::logic::Formula const> formulaNoBound;
53 if (formula->asOperatorFormula().hasBound()) {
54 std::shared_ptr<storm::logic::Formula> formulaWithoutBounds = formula->clone();
55 formulaWithoutBounds->asOperatorFormula().removeBound();
56 formulaNoBound = formulaWithoutBounds->asSharedPointer();
58 formulaNoBound = formula;
64 if (formula->asOperatorFormula().hasBound()) {
65 t.
setBound(formula->asOperatorFormula().getBound());
67 STORM_LOG_THROW(!feasibilitySettings.isParameterDirectionSet(), storm::exceptions::NotSupportedException,
68 "With a bound, the direction for the parameters is inferred from the bound.");
69 STORM_LOG_THROW(!feasibilitySettings.hasOptimalValueGuaranteeBeenSet(), storm::exceptions::NotSupportedException,
70 "When a bound is given, the guarantee is that this bound will be satisfied by a solution.");
72 if (feasibilitySettings.hasOptimalValueGuaranteeBeenSet()) {
76 STORM_LOG_THROW(feasibilitySettings.isParameterDirectionSet(), storm::exceptions::NotSupportedException,
77 "Without a bound, the direction for the parameters must be explicitly given.");
80 if (regions.size() == 1) {
83 return std::make_shared<FeasibilitySynthesisTask const>(std::move(t));
86template<
typename ValueType>
88 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
93 if (task->isRegionSet()) {
107 STORM_LOG_THROW(
false, storm::exceptions::NotImplementedException,
"SCP is not yet implemented.");
111template<
typename ValueType>
113 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
118 "Gradient descent is currently only supported for DTMCs.");
119 std::shared_ptr<storm::models::sparse::Dtmc<ValueType>> dtmc = model->template as<storm::models::sparse::Dtmc<ValueType>>();
120 STORM_LOG_THROW(task->getFormula().isProbabilityOperatorFormula() || task->getFormula().isRewardOperatorFormula(), storm::exceptions::NotSupportedException,
121 "Input formula needs to be either a probability operator formula or a reward operator formula.");
122 STORM_LOG_THROW(task->isBoundSet(), storm::exceptions::NotImplementedException,
"GD (right now) requires an explicitly given bound.");
123 STORM_LOG_THROW(task->getMaximalAllowedGap() == std::nullopt, storm::exceptions::NotSupportedException,
124 "GD cannot provide guarantees on the optimality of the solution..");
126 if (omittedParameters && !omittedParameters->empty()) {
128 std::cout <<
"Parameters ";
129 for (
auto const& entry : *omittedParameters) {
130 std::cout << entry <<
" ";
132 std::cout <<
"are inconsequential.";
133 if (derSettings.areInconsequentialParametersOmitted()) {
134 std::cout <<
" They will be omitted in the found instantiation.\n";
136 std::cout <<
" They will be set to 0.5 in the found instantiation. To omit them, set the flag --omit-inconsequential-params.\n";
140 boost::optional<derivative::GradientDescentConstraintMethod> constraintMethod = derSettings.getConstraintMethod();
141 if (!constraintMethod) {
142 STORM_LOG_ERROR(
"Unknown Gradient Descent Constraint method: " << derSettings.getConstraintMethodAsString());
146 boost::optional<derivative::GradientDescentMethod> method = derSettings.getGradientDescentMethod();
148 STORM_LOG_ERROR(
"Unknown Gradient Descent method: " << derSettings.getGradientDescentMethodAsString());
155 std::optional<storage::ParameterRegion<storm::RationalFunction>> region;
156 if (task->isRegionSet()) {
157 region = task->getRegion();
162 STORM_PRINT(
"Finding an extremum using Gradient Descent\n");
165 env, *dtmc, *method, derSettings.getLearningRate(), derSettings.getAverageDecay(), derSettings.getSquaredAverageDecay(), derSettings.getMiniBatchSize(),
166 derSettings.getTerminationEpsilon(), startPoint, *constraintMethod, region, derSettings.isPrintJsonSet());
168 gdsearch.
setup(env, task);
171 if (!derSettings.areInconsequentialParametersOmitted() && omittedParameters) {
174 instantiationAndValue.first[param] = startPoint->at(param);
180 derivativeWatch.
stop();
183 std::pair<double, typename storm::storage::ParameterRegion<ValueType>::Valuation> valueValuationPair;
184 valueValuationPair.first = instantiationAndValue.second;
185 valueValuationPair.second = instantiationAndValue.first;
187 if (derSettings.isPrintJsonSet()) {
191 if (task->isBoundSet()) {
192 printFeasibilityResult(task->getBound().isSatisfied(valueValuationPair.first), valueValuationPair, derivativeWatch);
198template<
typename ValueType>
200 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
202 STORM_LOG_THROW(task->isRegionSet(), storm::exceptions::NotSupportedException,
"PLA requires an explicitly given region.");
207 auto engine = regionVerificationSettings.getRegionCheckEngine();
209 auto const graphPreservationStatus =
214 regionSplittingStrategy.heuristic = regionVerificationSettings.getRegionSplittingHeuristic();
215 regionSplittingStrategy.estimateKind = regionVerificationSettings.getRegionSplittingEstimateMethod();
216 if (regionVerificationSettings.isSplittingThresholdSet()) {
217 regionSplittingStrategy.maxSplitDimensions = regionVerificationSettings.getSplittingThreshold();
220 if (task->isBoundSet()) {
225 regionSplittingStrategy,
229 graphPreservationStatus};
231 !task->isMaxGapRelative(), task->getBound().getInvertedBound());
236 STORM_LOG_THROW(task->getMaximalAllowedGap() != std::nullopt, storm::exceptions::NotSupportedException,
237 "Without a bound, PLA requires an explicit target in form of a guarantee.");
244 regionSplittingStrategy,
248 graphPreservationStatus};
250 !task->isMaxGapRelative(), std::nullopt);
258 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
262 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
266 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
267 boost::optional<std::set<RationalFunctionVariable>> omittedParameters,
void printRunAsJson()
Print the previously done run as JSON.
std::pair< std::map< typename utility::parametric::VariableType< FunctionType >::type, typename utility::parametric::CoefficientType< FunctionType >::type >, ExtendedConstantType > gradientDescent()
Perform Gradient Descent.
void setup(Environment const &env, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task)
This will setup the matrices used for computing the derivatives by constructing the SparseDerivativeI...
Base class for all sparse models.
void setOptimizationDirection(storm::solver::OptimizationDirection const &dir)
void setMaximalAllowedGapIsRelative(bool newValue)
void setMaximalAllowedGap(storm::RationalNumber const &maxGap)
void setBound(storm::logic::Bound const &bound)
void setRegion(storm::storage::ParameterRegion< storm::RationalFunction > const ®ion)
storm::utility::parametric::Valuation< ParametricType > Valuation
A class that provides convenience operations to display run times.
void stop()
Stop stopwatch and add measured time to total time.
#define STORM_LOG_ERROR(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::pair< storm::ExtendedRationalNumber, typename storm::storage::ParameterRegion< ValueType >::Valuation > computeExtremalValue(Environment const &env, RefinementOptions< ValueType > settings, storm::storage::ParameterRegion< ValueType > const ®ion, storm::solver::OptimizationDirection const &dir, std::optional< ValueType > const &precision, bool absolutePrecision, std::optional< storm::logic::Bound > const &boundInvariant)
Finds the extremal value in the given region.
storm::pars::modelchecker::MonotonicityOptions MonotonicitySetting
storm::pars::modelchecker::RegionRefinementOptions< ValueType > RefinementOptions
@ RobustParameterLifting
Parameter lifting approach based on robust markov models instead of generating nondeterminism.
storm::pars::analysis::GraphPreservationStatus establishGraphPreservation(std::shared_ptr< storm::models::ModelBase > const &model, std::vector< storm::storage::ParameterRegion< ValueType > > const ®ions, bool graphPreservationRequired)
Determines to what extent the regions are known to be well-defined and graph-preserving.
void runFeasibilityWithGD(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > model, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task, boost::optional< std::set< RationalFunctionVariable > > omittedParameters, storm::api::MonotonicitySetting monotonicitySettings)
void printFeasibilityResult(bool success, std::pair< VT1, typename storm::storage::ParameterRegion< storm::RationalFunction >::Valuation > const &valueValuationPair, storm::utility::Stopwatch const &watch)
void performFeasibility(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > model, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task, boost::optional< std::set< RationalFunctionVariable > > omittedParameters, storm::api::MonotonicitySetting monotonicitySettings)
void runFeasibilityWithPLA(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task, boost::optional< std::set< RationalFunctionVariable > > omittedParameters, storm::api::MonotonicitySetting monotonicitySettings)
std::shared_ptr< FeasibilitySynthesisTask const > createFeasibilitySynthesisTaskFromSettings(std::shared_ptr< storm::logic::Formula const > const &formula, std::vector< storm::storage::ParameterRegion< storm::RationalFunction > > const ®ions)
SettingsType const & getModule()
Get module.
TargetType convertNumber(SourceType const &number)
carl::Variable RationalFunctionVariable
#define STORM_PRINT_AND_LOG(message)
#define STORM_PRINT(message)
Define the macros that print information to stdout and optionally also log it.