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