- 3.0.2 optimal control module.
NLOCResults.hpp
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 #ifdef MATLAB
9 #include <ct/optcon/matlab.hpp>
10 #endif
11 
17 template <typename SCALAR = double>
19 {
21  std::vector<size_t> iterations;
22 
24  std::vector<SCALAR> defect_l1_norms;
25  std::vector<SCALAR> defect_l2_norms;
26  std::vector<SCALAR> e_box_norms;
27  std::vector<SCALAR> e_gen_norms;
28 
30  std::vector<SCALAR> lx_norms;
31  std::vector<SCALAR> lu_norms;
32 
34  std::vector<SCALAR> intermediateCosts;
35  std::vector<SCALAR> finalCosts;
36  std::vector<SCALAR> totalCosts;
37  std::vector<SCALAR> merits;
38 
40  std::vector<SCALAR> stepSizes;
41 
43  std::vector<SCALAR> smallestEigenvalues;
44 
46  template <int NUM_PRECISION = 12>
48  {
49  std::cout << "NLOC Summary of iteration " << iterations.back() << std::endl;
50  std::cout << "==============================" << std::endl;
51 
52  std::cout << std::setprecision(NUM_PRECISION) << "interm. cost:\t" << intermediateCosts.back() << std::endl;
53  std::cout << std::setprecision(NUM_PRECISION) << "final cost:\t" << finalCosts.back() << std::endl;
54  std::cout << std::setprecision(NUM_PRECISION) << "total cost:\t" << totalCosts.back() << std::endl;
55  std::cout << std::setprecision(NUM_PRECISION) << "total merit:\t" << merits.back() << std::endl;
56  std::cout << std::setprecision(NUM_PRECISION) << "tot. defect L1:\t" << defect_l1_norms.back() << std::endl;
57  std::cout << std::setprecision(NUM_PRECISION) << "tot. defect L2:\t" << defect_l2_norms.back() << std::endl;
58  std::cout << std::setprecision(NUM_PRECISION) << "box cstr.err:\t" << e_box_norms.back() << std::endl;
59  std::cout << std::setprecision(NUM_PRECISION) << "gen cstr.err:\t" << e_gen_norms.back() << std::endl;
60  std::cout << std::setprecision(NUM_PRECISION) << "total lx norm:\t" << lx_norms.back() << std::endl;
61  std::cout << std::setprecision(NUM_PRECISION) << "total lu norm:\t" << lu_norms.back() << std::endl;
62  std::cout << std::setprecision(NUM_PRECISION) << "step-size:\t" << stepSizes.back() << std::endl;
63  std::cout << " ===========" << std::endl;
64  std::cout << std::endl;
65  }
66 
67 
68  void logToMatlab(const std::string& fileName)
69  {
70 #ifdef MATLAB
71  std::cout << "Logging NLOC summary to Matlab" << std::endl;
72  matFile_.open(fileName + ".mat");
73 
74  matFile_.put("iterations", iterations);
75  matFile_.put("defect_l1_norms", defect_l1_norms);
76  matFile_.put("defect_l2_norms", defect_l2_norms);
77  matFile_.put("box_constr_norms", e_box_norms);
78  matFile_.put("gen_constr_norms", e_gen_norms);
79  matFile_.put("lx_norms", lx_norms);
80  matFile_.put("lu_norms", lu_norms);
81  matFile_.put("intermediateCosts", intermediateCosts);
82  matFile_.put("finalCosts", finalCosts);
83  matFile_.put("totalCosts", totalCosts);
84  matFile_.put("merits", merits);
85  matFile_.put("stepSizes", stepSizes);
86  matFile_.put("smallestEigenvalues", smallestEigenvalues);
87  matFile_.close();
88 #endif
89  }
90 
92 #ifdef MATLAB
93  matlab::MatFile matFile_;
94 #endif //MATLAB
95 };
void printSummaryLastIteration()
print summary of the last iteration with desired numeric precision
Definition: NLOCResults.hpp:47
std::vector< SCALAR > merits
Definition: NLOCResults.hpp:37
std::vector< size_t > iterations
log of the iterations
Definition: NLOCResults.hpp:21
std::vector< SCALAR > defect_l2_norms
Definition: NLOCResults.hpp:25
std::vector< SCALAR > totalCosts
Definition: NLOCResults.hpp:36
Definition: NLOCResults.hpp:18
std::vector< SCALAR > intermediateCosts
costs and merits
Definition: NLOCResults.hpp:34
std::vector< SCALAR > finalCosts
Definition: NLOCResults.hpp:35
void logToMatlab(const std::string &fileName)
Definition: NLOCResults.hpp:68
std::vector< SCALAR > e_box_norms
Definition: NLOCResults.hpp:26
std::vector< SCALAR > stepSizes
step size
Definition: NLOCResults.hpp:40
std::vector< SCALAR > lx_norms
step update norms
Definition: NLOCResults.hpp:30
std::vector< SCALAR > smallestEigenvalues
smallest eigenvalues
Definition: NLOCResults.hpp:43
std::vector< SCALAR > defect_l1_norms
different overall defect norms
Definition: NLOCResults.hpp:24
a dummy class which is created for compatibility reasons if the MATLAB flag is not set...
Definition: matlab.hpp:17
std::vector< SCALAR > e_gen_norms
Definition: NLOCResults.hpp:27
std::vector< SCALAR > lu_norms
Definition: NLOCResults.hpp:31