Browse Source

make minmax solvers use policy iteration when --exact is set and no other method was explicitly set

main
dehnert 8 years ago
parent
commit
8cdbf281fa
  1. 10
      src/storm/settings/Argument.cpp
  2. 5
      src/storm/settings/Argument.h
  3. 4
      src/storm/settings/ArgumentBase.h
  4. 4
      src/storm/settings/modules/MinMaxEquationSolverSettings.cpp
  5. 11
      src/storm/settings/modules/MinMaxEquationSolverSettings.h
  6. 2
      src/storm/solver/IterativeMinMaxLinearEquationSolver.h
  7. 15
      src/storm/solver/MinMaxLinearEquationSolver.cpp

10
src/storm/settings/Argument.cpp

@ -12,12 +12,12 @@ namespace storm {
namespace settings { namespace settings {
template<typename T> template<typename T>
Argument<T>::Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators): ArgumentBase(name, description), argumentValue(), argumentType(inferToEnumType<T>()), validators(validators), isOptional(false), defaultValue(), hasDefaultValue(false) { Argument<T>::Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators): ArgumentBase(name, description), argumentValue(), argumentType(inferToEnumType<T>()), validators(validators), isOptional(false), defaultValue(), hasDefaultValue(false), wasSetFromDefaultValueFlag(false) {
// Intentionally left empty. // Intentionally left empty.
} }
template<typename T> template<typename T>
Argument<T>::Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators, bool isOptional, T defaultValue): ArgumentBase(name, description), argumentValue(), argumentType(inferToEnumType<T>()), validators(validators), isOptional(isOptional), defaultValue(), hasDefaultValue(true) { Argument<T>::Argument(std::string const& name, std::string const& description, std::vector<std::shared_ptr<ArgumentValidator<T>>> const& validators, bool isOptional, T defaultValue): ArgumentBase(name, description), argumentValue(), argumentType(inferToEnumType<T>()), validators(validators), isOptional(isOptional), defaultValue(), hasDefaultValue(true), wasSetFromDefaultValueFlag(false) {
this->setDefaultValue(defaultValue); this->setDefaultValue(defaultValue);
} }
@ -71,6 +71,12 @@ namespace storm {
STORM_LOG_THROW(this->hasDefaultValue, storm::exceptions::IllegalFunctionCallException, "Unable to set value from default value, because the argument " << name << " has none."); STORM_LOG_THROW(this->hasDefaultValue, storm::exceptions::IllegalFunctionCallException, "Unable to set value from default value, because the argument " << name << " has none.");
bool result = this->setFromTypeValue(this->defaultValue, false); bool result = this->setFromTypeValue(this->defaultValue, false);
STORM_LOG_THROW(result, storm::exceptions::IllegalArgumentValueException, "Unable to assign default value to argument " << name << ", because it was rejected."); STORM_LOG_THROW(result, storm::exceptions::IllegalArgumentValueException, "Unable to assign default value to argument " << name << ", because it was rejected.");
this->wasSetFromDefaultValueFlag = true;
}
template<typename T>
bool Argument<T>::wasSetFromDefaultValue() const {
return wasSetFromDefaultValueFlag;
} }
template<typename T> template<typename T>

5
src/storm/settings/Argument.h

