DART  6.10.1
MultiObjectiveSolver.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_OPTIMIZER_MULTIOBJECTIVESOLVER_HPP_
34 #define DART_OPTIMIZER_MULTIOBJECTIVESOLVER_HPP_
35 
36 #include <iostream>
37 #include <memory>
38 #include <vector>
39 
40 #include <Eigen/Dense>
41 
43 
44 namespace dart {
45 namespace optimizer {
46 
47 class MultiObjectiveProblem;
48 
58 {
59 public:
64  struct Properties
65  {
67  std::shared_ptr<MultiObjectiveProblem> mProblem;
68 
70  std::size_t mNumPopulations;
71 
73  std::size_t mPopulationSize;
74 
76  double mTolerance;
77 
80 
83  std::size_t mIterationsPerPrint;
84 
86  std::ostream* mOutStream;
87 
90 
92  Properties(
93  std::shared_ptr<MultiObjectiveProblem> problem = nullptr,
94  std::size_t numPopulations = 1u,
95  std::size_t populationSize = 100u,
96  double tolerance = 1e-9,
97  std::size_t numMaxIterations = 500u,
98  std::size_t iterationsPerPrint = 0u,
99  std::ostream* ostream = &std::cout,
100  bool printFinalResult = false);
101  };
102 
105 
107  virtual ~MultiObjectiveSolver() = default;
108 
110  virtual bool solve(std::size_t numEvolutions = 1u) = 0;
111 
113  virtual std::string getType() const = 0;
114 
116  virtual std::shared_ptr<MultiObjectiveSolver> clone() const = 0;
117 
119  void setProperties(const Properties& properties);
120 
122  const Properties& getSolverProperties() const;
123 
124  virtual void setProblem(std::shared_ptr<MultiObjectiveProblem> problem);
125 
127  std::shared_ptr<MultiObjectiveProblem> getProblem() const;
128 
130 
132  void setPopulationSize(std::size_t size);
133 
135  std::size_t getPopulationSize() const;
136 
138  void setNumPopulations(std::size_t size);
139 
141  std::size_t getNumPopulations() const;
142 
144  const Population& getPopulation(std::size_t index) const;
145 
147  const std::vector<Population>& getPopulations() const;
148 
150 
152  void setNumIterationsPerEvolution(std::size_t maxIterations);
153 
155  std::size_t getNumIterationsPerEvolution() const;
156 
157 protected:
160 
162  std::vector<Population> mPopulations;
163 };
164 
165 } // namespace optimizer
166 } // namespace dart
167 
168 #endif // DART_OPTIMIZER_MULTIOBJECTIVESOLVER_HPP_
BodyPropPtr properties
Definition: SdfParser.cpp:80
std::size_t index
Definition: SkelParser.cpp:1672
Abstract class that provides a common interface for different multi-objective optimization solvers.
Definition: MultiObjectiveSolver.hpp:58
const std::vector< Population > & getPopulations() const
Returns all the populations.
Definition: MultiObjectiveSolver.cpp:137
virtual void setProblem(std::shared_ptr< MultiObjectiveProblem > problem)
Definition: MultiObjectiveSolver.cpp:92
void setNumIterationsPerEvolution(std::size_t maxIterations)
Sets the number of iterations per evolution.
Definition: MultiObjectiveSolver.cpp:143
std::size_t getNumIterationsPerEvolution() const
Returns the number of iterations per evolution.
Definition: MultiObjectiveSolver.cpp:150
virtual std::shared_ptr< MultiObjectiveSolver > clone() const =0
Creates an identical clone of this Solver.
virtual std::string getType() const =0
Returns the type (implementation) of this Solver.
const Properties & getSolverProperties() const
Get the generic Properties of this Solver.
Definition: MultiObjectiveSolver.cpp:86
void setNumPopulations(std::size_t size)
Sets the number of populations.
Definition: MultiObjectiveSolver.cpp:117
std::size_t getPopulationSize() const
Return sthe number of decision vectors in one population.
Definition: MultiObjectiveSolver.cpp:111
void setPopulationSize(std::size_t size)
Sets the number of decision vectors in one population.
Definition: MultiObjectiveSolver.cpp:105
virtual bool solve(std::size_t numEvolutions=1u)=0
Solve optimization problem.
MultiObjectiveSolver(const Properties &properties=Properties())
Default constructor.
Definition: MultiObjectiveSolver.cpp:65
void setProperties(const Properties &properties)
Set the generic Properties of this Solver.
Definition: MultiObjectiveSolver.cpp:71
virtual ~MultiObjectiveSolver()=default
Destructor.
std::shared_ptr< MultiObjectiveProblem > getProblem() const
Get nonlinear optimization problem.
Definition: MultiObjectiveSolver.cpp:99
std::size_t getNumPopulations() const
Returns the number of populations.
Definition: MultiObjectiveSolver.cpp:124
const Population & getPopulation(std::size_t index) const
Returns a population at index.
Definition: MultiObjectiveSolver.cpp:131
Properties mProperties
Properties.
Definition: MultiObjectiveSolver.hpp:159
std::vector< Population > mPopulations
Populations.
Definition: MultiObjectiveSolver.hpp:162
Definition: Population.hpp:50
Definition: BulletCollisionDetector.cpp:65
The MultiObjectiveSolver::Properties class contains Solver parameters that are common to all MultiObj...
Definition: MultiObjectiveSolver.hpp:65
std::size_t mNumPopulations
Number of populations.
Definition: MultiObjectiveSolver.hpp:70
std::shared_ptr< MultiObjectiveProblem > mProblem
Multi-objective optimization problem to be solved.
Definition: MultiObjectiveSolver.hpp:67
std::size_t mIterationsPerPrint
How many iterations between printing the Solver's progress to the terminal.
Definition: MultiObjectiveSolver.hpp:83
std::ostream * mOutStream
Stream for printing the Solver's progress. Default is std::cout.
Definition: MultiObjectiveSolver.hpp:86
std::size_t mIterationsPerEvolution
How many iterations per evolution.
Definition: MultiObjectiveSolver.hpp:79
std::size_t mPopulationSize
Number of decision vectors in one population.
Definition: MultiObjectiveSolver.hpp:73
bool mPrintFinalResult
Set to true if the final result should be printed to the terminal.
Definition: MultiObjectiveSolver.hpp:89
Properties(std::shared_ptr< MultiObjectiveProblem > problem=nullptr, std::size_t numPopulations=1u, std::size_t populationSize=100u, double tolerance=1e-9, std::size_t numMaxIterations=500u, std::size_t iterationsPerPrint=0u, std::ostream *ostream=&std::cout, bool printFinalResult=false)
Constructor.
Definition: MultiObjectiveSolver.cpp:43
double mTolerance
The maximum step size allowed for the Problem to be considered converged.
Definition: MultiObjectiveSolver.hpp:76