Browse Source

introduced top-level solve equations function to centrally check for requirements

tempestpy_adaptions
dehnert 7 years ago
parent
commit
3829b58e0d
  1. 4
      src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp
  2. 8
      src/storm/solver/IterativeMinMaxLinearEquationSolver.h
  3. 4
      src/storm/solver/LpMinMaxLinearEquationSolver.cpp
  4. 9
      src/storm/solver/LpMinMaxLinearEquationSolver.h
  5. 15
      src/storm/solver/MinMaxLinearEquationSolver.cpp
  6. 16
      src/storm/solver/MinMaxLinearEquationSolver.h
  7. 2
      src/storm/solver/StandardMinMaxLinearEquationSolver.cpp
  8. 7
      src/storm/solver/StandardMinMaxLinearEquationSolver.h
  9. 4
      src/storm/solver/TopologicalMinMaxLinearEquationSolver.cpp
  10. 4
      src/storm/solver/TopologicalMinMaxLinearEquationSolver.h

4
src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp

@ -91,7 +91,7 @@ namespace storm {
}
template<typename ValueType>
bool IterativeMinMaxLinearEquationSolver<ValueType>::solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
bool IterativeMinMaxLinearEquationSolver<ValueType>::internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
switch (this->getSettings().getSolutionMethod()) {
case IterativeMinMaxLinearEquationSolverSettings<ValueType>::SolutionMethod::ValueIteration:
return solveEquationsValueIteration(dir, x, b);
@ -464,7 +464,7 @@ namespace storm {
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> IterativeMinMaxLinearEquationSolverFactory<ValueType>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> IterativeMinMaxLinearEquationSolverFactory<ValueType>::create() const {
STORM_LOG_ASSERT(this->linearEquationSolverFactory, "Linear equation solver factory not initialized.");
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> result = std::make_unique<IterativeMinMaxLinearEquationSolver<ValueType>>(this->linearEquationSolverFactory->clone(), settings);

8
src/storm/solver/IterativeMinMaxLinearEquationSolver.h

@ -40,7 +40,7 @@ namespace storm {
IterativeMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType> const& A, std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory, IterativeMinMaxLinearEquationSolverSettings<ValueType> const& settings = IterativeMinMaxLinearEquationSolverSettings<ValueType>());
IterativeMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType>&& A, std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory, IterativeMinMaxLinearEquationSolverSettings<ValueType> const& settings = IterativeMinMaxLinearEquationSolverSettings<ValueType>());
virtual bool solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
virtual bool internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
IterativeMinMaxLinearEquationSolverSettings<ValueType> const& getSettings() const;
void setSettings(IterativeMinMaxLinearEquationSolverSettings<ValueType> const& newSettings);
@ -87,8 +87,10 @@ namespace storm {
virtual void setMinMaxMethod(MinMaxMethodSelection const& newMethod) override;
virtual void setMinMaxMethod(MinMaxMethod const& newMethod) override;
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const override;
// Make the other create methods visible.
using MinMaxLinearEquationSolverFactory<ValueType>::create;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const override;
private:
IterativeMinMaxLinearEquationSolverSettings<ValueType> settings;

4
src/storm/solver/LpMinMaxLinearEquationSolver.cpp

@ -25,7 +25,7 @@ namespace storm {
}
template<typename ValueType>
bool LpMinMaxLinearEquationSolver<ValueType>::solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
bool LpMinMaxLinearEquationSolver<ValueType>::internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
// Set up the LP solver
std::unique_ptr<storm::solver::LpSolver<ValueType>> solver = lpSolverFactory->create("");
@ -124,7 +124,7 @@ namespace storm {
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> LpMinMaxLinearEquationSolverFactory<ValueType>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> LpMinMaxLinearEquationSolverFactory<ValueType>::create() const {
STORM_LOG_ASSERT(this->lpSolverFactory, "Lp solver factory not initialized.");
STORM_LOG_ASSERT(this->linearEquationSolverFactory, "Linear equation solver factory not initialized.");

9
src/storm/solver/LpMinMaxLinearEquationSolver.h

@ -14,7 +14,7 @@ namespace storm {
LpMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType> const& A, std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory, std::unique_ptr<storm::utility::solver::LpSolverFactory<ValueType>>&& lpSolverFactory);
LpMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType>&& A, std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory, std::unique_ptr<storm::utility::solver::LpSolverFactory<ValueType>>&& lpSolverFactory);
virtual bool solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
virtual bool internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
virtual void clearCache() const override;
@ -32,9 +32,10 @@ namespace storm {
virtual void setMinMaxMethod(MinMaxMethodSelection const& newMethod) override;
virtual void setMinMaxMethod(MinMaxMethod const& newMethod) override;
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const override;
std::unique_ptr<LinearEquationSolverFactory<ValueType>> createLpEquationSolverFactory() const;
// Make the other create methods visible.
using MinMaxLinearEquationSolverFactory<ValueType>::create;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const override;
private:
std::unique_ptr<storm::utility::solver::LpSolverFactory<ValueType>> lpSolverFactory;

15
src/storm/solver/MinMaxLinearEquationSolver.cpp

@ -28,6 +28,11 @@ namespace storm {
// Intentionally left empty.
}
template<typename ValueType>
bool MinMaxLinearEquationSolver<ValueType>::solveEquations(OptimizationDirection d, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
return internalSolveEquations(d, x, b);
}
template<typename ValueType>
void MinMaxLinearEquationSolver<ValueType>::solveEquations(std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
STORM_LOG_THROW(isSet(this->direction), storm::exceptions::IllegalFunctionCallException, "Optimization direction not set.");
@ -196,20 +201,20 @@ namespace storm {
template<typename ValueType>
std::vector<MinMaxLinearEquationSolverRequirement> MinMaxLinearEquationSolverFactory<ValueType>::getRequirements() const {
// Create dummy solver and ask it for requirements.
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->internalCreate();
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->create();
return solver->getRequirements();
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> MinMaxLinearEquationSolverFactory<ValueType>::create(storm::storage::SparseMatrix<ValueType> const& matrix) const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->internalCreate();
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->create();
solver->setMatrix(matrix);
return solver;
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> MinMaxLinearEquationSolverFactory<ValueType>::create(storm::storage::SparseMatrix<ValueType>&& matrix) const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->internalCreate();
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> solver = this->create();
solver->setMatrix(std::move(matrix));
return solver;
}
@ -220,7 +225,7 @@ namespace storm {
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> GeneralMinMaxLinearEquationSolverFactory<ValueType>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> GeneralMinMaxLinearEquationSolverFactory<ValueType>::create() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> result;
auto method = this->getMinMaxMethod();
if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::Acyclic) {
@ -239,7 +244,7 @@ namespace storm {
}
template<>
std::unique_ptr<MinMaxLinearEquationSolver<storm::RationalNumber>> GeneralMinMaxLinearEquationSolverFactory<storm::RationalNumber>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<storm::RationalNumber>> GeneralMinMaxLinearEquationSolverFactory<storm::RationalNumber>::create() const {
std::unique_ptr<MinMaxLinearEquationSolver<storm::RationalNumber>> result;
auto method = this->getMinMaxMethod();
if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::Acyclic) {

16
src/storm/solver/MinMaxLinearEquationSolver.h

@ -55,7 +55,7 @@ namespace storm {
* solver, but may be ignored.
* @param b The vector to add after matrix-vector multiplication.
*/
virtual bool solveEquations(OptimizationDirection d, std::vector<ValueType>& x, std::vector<ValueType> const& b) const = 0;
bool solveEquations(OptimizationDirection d, std::vector<ValueType>& x, std::vector<ValueType> const& b) const;
/*!
* Behaves the same as the other variant of <code>solveEquations</code>, with the distinction that
@ -184,6 +184,8 @@ namespace storm {
bool getRequirementsChecked() const;
protected:
virtual bool internalSolveEquations(OptimizationDirection d, std::vector<ValueType>& x, std::vector<ValueType> const& b) const = 0;
/// The optimization direction to use for calls to functions that do not provide it explicitly. Can also be unset.
OptimizationDirectionSetting direction;
@ -217,7 +219,8 @@ namespace storm {
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create(storm::storage::SparseMatrix<ValueType> const& matrix) const;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create(storm::storage::SparseMatrix<ValueType>&& matrix) const;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const = 0;
void setTrackScheduler(bool value);
bool isTrackSchedulerSet() const;
@ -228,9 +231,6 @@ namespace storm {
std::vector<MinMaxLinearEquationSolverRequirement> getRequirements() const;
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const = 0;
private:
bool trackScheduler;
MinMaxMethod method;
@ -241,8 +241,10 @@ namespace storm {
public:
GeneralMinMaxLinearEquationSolverFactory(MinMaxMethodSelection const& method = MinMaxMethodSelection::FROMSETTINGS, bool trackScheduler = false);
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const override;
// Make the other create methods visible.
using MinMaxLinearEquationSolverFactory<ValueType>::create;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const override;
};
} // namespace solver

2
src/storm/solver/StandardMinMaxLinearEquationSolver.cpp

@ -104,7 +104,7 @@ namespace storm {
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> StandardMinMaxLinearEquationSolverFactory<ValueType>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> StandardMinMaxLinearEquationSolverFactory<ValueType>::create() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> result;
auto method = this->getMinMaxMethod();
if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::Acyclic) {

7
src/storm/solver/StandardMinMaxLinearEquationSolver.h

@ -48,9 +48,12 @@ namespace storm {
StandardMinMaxLinearEquationSolverFactory(std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory, MinMaxMethodSelection const& method = MinMaxMethodSelection::FROMSETTINGS, bool trackScheduler = false);
StandardMinMaxLinearEquationSolverFactory(EquationSolverType const& solverType, MinMaxMethodSelection const& method = MinMaxMethodSelection::FROMSETTINGS, bool trackScheduler = false);
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const override;
// Make the other create methods visible.
using MinMaxLinearEquationSolverFactory<ValueType>::create;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const override;
protected:
std::unique_ptr<LinearEquationSolverFactory<ValueType>> linearEquationSolverFactory;
private:

4
src/storm/solver/TopologicalMinMaxLinearEquationSolver.cpp

@ -49,7 +49,7 @@ namespace storm {
}
template<typename ValueType>
bool TopologicalMinMaxLinearEquationSolver<ValueType>::solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
bool TopologicalMinMaxLinearEquationSolver<ValueType>::internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
#ifdef GPU_USE_FLOAT
#define __FORCE_FLOAT_CALCULATION true
@ -478,7 +478,7 @@ namespace storm {
}
template<typename ValueType>
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> TopologicalMinMaxLinearEquationSolverFactory<ValueType>::internalCreate() const {
std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> TopologicalMinMaxLinearEquationSolverFactory<ValueType>::create() const {
return std::make_unique<TopologicalMinMaxLinearEquationSolver<ValueType>>();
}

4
src/storm/solver/TopologicalMinMaxLinearEquationSolver.h

@ -37,7 +37,7 @@ namespace storm {
virtual void setMatrix(storm::storage::SparseMatrix<ValueType> const& matrix) override;
virtual void setMatrix(storm::storage::SparseMatrix<ValueType>&& matrix) override;
virtual bool solveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
virtual bool internalSolveEquations(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b) const override;
virtual void repeatedMultiply(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint_fast64_t n) const override;
@ -151,7 +151,7 @@ namespace storm {
TopologicalMinMaxLinearEquationSolverFactory(bool trackScheduler = false);
protected:
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> internalCreate() const override;
virtual std::unique_ptr<MinMaxLinearEquationSolver<ValueType>> create() const override;
};
} // namespace solver

Loading…
Cancel
Save