Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
ObjectiveFunctions
AbstractConstraintHandler.h
Go to the documentation of this file.
1
//===========================================================================
2
/*!
3
*
4
*
5
* \brief Base class for constraints.
6
* \file
7
*
8
* \author O.Krause
9
* \date 2013
10
*
11
*
12
* \par Copyright 1995-2017 Shark Development Team
13
*
14
* <BR><HR>
15
* This file is part of Shark.
16
* <https://shark-ml.github.io/Shark/>
17
*
18
* Shark is free software: you can redistribute it and/or modify
19
* it under the terms of the GNU Lesser General Public License as published
20
* by the Free Software Foundation, either version 3 of the License, or
21
* (at your option) any later version.
22
*
23
* Shark is distributed in the hope that it will be useful,
24
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
* GNU Lesser General Public License for more details.
27
*
28
* You should have received a copy of the GNU Lesser General Public License
29
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
30
*
31
*/
32
//===========================================================================
33
#ifndef SHARK_OBJECTIVEFUNCTIONS_ABSTRACTCONSTRAINTHANDLER_H
34
#define SHARK_OBJECTIVEFUNCTIONS_ABSTRACTCONSTRAINTHANDLER_H
35
36
#include <
shark/Core/Exception.h
>
37
#include <
shark/Core/Flags.h
>
38
#include <
shark/Core/Random.h
>
39
40
namespace
shark
{
41
42
/// \defgroup constraint_handling Constraint Handling
43
/// \ingroup objfunctions
44
/// \brief Objects for handling constraints
45
///
46
47
/// \brief Implements the base class for constraint handling.
48
///
49
/// A constraint handler provides information about the feasible region of a constrained optimization problem.
50
/// In the minimum it checks whether a point is feasible, or what the next fasible point would be.
51
/// \ingroup constraint_handling
52
template
<
class
SearchPo
int
Type>
53
class
AbstractConstraintHandler
{
54
public
:
55
enum
Feature
{
56
CAN_PROVIDE_CLOSEST_FEASIBLE
= 1,
///< The constraint handler can provide a close feasible point to an infeasible one
57
IS_BOX_CONSTRAINED
= 2,
///< The constraint handler is an instance of BoxConstraintHandler
58
CAN_GENERATE_RANDOM_POINT
= 4
///< The ConstraintHandler can generate a random point inside the feasible region
59
};
60
SHARK_FEATURE_INTERFACE
;
61
62
virtual
~AbstractConstraintHandler
(){}
63
64
/// \brief Returns whether this function can calculate the closest feasible to an infeasible point.
65
bool
canProvideClosestFeasible
()
const
{
66
return
m_features
&
CAN_PROVIDE_CLOSEST_FEASIBLE
;
67
}
68
69
/// \brief Returns whether this function is an instance of BoxConstraintHandler
70
bool
isBoxConstrained
()
const
{
71
return
m_features
&
IS_BOX_CONSTRAINED
;
72
}
73
/// \brief Returns whether this function is an instance of BoxConstraintHandler
74
bool
canGenerateRandomPoint
()
const
{
75
return
m_features
&
CAN_GENERATE_RANDOM_POINT
;
76
}
77
78
/// \brief If supported, generates a random point inside the feasible region.
79
///
80
/// \param rng The random number generator used for generating the point
81
/// \param startingPoint The proposed point
82
virtual
void
generateRandomPoint
( random::rng_type& rng, SearchPointType & startingPoint )
const
{
83
SHARK_FEATURE_EXCEPTION
(
CAN_GENERATE_RANDOM_POINT
);
84
}
85
86
/// \brief Returns true if the point is in the feasible Region.
87
///
88
/// This function must be implemented by a ConstraintHandler
89
virtual
bool
isFeasible
(SearchPointType
const
&)
const
= 0;
90
virtual
void
closestFeasible
(SearchPointType& )
const
{
91
SHARK_FEATURE_EXCEPTION
(
CAN_PROVIDE_CLOSEST_FEASIBLE
);
92
}
93
94
};
95
}
96
#endif