Appendix

A.1 Header File

#include <stdio.h>
#define Error(i) {printf("Not enough memory at code %d \n",i);exit(0);}
#define CHROMOLENGTH 2
#define CHROMO_PER_VARIABLE 2
//#define __GRIEWANGK_FUNCTION__
//#define __ACKLEY_FUNCTION__
//#define __RASTRIGIN_FUNCTION__
//#define __SCHWEFEL_FUNCTION__
#define __ROSENBROCK_FUNCTION__
class CEcosystem;
struct Chromosome
{
 unsigned char gene[CHROMOLENGTH];
};
class CSpecies
{
 private:
 CEcosystem * theEcosystem;
 int SpeciesID;
 static unsigned char BitMask[],Bit[];
 int New,Old;
 int JCross;
 int LChromo,MaxGen;
 float PCross,PMutation;
 int PopSize,NGen,NCross,NMutation;
 int MaxCrossTimes;
 double FitMax,FitMin,FitAvrg,FitSum;
 Chromosome (*Chromo)[2];
 double (*Fitness)[2];
 double LowerBound,UpperBound;
 void InitPop();
 void WriteChromo(FILE*,struct Chromosome&,int);
 void Crossover(int,int,struct Chromosome&,struct Chromosome&);
 void Mutation(struct Chromosome&);
 int  ObjFunc(double&,struct Chromosome&);
 int Select();
 public:
 Chromosome ChromoMax,ChromoMin;
 void SetParam(CEcosystem* CEcosystem,int speciesID,int maxgen,
                int popsize,int lchrom,float pcross,float pmutation);
 ˜CSpecies();
 void Initialize();
 void Statistics();
 void Report(FILE*);
 void Generation();
};
class CEcosystem
{
 public:
 int NSpecies;
 Chromosome *Representative;
 CEcosystem();
 ˜CEcosystem();
 void Initialize();
 void SetParam(int n_species);
};

A.2 Species Class

#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "Coevolution.h"
#define PI 3.1415927 #define E 2.7182818 ...

Get Power System Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.