28template<
typename ConstantType>
30 std::stringstream valuationStr;
38 valuationStr << v.first <<
"=" << v.second;
42 << valuationStr.str() <<
"].\n");
51 STORM_LOG_THROW(formula->isRewardOperatorFormula() || formula->isProbabilityOperatorFormula(), storm::exceptions::NotSupportedException,
52 "We only support reward- and probability operator formulas.");
53 STORM_LOG_THROW(regions.size() <= 1, storm::exceptions::NotSupportedException,
"Storm only supports one or zero regions.");
55 std::shared_ptr<storm::logic::Formula const> formulaNoBound;
56 if (formula->asOperatorFormula().hasBound()) {
57 std::shared_ptr<storm::logic::Formula> formulaWithoutBounds = formula->clone();
58 formulaWithoutBounds->asOperatorFormula().removeBound();
59 formulaNoBound = formulaWithoutBounds->asSharedPointer();
61 formulaNoBound = formula;
67 if (formula->asOperatorFormula().hasBound()) {
68 t.
setBound(formula->asOperatorFormula().getBound());
70 STORM_LOG_THROW(!feasibilitySettings.isParameterDirectionSet(), storm::exceptions::NotSupportedException,
71 "With a bound, the direction for the parameters is inferred from the bound.");
72 STORM_LOG_THROW(!feasibilitySettings.hasOptimalValueGuaranteeBeenSet(), storm::exceptions::NotSupportedException,
73 "When a bound is given, the guarantee is that this bound will be satisfied by a solution.");
75 if (feasibilitySettings.hasOptimalValueGuaranteeBeenSet()) {
79 STORM_LOG_THROW(feasibilitySettings.isParameterDirectionSet(), storm::exceptions::NotSupportedException,
80 "Without a bound, the direction for the parameters must be explicitly given.");
83 if (regions.size() == 1) {
86 return std::make_shared<FeasibilitySynthesisTask const>(std::move(t));
89template<
typename ValueType>
91 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
96 if (task->isRegionSet()) {
114template<
typename ValueType>
116 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
121 "Gradient descent is currently only supported for DTMCs.");
122 std::shared_ptr<storm::models::sparse::Dtmc<ValueType>> dtmc = model->template as<storm::models::sparse::Dtmc<ValueType>>();
123 STORM_LOG_THROW(task->getFormula().isProbabilityOperatorFormula() || task->getFormula().isRewardOperatorFormula(), storm::exceptions::NotSupportedException,
124 "Input formula needs to be either a probability operator formula or a reward operator formula.");
125 STORM_LOG_THROW(task->isBoundSet(), storm::exceptions::NotImplementedException,
"GD (right now) requires an explicitly given bound.");
126 STORM_LOG_THROW(task->getMaximalAllowedGap() == std::nullopt, storm::exceptions::NotSupportedException,
127 "GD cannot provide guarantees on the optimality of the solution..");
129 if (omittedParameters && !omittedParameters->empty()) {
131 std::cout <<
"Parameters ";
132 for (
auto const& entry : *omittedParameters) {
133 std::cout << entry <<
" ";
135 std::cout <<
"are inconsequential.";
136 if (derSettings.areInconsequentialParametersOmitted()) {
137 std::cout <<
" They will be omitted in the found instantiation.\n";
139 std::cout <<
" They will be set to 0.5 in the found instantiation. To omit them, set the flag --omit-inconsequential-params.\n";
143 boost::optional<derivative::GradientDescentConstraintMethod> constraintMethod = derSettings.getConstraintMethod();
144 if (!constraintMethod) {
145 STORM_LOG_ERROR(
"Unknown Gradient Descent Constraint method: " << derSettings.getConstraintMethodAsString());
149 boost::optional<derivative::GradientDescentMethod> method = derSettings.getGradientDescentMethod();
151 STORM_LOG_ERROR(
"Unknown Gradient Descent method: " << derSettings.getGradientDescentMethodAsString());
158 std::optional<storage::ParameterRegion<storm::RationalFunction>> region;
159 if (task->isRegionSet()) {
160 region = task->getRegion();
165 STORM_PRINT(
"Finding an extremum using Gradient Descent\n");
168 env, *dtmc, *method, derSettings.getLearningRate(), derSettings.getAverageDecay(), derSettings.getSquaredAverageDecay(), derSettings.getMiniBatchSize(),
169 derSettings.getTerminationEpsilon(), startPoint, *constraintMethod, region, derSettings.isPrintJsonSet());
171 gdsearch.
setup(env, task);
174 if (!derSettings.areInconsequentialParametersOmitted() && omittedParameters) {
177 result.valuation[param] = startPoint->at(param);
183 derivativeWatch.
stop();
185 if (derSettings.isPrintJsonSet()) {
189 if (task->isBoundSet()) {
196template<
typename ValueType>
198 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
200 STORM_LOG_THROW(task->isRegionSet(), storm::exceptions::NotSupportedException,
"PLA requires an explicitly given region.");
205 auto engine = regionVerificationSettings.getRegionCheckEngine();
207 auto const graphPreservationStatus =
212 regionSplittingStrategy.heuristic = regionVerificationSettings.getRegionSplittingHeuristic();
213 regionSplittingStrategy.estimateKind = regionVerificationSettings.getRegionSplittingEstimateMethod();
214 if (regionVerificationSettings.isSplittingThresholdSet()) {
215 regionSplittingStrategy.maxSplitDimensions = regionVerificationSettings.getSplittingThreshold();
218 if (task->isBoundSet()) {
223 regionSplittingStrategy,
227 graphPreservationStatus};
229 !task->isMaxGapRelative(), task->getBound().getInvertedBound());
234 STORM_LOG_THROW(task->getMaximalAllowedGap() != std::nullopt, storm::exceptions::NotSupportedException,
235 "Without a bound, PLA requires an explicit target in form of a guarantee.");
242 regionSplittingStrategy,
246 graphPreservationStatus};
248 !task->isMaxGapRelative(), std::nullopt);
255template<
typename ValueType>
257 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
261 "SCP is only supported for MDPs and DTMCs.");
263 STORM_LOG_THROW(task->isRegionSet(), storm::exceptions::NotSupportedException,
"SCP requires an explicitly given region.");
277 auto run = [&]<
typename ConstantType>() {
281 auto mdp = model->template as<storm::models::sparse::Mdp<ValueType>>();
284 auto dtmc = model->template as<storm::models::sparse::Dtmc<ValueType>>();
290 if (scpSettings.isExactSet()) {
291 run.template operator()<storm::RationalNumber>();
293 run.template operator()<
double>();
298 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
302 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
306 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
307 boost::optional<std::set<RationalFunctionVariable>> omittedParameters,
311 std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task,
312 boost::optional<std::set<RationalFunctionVariable>> omittedParameters,
void printRunAsJson()
Print the previously done run as JSON.
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...
storm::pars::FeasibilityResult< ConstantType > gradientDescent()
Perform Gradient Descent.
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)
Finds a parameter valuation satisfying an unbounded reachability threshold property (probability or r...
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)
storm::pars::FeasibilityResult< storm::RationalNumber > 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.
void runFeasibilityWithSCP(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, storm::pars::FeasibilityResult< ConstantType > const &result, storm::utility::Stopwatch const &watch)
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 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.
The result of a feasibility synthesis: a parameter valuation and the value at the initial state under...
std::map< storm::RationalFunctionVariable, storm::RationalFunctionCoefficient > valuation
storm::utility::ExtendedValueType< ConstantType > value
Configuration for the SCP feasibility search (SparseScpInstantiationSearcher).
double trustRegionMinExcess
Termination threshold on (radius - 1).
double trustRegionMax
Upper cap on the trust region radius.
double initialStateBias
Weight of the initial state's value in the LP objective. It is dominated by the violation objective a...
double trustRegionInitial
Initial trust region radius (delta_0).
bool useMaxViolationObjective
If true, the LP objective minimizes the maximum per-state constraint violation; if false,...
uint64_t maxIterations
Maximum number of SCP iterations before giving up.
double trustRegionFactor
Multiplicative factor (gamma) by which the trust region grows after an accepted step and shrinks afte...
The outcome of an SCP search at ConstantType precision (double or storm::RationalNumber): the best po...