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

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

00001 #include <ecf/ECF.h>
00002 #include "FunctionMinEvalOp.h"
00003 #include <ecf/AlgGenHookeJeeves.h>
00004 
00005 
00006 //
00007 // this main() function optimizes a single COCO function (Id set in config file)
00008 // function Ids: noiseless 1-24, noisy 101-130
00009 //
00010 
00011 int main(int argc, char **argv)
00012 {
00013     StateP state (new State);
00014 
00015     // set the evaluation operator
00016     state->setEvalOp(new FunctionMinEvalOp);
00017 
00018     GenHookeJeevesP alg (new GenHookeJeeves);
00019     state->addAlgorithm(alg);
00020 
00021     state->initialize(argc, argv);
00022     state->run();
00023 
00024 //
00025 //  ispis populacije u txt fajl, za potrebe landscape analysis  
00026 //
00027     //ofstream fajl("popis.txt");
00028     //for(uint i = 0; i < state->getPopulation()->getLocalDeme()->getSize(); i++) {
00029     //  IndividualP ind = state->getPopulation()->getLocalDeme()->at(i);
00030     //  fajl << ind->fitness->getValue() << "\t";
00031     //  FloatingPointP fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype());
00032     //  for(uint dim = 0; dim < fp->realValue.size(); dim++)
00033     //      fajl << fp->realValue[dim] << "\t";
00034     //  fp = boost::static_pointer_cast<FloatingPoint::FloatingPoint> (ind->getGenotype(2));
00035     //  fajl << fp->realValue[0];
00036     //  fajl << "\n";
00037     //}
00038 
00039     return 0;
00040 }
00041 
00042 
00043 
00044 //
00045 // this main() function iterates over multiple COCO functions and optimizes each one in turn
00046 // function Ids: noiseless 1-24, noisy 101-130
00047 //
00048 /*
00049 int main(int argc, char **argv)
00050 {
00051     // run for selected COCO functions
00052     for(uint function = 1; function < 29; function++) {
00053 
00054         // read XML config
00055         std::ifstream fin(argv[1]);
00056         if (!fin) {
00057             std::cerr << "Error opening config file! (" << argv[1] << ")\n";
00058             return 1;
00059         }
00060 
00061         std::string xmlFile, temp;
00062         while (!fin.eof()) {
00063             getline(fin, temp);
00064             xmlFile += "\n" + temp;
00065         }
00066         fin.close();
00067 
00068         // set log and stats parameters
00069         std::string funcName = uint2str(function);
00070         std::string logName = "log", statsName = "stats";
00071         if(function < 10) {
00072             logName += "0";
00073             statsName += "0";
00074         }
00075         logName += uint2str(function) + ".txt";
00076         statsName += uint2str(function) + ".txt";
00077 
00078         // update in XML
00079         XMLResults results;
00080         XMLNode xConfig = XMLNode::parseString(xmlFile.c_str(), "ECF", &results);
00081         XMLNode registry = xConfig.getChildNode("Registry");
00082 
00083         XMLNode func = registry.getChildNodeWithAttribute("Entry", "key", "cec.function");
00084         func.updateText(funcName.c_str());
00085         XMLNode log = registry.getChildNodeWithAttribute("Entry", "key", "log.filename");
00086         log.updateText(logName.c_str());
00087         XMLNode stats = registry.getChildNodeWithAttribute("Entry", "key", "batch.statsfile");
00088         stats.updateText(statsName.c_str());
00089 
00090         // write back
00091         std::ofstream fout(argv[1]);
00092         fout << xConfig.createXMLString(true);
00093         fout.close();
00094 
00095 
00096         // finally, run ECF on single function
00097         StateP state (new State);
00098 
00099         // set the evaluation operator
00100         state->setEvalOp(new FunctionMinEvalOp);
00101 
00102         GenHookeJeevesP alg (new GenHookeJeeves);
00103         state->addAlgorithm(alg);
00104 
00105         state->initialize(argc, argv);
00106         state->run();
00107     }
00108 
00109     return 0;
00110 }*/

Generated on Thu Jul 10 2014 14:13:40 for ECF by  doxygen 1.7.1