- 3.0.2 optimal control module.
DmsSettings.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <map>
9 
10 #include <boost/property_tree/info_parser.hpp>
11 
13 
14 namespace ct {
15 namespace optcon {
16 
17 
24 {
25 public:
30 
37  : N_(30),
38  T_(5),
39  nThreads_(1),
43  h_min_(0.1),
45  dt_sim_(0.01),
46  absErrTol_(1e-10),
47  relErrTol_(1e-10)
48  {
49  }
50 
51  size_t N_; // the number of shots
52  double T_; // the time horizon
53  size_t nThreads_; // number of threads
54  SplineType_t splineType_; // spline interpolation type between the nodes
55  CostEvaluationType_t costEvaluationType_; // the the of costevaluator
56  ObjectiveType_t objectiveType_; // Timegrid optimization on(expensive) or off?
57  double h_min_; // minimum admissible distance between two nodes in [sec]
58  IntegrationType_t integrationType_; // the integration type between the nodes
59  double dt_sim_; // and the corresponding integration timestep
60  double absErrTol_; // the absolute and relative integrator tolerances when using RK5
61  double relErrTol_;
62 
65 
66  void print()
67  {
68  std::cout << "=============================================================" << std::endl;
69  std::cout << "\tMultiple Shooting Settings: " << std::endl;
70  std::cout << "=============================================================" << std::endl;
71 
72  std::cout << "Shooting intervals N : " << N_ << std::endl;
73  std::cout << "Total Time horizon: " << T_ << "s" << std::endl;
74  std::cout << "Number of threads: " << nThreads_ << std::endl;
75  std::cout << "Splinetype: " << splineToString[splineType_] << std::endl;
76  std::cout << "Cost eval: " << costEvalToString[costEvaluationType_] << std::endl;
77  std::cout << "Objective type: " << objTypeToString[objectiveType_] << std::endl;
78  std::cout << "Integration type: " << integratorToString[integrationType_] << std::endl;
79  std::cout << "Simulation timestep dt_sim: " << dt_sim_ << std::endl;
80 
81  std::cout << "=============================================================" << std::endl;
82 
83  solverSettings_.print();
84  }
85 
86  bool parametersOk() const
87  {
88  if (N_ < 1 || N_ > 1000)
89  return false;
90 
91  if (T_ <= 0.0)
92  return false;
93 
94  if (nThreads_ < 1 || nThreads_ > 32)
95  return false;
96 
97  if (splineType_ < 0 || !(splineType_ < SplineType_t::num_types_splining))
98  return false;
99 
100  if (costEvaluationType_ < 0 || !(costEvaluationType_ < CostEvaluationType_t::num_types_costevaluation))
101  return false;
102 
103  if (objectiveType_ < 0 || !(objectiveType_ < ObjectiveType_t::num_types_objectives))
104  return false;
105 
106  if (h_min_ < 0.01 || h_min_ > T_)
107  return false;
108 
109  if (integrationType_ < 0 || !(integrationType_ < IntegrationType_t::num_types_integration))
110  return false;
111 
112  if (dt_sim_ <= 0.0 || dt_sim_ > 100.0)
113  return false;
114 
115  if (absErrTol_ <= 1e-20 || absErrTol_ > 1.0)
116  return false;
117 
118  if (relErrTol_ <= 1e-20 || relErrTol_ > 1.0)
119  return false;
120 
121  return solverSettings_.parametersOk();
122  }
123 
124  void load(const std::string& filename, bool verbose = true, const std::string& ns = "dms")
125  {
126  if (verbose)
127  std::cout << "Trying to load DMS config from " << filename << ": " << std::endl;
128 
129  boost::property_tree::ptree pt;
130  boost::property_tree::read_info(filename, pt);
131 
132  N_ = pt.get<unsigned int>(ns + ".N");
133  T_ = pt.get<double>(ns + ".T");
134  nThreads_ = pt.get<unsigned int>(ns + ".nThreads");
135  splineType_ = static_cast<SplineType_t>(pt.get<unsigned int>(ns + ".InterpolationType"));
136  costEvaluationType_ = static_cast<CostEvaluationType_t>(pt.get<unsigned int>(ns + ".CostEvaluationType"));
137  objectiveType_ = static_cast<ObjectiveType_t>(pt.get<unsigned int>(ns + ".ObjectiveType"));
138  h_min_ = pt.get<double>(ns + ".h_min");
139 
140  integrationType_ = static_cast<IntegrationType_t>(pt.get<unsigned int>(ns + ".IntegrationType"));
141  dt_sim_ = pt.get<double>(ns + ".dt_sim");
142  absErrTol_ = pt.get<double>(ns + ".AbsErrTol");
143  relErrTol_ = pt.get<double>(ns + ".RelErrTol");
144 
145  solverSettings_.load(filename, verbose, ns + ".solver"); // todo bring in again
146  cppadSettings_.load(filename, verbose, ns + ".cppad");
147 
148  if (verbose)
149  {
150  std::cout << "Loaded DMS config from " << filename << ": " << std::endl;
151  print();
152  }
153  }
154 
155 private:
156  std::map<SplineType, std::string> splineToString = {
157  {ZERO_ORDER_HOLD, "Zero order hold"}, {PIECEWISE_LINEAR, "Piecewise Linear"}};
158  std::map<ObjectiveType, std::string> objTypeToString = {
159  {KEEP_TIME_AND_GRID, "Timegrid fix"}, {OPTIMIZE_GRID, "Timegrid Optimization On"}};
160  std::map<IntegrationType, std::string> integratorToString = {
161  {EULER, "Euler"}, {RK4, "Runge-Kutta 4th order"}, {RK5, "RK5 adaptive step size"}};
162  std::map<CostEvaluationType, std::string> costEvalToString = {{SIMPLE, "Simple"}, {FULL, "Full"}};
163 };
164 }
165 }
double absErrTol_
Definition: DmsSettings.h:60
ObjectiveType_t objectiveType_
Definition: DmsSettings.h:56
double relErrTol_
Definition: DmsSettings.h:61
enum ct::optcon::DmsSettings::SplineType SplineType_t
Definition: DmsSettings.h:28
Definition: DmsSettings.h:26
Definition: DmsSettings.h:27
Contains the NLP solver settings.
Definition: NlpSolverSettings.h:261
enum ct::optcon::DmsSettings::IntegrationType IntegrationType_t
bool parametersOk() const
Checks whether to settings are filled with meaningful values.
Definition: NlpSolverSettings.h:308
double dt_sim_
Definition: DmsSettings.h:59
Definition: DmsSettings.h:29
double T_
Definition: DmsSettings.h:52
Definition: DmsSettings.h:29
Definition: DmsSettings.h:28
size_t N_
Definition: DmsSettings.h:51
ct::core::DerivativesCppadSettings cppadSettings_
Definition: DmsSettings.h:64
Definition: DmsSettings.h:26
void print()
Prints out settings.
Definition: NlpSolverSettings.h:281
CostEvaluationType
Definition: DmsSettings.h:29
double h_min_
Definition: DmsSettings.h:57
bool parametersOk() const
Definition: DmsSettings.h:86
ObjectiveType
Definition: DmsSettings.h:27
enum ct::optcon::DmsSettings::CostEvaluationType CostEvaluationType_t
NlpSolverSettings solverSettings_
Definition: DmsSettings.h:63
void load(const std::string &filename, bool verbose=true, const std::string &ns="solver")
Loads the settings from a .info file.
Definition: NlpSolverSettings.h:325
SplineType_t splineType_
Definition: DmsSettings.h:54
void load(const std::string &filename, bool verbose=true, const std::string &ns="solver")
Defines the DMS settings.
Definition: DmsSettings.h:23
void load(const std::string &filename, bool verbose=true, const std::string &ns="dms")
Definition: DmsSettings.h:124
void print()
Definition: DmsSettings.h:66
enum ct::optcon::DmsSettings::ObjectiveType ObjectiveType_t
IntegrationType
Definition: DmsSettings.h:28
size_t nThreads_
Definition: DmsSettings.h:53
const bool verbose
Definition: ConstraintComparison.h:18
DmsSettings()
Default constructor. Sets some default DMS settings. Note that the optimal settings are strongly depe...
Definition: DmsSettings.h:36
CostEvaluationType_t costEvaluationType_
Definition: DmsSettings.h:55
IntegrationType_t integrationType_
Definition: DmsSettings.h:58
Definition: DmsSettings.h:28
SplineType
Definition: DmsSettings.h:26