ECF 1.5
main.cpp
1#include <ecf/ECF.h>
2#include "TSPEvalOp.h"
3
4
5int main(int argc, char **argv)
6{
7 StateP state (new State);
8
9 TSPEvalOp* tsp = new TSPEvalOp();
10 state->setEvalOp(tsp);
11
12 //state->addAlgorithm((AlgorithmP) new Alg);
13
14 state->initialize(argc, argv);
15 state->run();
16
17 return 0;
18}
19
20
21
22//
23// this main() function iterates over multiple TSP instances and optimizes each one in turn
24// TSP instance filenames are read from 'instances.txt'
25//
26/*
27int main(int argc, char **argv)
28{
29
30 // open file with TSP instance names
31 std::ifstream inFile("instances.txt");
32 if(!inFile) {
33 std::cerr << "Error opening file instances.txt!\n";
34 return 1;
35 }
36
37 // read instances from file
38 std::vector< std::string > instances;
39 std::string fileName;
40 while(getline(inFile, fileName))
41 instances.push_back(fileName);
42
43
44 // run for selected TSP instances
45 for(uint instance = 1; instance <= instances.size(); instance++) {
46
47 // read XML config
48 std::ifstream fin(argv[1]);
49 if (!fin) {
50 std::cerr << "Error opening config file! ";
51 return 1;
52 }
53
54 std::string xmlFile, temp;
55 while (!fin.eof()) {
56 getline(fin, temp);
57 xmlFile += "\n" + temp;
58 }
59 fin.close();
60
61 // set log and stats parameters
62 std::string instanceName = instances[instance - 1];
63 std::string logName = "log", statsName = "stats";
64 if(instance < 10) {
65 logName += "0";
66 statsName += "0";
67 }
68 logName += uint2str(instance) + ".txt";
69 statsName += uint2str(instance) + ".txt";
70
71 // update in XML
72 XMLResults results;
73 XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
74 XMLNode registry = xConfig.getChildNode("Registry");
75
76 XMLNode func = registry.getChildNodeWithAttribute("Entry", "key", "tsp.infile");
77 func.updateText(instanceName.c_str());
78 XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
79 log.updateText(logName.c_str());
80 XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
81 stats.updateText(statsName.c_str());
82
83 // write back
84 std::ofstream fout(argv[1]);
85 fout << xConfig.createXMLString(true);
86 fout.close();
87
88
89 // finally, run ECF on a single instance
90 StateP state (new State);
91
92 // set the evaluation operator
93 state->setEvalOp(new TSPEvalOp);
94
95 state->initialize(argc, argv);
96 state->run();
97 }
98
99 return 0;
100}
101*/
State class - backbone of the framework.
Definition: State.h:39
TSP evaluation operator.
Definition: TSPEvalOp.h:33