O'Reilly logo

Power System Optimization by Honwing Ngan, Yongjun Zhang, Haoyong Chen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required