From 97c24fe22930e924901d38fc3b2316d18480ed0d Mon Sep 17 00:00:00 2001 From: sjunges Date: Mon, 24 Aug 2015 11:44:11 +0200 Subject: [PATCH] solver settings now within solver, minmax refactored to share common variables Former-commit-id: b3c78ae0388158ca57613441d10937c6cbfc226c --- src/solver/MinMaxLinearEquationSolver.cpp | 19 +++++++++++ src/solver/SolverSelectionOptions.cpp | 32 +++++++++++++++++++ src/solver/SolverSelectionOptions.h | 20 ++++++++++++ .../ExtendSettingEnumWithSelectionField.h | 28 ++++++++++++++++ .../solver/MinMaxTechniqueSelectionTest.cpp | 11 +++++++ 5 files changed, 110 insertions(+) create mode 100644 src/solver/MinMaxLinearEquationSolver.cpp create mode 100644 src/solver/SolverSelectionOptions.cpp create mode 100644 src/solver/SolverSelectionOptions.h create mode 100644 src/utility/ExtendSettingEnumWithSelectionField.h create mode 100644 test/functional/solver/MinMaxTechniqueSelectionTest.cpp diff --git a/src/solver/MinMaxLinearEquationSolver.cpp b/src/solver/MinMaxLinearEquationSolver.cpp new file mode 100644 index 000000000..2aad22bda --- /dev/null +++ b/src/solver/MinMaxLinearEquationSolver.cpp @@ -0,0 +1,19 @@ +#include "MinMaxLinearEquationSolver.h" +#include "src/settings/SettingsManager.h" +#include "src/settings/modules/GeneralSettings.h" +#include + +namespace storm { + namespace solver { + AbstractMinMaxLinearEquationSolver::AbstractMinMaxLinearEquationSolver(double precision, bool relativeError, uint_fast64_t maximalIterations, bool trackPolicy, MinMaxTechniqueSelection prefTech) : + precision(precision), relative(relativeError), maximalNumberOfIterations(maximalIterations), trackPolicy(trackPolicy) + { + + if(prefTech == MinMaxTechniqueSelection::FROMSETTINGS) { + useValueIteration = (storm::settings::generalSettings().getMinMaxEquationSolvingTechnique() == storm::solver::MinMaxTechnique::ValueIteration); + } else { + useValueIteration = (prefTech == MinMaxTechniqueSelection::ValueIteration); + } + } + } +} diff --git a/src/solver/SolverSelectionOptions.cpp b/src/solver/SolverSelectionOptions.cpp new file mode 100644 index 000000000..63e56eda7 --- /dev/null +++ b/src/solver/SolverSelectionOptions.cpp @@ -0,0 +1,32 @@ +#include "src/solver/SolverSelectionOptions.h" + +namespace storm { + namespace solver { + std::string toString(MinMaxTechnique m) { + switch(m) { + case MinMaxTechnique::PolicyIteration: + return "policy"; + case MinMaxTechnique::ValueIteration: + return "value"; + } + + } + std::string toString(LpSolverType t) { + switch(t) { + case LpSolverType::Gurobi: + return "Gurobi"; + case LpSolverType::Glpk: + return "Glpk"; + } + } + + std::string toString(EquationSolverType t) { + switch(t) { + case EquationSolverType::Native: + return "Native"; + case EquationSolverType::Gmmxx: + return "Gmmxx"; + } + } + } +} diff --git a/src/solver/SolverSelectionOptions.h b/src/solver/SolverSelectionOptions.h new file mode 100644 index 000000000..cfba09a15 --- /dev/null +++ b/src/solver/SolverSelectionOptions.h @@ -0,0 +1,20 @@ + +#ifndef SOLVERSELECTIONOPTIONS_H +#define SOLVERSELECTIONOPTIONS_H + + +#include "src/utility/ExtendSettingEnumWithSelectionField.h" + +namespace storm { + namespace solver { + ExtendEnumsWithSelectionField(MinMaxTechnique, PolicyIteration, ValueIteration) + + + ExtendEnumsWithSelectionField(LpSolverType, Gurobi, Glpk) + ExtendEnumsWithSelectionField(EquationSolverType, Native, Gmmxx) + + } +} + +#endif + diff --git a/src/utility/ExtendSettingEnumWithSelectionField.h b/src/utility/ExtendSettingEnumWithSelectionField.h new file mode 100644 index 000000000..997571f6e --- /dev/null +++ b/src/utility/ExtendSettingEnumWithSelectionField.h @@ -0,0 +1,28 @@ +#ifndef EXTENDSETTINGENUMWITHSELECTIONFIELD_H +#define EXTENDSETTINGENUMWITHSELECTIONFIELD_H + + + +#include +#include + + +#define ExtendEnumsWithSelectionField( NAME, ...) \ + enum class NAME : int { __VA_ARGS__ }; \ + enum class NAME##Selection : int { __VA_ARGS__, FROMSETTINGS }; \ + std::string toString(NAME); \ + inline NAME convert(NAME##Selection e) { \ + assert(e != NAME##Selection::FROMSETTINGS); \ + return static_cast< NAME >(e); \ + } \ + inline std::string toString(NAME##Selection e) { \ + if(e == NAME##Selection::FROMSETTINGS) { \ + return "[from settings]"; \ + }\ + else { \ + return toString(convert(e)); \ + } \ + } + +#endif /* EXTENDSETTINGENUMWITHSELECTIONFIELD_H */ + diff --git a/test/functional/solver/MinMaxTechniqueSelectionTest.cpp b/test/functional/solver/MinMaxTechniqueSelectionTest.cpp new file mode 100644 index 000000000..78cc8696e --- /dev/null +++ b/test/functional/solver/MinMaxTechniqueSelectionTest.cpp @@ -0,0 +1,11 @@ +#include "gtest/gtest.h" + +#include "src/solver/MinMaxLinearEquationSolver.h" + +TEST( MinMaxTechnique, Simple ) { + storm::solver::MinMaxTechniqueSelection ts = storm::solver::MinMaxTechniqueSelection::PolicyIteration; + storm::solver::MinMaxTechnique t = storm::solver::MinMaxTechnique::PolicyIteration; + ASSERT_EQ(convert(ts), t); + + +} \ No newline at end of file