ECF 1.5
main_landscape.cpp
1#include <ecf/ECF.h>
2#include "FunctionMinEvalOp.h"
3
4#include "ecf/AlgGenHookeJeeves.h"
5
6
7
8//
9// this main() function optimizes a single COCO function (Id set in config file)
10// function Ids: noiseless 1-24, noisy 101-130
11//
12
13int main(int argc, char **argv)
14{
15 StateP state (new State);
16
17 // set the evaluation operator
18 state->setEvalOp(new FunctionMinEvalOp);
19
20 GenHookeJeevesP alg (new GenHookeJeeves);
21 state->addAlgorithm(alg);
22
23 state->initialize(argc, argv);
24 state->run();
25
26
27//
28// ispis populacije u txt fajl, za potrebe landscape analysis
29//
30 ofstream fajl("popis.txt");
31 for(uint i = 0; i < state->getPopulation()->getLocalDeme()->getSize(); i++) {
32 IndividualP ind = state->getPopulation()->getLocalDeme()->at(i);
33 fajl << ind->fitness->getValue() << "\t";
34 FloatingPointP fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype());
35 for(uint dim = 0; dim < fp->realValue.size(); dim++)
36 fajl << fp->realValue[dim] << "\t";
37 fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype(2));
38 fajl << fp->realValue[0];
39 fajl << "\n";
40 }
41
42
43 return 0;
44}
45
46
47
48//
49// this main() function iterates over multiple COCO functions and optimizes each one in turn
50// function Ids: noiseless 1-24, noisy 101-130
51//
52/*
53int main(int argc, char **argv)
54{
55 // run for selected COCO functions
56 for(uint function = 1; function < 25; function++) {
57
58 // read XML config
59 std::ifstream fin(argv[1]);
60 if (!fin) {
61 std::cerr << "Error opening config file! (" << argv[1] << ")\n";
62 return 1;
63 }
64
65 std::string xmlFile, temp;
66 while (!fin.eof()) {
67 getline(fin, temp);
68 xmlFile += "\n" + temp;
69 }
70 fin.close();
71
72 // set log and stats parameters
73 std::string funcName = uint2str(function);
74 std::string logName = "log", statsName = "stats";
75 if(function < 10) {
76 logName += "0";
77 statsName += "0";
78 }
79 logName += uint2str(function) + ".txt";
80 statsName += uint2str(function) + ".txt";
81
82 // update in XML
83 XMLResults results;
84 XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
85 XMLNode registry = xConfig.getChildNode("Registry");
86
87 XMLNode func = registry.getChildNodeWithAttribute("Entry", "key", "coco.function");
88 func.updateText(funcName.c_str());
89 XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
90 log.updateText(logName.c_str());
91 XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
92 stats.updateText(statsName.c_str());
93
94 // write back
95 std::ofstream fout(argv[1]);
96 fout << xConfig.createXMLString(true);
97 fout.close();
98
99
100 // finally, run ECF on single function
101 StateP state (new State);
102
103 GenHookeJeevesP alg (new GenHookeJeeves);
104 state->addAlgorithm(alg);
105
106 // set the evaluation operator
107 state->setEvalOp(new FunctionMinEvalOp);
108
109 state->initialize(argc, argv);
110 state->run();
111
112//
113// ispis populacije u txt fajl, za potrebe landscape analysis
114//
115 std::string out = funcName + ".txt";
116 ofstream fajl(out.c_str());
117 for(uint i = 0; i < state->getPopulation()->getLocalDeme()->getSize(); i++) {
118 IndividualP ind = state->getPopulation()->getLocalDeme()->at(i);
119 fajl << ind->fitness->getValue() << "\t";
120 FloatingPointP fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype());
121 for(uint dim = 0; dim < fp->realValue.size(); dim++)
122 fajl << fp->realValue[dim] << "\t";
123 fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype(2));
124 fajl << fp->realValue[0];
125 fajl << "\n";
126 }
127 fajl.close();
128
129 }
130
131
132 return 0;
133}
134*/
Function minimization evaluation class.
new algorithm, in development
State class - backbone of the framework.
Definition: State.h:39