ResultSets.h
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Result sets for algorithms.
5 *
6 *
7 *
8 * \author T.Voss, T. Glasmachers, O.Krause
9 * \date 2010-2011
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_CORE_RESULTSETS_H
34#define SHARK_CORE_RESULTSETS_H
35
36#include <ostream>
37
38namespace shark{
39
40template<class SearchPointT, class ResultT>
41struct ResultSet{
42 typedef SearchPointT SearchPointType;
43 typedef ResultT ResultType;
47
50
51 template<typename Archive>
52 void serialize( Archive & archive, const unsigned int /*version*/ ) {
53 archive & point;
54 archive & value;
55 }
56
57 friend void swap(ResultSet& set1, ResultSet& set2){
58 using std::swap;
59 swap(set1.point,set2.point);
60 swap(set1.value,set2.value);
61 }
62};
63
64/// \brief Generates a typed solution given the search point and the corresponding objective function value.
65///
66/// \param [in] t The search point.
67/// \param [in] u The objective function value.
68///
69/// \returns A ResultSet containing the supplied search point and objective function value.
70template<typename T, typename U>
71ResultSet<T,U> makeResultSet(T const& t, U const& u ) {
72 return ResultSet<T,U>( u, t );
73}
74template<class SearchPoint,class Result>
75std::ostream & operator<<( std::ostream & out, ResultSet<SearchPoint,Result> const& solution ) {
76 out << solution.value << " " << solution.point;
77 return out;
78}
79
80///\brief Result set for single objective algorithm.
81///
82///Contains a point of the search space as well its value on the objective function.
83template<class SearchPointTypeT>
84struct SingleObjectiveResultSet: public ResultSet<SearchPointTypeT,double>{
85 typedef SearchPointTypeT SearchPointType;
86 typedef double ResultType;
87
90 :ResultSet<SearchPointTypeT,double>(value, point){}
91
92 ///\brief Compares two SingleObjectiveResultSets. Returns true if op1.value < op2.value.
93 friend bool operator<(SingleObjectiveResultSet const& op1, SingleObjectiveResultSet const& op2){
94 return op1.value < op2.value;
95 }
96};
97
98
99
100
101///\brief Result set for validated points.
102///
103///If validation is applied, this error function additionally saves the value on the validation set.
104///order between sets is by the validation error.
105template<class SearchPointTypeT>
107private:
109public:
115
117
118 template<typename Archive>
119 void serialize( Archive & archive, const unsigned int /*version*/ ) {
120 archive & boost::serialization::base_object<base_type >(*this);
121 archive & validation;
122 }
123
124 /// \brief Compares two ValidatedSingleObjectiveResultSets. Returns true if op1.validation < op2.validation
126 return op1.validation < op2.validation;
127 }
128};
129
130template<class SearchPoint>
131std::ostream & operator<<( std::ostream & out, ValidatedSingleObjectiveResultSet<SearchPoint> const& solution ) {
132 out << solution.validation << " "<< solution.value << " " << solution.point;
133 return out;
134}
135}
136
137#endif