📄 master.c
字号:
/* ---------------------------------------------------------------------------- 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -