MOCMASimple.cpp
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Example for running MO-CMA-ES on an exemplary benchmark function.
5
6 *
7 *
8 * \author tvoss
9 * \date -
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// Implementation of the MO-CMA-ES
34// Access to benchmark functions
36
37int main( int argc, char ** argv ) {
38
39 // Adjust the floating-point format to scientific and increase output precision.
40 std::cout.setf( std::ios_base::scientific );
41 std::cout.precision( 10 );
42
43 // Instantiate both the problem and the optimizer.
45 dtlz2.setNumberOfVariables( 3 );
46
47 shark::MOCMA mocma;
48
49 // Initialize the optimizer for the objective function instance.
50 dtlz2.init();
51 mocma.init( dtlz2 );
52
53 // Iterate the optimizer
54 while( dtlz2.evaluationCounter() < 25000 ) {
55 mocma.step( dtlz2 );
56 }
57
58 // Print the optimal pareto front
59 for( std::size_t i = 0; i < mocma.solution().size(); i++ ) {
60 for( std::size_t j = 0; j < dtlz2.numberOfObjectives(); j++ ) {
61 std::cout<< mocma.solution()[ i ].value[j]<<" ";
62 }
63 std::cout << std::endl;
64 }
65}