TVM  0.9.4
WeightedLeastSquares.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/internal/traits.h>
10 
11 namespace tvm
12 {
13 
14 namespace scheme
15 {
18 {
22  TVM_ADD_NON_DEFAULT_OPTION(autoDamping, false)
27  TVM_ADD_NON_DEFAULT_OPTION(scalarizationWeight, 1000.)
28 };
29 
32 {
33 private:
34  struct Memory : public internal::LinearizedProblemComputationData
35  {
36  Memory(int solverId, std::unique_ptr<solver::abstract::LeastSquareSolver> solver);
37 
38  void reset(std::unique_ptr<solver::abstract::LeastSquareSolver> solver);
39 
40  std::unique_ptr<solver::abstract::LeastSquareSolver> solver;
41 
42  int maxp = 0;
43 
44  protected:
45  void setVariablesToSolution_(tvm::internal::VariableCountingVector & x) override;
46  };
47 
48  const static internal::SchemeAbilities abilities_;
49 
51  template<typename T>
52  using isFactory = std::is_base_of<solver::abstract::LSSolverFactory, T>;
54  template<typename T>
55  struct FactoryMemberIsFactory
56  {
57  static constexpr bool value = isFactory<typename T::Factory>::value;
58  };
60  template<typename T>
61  using isLSSolverFactoryOption =
62  std::conjunction<tvm::internal::has_public_member_type_Factory<T>, FactoryMemberIsFactory<T>>;
63 
64 public:
65  using ComputationDataType = Memory;
66 
72  template<class SolverFactory, typename std::enable_if<isFactory<SolverFactory>::value, int>::type = 0>
73  WeightedLeastSquares(const SolverFactory & solverFactory, WeightedLeastSquaresOptions schemeOptions = {})
74  : LinearResolutionScheme<WeightedLeastSquares>(abilities_), options_(schemeOptions),
75  solverFactory_(solverFactory.clone())
76  {}
77 
85  template<class SolverOptions, typename std::enable_if<isLSSolverFactoryOption<SolverOptions>::value, int>::type = 0>
86  WeightedLeastSquares(const SolverOptions & solverOptions, WeightedLeastSquaresOptions schemeOptions = {})
87  : WeightedLeastSquares(typename SolverOptions::Factory(solverOptions), schemeOptions)
88  {}
89 
93  template<typename T,
94  typename std::enable_if<!isFactory<T>::value && !isLSSolverFactoryOption<T>::value, int>::type = 0>
96  : LinearResolutionScheme<WeightedLeastSquares>(abilities_)
97  {
99  "First argument can only be a LSSolverFactory or a solver configuration. "
100  "A configuration needs to have a Factory member type that is itself deriving from LSSolverFactory. "
101  "See LSSOLLSSolverOptions for an example.");
102  }
103 
112 
116  std::unique_ptr<Memory> createComputationData_(const LinearizedControlProblem & problem) const;
117 
118 protected:
119  void resetComputationData(const LinearizedControlProblem & problem, Memory * memory) const;
120  void processProblem(const LinearizedControlProblem & problem, Memory * memory) const;
121 
122  void addTask(const LinearizedControlProblem & problem,
123  Memory * memory,
124  const TaskWithRequirements & task,
125  solver::internal::SolverEvents & se) const;
126  void removeTask(const LinearizedControlProblem & problem,
127  Memory * memory,
128  const TaskWithRequirements & task,
129  solver::internal::SolverEvents & se) const;
130 
133  std::unique_ptr<solver::abstract::LSSolverFactory> solverFactory_;
134 };
135 
136 } // namespace scheme
137 
138 } // namespace tvm
#define TVM_ADD_NON_DEFAULT_OPTION(optionName, defaultValue)
Definition: Option.h:30
#define TVM_DLLAPI
Definition: api.h:35
Definition: LinearizedControlProblem.h:24
Definition: ControlProblem.h:22
Definition: VariableCountingVector.h:30
Definition: meta.h:91
Definition: WeightedLeastSquares.h:18
Definition: WeightedLeastSquares.h:32
Memory ComputationDataType
Definition: WeightedLeastSquares.h:65
void removeTask(const LinearizedControlProblem &problem, Memory *memory, const TaskWithRequirements &task, solver::internal::SolverEvents &se) const
WeightedLeastSquares(const SolverOptions &solverOptions, WeightedLeastSquaresOptions schemeOptions={})
Definition: WeightedLeastSquares.h:86
void processProblem(const LinearizedControlProblem &problem, Memory *memory) const
WeightedLeastSquares(WeightedLeastSquares &&)=delete
WeightedLeastSquares(const SolverFactory &solverFactory, WeightedLeastSquaresOptions schemeOptions={})
Definition: WeightedLeastSquares.h:73
WeightedLeastSquares(const T &, WeightedLeastSquaresOptions={})
Definition: WeightedLeastSquares.h:95
void resetComputationData(const LinearizedControlProblem &problem, Memory *memory) const
std::unique_ptr< solver::abstract::LSSolverFactory > solverFactory_
Definition: WeightedLeastSquares.h:133
bool solve_(const LinearizedControlProblem &problem, internal::ProblemComputationData *data) const
void updateComputationData_(const LinearizedControlProblem &problem, internal::ProblemComputationData *data) const
WeightedLeastSquares & operator=(const WeightedLeastSquares &)=delete
WeightedLeastSquares & operator=(WeightedLeastSquares &&)=delete
WeightedLeastSquaresOptions options_
Definition: WeightedLeastSquares.h:131
void addTask(const LinearizedControlProblem &problem, Memory *memory, const TaskWithRequirements &task, solver::internal::SolverEvents &se) const
std::unique_ptr< Memory > createComputationData_(const LinearizedControlProblem &problem) const
WeightedLeastSquares(const WeightedLeastSquares &)=delete
Definition: ResolutionScheme.h:65
Definition: LinearizedProblemComputationData.h:20
Definition: ProblemComputationData.h:27
Definition: SchemeAbilities.h:59
Definition: SolverEvents.h:14
Definition: Clock.h:12