pso.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef IGL_PSO_H
  2. #define IGL_PSO_H
  3. #include <igl/igl_inline.h>
  4. #include <Eigen/Core>
  5. #include <functional>
  6. namespace igl
  7. {
  8. // Solve the problem:
  9. //
  10. // minimize f(x)
  11. // subject to lb ≤ x ≤ ub
  12. //
  13. // by particle swarm optimization (PSO).
  14. //
  15. // Inputs:
  16. // f function that evaluates the objective for a given "particle" location
  17. // LB #X vector of lower bounds
  18. // UB #X vector of upper bounds
  19. // max_iters maximum number of iterations
  20. // population number of particles in swarm
  21. // Outputs:
  22. // X best particle seen so far
  23. // Returns 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. // Inputs:
  37. // 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