ECF 1.5
main.cpp
1#include <ecf/ECF.h>
2#include "fitnes.hpp"
3//#include <ecf/AlgGenHookeJeeves.h>
4#include "EvaluateAlternate.h"
5#include "WriteBest.h"
6#include "IntGenotype.h"
7
8
9
10//
11// Evolution of scheduling heuristics
12//
13int main(int argc, char **argv)
14{
15 StateP state (new State);
16
17 SchedulingEvalOpP evalOp (new SchedulingEvalOp);
18 state->setEvalOp(evalOp);
19
20// EvaluateAlternate *z = new EvaluateAlternate;
21// state->addOperator((OperatorP) z);
22
23 WriteBest *b = new WriteBest;
24 state->addOperator((OperatorP) b);
25
26 // integer values genotype
27 IntGenotypeP gen = (IntGenotypeP) (new IntGenotype::IntGenotype);
28 state->addGenotype(gen);
29
30 // if 3rd argument is present, read that as a single test case to evaluate
31 if(argc > 2) {
32 uint primjer = atoi(argv[2]);
33 state->getContext()->environment = new uint(primjer);
34 }
35
36 state->initialize(argc, argv);
37 state->run();
38
39 return 0;
40}
41
42
43
44
45//
46// Citanje jedinki iz drugog argumenta (npr. "<exe> parameters.txt susjedstvo.txt") i njihova evaluacija
47// - opcija: ako je zadan treci argument, u njega se upisuju dobrote jedinki (npr. "<exe> parameters.txt susjedstvo.txt" "rezultati.txt")
48//
49/*
50#include<string>
51#include<fstream>
52using namespace std;
53
54int main(int argc, char **argv)
55{
56 StateP state (new State);
57
58 SchedulingEvalOpP evalOp (new SchedulingEvalOp);
59 state->setEvalOp(evalOp);
60
61 // if 3rd argument is present, read that as a single test case to evaluate
62 if(argc > 4) {
63 uint primjer = atoi(argv[4]);
64 state->getContext()->environment = new uint(primjer);
65 }
66
67 state->initialize(argc, argv);
68
69 // otvori datoteku sa stablima
70 ifstream inFile(argv[2]);
71 if(!inFile) {
72 cout << "ne mogu otvoriti " << argv[1] << endl;
73 return 1;
74 }
75
76 // je li zadana izlazna datoteka
77 ofstream outFile;
78 bool output = false;
79 if(argc > 3) {
80 outFile.open(argv[3]);
81 output = true;
82 }
83
84 // za svako stablo
85 string stablo;
86 while(getline(inFile, stablo)) {
87
88 // prebroji elemente
89 stringstream ss(stablo);
90 uint size = 0;
91 string node;
92 while(ss >> node)
93 size++;
94
95 // izgradi novi <Tree>
96 string treeString = "<Tree size=\"";
97 treeString += uint2str(size) + "\">";
98 treeString += stablo + "</Tree>";
99 XMLNode xTree = XMLNode::parseString(treeString.c_str(),"Tree");
100
101 // dohvati ispravnu jedinku (prvu iz populacije)
102 IndividualP ind = (IndividualP) state->getPopulation()->getLocalDeme()->at(0);
103 Tree::Tree* tree = (Tree::Tree*) ind->getGenotype().get();
104
105 // umetni zadano stablo i evaluairaj
106 tree->read(xTree);
107 state->getAlgorithm()->evaluate(ind);
108 std::cout << ind->toString();
109 if(output)
110 outFile << ind->getFitness()->getValue() << endl;
111 }
112
113 return 0;
114}
115*/
116
117
118
119int nJob[] = {12,12,12,12,12,25,25,25,25,25,50,50,50,50,50,100,100,100,100,100,12,12,12,12,12,25,25,25,25,25,50,50,50,50,50,100,100,100,100,100,25,25,25,25,25,25,25,25,25,25,50,50,50,50,50,100,100,100,100,100};
120int nMachine[] = {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
121double minminFitnessTwt[] = {0,0.351335,0.775731,0,0.162144,0,0.343002,0,0.00093811,0.509995,0.411098,0,0.318593,1.25417,0.0949641,0,0.420343,0.89277,1.23169,0,0.212096,0.0322857,1.74496,0.1597,1.44875,0.00526594,1.0816,0.0258827,0.0913783,0.544015,0,0,0,0.325736,0,0,0.293291,0.162959,0,1.18106,1.17654,0.0529384,0,0,0,0,0,0,1.23031,0.102041,0,0,0,0,0,0,0,0.0796966,0,0};
122double minminFitnessNwt[] = {0,0.120459,0.712934,0,0.116541,0,0.0704545,0,0.00724638,0.242726,0.202834,0,0.0493111,0.38319,0.0165419,0,0.0412632,0.200675,0.36992,0,0.222591,0.127424,0.769231,0.0930599,0.625817,0.0219619,0.521739,0.0181388,0.147473,0.21269,0,0,0,0.119905,0,0,0.14996,0.112807,0,0.402632,0.46743,0.0402629,0,0,0,0,0,0,0.398693,0.110018,0,0,0,0,0,0,0,0.0478261,0,0};
123double minminFitnessFt[] = {2.75891,2.73719,2.58666,2.65558,2.48309,2.62446,2.68684,1.67788,2.90506,3.22549,3.28158,2.58359,3.20613,3.38196,3.44676,4.54202,4.11355,4.8902,3.84506,4.91718,2.9556,1.85806,2.57548,2.03072,1.95982,2.1436,2.49545,2.08072,2.70303,2.83302,1.52904,2.71568,2.30128,2.30081,1.77112,2.25032,2.63377,2.76261,2.39376,3.05933,2.80241,2.01816,1.84371,2.55728,1.64157,2.62141,2.04493,2.21846,2.50419,1.92939,2.18998,2.11,2.4309,2.15589,2.34797,2.30569,2.50005,2.33383,2.2751,2.47067};
124double minminFitnessCmax[] = {0.804682,0.852891,0.741121,0.791846,0.792271,0.67554,0.739474,0.572115,0.745685,0.732843,0.604867,0.588881,0.641469,0.61283,0.628647,0.607881,0.606801,0.591992,0.606118,0.659408,0.910906,0.665103,0.839584,0.85805,0.775546,0.671373,0.744645,0.607092,0.635024,0.55739,0.572142,0.591605,0.497511,0.541233,0.596765,0.493602,0.56379,0.558336,0.513118,0.563317,0.648431,0.737406,0.620315,0.750762,0.541876,0.562931,0.557707,0.605034,0.700259,0.592427,0.531137,0.715189,0.590871,0.601737,0.548402,0.525175,0.52299,0.517088,0.526662,0.561964};
125
126double sufferageFitnessTwt[] = {0,0.351335,0.731357,0,0.357343,0,0.197593,0,0.232182,0.924466,0.523829,0,0.122856,1.27387,0,0,0.098252,0.680526,1.47564,0,0.0272364,0.0322857,1.6209,0.1597,1.44875,0.00526594,1.0816,0.0762159,0.0913783,0.503672,0,0,0,0.301401,0,0,0.283494,0.206471,0,1.22005,1.17654,0.0529384,0,0,0,0,0,0,1.23031,0.0913001,0,0,0,0,0,0,0,0.0735171,0,0};
127double sufferageFitnessNwt[] = {0,0.120459,0.613565,0,0.174185,0,0.164773,0,0.121377,0.333078,0.227935,0,0.0503988,0.416379,0,0,0.0214737,0.157602,0.358878,0,0.0780731,0.127424,0.670118,0.0930599,0.625817,0.0219619,0.521739,0.0828076,0.147473,0.21269,0,0,0,0.119905,0,0,0.15016,0.122115,0,0.397166,0.46743,0.0402629,0,0,0,0,0,0,0.398693,0.110018,0,0,0,0,0,0,0,0.0478261,0,0};
128double sufferageFitnessFt[] = {2.79723,2.73719,2.72229,2.66041,2.64251,2.6331,2.73947,1.7524,3.1355,3.99265,3.42063,2.80371,3.02632,3.16798,3.81622,4.77396,5.13853,5.42356,3.93503,4.39351,2.90715,1.85806,2.56413,2.03072,1.95982,2.17717,2.49545,2.226,2.70303,2.86987,1.71143,2.67054,2.43097,2.48737,1.72319,2.18071,2.54413,2.93702,2.56677,2.96758,2.80241,2.01816,1.84371,2.55728,1.64157,2.56259,2.04493,2.21846,2.50419,1.84133,2.18613,2.13766,2.39521,2.15589,2.30735,2.30569,2.60306,2.32987,2.27898,2.50813};
129double sufferageFitnessCmax[] = {0.790313,0.852891,0.692682,0.791846,0.884058,0.677698,0.689474,0.572115,0.675777,0.735294,0.593279,0.611574,0.575864,0.59637,0.62751,0.603959,0.611546,0.578331,0.584217,0.61377,0.79462,0.665103,0.839584,0.85805,0.775546,0.671373,0.744645,0.607092,0.635024,0.55739,0.549656,0.608236,0.497511,0.541233,0.596765,0.493602,0.56379,0.564392,0.514303,0.551702,0.648431,0.737406,0.620315,0.750762,0.541876,0.562931,0.557707,0.596967,0.700259,0.592427,0.531137,0.715189,0.590871,0.601737,0.548402,0.525175,0.52299,0.517088,0.526662,0.550133};
130
131double minmaxFitnessTwt[] = {0.0346738,0.351335,1.02804,0,0.518833,0,0.155951,0,0.26226,0.411703,0.485666,0,0.1353,1.49895,0,0,0.119231,1.00555,1.45751,0,0.212096,0.0322857,1.74496,0.1597,1.44875,0.00526594,1.0816,0.0678271,0.0913783,0.544015,0,0,0,0.316166,0,0,0.322755,0.210462,0,1.15875,1.17654,0.0529384,0,0,0,0,0,0,1.23031,0.0913001,0,0,0,0,0,0,0,0.0796966,0,0};
132double minmaxFitnessNwt[] = {0.100543,0.120459,0.712934,0,0.293233,0,0.111364,0,0.136775,0.18147,0.284211,0,0.0964467,0.434483,0,0,0.0301053,0.243351,0.368154,0,0.222591,0.127424,0.769231,0.0930599,0.625817,0.0219619,0.521739,0.0828076,0.147473,0.21269,0,0,0,0.119905,0,0,0.140176,0.128071,0,0.402632,0.46743,0.0402629,0,0,0,0,0,0,0.398693,0.110018,0,0,0,0,0,0,0,0.0478261,0,0};
133double minmaxFitnessFt[] = {2.81639,2.7719,2.77073,3.11427,2.81643,2.99569,2.76053,1.75,3.38665,3.35049,3.64195,2.8854,3.47098,3.48706,3.85941,5.43955,5.64509,6.34969,4.45532,5.06345,2.9556,1.85806,2.57548,2.03072,1.95982,2.17717,2.49545,2.24676,2.87432,2.83302,1.68395,2.95802,2.43568,2.48967,1.76872,2.26171,2.76823,3.05571,2.4779,3.04423,2.80241,2.04921,1.84371,2.55728,1.64157,2.56259,2.17661,2.21846,2.50419,1.79329,2.20152,2.16137,2.4428,2.21168,2.34797,2.33108,2.59118,2.3477,2.26736,2.47067};
134double minmaxFitnessCmax[] = {0.790313,0.852891,0.770185,0.767704,0.792271,0.714389,0.689474,0.572115,0.652474,0.776961,0.589803,0.588881,0.579509,0.617895,0.628647,0.603399,0.596124,0.568654,0.597239,0.613185,0.910906,0.665103,0.839584,0.85805,0.775546,0.671373,0.744645,0.607092,0.635024,0.55739,0.549656,0.608236,0.497511,0.541233,0.596765,0.493602,0.568508,0.558336,0.513118,0.560994,0.648431,0.737406,0.620315,0.750762,0.541876,0.562931,0.557707,0.596967,0.700259,0.592427,0.531137,0.715189,0.590871,0.601737,0.548402,0.525175,0.52299,0.517088,0.526662,0.561964};
135
136double maxminFitnessTwt[] = {0.0245997,0.388426,1.02804,0,0.249319,0,0.224357,0,0.207205,0.645963,1.34112,0,0.204437,2.58511,0.0636676,0,0.175925,2.44985,2.29084,0,0.212096,0.0322857,1.74496,0.1597,1.44875,0.00526594,1.0816,0.0678271,0.0913783,0.544015,0,0,0,0.316166,0,0,0.357164,0.210462,0,1.28611,1.17654,0.0529384,0,0,0,0,0,0,1.23031,0.0913001,0,0,0,0,0,0,0,0.0796966,0,0};
137double maxminFitnessNwt[] = {0.0611413,0.23327,0.712934,0,0.216792,0,0.170455,0,0.0851449,0.18147,0.406073,0,0.0819434,0.515948,0.0311146,0,0.0627368,0.3289,0.368154,0,0.222591,0.127424,0.769231,0.0930599,0.625817,0.0219619,0.521739,0.0828076,0.147473,0.21269,0,0,0,0.119905,0,0,0.142772,0.128071,0,0.402632,0.46743,0.0402629,0,0,0,0,0,0,0.398693,0.110018,0,0,0,0,0,0,0,0.0478261,0,0};
138double maxminFitnessFt[] = {3.11814,3.09917,2.77073,3.22532,2.7343,3.04101,3.01053,1.75,3.77503,4.1348,5.88528,5.15015,5.09895,5.72059,5.73967,7.69795,8.69986,10.7213,6.78331,8.61735,2.9556,1.85806,2.57548,2.03072,1.95982,2.17717,2.49545,2.24676,2.87432,2.83302,1.68395,3.16711,2.43568,2.48967,1.76872,2.34524,2.83311,3.07388,2.51819,3.20452,2.80241,2.04921,1.84371,2.55728,1.64157,2.56259,2.17661,2.21846,2.50419,1.79329,2.23616,2.16137,2.4428,2.21168,2.34797,2.33303,2.6308,2.3477,2.26736,2.45884};
139double maxminFitnessCmax[] = {0.838211,0.778511,0.770185,0.767704,0.792271,0.697123,0.818421,0.572115,0.693901,0.801471,0.661645,0.630863,0.606237,0.667276,0.703675,0.682395,0.66849,0.64493,0.649919,0.70095,0.910906,0.665103,0.839584,0.85805,0.775546,0.671373,0.744645,0.607092,0.635024,0.55739,0.549656,0.612988,0.497511,0.541233,0.596765,0.496133,0.568508,0.558336,0.513118,0.551702,0.648431,0.737406,0.620315,0.750762,0.541876,0.562931,0.557707,0.596967,0.700259,0.592427,0.531137,0.715189,0.590871,0.601737,0.548402,0.525175,0.52299,0.517088,0.526662,0.550133};
140
141//
142// Evolution of scheduling heuristics for GA FP
143//
144
145//
146//int main(int argc, char **argv)
147//{
148// int i=0;
149//
150// for(i=0; i <60; i++){
151//
152// // read XML config
153// std::ifstream fin(argv[1]);
154// if (!fin) {
155// std::cerr << "Error opening config file! ";
156// return 1;
157// }
158//
159// std::string xmlFile, temp;
160// while (!fin.eof()) {
161// getline(fin, temp);
162// xmlFile += "\n" + temp;
163// }
164// fin.close();
165//
166// std::string logName = "log", statsName = "stats";
167// if(i < 10) {
168// logName += "0";
169// statsName += "0";
170// }
171// logName += uint2str(i) + ".txt";
172// statsName += uint2str(i) + ".txt";
173//
174// int nPoslova = nJob[i];
175// uint nStrojeva = nMachine[i];
176//
177//
178// stringstream ss;
179// ss << nPoslova;
180// string jobString = ss.str();
181// // std::cout<<jobString<<std::endl;
182// // update in XML
183// //XMLResults results;
184//
185// // std::cout<<xmlFile<<std::endl;
186//
187// XMLResults results;
188// XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
189// XMLNode genotype = xConfig.getChildNode("Genotype");
190// XMLNode fp = genotype.getChildNode("FloatingPoint");
191// XMLNode dim = fp.getChildNodeWithAttribute("Entry", "key", "dimension");
192// dim.updateText(jobString.c_str());
193//
194//
195// XMLNode registry = xConfig.getChildNode("Registry");
196// XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
197// log.updateText(logName.c_str());
198// XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
199// stats.updateText(statsName.c_str());
200//
201// // write back
202// std::ofstream fout(argv[1]);
203// // std::cout<<xConfig.createXMLString(true)<<std::endl;
204// fout << xConfig.createXMLString(true);
205// fout.close();
206//
207//
208//
209// StateP state (new State);
210//
211// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
212// state->setEvalOp(evalOp);
213//
214// // EvaluateAlternate *z = new EvaluateAlternate;
215// // state->addOperator((OperatorP) z);
216//
217// WriteBest *b = new WriteBest;
218// state->addOperator((OperatorP) b);
219//
220// // integer values genotype
221// IntGenotypeP gen = (IntGenotypeP) (new IntGenotype::IntGenotype);
222// state->addGenotype(gen);
223//
224// // if 3rd argument is present, read that as a single test case to evaluate
225// //if(argc > 2) {
226// // uint primjer = atoi(argv[2]);
227// state->getContext()->environment = new uint(i);
228// //}
229//
230// state->initialize(argc, argv);
231//
232//
233// state->run();
234// }
235// return 0;
236//}
237
238
239//FOR GA PERM
240//int main(int argc, char **argv)
241//{
242// int i=0;
243//
244// for(i=0; i <60; i++){
245//
246// // read XML config
247// std::ifstream fin(argv[1]);
248// if (!fin) {
249// std::cerr << "Error opening config file! ";
250// return 1;
251// }
252//
253// std::string xmlFile, temp;
254// while (!fin.eof()) {
255// getline(fin, temp);
256// xmlFile += "\n" + temp;
257// }
258// fin.close();
259//
260// std::string logName = "log", statsName = "stats";
261// if(i < 10) {
262// logName += "0";
263// statsName += "0";
264// }
265// logName += uint2str(i) + ".txt";
266// statsName += uint2str(i) + ".txt";
267//
268// int nPoslova = nJob[i];
269// uint nStrojeva = nMachine[i];
270//
271//
272// stringstream ss;
273// ss << nPoslova;
274// string jobString = ss.str();
275// // std::cout<<jobString<<std::endl;
276// // update in XML
277// //XMLResults results;
278//
279// // std::cout<<xmlFile<<std::endl;
280//
281// stringstream ss1;
282// ss1 << (nStrojeva-1);
283// string machineString = ss1.str();
284//
285// XMLResults results;
286// XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
287// XMLNode genotype = xConfig.getChildNode("Genotype");
288// XMLNode fp = genotype.getChildNode("Permutation");
289// XMLNode dim = fp.getChildNodeWithAttribute("Entry", "key", "size");
290// dim.updateText(jobString.c_str());
291//
292// fp = genotype.getChildNode("IntGenotype");
293// dim = fp.getChildNodeWithAttribute("Entry", "key", "size");
294// dim.updateText(jobString.c_str());
295//
296// dim = fp.getChildNodeWithAttribute("Entry", "key", "ubound");
297// dim.updateText(machineString.c_str());
298//
299//
300// XMLNode registry = xConfig.getChildNode("Registry");
301// XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
302// log.updateText(logName.c_str());
303// XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
304// stats.updateText(statsName.c_str());
305//
306// // write back
307// std::ofstream fout(argv[1]);
308// // std::cout<<xConfig.createXMLString(true)<<std::endl;
309// fout << xConfig.createXMLString(true);
310// fout.close();
311//
312//
313//
314// StateP state (new State);
315//
316// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
317// state->setEvalOp(evalOp);
318//
319// // EvaluateAlternate *z = new EvaluateAlternate;
320// // state->addOperator((OperatorP) z);
321//
322// WriteBest *b = new WriteBest;
323// state->addOperator((OperatorP) b);
324//
325// // integer values genotype
326// IntGenotypeP gen = (IntGenotypeP) (new IntGenotype::IntGenotype);
327// state->addGenotype(gen);
328//
329// // if 3rd argument is present, read that as a single test case to evaluate
330// //if(argc > 2) {
331// // uint primjer = atoi(argv[2]);
332// state->getContext()->environment = new uint(i);
333// //}
334//
335// state->initialize(argc, argv);
336//
337//
338// state->run();
339// }
340// return 0;
341//}
342//
343
344
345//
346// Evaluation of a preevolved individual from "ind.txt"
347//
348
349//int main(int argc, char **argv)
350//{
351// StateP state (new State);
352//
353// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
354// state->setEvalOp(evalOp);
355// state->initialize(argc, argv);
356//
357// // citanje jedinke iz 'ind.txt' i provjera dobrote
358// XMLNode xInd = XMLNode::parseFile("./ind.txt", "Individual");
359// IndividualP ind = (IndividualP) new Individual(state);
360// ind->read(xInd);
361// state->getAlgorithm()->evaluate(ind);
362// std::cout << ind->toString();
363//
364// return 0;
365//}
366
367
368
369//FOR GA PERM with time calculation
370//int main1(int argc, char **argv)
371//{
372// StateP state (new State);
373//
374// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
375// state->setEvalOp(evalOp);
376//
377// // EvaluateAlternate *z = new EvaluateAlternate;
378// // state->addOperator((OperatorP) z);
379//
380// WriteBest *b = new WriteBest;
381// state->addOperator((OperatorP) b);
382//
383// // integer values genotype
384// IntGenotypeP gen = (IntGenotypeP) (new IntGenotype::IntGenotype);
385// state->addGenotype(gen);
386//
387//
388// int i=0;
389//
390// ofstream outstr;
391// outstr.open("duration.txt");
392// ofstream hits;
393// hits.open("hits.txt");
394// vector<double> durations;
395// for(i=0; i <60; i++){
396// double time=0.0;
397// int hit = 0;
398// for(int j =0; j<30; j++){
399// // read XML config
400// std::ifstream fin(argv[1]);
401// if (!fin) {
402// std::cerr << "Error opening config file! ";
403// return 1;
404// }
405//
406// std::string xmlFile, temp;
407// while (!fin.eof()) {
408// getline(fin, temp);
409// xmlFile += "\n" + temp;
410// }
411// fin.close();
412//
413// std::string logName = "log", statsName = "stats";
414// logName+="_";
415// logName+=uint2str(j);
416// logName+="_";
417// if(i < 10) {
418// logName += "0";
419// statsName += "0";
420// }
421//
422// logName += uint2str(i) + ".txt";
423// statsName += uint2str(i) + ".txt";
424//
425// int nPoslova = nJob[i];
426// uint nStrojeva = nMachine[i];
427//
428//
429// stringstream ss;
430// ss << nPoslova;
431// string jobString = ss.str();
432// // std::cout<<jobString<<std::endl;
433// // update in XML
434// //XMLResults results;
435//
436// // std::cout<<xmlFile<<std::endl;
437//
438// stringstream ss1;
439// ss1 << (nStrojeva-1);
440// string machineString = ss1.str();
441//
442// XMLResults results;
443// XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
444// XMLNode genotype = xConfig.getChildNode("Genotype");
445// XMLNode fp = genotype.getChildNode("Permutation");
446// XMLNode dim = fp.getChildNodeWithAttribute("Entry", "key", "size");
447// dim.updateText(jobString.c_str());
448//
449// fp = genotype.getChildNode("IntGenotype");
450// dim = fp.getChildNodeWithAttribute("Entry", "key", "size");
451// dim.updateText(jobString.c_str());
452//
453// dim = fp.getChildNodeWithAttribute("Entry", "key", "ubound");
454// dim.updateText(machineString.c_str());
455//
456//
457// XMLNode registry = xConfig.getChildNode("Registry");
458// XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
459// log.updateText(logName.c_str());
460// XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
461// stats.updateText(statsName.c_str());
462//
463// stringstream ss2;
464// double val = maxminFitnessTwt[i];
465// ss2 << val+1e-6;
466// string fir = ss2.str();
467// XMLNode term = registry.getChildNodeWithAttribute("Entry", "key", "term.fitnessval");
468// term.updateText(fir.c_str());
469//
470// // write back
471//
472// std::ofstream fout(argv[1]);
473// // std::cout<<xConfig.createXMLString(true)<<std::endl;
474// fout << xConfig.createXMLString(true);
475// fout.close();
476//
477//
478//
479//
480//
481// // if 3rd argument is present, read that as a single test case to evaluate
482// //if(argc > 2) {
483// // uint primjer = atoi(argv[2]);
484// state->getContext()->environment = new uint(i);
485// //}
486//
487// state->initialize(argc, argv);
488//
489//
490//
491// state->run();
492// double min = state->getStats()->getFitnessMin();
493//
494// if(min<(val+1e-6)){
495// hit++;
496// }
497// time+=state->elapsedTime_;
498// durations.push_back(state->elapsedTime_);
499//
500// }
501// double avgTime = time/10;
502// std::sort(durations.begin(), durations.end());
503//
504// outstr<<avgTime<<"\t"<<(durations[14]+durations[15])/2.0<<endl;
505// hits<<hit<<endl;
506// }
507// hits.close();
508// outstr.close();
509// return 0;
510//}
511//
512//
514//
515//int main(int argc, char **argv)
516//{
517//
518//
519// StateP state (new State);
520//
521// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
522// state->setEvalOp(evalOp);
523//
524// // EvaluateAlternate *z = new EvaluateAlternate;
525// // state->addOperator((OperatorP) z);
526//
527// WriteBest *b = new WriteBest;
528// state->addOperator((OperatorP) b);
529//
530// // integer values genotype
531// IntGenotypeP gen = (IntGenotypeP) (new IntGenotype::IntGenotype);
532// state->addGenotype(gen);
533//
534// int i=0;
535//
536// ofstream outstr;
537// outstr.open("duration.txt");
538// ofstream hits;
539// hits.open("hits.txt");
540// vector<double> durations;
541//
542// for(i=0; i <60; i++){
543// double time=0.0;
544// int hit = 0;
545// for(int j =0; j<30; j++){
546// // read XML config
547// std::ifstream fin(argv[1]);
548// if (!fin) {
549// std::cerr << "Error opening config file! ";
550// return 1;
551// }
552//
553// std::string xmlFile, temp;
554// while (!fin.eof()) {
555// getline(fin, temp);
556// xmlFile += "\n" + temp;
557// }
558// fin.close();
559//
560// std::string logName = "log", statsName = "stats";
561// logName+="_";
562// logName+=uint2str(j);
563// logName+="_";
564// if(i < 10) {
565// logName += "0";
566// statsName += "0";
567// }
568// logName += uint2str(i) + ".txt";
569// statsName += uint2str(i) + ".txt";
570//
571// int nPoslova = nJob[i];
572// uint nStrojeva = nMachine[i];
573//
574//
575// stringstream ss;
576// ss << nPoslova;
577// string jobString = ss.str();
578// // std::cout<<jobString<<std::endl;
579// // update in XML
580// //XMLResults results;
581//
582// // std::cout<<xmlFile<<std::endl;
583//
584// XMLResults results;
585// XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
586// XMLNode genotype = xConfig.getChildNode("Genotype");
587// XMLNode fp = genotype.getChildNode("FloatingPoint");
588// XMLNode dim = fp.getChildNodeWithAttribute("Entry", "key", "dimension");
589// dim.updateText(jobString.c_str());
590//
591//
592// XMLNode registry = xConfig.getChildNode("Registry");
593// XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
594// log.updateText(logName.c_str());
595// XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
596// stats.updateText(statsName.c_str());
597//
598// stringstream ss2;
599// double val = maxminFitnessNwt[i];
600// ss2 << val+1e-6;
601// string fir = ss2.str();
602// XMLNode term = registry.getChildNodeWithAttribute("Entry", "key", "term.fitnessval");
603// term.updateText(fir.c_str());
604//
605//
606// // write back
607// std::ofstream fout(argv[1]);
608// // std::cout<<xConfig.createXMLString(true)<<std::endl;
609// fout << xConfig.createXMLString(true);
610// fout.close();
611//
612//
613//
614//
615// // if 3rd argument is present, read that as a single test case to evaluate
616// //if(argc > 2) {
617// // uint primjer = atoi(argv[2]);
618// state->getContext()->environment = new uint(i);
619// //}
620//
621// state->initialize(argc, argv);
622//
623//
624// state->run();
625//
626// double min = state->getStats()->getFitnessMin();
627//
628// if(min<(val+1e-6)){
629// hit++;
630//
631// }
632// time+=state->elapsedTime_;
633// durations.push_back(state->elapsedTime_);
634// }
635// double avgTime = time/10;
636// std::sort(durations.begin(), durations.end());
637//
638// outstr<<avgTime<<"\t"<<(durations[14]+durations[15])/2.0<<endl;
639// hits<<hit<<endl;
640// }
641// hits.close();
642// outstr.close();
643// return 0;
644//}
645
646
647
648
649
650// Evaluation of a preevolved individual from "ind.txt"
651//
652//
653//int main(int argc, char **argv)
654//{
655// StateP state (new State);
656// TreeP tree (new Tree::Tree);
657// state->addGenotype(tree);
658//
659// SchedulingEvalOpP evalOp (new SchedulingEvalOp);
660// state->setEvalOp(evalOp);
661// state->initialize(argc, argv);
662//
663// // citanje jedinke iz 'ind.txt' i provjera dobrote
664// XMLNode xInd = XMLNode::parseFile("./ind.txt", "Individual");
665// IndividualP ind = (IndividualP) new Individual(state);
666// ind->initialize(state);
667// ind->read(xInd);
668// state->getAlgorithm()->evaluate(ind);
669// std::cout << ind->toString();
670//
671// return 0;
672//}
State class - backbone of the framework.
Definition: State.h:39