MOCMAApproximated.cpp
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Example for running the approximated hypervolume 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.setNumberOfObjectives( 5 );
46 dtlz2.setNumberOfVariables( 25 );
47
48
49 shark::MOCMA mocma;
50 mocma.mu() = 120;
51 mocma.indicator().useApproximation(true);
52 mocma.indicator().approximationDelta() = 0.05;
53 mocma.indicator().setReference(shark::RealVector(dtlz2.numberOfObjectives(),11));
54 // Initialize the optimizer for the objective function instance.
55 dtlz2.init();
56 mocma.init( dtlz2 );
57
58 // Iterate the optimizer
59 while( dtlz2.evaluationCounter() < 2000 ) {
60 mocma.step( dtlz2 );
61 std::cout<<dtlz2.evaluationCounter()<<std::endl;
62 }
63
64 // Print the optimal pareto front
65 for( std::size_t i = 0; i < mocma.solution().size(); i++ ) {
66 for( std::size_t j = 0; j < dtlz2.numberOfObjectives(); j++ ) {
67 std::cout<< mocma.solution()[ i ].value[j]<<" ";
68 }
69 std::cout << std::endl;
70 }
71}