25 #include <boost/math/constants/constants.hpp>
30 #include "../exceptions.h"
33 #include "lennard_jones.h"
35 namespace pagmo {
namespace problem {
47 if (atoms <= 0 || atoms < 3) {
48 pagmo_throw(value_error,
"number of atoms for lennard-jones problem must be positive and greater than 2");
50 for (
int i = 0; i < 3*atoms-6; i++) {
51 if ( (i != 0) && (i % 3) == 0 ) {
68 double lennard_jones::r(
const int& atom,
const int& coord,
const std::vector<double>& x) {
71 }
else if(atom == 1) {
77 }
else if(atom == 2) {
84 return x[3 * (atom - 2) + coord];
91 pagmo_assert(f.size() == 1);
92 std::vector<double>::size_type n = x.size();
93 int atoms = (n + 6) / 3;
98 for (
int i=0; i<(atoms-1); i++ ) {
99 for (
int j=(i+1); j<atoms; j++ ) {
100 dist = pow(r(i, 0, x) - r(j, 0, x), 2) + pow(r(i, 1, x) - r(j, 1, x), 2) + pow(r(i, 2, x) - r(j, 2, x), 2);
105 sixth = pow(dist, -3);
106 f[0] += (pow(sixth, 2) - sixth);
115 return "Lennard-Jones";
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
The Lennard-Jones problem.
void set_lb(const decision_vector &)
Set lower bounds from pagmo::decision_vector.
std::string get_name() const
Get problem's name.
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
void set_ub(const decision_vector &)
Set upper bounds from pagmo::decision_vector.
std::vector< double > fitness_vector
Fitness vector type.
lennard_jones(int=3)
Constructor from dimension.
base_ptr clone() const
Clone method.