本文整理汇总了C++中Candidate::get_x方法的典型用法代码示例。如果您正苦于以下问题:C++ Candidate::get_x方法的具体用法?C++ Candidate::get_x怎么用?C++ Candidate::get_x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Candidate
的用法示例。
在下文中一共展示了Candidate::get_x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
int dim = 9; // problem dimensions.
// std::vector<double> x0({-0.1,-1.4,-0.5,1.5,0.5,0.5});
std::vector<double> x0({-0.1,-1.4,-0.5,1.5,0.5,0.5,1.0,0.001,0.001});
// double sigma = 0.1;
//Start from a good solution
// std::vector<double> x0({-0.00138611487182065,-1.53859247193321,-0.532506967778129,1.9864034821433,0.52119274561097,0.269452637112695,0.13281810737985,0.523979626929375,0.510355579117084});
double sigma = 0.1;
//int lambda = 100; // offsprings at each generation.
CMAParameters<> cmaparams(x0,sigma);
cmaparams.set_mt_feval(true); //multithread
// cmaparams.set_algo(aCMAES); //standard
cmaparams.set_algo(aBIPOP_CMAES);
// cmaparams.set_elitism(true);
cmaparams.set_restarts(3);
// cmaparams.set_restarts(1);
cmaparams.set_ftarget(1e-15);
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer,80,"%d-%m-%Y_%I%M.dat",timeinfo);
std::string str(buffer);
cmaparams.set_fplot(str);
std::cout.precision(25);
CMASolutions cmasols = cmaes<>(walk,cmaparams);
std::cout << "best solution: " << cmasols << std::endl;
std::cout << "optimization took " << cmasols.elapsed_time() / 1000.0 << " seconds\n";
Candidate bcand = cmasols.best_candidate();
std::vector<double>x = bcand.get_x();
strftime(buffer,80,"best_solution_%d-%m-%Y_%I%M.json",timeinfo);
std::string file(buffer);
save_solution(x,file.c_str());
return cmasols.run_status();
}