#ifndef PARTICLE_H
#define PARTICLE_H
#include<vector>
#include<iostream>
using namespace std;
class Particle
{
protected:
public:
Particle();
Particle(const int aDim);
int dimension;
vector<double> velocity;
vector<double> position;
vector<double> pBest;
double pBestFitness;
double fitness;
bool valid;
bool operator<(const Particle& aP2) const;
~Particle(void);
};
#endif
#define SWARM_H
#include"Particle.h"
#include<vector>
#include <Algorithm>
#include<iostream>
#include<stdexcept>
using namespace std;
class Swarm:public vector<Particle>
{
protected:
unsigned int swarmSize;
public:
Swarm();
Swarm(const int& asize);
~Swarm(void);
unsigned int& getSwarmSize();
void append(const unsigned int newsize);
struct Cmp
{
bool operator()(const Particle & a,const Particle & b) const
{ return a<b; }
};
const Particle & bestParticle() const;
};
#endif
Dear friends:
I have two classed, the class particle class has dimension, postion, and velocity. The other class is swarm, it is a swarm of particles.
I can declare a new swarm class as:
Swarm aSwarem(asize);
My problem is how to set the particle's dimension. How to modify the constructor of the swarem.
Regards/.