📄 mimic_onemax.cxx
字号:
// Time-stamp: <2007-07-16 13:15:31 handa>//#include "stdafx.h"
#include <vector>#include "chromoso.h"#include <iostream>#include "basic_edas.hxx"#include "generatingRules.hxx"#include "m2n.hxx"#include "MIMIC.hxx"using namespace std;int main1(int argc, char **argv){ int i,k,j; long tcr = 100000; // terminal criterion for quitting experiment. int ps = 100000; // population size for H-GA int pools = 200; // pool size for H-GA int sdg = 0; // random seed for ga. int sdp = 0; // random seed for problem generation. char *fname; char *fnameout;
int nod; int len = 20; if (argc != 7) { cerr << "Error is occurred!" << endl << "Usage: " << argv[0] << " seed seed factorcount linecount filein fileout" << endl; return 0; } sdp = atoi(argv[1]); sdg = atoi(argv[2]); len = atoi(argv[3]); nod = atoi(argv[4]); fname = argv[5]; fnameout = argv[6];
random_number rn(sdp), rn1(sdg); generatingRules<int> om(rn, len, nod, fname); list<chromosome<int> *> ch; vector<chromosome<int> *> pool(pools); for(i =0;i < ps;i++) { chromosome<int>* te = new chromosome<int>(om, i%nod); ch.push_back(te); } m2n<int> sel(rn1); mimic<int> eas(rn1, len, 3, 200, om); basic_EDAs<int> test(ch, eas, sel, om, pool); list<chromoIntP>::iterator il; double ave = 0.0; double max = 0.0; for (il = ch.begin(); il != ch.end(); il++) { ave += (*il)->fitness(0); if(max < (*il)->fitness(0)) max = (*il)->fitness(0); } cout <<ch.size() << " ave: " << ave / ch.size() << "\tmax: " << max ; ave = 0.0; max = 0.0; // for (i = 0; i < 500; i++) { Wolf 2007/10/17 for (i = 0; i < nod; i++) {
double dtmp = om.maxFitInMatchingSet(ch, i); ave += dtmp; if(max < dtmp) max = dtmp; }
// cout << " aveD: " << ave / 500 << "\tmaxD: " << max << endl; Wolf 2007/10/17 cout << " aveD: " << ave / nod << "\tmaxD: " << max << endl; for(long t =0;t < 10;t++) { test.generation(); cout << t << " th generation\n"; ave = 0.0; max = 0.0; for (il = ch.begin(); il != ch.end(); il++) { ave += (*il)->fitness(0); if(max < (*il)->fitness(0)) max = (*il)->fitness(0); } cout <<ch.size() << " ave: " << ave / ch.size() << "\tmax: " << max ; ave = 0.0; max = 0.0; // for (i = 0; i < 500; i++) { Wolf 2007/10/17 for (i = 0; i < nod; i++) {
double dtmp = om.maxFitInMatchingSet(ch, i); ave += dtmp; if(max < dtmp) max = dtmp; } // cout << " aveD: " << ave / 500 << "\tmaxD: " << max << endl; Wolf 2007/10/17 cout << " aveD: " << ave / nod << "\tmaxD: " << max << endl;
} FILE *fp = fopen(fnameout, "w"); for (il = ch.begin(); il != ch.end(); il++) { if ((*il)->fitness(0) < 1.0005) continue; for (i = 0; i < (*il)->Size(); i++) { fprintf(fp, "%d ", (*il)->getgene(i)); } fprintf(fp, "%d ", (*il)->isDecedent()); fprintf(fp, "%lf\n", (*il)->fitness(0)); } fclose(fp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -