-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjective.hpp
More file actions
92 lines (63 loc) · 2.19 KB
/
Objective.hpp
File metadata and controls
92 lines (63 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*==============================================================================
Objective function
The abstract objective class defines the real function to optimize taking a
vector of real values as argument values and returning a real number for the
objective function at that point.
The abstract gradient class defines a gradient function that is required by
some of the optimization algorithms. It takes a vector of real values and
returns a vector of real values of the same size as the argument vector
representing the gradient at the evaluation point.
Author and Copyright: Geir Horn, 2018
License: LGPL 3.0
==============================================================================*/
#ifndef OPTIMMIZATION_OBJECTIVE
#define OPTIMMIZATION_OBJECTIVE
#include <vector>
#include "Variables.hpp"
namespace Optimization
{
/*==============================================================================
Objective function base class
==============================================================================*/
class Objective
{
public:
// Even though the standard optimization is to minimize, both minimization
// and maximization are possible, and the direction can in some cases be set.
enum class Goal
{
Minimize,
Maximize
};
protected:
virtual VariableType
ObjectiveFunction( const Variables & VariableValues ) = 0;
// The constructor is protected to prevent direct construction of this
// class although it does not do anything.
Objective( void )
{}
public:
// The virtual destructor is defined to allow derived classes to destruct
// properly
virtual ~Objective( void )
{}
};
/*==============================================================================
Gradient function base class
==============================================================================*/
class ObjectiveGradient : virtual public Objective
{
protected:
virtual GradientVector
GradientFunction( const Variables & VariableValues ) = 0;
ObjectiveGradient( void )
: Objective()
{}
public:
// Again there is a virtual destructor to allow derived classes to be
// correctly destructed
virtual ~ObjectiveGradient( void )
{ }
};
} // end name space Optimization
#endif // OPTIMMIZATION_OBJECTIVE