// ntrees.cc File to demonstrate to test random tree generator // W.B.Langdon cs.bham.ac.uk // See ETL-TR-95-35 14 Nov 1995 Hitoshi Iba Random tree generator for GP // Or Random Generation of Trees, Laurent Alonso and Rene Schott, Kulwer, 1995 #define main_version "19 October 1997 $Revision: 1.5 $" //WBL 29 Dec 21 Ok with gcc version 4.8.5 and gcc version 9.3.1 //WBL 6 May 01 Tweak so compatible with gcc 2.95.2 //WBL 21 Jan 98 Add display of numberdnz //WBL 19 Oct 97 Cut down version of rand_tree-test.cc with only tree counting //WBL 26 Aug 97 Extend to take into account number of each functions //WBL 22 Aug 97 Use for generating plots of Cn(s) for ant //WBL 12 Aug 97 Use log of factorial, add remove i[4] loop //WBL 11 Aug 97 Extend range of size before overflow // BUGFIX limit (efficiency saving only), // BUGFIX display of done time //compiling on Linux g++ -o ntrees -O2 -Wno-write-strings ntrees.cc //compiling in 2020 g++ -o ntrees -O2 ntrees.cc -lm //compiling on SUN g++ -o ntrees -O2 ntrees.cc -lg++ -lm //compiling on Alpha cxx -o ntrees -O5 ntrees.cc -lm // Includes main function #include #include #include #include #include #include #include using namespace std; //dont change! #define max_arity 4 double* log_fact; int log_fact_size = 0; void new_log_fact(const int x) { log_fact = new double[x+1]; log_fact_size = x+1; double f = 0; log_fact[0] = 0; for(int i=1;i0 || i[4]==0)) { number++; double tree = tree_count(size,i,arity); if(tree>max) {max = tree; memcpy(best,i,sizeof(i)); } } } //now run it all again but report those some fraction of best double total = 0; int numbernz = 0; int numberdnz= 0; //cout<<"All possible combinations of arities for tree of size "<0 || i[4]==0)) { const double tree = tree_count(size,i,arity); const double ratio = exp(tree-max); total += ratio; if(ratio>FLT_EPSILON) numbernz++; if(ratio>DBL_EPSILON) numberdnz++; } } cout<<"\t"<0) { cout<<" "<<(max+log(total))<FLT_EPSILON chance of being " <<" picked \n"; cerr<<" \tTotal probability before normalising \n"; cerr<<" \tNatural Logrithm (Number of trees of this size) \n"; cerr<<" \tLogrithm Base10(Number of trees of this size) \n"; cerr<<" \tNumber of trees of this size \n"; cerr<<" \n"; cerr<<" \tTotal for all displayed sizes (if available)\n"; cerr<<" \n"; exit(EXIT_FAILURE); }//end help void error(char* message, char* message2) { cerr<7) error("Need 3, 4, 5 or 6 arguments",""); int start, end, incr; const int t = sscanf(argv[1],"%d,%d,%d",&start,&end,&incr); switch(t) { case 1: end=start; incr=1; break; case 2: incr=1; break; case 3: break; otherwise: error("Syntax error on ",argv[1]); break; } if(start<1 || end<1 || incr<1 ) { cerr<0) cout<