示例#1
0
void SmallWorld::initialize() {
	
	for (int i = 0; i < bugNum; i++) {
		Gene gene;
		gene.initialize(minSpeed, maxSpeed, nodeNum * turn);
		genes[i] = gene;
	}
	
	generations++;
}
示例#2
0
void SmallWorld::breed() {
	
	if (bugs.size() > 2) {
		
		vector<Gene> tmp;
		tmp.resize(bugs.size());
		
		tmp[0] = bugs[0].getGene();
		tmp[1] = bugs[1].getGene();
		
		for (int i = 2; i < bugs.size() - 1; i++) {
			Gene gene;
			gene.crossover(tmp[0].dna, tmp[1].dna, nodeNum * turn);
			
			for (int j = 0; j < int(nodeNum / 4); j++) {
				gene.mutation(minSpeed, maxSpeed, probability);
			}
			
			tmp[i] = gene;
		}
		
		for (int i = bugs.size() - 2; i < bugs.size() - 1; i++) {
			Gene gene;
			gene.crossover(tmp[0].dna, tmp[1].dna, nodeNum * turn);
			
			for (int j = 0; j < int(nodeNum / 4); j++) {
				gene.mutation(minSpeed, maxSpeed, probability * 10);
			}
			
			tmp[i] = gene;
		}
		
		for (int i = bugs.size() - 1; i < bugs.size(); i++) {
			Gene gene;
			gene.initialize(minSpeed, maxSpeed, nodeNum * turn);
			tmp[i] = gene;
		}
		
		genes.swap(tmp);
	}
	
	generations++;
}