?? main.cpp
字號:
//
//Please find details of the method from
//
// Q. Zhang, A. Zhou and Y. Jin, "RM-MEDA: A Regularity Model Based Multiobjective Estimation of Distribution Algorithm", IEEE Trans. Evolutionary Computation, Vol. 12, no. 1, pp41-63, 2008.
//
//The source codes are free for reserach work. If you have any problem with the source codes, please contact with
// Qingfu Zhang,
// Department of Computing and Electronic Systems,
// University of Essex,
// Colchester, CO4 3SQ, UK
// http://cswww.essex.ac.uk/staff/zhang
// Email: qzhang@essex.ac.uk
// Aimin Zhou
// Department of Computing and Electronic Systems,
// University of Essex,
// Colchester, CO4 3SQ, UK
// http://privatewww.essex.ac.uk/~azhou/
// Email: azhou@essex.ac.uk or amzhou@gmail.com
//Programmer:
// Aimin Zhou
//Last Update:
// Feb. 21, 2008
//
//main.cpp is the RM-MEDA main program
//
//Please run command 'Front('F')' or 'Front('X')' in Matlab to view the final results
//
#include <cmath>
#include <ctime>
#include <vector>
#include "Random.h"
#include "Parameter.h"
#include "Initialization.h"
#include "Alg.h"
#include "GenMod.h"
#include "Sel.h"
#include "Problem.h"
// test problem
// min (f1(X),...,fm(X))
// g1(X) = 0; ... gk(X) = 0;
// h1(X) <= 0; ... hs(X) <= 0;
// F is objective vector (return)
// E is equality constraint vector (return)
// I is inequality constraint vector (return)
// X is decision vector (input)
// main function
int main()
{
// NOTE: the following parameters MUST be set correctly and the other parameters may use default values
// population size, maximum generation, number of clusters,
// number of objectives, number of equality constraints, number of inequality constraints, fitness function,
// dimension of decision variables, and their boundaries
unsigned int i,
popsize, // population size
maxgen, // maximum generation
cluster; // number of clusters
//------------------------------------------------------------------------
// set random seed
az::rnd::seed((long) time(NULL));
//------------------------------------------------------------------------
// algorithm parameters
popsize = 200; // population size
maxgen = 200; // maximum generation
cluster = 5; // number of clusters
az::mea::CParameter mPar; // parameter object
mPar.TolF() = 1.0E-5; // objective tolerance
mPar.TolX() = 1.0E-5; // decision variable tolerance
mPar.TolC() = 1.0E-5; // constraint tolerance
mPar.FSize( 3 ); // set number of objectives
mPar.ESize( 0 ); // set number of equality constraints
mPar.ISize( 0 ); // set number of inequality constraints
mPar.Evaluator( PROBLEM::ZZJ08_F8 ); // set fitness function
mPar.XSize(30); // set dimension of decision variables
mPar.XCoding() = false; // do not normalize the decision varialbes
for(i=0; i<mPar.XSize(); i++) // set the boundaries of decision variables
{
mPar.XRealLow(i) = 0.0; // [XRealLow, XRealUpp] is the real boundary (the boundary of search space)
mPar.XRealUpp(i) = 1.0; //
mPar.XLow(i) = mPar.XRealLow(i); // [XLow, XUpp] is the working boundary
mPar.XUpp(i) = mPar.XRealUpp(i); // since the decision variables are not normalized, [XLow, XUpp] = [XRealLow, XRealUpp]
}
//mPar.XCoding() = true; // normalize the decision varialbes if the range of search space is quite different, for exammple, -1 <= x1 <= 0, -1000 <= x2 <= 1000
//for(i=0; i<mPar.XSize(); i++) // set the boundaries of decision variables
//{
// mPar.XRealLow(i) = low[i]; // [XRealLow, XRealUpp] is the real boundary (the boundary of search space)
// mPar.XRealUpp(i) = upp[i]; //
// mPar.XLow(i) = 0.0; // [XLow, XUpp] is the working boundary
// mPar.XUpp(i) = 1.0; // it is normalized to [XLow, XUpp] = [0.0, 1.0]
//}
//------------------------------------------------------------------------
// initialize population and algorithm
az::mea::CPopulationMO inipop(mPar);
az::mea::ini::Random init;
init.Initialize(inipop, popsize); // set populatin size here
typedef az::mea::CEA< az::mea::gen::mod::ModelLocalPCAU, az::mea::sel::SCrowd2 > EA;
EA* pEA = new EA(maxgen, mPar, inipop); // set maximum generation here
pEA->EvaTimes() += init.EvaTimes();
// set parameters of Local PCA method
pEA->Set( mPar.FSize()-1, // dimension of manifold of Pareto set = number of objectives - 1
cluster, // number of clusters partitioned by Local PCA
50, // training steps in Local PCA, 50 (default, usually it is more than enough)
0.25); // extension ratio, 0.25 (default)
//------------------------------------------------------------------------
// main loop
while(!pEA->IsTerminate())
{
pEA->Step();
std::cout<<pEA->CurStep()<<std::endl;
}
//------------------------------------------------------------------------
// save final population (nondominated solutions)
// format is:
// number of point (n)
// number of objectives (m) number of decision variables (k)
// obj11 ... obj1m x11 ... x1k
// ...
// objn1 ... objnm xn1 ... xnk
// in Matlab, use command 'Front('F')' to observe the Pareto front
// and command 'Front('X')' to observe the Pareto set
pEA->Population().Write("pop.dat");
std::cout<<"Over."<<std::endl;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -