利用泛型编程思想,C++模板。

首先定义变量或者重新typedef variables:

  模板中的变量:_TRandom、double  _TReal、_TProblem::TDecision _TDecision

  类    变    量:DTLZ<_TReal> _TProblem(测试问题)、SimulatedBinaryCrossover<_TReal,TRandom &> _TCrossover(交叉)、PolynomialMutation<_TReal,_TRandom &> _TMutation(变异) ClassName(_TReal,_TDecision,_TRandom &) _TOptimizer

  初始化测试问题:如 DTLZ2<_TReal>(nObjectives)--->DTLZ2(const size_t nObjectives, const size_t distDecisions =10)--->Tsuper(nObjectives, TBoundary(nObjectives-1+distDecisions, std::make_pair<TReal, TReal>(0,1)))。(这里设置TBoundary时,是初始化nObjectives-1+distDecisions 个(0,1)组?)

  初始化种群决策变量:initial = PopulationUniformReal(random, problem.GetBoundary(), 100)--->initial[i]= dist(random), where dist is std::uniform_real_distribution<_TReal>dist(boundary[i].first, boundary[i].second) ,boundary[i].first 到 boundary[i].second的均匀分布函数。

  初始化交叉类变量: _crossover( random, 1, problem.GetBoundary(), 20)。 CoupleCoupleCrossoverAdapter<_TReal, _TDecision, _TRandom &> crossover(_crossover, random)--->WithcoupleCoupleCrossover<TReal, TDecision>(crossover), WithRandom<TRandom>(random)。

  初始化变异类变量: mutation(random, 1/(_TReal)problem.GetBoundary().size(), problem.GetBoundary(), 20)。

  初始化具体类对象变量: optimizer(random, problem, initial, crossover, mutation, 相对应的变量)。

04-23 09:41