LCOV - code coverage report
Current view: top level - src/common/optimization/src - optimizer_options.cpp (source / functions) Hit Total Coverage
Test: lcov.total.filtered Lines: 24 28 85.7 %
Date: 2021-01-26 05:02:50 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright 2019 the Autoware Foundation
       2                 :            : //
       3                 :            : // Licensed under the Apache License, Version 2.0 (the "License");
       4                 :            : // you may not use this file except in compliance with the License.
       5                 :            : // You may obtain a copy of the License at
       6                 :            : //
       7                 :            : //     http://www.apache.org/licenses/LICENSE-2.0
       8                 :            : //
       9                 :            : // Unless required by applicable law or agreed to in writing, software
      10                 :            : // distributed under the License is distributed on an "AS IS" BASIS,
      11                 :            : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :            : // See the License for the specific language governing permissions and
      13                 :            : // limitations under the License.
      14                 :            : //
      15                 :            : // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
      16                 :            : 
      17                 :            : #include <common/types.hpp>
      18                 :            : #include <optimization/optimizer_options.hpp>
      19                 :            : #include <stdexcept>
      20                 :            : #include <cmath>
      21                 :            : 
      22                 :            : using autoware::common::types::float64_t;
      23                 :            : 
      24                 :            : namespace autoware
      25                 :            : {
      26                 :            : namespace common
      27                 :            : {
      28                 :            : namespace optimization
      29                 :            : {
      30                 :         23 : OptimizationOptions::OptimizationOptions(
      31                 :            :   uint64_t max_num_iterations,
      32                 :            :   float64_t function_tolerance,
      33                 :            :   float64_t parameter_tolerance,
      34                 :         23 :   float64_t gradient_tolerance)
      35                 :            : : m_max_num_iterations(max_num_iterations),
      36                 :            :   m_function_tolerance(function_tolerance), m_parameter_tolerance(parameter_tolerance),
      37         [ +  - ]:         23 :   m_gradient_tolerance(gradient_tolerance)
      38                 :            : {
      39         [ +  - ]:         23 :   if (!std::isfinite(m_function_tolerance) ||
      40   [ +  -  -  + ]:         46 :     !std::isfinite(m_parameter_tolerance) ||
      41                 :            :     !std::isfinite(m_gradient_tolerance))
      42                 :            :   {
      43         [ #  # ]:          0 :     throw std::domain_error("OptimizationOptions: Tolerance values must be finite.");
      44                 :            :   }
      45                 :            : 
      46   [ +  +  +  + ]:         23 :   if ((m_function_tolerance <= 0.0) &&
      47         [ -  + ]:         14 :     (m_parameter_tolerance <= 0.0) &&
      48                 :            :     (m_gradient_tolerance <= 0.0))
      49                 :            :   {
      50                 :            :     throw std::domain_error(
      51                 :            :             "OptimizationOptions: "
      52                 :            :             "There should at least be one positive tolerance value "
      53         [ #  # ]:          0 :             "for convergence.");
      54                 :            :   }
      55                 :         23 : }
      56                 :            : 
      57                 :        142 : uint64_t OptimizationOptions::max_num_iterations() const noexcept
      58                 :            : {
      59                 :        142 :   return m_max_num_iterations;
      60                 :            : }
      61                 :        126 : float64_t OptimizationOptions::function_tolerance() const noexcept
      62                 :            : {
      63                 :        126 :   return m_function_tolerance;
      64                 :            : }
      65                 :        262 : float64_t OptimizationOptions::parameter_tolerance() const noexcept
      66                 :            : {
      67                 :        262 :   return m_parameter_tolerance;
      68                 :            : }
      69                 :        154 : float64_t OptimizationOptions::gradient_tolerance() const noexcept
      70                 :            : {
      71                 :        154 :   return m_gradient_tolerance;
      72                 :            : }
      73                 :            : 
      74                 :         25 : OptimizationSummary::OptimizationSummary(
      75                 :            :   float64_t dist, TerminationType termination_type,
      76                 :         25 :   uint64_t iter)
      77                 :            : : m_estimated_distance_to_optimum(dist),
      78                 :            :   m_number_of_iterations_made(iter),
      79                 :         25 :   m_termination_type(termination_type)
      80                 :         25 : {}
      81                 :            : 
      82                 :          7 : float64_t OptimizationSummary::estimated_distance_to_optimum() const noexcept
      83                 :            : {
      84                 :          7 :   return m_estimated_distance_to_optimum;
      85                 :            : }
      86                 :         25 : TerminationType OptimizationSummary::termination_type() const noexcept
      87                 :            : {
      88                 :         25 :   return m_termination_type;
      89                 :            : }
      90                 :          0 : uint64_t OptimizationSummary::number_of_iterations_made() const noexcept
      91                 :            : {
      92                 :          0 :   return m_number_of_iterations_made;
      93                 :            : }
      94                 :            : }  // namespace optimization
      95                 :            : }  // namespace common
      96                 :            : }  // namespace autoware

Generated by: LCOV version 1.14