@ -85,6 +85,8 @@ namespace storm {
void setFromDefaultValue() override; void setFromDefaultValue() override;
virtual bool wasSetFromDefaultValue() const override;
virtual std::string getValueAsString() const override; virtual std::string getValueAsString() const override;
virtual int_fast64_t getValueAsInteger() const override; virtual int_fast64_t getValueAsInteger() const override;
@ -116,6 +118,9 @@ namespace storm {
// A flag indicating whether a default value has been provided. // A flag indicating whether a default value has been provided.
bool hasDefaultValue; bool hasDefaultValue;
// A flag indicating whether the argument was set from the default value.
bool wasSetFromDefaultValueFlag;
/*! /*!
* Sets the default value of the argument to the provided value. * Sets the default value of the argument to the provided value.
* *

4
src/storm/settings/ArgumentBase.h

@ -80,6 +80,8 @@ namespace storm {
*/ */
virtual void setFromDefaultValue() = 0; virtual void setFromDefaultValue() = 0;
virtual bool wasSetFromDefaultValue() const = 0;
/*! /*!
* Tries to set the value of the argument from the given string. * Tries to set the value of the argument from the given string.
* *
@ -134,7 +136,7 @@ namespace storm {
friend std::ostream& operator<<(std::ostream& out, ArgumentBase const& argument); friend std::ostream& operator<<(std::ostream& out, ArgumentBase const& argument);
protected: protected:
// A flag indicating whether the argument has been set. // A flag indicating whether the argument has been set.
bool hasBeenSet; bool hasBeenSet;

4
src/storm/settings/modules/MinMaxEquationSolverSettings.cpp

@ -50,6 +50,10 @@ namespace storm {
STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentValueException, "Unknown min/max equation solving technique '" << minMaxEquationSolvingTechnique << "'."); STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentValueException, "Unknown min/max equation solving technique '" << minMaxEquationSolvingTechnique << "'.");
} }
bool MinMaxEquationSolverSettings::isMinMaxEquationSolvingMethodSetFromDefaultValue() const {
return !this->getOption(solvingMethodOptionName).getArgumentByName("name").getHasBeenSet() || this->getOption(solvingMethodOptionName).getArgumentByName("name").wasSetFromDefaultValue();
}
bool MinMaxEquationSolverSettings::isMinMaxEquationSolvingMethodSet() const { bool MinMaxEquationSolverSettings::isMinMaxEquationSolvingMethodSet() const {
return this->getOption(solvingMethodOptionName).getHasOptionBeenSet(); return this->getOption(solvingMethodOptionName).getHasOptionBeenSet();
} }

11
src/storm/settings/modules/MinMaxEquationSolverSettings.h

@ -27,12 +27,19 @@ namespace storm {
bool isMinMaxEquationSolvingMethodSet() const; bool isMinMaxEquationSolvingMethodSet() const;
/*! /*!
* Retrieves the selected min/max equation solving technique. * Retrieves the selected min/max equation solving method.
* *
* @return The selected min/max equation solving technique. * @return The selected min/max equation solving method.
*/ */
storm::solver::MinMaxMethod getMinMaxEquationSolvingMethod() const; storm::solver::MinMaxMethod getMinMaxEquationSolvingMethod() const;
/*!
* Retrieves whether the min/max equation solving method is set from its default value.
*
* @return True iff if it is set from its default value.
*/
bool isMinMaxEquationSolvingMethodSetFromDefaultValue() const;
/*! /*!
* Retrieves whether the maximal iteration count has been set. * Retrieves whether the maximal iteration count has been set.
* *

2
src/storm/solver/IterativeMinMaxLinearEquationSolver.h

@ -73,7 +73,7 @@ namespace storm {
IterativeMinMaxLinearEquationSolverSettings<ValueType> settings; IterativeMinMaxLinearEquationSolverSettings<ValueType> settings;
}; };
template<typename ValueType> template<typename ValueType>
class IterativeMinMaxLinearEquationSolverFactory : public StandardMinMaxLinearEquationSolverFactory<ValueType> { class IterativeMinMaxLinearEquationSolverFactory : public StandardMinMaxLinearEquationSolverFactory<ValueType> {
public: public:
IterativeMinMaxLinearEquationSolverFactory(MinMaxMethodSelection const& method = MinMaxMethodSelection::FROMSETTINGS, bool trackScheduler = false); IterativeMinMaxLinearEquationSolverFactory(MinMaxMethodSelection const& method = MinMaxMethodSelection::FROMSETTINGS, bool trackScheduler = false);

15
src/storm/solver/MinMaxLinearEquationSolver.cpp

@ -154,7 +154,19 @@ namespace storm {
template<typename ValueType> template<typename ValueType>
void MinMaxLinearEquationSolverFactory<ValueType>::setMinMaxMethod(MinMaxMethodSelection const& newMethod) { void MinMaxLinearEquationSolverFactory<ValueType>::setMinMaxMethod(MinMaxMethodSelection const& newMethod) {
if (newMethod == MinMaxMethodSelection::FROMSETTINGS) { if (newMethod == MinMaxMethodSelection::FROMSETTINGS) {
setMinMaxMethod(storm::settings::getModule<storm::settings::modules::MinMaxEquationSolverSettings>().getMinMaxEquationSolvingMethod()); bool wasSet = false;
auto const& minMaxSettings = storm::settings::getModule<storm::settings::modules::MinMaxEquationSolverSettings>();
if (std::is_same<ValueType, storm::RationalNumber>::value) {
if (minMaxSettings.isMinMaxEquationSolvingMethodSetFromDefaultValue()) {
STORM_LOG_WARN("Selecting policy iteration as the solution method to guarantee exact results. If you want to override this, please explicitly specify a different method.");
this->setMinMaxMethod(MinMaxMethod::PolicyIteration);
wasSet = true;
}
}
if (!wasSet) {
setMinMaxMethod(minMaxSettings.getMinMaxEquationSolvingMethod());
}
} else { } else {
setMinMaxMethod(convert(newMethod)); setMinMaxMethod(convert(newMethod));
} }
@ -162,6 +174,7 @@ namespace storm {
template<typename ValueType> template<typename ValueType>
void MinMaxLinearEquationSolverFactory<ValueType>::setMinMaxMethod(MinMaxMethod const& newMethod) { void MinMaxLinearEquationSolverFactory<ValueType>::setMinMaxMethod(MinMaxMethod const& newMethod) {
STORM_LOG_WARN_COND(!(std::is_same<ValueType, storm::RationalNumber>::value) || newMethod == MinMaxMethod::PolicyIteration, "The selected solution method does not guarantee exact result. Consider using policy iteration.");
method = newMethod; method = newMethod;
} }

|||||||
100:0
Loading…
Cancel
Save