• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/examples/GATSP/main.cpp

00001 #include <ecf/ECF.h>
00002 #include "TSPEvalOp.h"
00003 
00004 
00005 int main(int argc, char **argv)
00006 {
00007     StateP state (new State);
00008 
00009     TSPEvalOp* tsp = new TSPEvalOp();
00010     state->setEvalOp(tsp);
00011 
00012     state->initialize(argc, argv);
00013     state->run();
00014 
00015     return 0;
00016 }
00017 
00018 
00019 
00020 //
00021 // this main() function iterates over multiple TSP instances and optimizes each one in turn
00022 // TSP instance filenames are read from 'instances.txt'
00023 //
00024 /*
00025 int main(int argc, char **argv)
00026 {
00027 
00028     // open file with TSP instance names
00029     std::ifstream inFile("instances.txt");
00030     if(!inFile) {
00031         std::cerr << "Error opening file instances.txt!\n";
00032         return 1;
00033     }
00034 
00035     // read instances from file
00036     std::vector< std::string > instances;
00037     std::string fileName;
00038     while(getline(inFile, fileName))
00039         instances.push_back(fileName);
00040 
00041 
00042     // run for selected TSP instances
00043     for(uint instance = 1; instance <= instances.size(); instance++) {
00044 
00045         // read XML config
00046         std::ifstream fin(argv[1]);
00047         if (!fin) {
00048             std::cerr << "Error opening config file! ";
00049             return 1;
00050         }
00051 
00052         std::string xmlFile, temp;
00053         while (!fin.eof()) {
00054             getline(fin, temp);
00055             xmlFile += "\n" + temp;
00056         }
00057         fin.close();
00058 
00059         // set log and stats parameters
00060         std::string instanceName = instances[instance - 1];
00061         std::string logName = "log", statsName = "stats";
00062         if(instance < 10) {
00063             logName += "0";
00064             statsName += "0";
00065         }
00066         logName += uint2str(instance) + ".txt";
00067         statsName += uint2str(instance) + ".txt";
00068 
00069         // update in XML
00070         XMLResults results;
00071         XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
00072         XMLNode registry = xConfig.getChildNode("Registry");
00073 
00074         XMLNode func = registry.getChildNodeWithAttribute("Entry", "key", "tsp.infile");
00075         func.updateText(instanceName.c_str());
00076         XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
00077         log.updateText(logName.c_str());
00078         XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
00079         stats.updateText(statsName.c_str());
00080 
00081         // write back
00082         std::ofstream fout(argv[1]);
00083         fout << xConfig.createXMLString(true);
00084         fout.close();
00085 
00086 
00087         // finally, run ECF on a single instance
00088         StateP state (new State);
00089 
00090         // set the evaluation operator
00091         state->setEvalOp(new TSPEvalOp);
00092 
00093         state->initialize(argc, argv);
00094         state->run();
00095     }
00096 
00097     return 0;
00098 }
00099 */

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1