pso.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. template <
  39. typename Scalar,
  40. typename DerivedX,
  41. typename DerivedLB,
  42. typename DerivedUB,
  43. typename DerivedP>
  44. IGL_INLINE Scalar pso(
  45. const std::function< Scalar (DerivedX &) > f,
  46. const Eigen::MatrixBase<DerivedLB> & LB,
  47. const Eigen::MatrixBase<DerivedUB> & UB,
  48. const Eigen::DenseBase<DerivedP> & P,
  49. const int max_iters,
  50. const int population,
  51. DerivedX & X);
  52. }
  53. #ifndef IGL_STATIC_LIBRARY
  54. # include "pso.cpp"
  55. #endif
  56. #endif