1#include "../include/GA/population.h"
16static double myFun(
const double& x) {
17 return x * std::sin(10.0 *
NA_PI * x) + 1.0;
23 m_groupNumber(groupNumber),
25 GeneFloat initGene(-1.0, 2.0, 1e-6);
28 for (
int i = 0; i < groupNumber; ++i) {
42 while (0 != (iterNum--)) {
55 std::cout <<
"第"<<k<<
"代最优秀的个体:" << x <<
"当前目标函数值:" <<
m_result[0].val << std::endl;
74 for (
int i = s1; i < s2; ++i) {
75 int randNum = rand() % 100;
84 for (
int i = s1; i < s2; ++i) {
85 int randNum = rand() % 100;
94 for (
int i = s1; i < s2; ++i) {
95 int randNum = rand() % 100;
104 int nSize =
static_cast<int>(
m_lives.size());
110 int outSize = remainingSpace >> 1;
111 remainingSpace -= outSize;
114 for (
int i = s1; i < s2; ++i) {
119 s2 += remainingSpace;
120 for (
int i = s1; i < s2; ++i) {
126 int id, fid, mid, temp, j;
127 std::list<int>::iterator iter =
m_lives.begin();
128 if (1 == (nSize % 2)) {
130 for (j = 0; j < (
id - 1); j++)
141 for (j = 0; j < (
id - 1); j++)
146 nSize =
static_cast<int>(
m_lives.size());
149 for (j = 0; j < (
id - 1); j++)
154 GeneFloat::cross(m_oldmembers[fid], m_oldmembers[mid],
m_members[s1++]);
160 GeneFloat::cross(m_oldmembers[mid], m_oldmembers[fid],
m_members[s1++]);
std::vector< CResult > m_result
上一代的成员
std::list< int > m_lives
活下来的个体
void choose()
天择(从种群中选择优秀的个体,认为是存活下来的个体)
Popultation(int groupNumber, int mutate)
std::vector< GeneFloat > m_members
成员
void run(int iterNum)
迭代多少次