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

D:/Projekt/ECF_trunk/examples/COCO/main_landscape.cpp

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

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