base_objective.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_OBJECTIVES_BASE_OBJECTIVE_H_
9 #define FIELDS2COVER_OBJECTIVES_BASE_OBJECTIVE_H_
10 
11 #include <vector>
12 #include "fields2cover/types.h"
13 
14 namespace f2c::obj {
15 
16 template <typename T>
18  public:
19  // Avoid using variadic templates. SWIG don't work well with it
20 
25  template <typename T1>
26  double computeCostWithMinimizingSign(const T1& t1) {
27  return (static_cast<T*>(this)->isMinimizing() ? 1.0 : -1.0) *
28  static_cast<T*>(this)->computeCost(t1);
29  }
30  template <typename T1, typename T2>
31  double computeCostWithMinimizingSign(const T1& t1, const T2& t2) {
32  return (static_cast<T*>(this)->isMinimizing() ? 1.0 : -1.0) *
33  static_cast<T*>(this)->computeCost(t1, t2);
34  }
35  template <typename T1, typename T2, typename T3>
37  const T1& t1, const T2& t2, const T3& t3) {
38  return (static_cast<T*>(this)->isMinimizing() ? 1.0 : -1.0) *
39  static_cast<T*>(this)->computeCost(t1, t2, t3);
40  }
41  template <typename T1, typename T2, typename T3, typename T4>
43  const T1& t1, const T2& t2, const T3& t3, const T4& t4) {
44  return (static_cast<T*>(this)->isMinimizing() ? 1.0 : -1.0) *
45  static_cast<T*>(this)->computeCost(t1, t2, t3, t4);
46  }
47 
48  public:
50  virtual bool isMinimizing() const { return true;}
52  virtual bool isMaximizing() const { return !isMinimizing();}
53 
54  virtual ~BaseObjective() = default;
55 };
56 
57 
58 } // namespace f2c::obj
59 
60 #endif // FIELDS2COVER_OBJECTIVES_BASE_OBJECTIVE_H_
types.h
f2c::obj::BaseObjective::~BaseObjective
virtual ~BaseObjective()=default
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1, const T2 &t2, const T3 &t3)
Definition: base_objective.h:36
f2c::obj
Objective algorithms' namespace.
Definition: base_objective.h:14
f2c::obj::BaseObjective::isMaximizing
virtual bool isMaximizing() const
Return true if the objective is to maximize the cost function.
Definition: base_objective.h:52
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1, const T2 &t2)
Definition: base_objective.h:31
f2c::obj::BaseObjective
Definition: base_objective.h:17
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1)
Compute the cost function with minimizing sign.
Definition: base_objective.h:26
f2c::obj::BaseObjective::isMinimizing
virtual bool isMinimizing() const
Return true if the objective is to minimize the cost function.
Definition: base_objective.h:50
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
Definition: base_objective.h:42


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31