pso.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef IGL_PSO_H
  2. #define IGL_PSO_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <functional>
  6. namespace igl
  7. {
  8. /// Global optimization with the particle swarm algorithm.
  9. ///
  10. /// Solve the problem:
  11. ///
  12. /// minimize f(x)
  13. /// subject to lb ≤ x ≤ ub
  14. ///
  15. /// by particle swarm optimization (PSO).
  16. ///
  17. /// @param[in] f function that evaluates the objective for a given "particle" location
  18. /// @param[in] LB #X vector of lower bounds
  19. /// @param[in] UB #X vector of upper bounds
  20. /// @param[in] max_iters maximum number of iterations
  21. /// @param[in] population number of particles in swarm
  22. /// @param[out] X best particle seen so far
  23. /// @return objective corresponding to best particle seen so far
  24. template <
  25. typename Scalar,
  26. typename DerivedX,
  27. typename DerivedLB,
  28. typename DerivedUB>
  29. IGL_INLINE Scalar pso(
  30. const std::function< Scalar (DerivedX &) > f,
  31. const Eigen::MatrixBase<DerivedLB> & LB,
  32. const Eigen::MatrixBase<DerivedUB> & UB,
  33. const int max_iters,
  34. const int population,
  35. DerivedX & X);
  36. /// \overload
  37. /// @param[out] P whether each DOF is periodic
  38. ///
  39. /// \bug `P` appears to be unused
  40. template <
  41. typename Scalar,
  42. typename DerivedX,
  43. typename DerivedLB,
  44. typename DerivedUB,
  45. typename DerivedP>
  46. IGL_INLINE Scalar pso(
  47. const std::function< Scalar (DerivedX &) > f,
  48. const Eigen::MatrixBase<DerivedLB> & LB,
  49. const Eigen::MatrixBase<DerivedUB> & UB,
  50. const Eigen::DenseBase<DerivedP> & P,
  51. const int max_iters,
  52. const int population,
  53. DerivedX & X);
  54. }
  55. #ifndef IGL_STATIC_LIBRARY
  56. # include "pso.cpp"
  57. #endif
  58. #endif