11 using namespace gplib;
20 int main(
int argc,
char *argv[])
22 string infilename, outfilename;
24 "$Id: sumobjective.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
26 cout <<
"Program " << version << endl;
27 cout <<
"Sum up the objective function values as output by the Pareto-GA"
29 cout <<
"and find the model with smallest distance from origin. " << endl;
31 <<
"The program expects a file that contains exactly 4 objective function values per line. "
33 cout <<
"If your program output differs, you have to adjust your file. "
36 <<
"The name of the output file is the same is the inputfile + .sum. "
44 infilename = AskFilename(
"Infile name:");
47 outfilename = infilename +
".sum";
49 ifstream objfile(infilename.c_str());
50 vector<double> objvalues;
51 copy(istream_iterator<double> (objfile), istream_iterator<double> (),
52 back_inserter(objvalues));
54 if ((objvalues.size() % 4) != 0)
56 cerr <<
"Not 4 objective function values ! " << endl;
60 vector<double> sumvalues, first, second, third, fourth;
61 ofstream sumfile(outfilename.c_str());
62 while (index <= objvalues.size() - 4)
64 first.push_back(objvalues.at(index));
65 second.push_back(objvalues.at(index + 1));
66 third.push_back(objvalues.at(index + 2));
67 fourth.push_back(objvalues.at(index + 3));
75 for (
size_t i = 0; i < first.size(); ++i)
78 sum = pow(first.at(i), 2) + pow(second.at(i), 2) + pow(third.at(i), 2)
79 + pow(fourth.at(i), 2);
80 sumvalues.push_back(sum / 4);
81 sumfile << i <<
" " << sum / 4 << endl;
84 vector<double>::iterator minref = min_element(sumvalues.begin(),
86 index = distance(sumvalues.begin(), minref);
87 cout <<
"Minimum: " << *minref <<
" at index " << index << endl;
88 cout <<
"Objective Function values: ";
89 for (
size_t i = index * 4; i < index * 4 + 4; ++i)
90 cout << objvalues.at(i) <<
" ";
92 ofstream namefile((infilename +
".name").c_str());
93 namefile <<
"best_" << index <<
".mtt";
int main(int argc, char *argv[])