diff --git a/cpp_frep/main.cpp b/cpp_frep/main.cpp index 27d04c75bf6fcbbc396ff377dd64a0dda1dd2fb9..b93ae21b2da5c9519cb10f09ef498ac01009b1d7 100755 --- a/cpp_frep/main.cpp +++ b/cpp_frep/main.cpp @@ -448,7 +448,7 @@ int main(int const, char const**) { bool smooth=true; - bool parametric=true; + bool parametric=false; bool tuneParameters=false; float precision = 0.001; @@ -483,13 +483,13 @@ int main(int const, char const**) { // genome.push_back(node2); - // // std::vector<scalar> node3; - // // node3.push_back(0.2472); - // // node3.push_back(0.452); - // // node3.push_back(0.727); - // // node3.push_back(0.17); - // // node3.push_back(0.227); - // // genome.push_back(node3); + // std::vector<scalar> node3; + // node3.push_back(0.2472); + // node3.push_back(0.452); + // node3.push_back(0.727); + // node3.push_back(0.17); + // node3.push_back(0.227); + // genome.push_back(node3); // Frep_tree tree(genome,smooth,parametric,bound); @@ -528,9 +528,66 @@ int main(int const, char const**) { // drawFrep(tree,minX, maxX, minY, maxY, dx, dy,"final",false); - // tree.printGenome(); - + + // best 5 nodes 0.00103913 + std::vector<scalar> params5={0.56645, 1.13557, 0.601257, 0.225314, 0.579243, 0.534814, 0.530563, 0.64434, 0.208775, 0.0954164, 0.309497, 0.632866, 0.341624, 0.124673, 0.376787, 0.542705, 0.481462, 0.369699, 0.751949, 0.717642, 0.326457, 0.211514, 0.34966, 0.284553, 0.438133, 2.60259}; + params5={0.2, + 1.15608, + 0.532703, + 0.236274, + 0.631038, + 0.520627, + 0.551214, + 0.682205, + 0.243995, + 0.1164, + 0.34611, + 0.620567, + 0.331086, + 0.132638, + 0.462726, + 0.550451, + 0.490349, + 0.348071, + 0.759609, + 0.740685, + 0.341778, + 0.223557, + 0.290785, + 0.308138, + 0.453482, + 2.60747}; + + //BEST //0.0007 + std::vector<scalar> params2={0.611069,0.353383,0.427557,0.764276,0.724136,0.339219,0.743547,0.309012,0.803405,0.0938337,2.60517}; + + unsigned n_nodes_=5; + std::vector<std::vector<scalar>> genome; + std::vector<std::vector<scalar>> nodes; + for (unsigned i=0;i<n_nodes_;i++ ){ + std::vector<scalar> node; + for (unsigned j=0;j<5;j++ ){ + node.push_back(params5[i*5+j]); + } + nodes.push_back(node); + genome.push_back(nodes[i]); + } + Frep_tree tree(genome,smooth,parametric,bound); + + Add gear ( + new Circle(1.0 ,0.0,0.0),//body + new PolarArray ( //teeth + new Scale ( //scale + tree.getFrep() //tooth //get teeth + ,0.0f,0.0f, 0.28f,0.28f) //scale + , 360.0/8.0,0.75) + ); + + drawFrep(&gear,minX, maxX, minY, maxY, dx, dy,"best_"+std::to_string(n_nodes_),true); + + std::cout<< gear.getPrintedName()<<'\n'; + // //////////tune parameters////////// // std::cout<<"Tuning parameters!!!!!!!!!!!!!!!!!!!\n"; @@ -545,87 +602,86 @@ int main(int const, char const**) { // drawFrep(tree,minX, maxX, minY, maxY, dx, dy,"finalt",false); //json - unsigned n_nodes_=2; - std::ifstream i2("2_nodes.json"); - std::ifstream i5("5_nodes.json"); - scalar scale_factor=1.5; - int n_teeth_=8; - json results; - if(n_nodes_==2){ - i2 >> results; - }else{ - i5 >> results; - } + // unsigned n_nodes_=2; + // std::ifstream i2("2_nodes.json"); + // std::ifstream i5("5_nodes.json"); + // scalar scale_factor=1.5; + // int n_teeth_=8; + // json results; + // if(n_nodes_==2){ + // i2 >> results; + // }else{ + // i5 >> results; + // } - std::cout<<results["population"]["0"][0]["point"]<<'\n'; + // std::cout<<results["population"]["0"][0]["point"]<<'\n'; - std::cout<<results["Best Index"].size()<<'\n'; - unsigned numGenerations=results["Best Index"].size(); - unsigned numPopulation=results["population"]["0"].size(); + // std::cout<<results["Best Index"].size()<<'\n'; + // unsigned numGenerations=results["Best Index"].size(); + // unsigned numPopulation=results["population"]["0"].size(); - //show best each iteration - for (unsigned generation=0;generation<numGenerations;generation++ ){ - std::vector<std::vector<scalar>> genome; - std::vector<std::vector<scalar>> nodes; - std::cout<<std::to_string(generation)<<'\n'; - unsigned bestPointIndex= results["Best Index"][std::to_string(generation)]; - std::cout<<bestPointIndex<<'\n'; - auto bestGenome=results["population"][std::to_string(generation)][bestPointIndex]["point"]; - std::cout<<bestGenome<<'\n'; - for (unsigned i=0;i<n_nodes_;i++ ){ - std::vector<scalar> node; - for (unsigned j=0;j<5;j++ ){ - node.push_back(bestGenome[i*5+j]); - } - nodes.push_back(node); - genome.push_back(nodes[i]); - Frep_tree tree(genome,smooth,parametric,bound); - Scale gear ( //scale - new Add ( //body and teeth - new Circle(1.0 ,0.0,0.0),//body - new PolarArray ( //teeth - new Scale ( //scale - tree.getFrep() //tooth //get teeth - ,0.0f,0.0f, 0.28f,0.28f) //scale - , 360.0/(scalar)n_teeth_,0.75) ) //body and teeth - ,scale_factor);//scale + // //show best each iteration + // for (unsigned generation=0;generation<numGenerations;generation++ ){ + // std::vector<std::vector<scalar>> genome; + // std::vector<std::vector<scalar>> nodes; + // std::cout<<std::to_string(generation)<<'\n'; + // unsigned bestPointIndex= results["Best Index"][std::to_string(generation)]; + // std::cout<<bestPointIndex<<'\n'; + // auto bestGenome=results["population"][std::to_string(generation)][bestPointIndex]["point"]; + // std::cout<<bestGenome<<'\n'; + // for (unsigned i=0;i<n_nodes_;i++ ){ + // std::vector<scalar> node; + // for (unsigned j=0;j<5;j++ ){ + // node.push_back(bestGenome[i*5+j]); + // } + // nodes.push_back(node); + // genome.push_back(nodes[i]); + // Frep_tree tree(genome,smooth,parametric,bound); + // Scale gear ( //scale + // new Add ( //body and teeth + // new Circle(1.0 ,0.0,0.0),//body + // new PolarArray ( //teeth + // new Scale ( //scale + // tree.getFrep() //tooth //get teeth + // ,0.0f,0.0f, 0.28f,0.28f) //scale + // , 360.0/(scalar)n_teeth_,0.75) ) //body and teeth + // ,scale_factor);//scale - drawFrep(&gear,minX, maxX, minY, maxY, dx, dy,"node"+std::to_string(n_nodes_)+"/"+std::to_string(generation),false); - //std::to_string() - } - } - - //save first 10 generations - for (unsigned generation=0;generation<5;generation++ ){ - for (unsigned population=0;population<numPopulation;population++ ){ - std::vector<std::vector<scalar>> genome; - std::vector<std::vector<scalar>> nodes; - auto bestGenome=results["population"][std::to_string(generation)][population]["point"]; - for (unsigned i=0;i<n_nodes_;i++ ){ - std::vector<scalar> node; - for (unsigned j=0;j<5;j++ ){ - node.push_back(bestGenome[i*5+j]); - } - nodes.push_back(node); - genome.push_back(nodes[i]); - Frep_tree tree(genome,smooth,parametric,bound); - Scale gear ( //scale - new Add ( //body and teeth - new Circle(1.0 ,0.0,0.0),//body - new PolarArray ( //teeth - new Scale ( //scale - tree.getFrep() //tooth //get teeth - ,0.0f,0.0f, 0.28f,0.28f) //scale - , 360.0/(scalar)n_teeth_,0.75) ) //body and teeth - ,scale_factor);//scale + // drawFrep(&gear,minX, maxX, minY, maxY, dx, dy,"node"+std::to_string(n_nodes_)+"/"+std::to_string(generation),false); + // //std::to_string() + // } + // } + + // //save first 10 generations + // for (unsigned generation=0;generation<5;generation++ ){ + // for (unsigned population=0;population<numPopulation;population++ ){ + // std::vector<std::vector<scalar>> genome; + // std::vector<std::vector<scalar>> nodes; + // auto bestGenome=results["population"][std::to_string(generation)][population]["point"]; + // for (unsigned i=0;i<n_nodes_;i++ ){ + // std::vector<scalar> node; + // for (unsigned j=0;j<5;j++ ){ + // node.push_back(bestGenome[i*5+j]); + // } + // nodes.push_back(node); + // genome.push_back(nodes[i]); + // Frep_tree tree(genome,smooth,parametric,bound); + // Scale gear ( //scale + // new Add ( //body and teeth + // new Circle(1.0 ,0.0,0.0),//body + // new PolarArray ( //teeth + // new Scale ( //scale + // tree.getFrep() //tooth //get teeth + // ,0.0f,0.0f, 0.28f,0.28f) //scale + // , 360.0/(scalar)n_teeth_,0.75) ) //body and teeth + // ,scale_factor);//scale - drawFrep(&gear,minX, maxX, minY, maxY, dx, dy,"first"+std::to_string(n_nodes_)+"/"+std::to_string(generation)+"_"+std::to_string(population),false); - //std::to_string() - } - } - - } + // drawFrep(&gear,minX, maxX, minY, maxY, dx, dy,"first"+std::to_string(n_nodes_)+"/"+std::to_string(generation)+"_"+std::to_string(population),false); + // //std::to_string() + // } + // } + // } // // write prettified JSON to another file // std::ofstream o("pretty_5_nodes.json");