ECF 1.5
main_susjedstvo.cpp
1#include <ecf/ECF.h>
2
3
4//
5// Citanje jedinki iz drugog argumenta (npr. "<exe> parameters.txt susjedstvo.txt") i njihova evaluacija
6// - opcija: ako je zadan treci argument, u njega se upisuju dobrote jedinki (npr. "<exe> parameters.txt susjedstvo.txt" "rezultati.txt")
7//
8#include<string>
9#include<fstream>
10using namespace std;
11
12int main(int argc, char **argv)
13{
14 StateP state (new State);
15
16 SchedulingEvalOpP evalOp (new SchedulingEvalOp);
17 state->setEvalOp(evalOp);
18
19 // if 4th argument is present, read that as a single test case to evaluate
20 if(argc > 4) {
21 uint primjer = atoi(argv[4]);
22 state->getContext()->environment = new uint(primjer);
23 }
24
25 state->initialize(argc, argv);
26
27 // otvori datoteku sa stablima
28 ifstream inFile(argv[2]);
29 if(!inFile) {
30 cout << "ne mogu otvoriti " << argv[1] << endl;
31 return 1;
32 }
33
34 // je li zadana izlazna datoteka
35 ofstream outFile;
36 bool output = false;
37 if(argc > 3) {
38 outFile.open(argv[3]);
39 output = true;
40 }
41
42 // za svako stablo
43 string stablo;
44 while(getline(inFile, stablo)) {
45
46 // prebroji elemente
47 stringstream ss(stablo);
48 uint size = 0;
49 string node;
50 while(ss >> node)
51 size++;
52
53 // izgradi novi <Tree>
54 string treeString = "<Tree size=\"";
55 treeString += uint2str(size) + "\">";
56 treeString += stablo + "</Tree>";
57 XMLNode xTree = XMLNode::parseString(treeString.c_str(),"Tree");
58
59 // dohvati ispravnu jedinku (prvu iz populacije)
60 IndividualP ind = (IndividualP) state->getPopulation()->getLocalDeme()->at(0);
61 Tree::Tree* tree = (Tree::Tree*) ind->getGenotype().get();
62
63 // umetni zadano stablo i evaluairaj
64 tree->read(xTree);
65 state->getAlgorithm()->evaluate(ind);
66 std::cout << ind->toString();
67 if(output)
68 outFile << ind->getFitness()->getValue() << endl;
69 }
70
71 return 0;
72}
State class - backbone of the framework.
Definition: State.h:39
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29
void read(XMLNode &)
Read genotype data from XMLNode.
Definition: Tree.cpp:550
Definition: nodes.h:92