master.c
来自「麻省理工开发的免费遗传算法类库GAlib,很好用」· C语言 代码 · 共 45 行
C
45 行
/* ---------------------------------------------------------------------------- master.C mbwall 5dec95 Copyright (c) 1995-1996 Massachusetts Institute of Technology DESCRIPTION: Example program to illustrate use of GAlib with PVM. This example uses amaster-slave configuration to parallelize the genetic algorithm. In this case,the master controls the evolution by specifying migrations between populationson various processes.---------------------------------------------------------------------------- */#include <stdio.h>#include <iostream.h>#include "PVMDemeGA.h"#include "genome.h"intmain(int argc, char** argv) { cout << "This program tries to fill a 1DBinaryStringGenome with\n"; cout << "alternating 1s and 0s using a simple genetic algorithm. It runs\n"; cout << "in parallel using PVM and a population on each process.\n\n"; cout.flush(); GA1DBinaryStringGenome genome(GENOME_LENGTH); PVMDemeGA ga(genome); ga.parameters(argc, argv); ga.parameters("settings.txt"); if(ga.spawn("slave") < 0) exit(1); cout << "initializing..." << endl; ga.initialize(); cout << ga.statistics().bestIndividual() << endl; cout << "evolving..." << endl; while(!ga.done()){ ga.step(); cout << ga.statistics().bestIndividual() << endl; } ga.flushScores(); cout << "\nThe GA found an individual with a score of "; cout << ga.statistics().bestIndividual().score() << endl; return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?