Diploma Thesis Percolation Simulation
C++ Sourcecode Documentation

www.AndreasKrueger.de/thesis/code

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

counters Namespace Reference


Functions

void neighbour_recursion (sphere *array, NUMBER first, NUMBER last, NUMBER actualsph, NUMBER clnumber)
NUMBER count_clusters_recursively (sphere *array, NUMBER first, NUMBER last, NUMBER first_clno)
NUMBER list_to_temp_array_and_find_cluster (sphere *spheres, NUMLIST &sphlist, NUMBER first_clno)
NUMBER neighbour_naive (sphere *array, NUMBER first, NUMBER last, NUMBER actualsph, NUMBER clnumber)
clock_t countclusters_naive (sphere *array, NUMBER first, NUMBER last, NUMBER *clustertable)
NUMBER neighbour_l (sphere *array, NUMLIST &sphlist, NUMLIST::iterator firstsph, NUMLIST::iterator actualsph, NUMBER clnumber)
clock_t countclusters_l (sphere *array, NUMLIST &sphlist, NUMBER *clustertable, NUMBER &clusternumber)
NUMBER list_to_given_array_and_find_cluster (sphere *spheres, sphere *copy, NUMLIST &sphlist, NUMBER first_clno)
NUMBER count_clusters_iteratively (sphere *array, NUMBER first, NUMBER last, NUMBER first_clno)
NUMBER count_clusters_iteratively2 (sphere *array, NUMBER first, NUMBER last, NUMBER first_clno)
NUMBER count_clusters_iteratively_only_selected_spherenumbers (sphere *array, std::vector< NUMBER > &sphnumber, NUMBER N, NUMBER first_clno)
clock_t naive_count_and_analyze (sphere *spheres, NUMBER first, NUMBER last, NUMBER *histo, NUMBER &biggestcl, REAL &averagecl)
NUMBER naive_arraycount_and_analyze (sphere *spheres, NUMBER first, NUMBER last, NUMBER *histo, NUMBER &biggestcl, REAL &averagecl)
clock_t sort_naivecount_and_analyze (sphere *spheres, sphere *copy, NUMBER first, NUMBER last, NUMBER *histo, NUMBER &biggestcl, REAL &averagecl)
clock_t naive_listcount_and_analyze (sphere *spheres, NUMLIST &sphlist, NUMBER N, NUMBER *histo, NUMBER &biggestcl, REAL &averagecl)
clock_t copy_l_count_and_analyze (sphere *spheres, sphere *copy, NUMLIST &sphlist, NUMBER *histo, NUMBER &biggestcl, REAL &averagecl)
bool reference_test (NUMBER N, int dim, COUNTER cuts)
one_result setR_count_analyze_step (NUMBER N, int dim, sphere *spheres, NUMLIST &L_sph_numbers, REAL radius, string &throwtime, clock_t &clcount_time, clock_t &spclsearch_time)
one_result throw_dnc_count_analyze_step (sphere *spheres, NUMLIST &L_sph_numbers, REAL radius, clock_t &clcount_time, clock_t &spclsearch_time)
void divide_all_spheres (sphere *array, NUMLIST &original, NUMLIST &lowerlist, NUMLIST &upperlist, COORDFLOAT border, int direction)
NUMBER combine (sphere *spheres, NUMLIST &sph1, NUMLIST &sph2, cluson *clst, NUMBER firstclno, NUMBER c1, NUMBER c2, COORDFLOAT border, int direction)
NUMBER divide_once_count_and_combine (sphere *spheres, sphere *temp, NUMLIST &all, cluson *clst, NUMBER firstclno, COORDFLOAT border, int direction)
NUMBER divide_once_count_and_analyze (sphere *spheres, sphere *temp, NUMLIST &all, NUMBER N, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
NUMBER divide_two_times_count_and_analyze (sphere *spheres, sphere *temp, NUMLIST &all, NUMBER N, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
NUMBER divide_three_times_count_and_analyze (sphere *spheres, sphere *temp, NUMLIST &all, NUMBER N, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
COUNTER maximal_dividings_in_one_coordinate (COORDFLOAT spacelength, REAL radius)
NUMBER partcount (sphere *spheres, NUMLIST &all, COORDFLOAT l, COORDFLOAT r, COORDFLOAT lm, COORDFLOAT rm, COUNTER divstep, COUNTER divmax, int direction, int dimension, cluson *clusters, NUMBER firstclno)
NUMBER divide_d_times_count_and_analyze (sphere *spheres, NUMLIST &all, NUMBER N, NUMBER d, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
COUNTER choose_optimal_cuts (int dim, NUMBER N, REAL R)
void test_cuts_function ()
NUMBER dividecount (sphere *spheres, NUMLIST &all, COORDFLOAT l, COORDFLOAT r, COORDFLOAT lm, COORDFLOAT rm, COUNTER divstep, COUNTER divcounter, int direction, int dimension, cluson *clusters, NUMBER firstclno)
NUMBER count_analyze_and_return_clusters (NUMBER c, sphere *spheres, NUMLIST &all, cluson *clusters, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
NUMBER divide_by_c_cuts_count_and_analyze (sphere *spheres, NUMLIST &all, NUMBER c, NUMBER *histogram, NUMBER &biggestcl, REAL &averagecl)
NUMBER divide_count_and_analyze (sphere *spheres, NUMLIST &all, NUMBER c, cluson *clusters, NUMBER &biggestcl, REAL &mean_clsz)


Function Documentation

COUNTER choose_optimal_cuts int    dim,
NUMBER    N,
REAL    R
 

Definition at line 732 of file divide_and_conquer.h.

References choose_optimal_cuts_ffc(), choose_optimal_cuts_ffs(), COUNTER, ff_critical_guessed(), give_radius(), GRIDSIZE, log(), NUMBER, pow(), REAL, rounded(), and saturating_fillingfactor().

Referenced by starters::into_file7_pt1(), starters::into_file8_pt1(), setR_count_analyze_step(), and test_cuts_function().

00732                                                        {
00733 
00734         REAL rc=give_radius(ff_critical_guessed(N, dim), N, GRIDSIZE, dim);
00735         REAL rs=give_radius(saturating_fillingfactor(dim, N), N, GRIDSIZE, dim);
00736 //      cout <<"rc="<<rc<<"  rs="<<rs<<"    this R="<<R<<endl;
00737         REAL lowest_N=39.0625;
00738         NUMBER Nclose=rounded(lowest_N * rounded(pow(2, 1+rounded(log(N/(2*lowest_N))/log(2)))));
00739         if (Nclose>480000) Nclose=480000;
00740 //      cout <<"N="<<N<<" Nclose="<<Nclose<<endl;
00741 
00742         COUNTER cuts_c=choose_optimal_cuts_ffc(dim, Nclose);
00743         COUNTER cuts_s=choose_optimal_cuts_ffs(dim, Nclose);
00744         if (cuts_s > cuts_c) cuts_s=cuts_c;
00745 
00746         if (dim==1) return cuts_c;  // because then rs==rc
00747         
00748         REAL cuts=cuts_c + (cuts_s-cuts_c)* (R-rc)/(rs-rc);
00749 
00750 //      cout <<"cuts_c="<<cuts_c<<"   cuts_s="<<cuts_s<<"   cuts_R="<<cuts<<"  return "<<endl;
00751         cuts=rounded(cuts);
00752         return (COUNTER)(cuts>0?cuts:0);
00753 }

NUMBER combine sphere   spheres,
NUMLIST   sph1,
NUMLIST   sph2,
cluson   clst,
NUMBER    firstclno,
NUMBER    c1,
NUMBER    c2,
COORDFLOAT    border,
int    direction
 

Definition at line 39 of file divide_and_conquer.h.

References sphere::c, sphere::clno, clusterneighbours::clusno, COORDFLOAT, analyze::edgespheres(), errorout(), find_biggestradius(), lower(), NUMBER, overlap2(), REAL, set_clusternumber(), cluson::sphlist, and swapcluson().

Referenced by divide_once_count_and_combine(), divide_three_times_count_and_analyze(), divide_two_times_count_and_analyze(), dividecount(), and partcount().

00048 {
00049         if (sph1.empty() || sph2.empty()) return c2;            // if one of the parts is empty, 
00050                                                                                                                                         // do nothing
00051 
00052         sphere s1=spheres[*sph1.begin()]; sphere s2=spheres[*sph2.begin()];
00053         sphere temp=s1; // for a faster overlap-check
00054 
00055         if (s1.clno  > s2.clno ) {
00056                 errorout("combine is not possible, \nbecause clusno's in first list greater than in second list");
00057                 cout <<s1.clno  <<"\t"<< s2.clno<<endl;
00058                 exit (1);
00059         }
00060         if (lower(s2.c-s1.c, 0,direction)) {
00061                 errorout("combine is not possible, \nbecause coordinates of first list are higher than of second list");
00062                 cout <<"(in direction "<<direction<<" ): s1.c="<<s1.c<<" s2.c="<<s2.c<<endl;
00063                 exit(1);
00064         }
00065 
00066         REAL radius1=find_biggestradius(spheres,sph1);
00067         REAL radius2=find_biggestradius(spheres,sph2);
00068         REAL radius=( (radius1 > radius2) ? radius1 : radius2);
00069 
00070         NUMLIST e1, e2;
00071         edgespheres(spheres, sph1, e1,border, 2*radius, direction);
00072         edgespheres(spheres, sph2, e2,border, 2*radius, -direction);
00073         // cout <<"number of edgespheres: "<< e1.size()<<"\t"<<e2.size()<<endl;
00074 
00075         // now find all overlapping edgespheres -> clstoverlap[ ]
00076         // = list of directly overlapping clno's (both ways "forwards" and "backwards"!)
00077         // !!! one clno might be mentioned several times !!!
00078 
00079         clusterneighbours *clstoverlap = new clusterneighbours[c2-firstclno];   
00080                                 // for the clusternumbers   [firstclno;...c1.............;c2-1]
00081                                 // use the (smaller) array  [0;...........c1-firstclno...;c2-firstclno-1]
00082 
00083         NUMLIST::iterator esph1, esph2;
00084 
00085         // idea: sort first perpendicular to cutline, 
00086         // then compare only those within a certain distance
00087         // but at the moment, this checks _all_ edgespheres:
00088         for (esph1=e1.begin();esph1!=e1.end();esph1++){
00089                 for (esph2=e2.begin();esph2!=e2.end();esph2++){
00090                         s1= spheres[*esph1];
00091                         s2= spheres[*esph2];
00092                         if (overlap2 (s1,s2,temp)) {            // overlapping spheres -> overlapping clusters
00093                                 clstoverlap[s1.clno-firstclno].clusno.push_back ( s2.clno); // forwards
00094                                 clstoverlap[s2.clno-firstclno].clusno.push_back ( s1.clno); // backwards
00095                         }
00096                 }
00097         }
00098 
00099         e1.clear(); e2.clear();
00100 
00101         // now follow all cluster-connections in clstoverlap[] 
00102         // delete the multiple entries
00103         // and collect all clno's of overlapping clusters 
00104         // in the list with the smallest clusternumber
00105 
00106         NUMLIST::iterator nneighb ;
00107         NUMBER clno;
00108         for (clno=firstclno;clno<=c1-1;clno++){
00109                 NUMLIST &neighbours=clstoverlap[clno-firstclno].clusno; // alias (!)
00110 
00111                 if (! neighbours.empty() ){                                                     // no overlap
00112                         if ( *(neighbours.begin()) != -1)                               // already counted
00113                         {
00114                                 for (nneighb=neighbours.begin();nneighb!=neighbours.end();nneighb++){
00115 
00116                                         while ( (*nneighb==clno) || (*(clstoverlap[*nneighb-firstclno].clusno.begin())==-1 )) {
00117                                                 nneighb=neighbours.erase(nneighb);
00118                                                 if (nneighb==neighbours.end()) break;
00119                                         }
00120                                         if (nneighb==neighbours.end()) break;
00121 
00122                                         neighbours.splice(neighbours.end(), clstoverlap[*nneighb-firstclno].clusno);
00123                                         clstoverlap[*nneighb-firstclno].clusno.push_front(-1);
00124                                 }
00125                         }
00126                         else    neighbours.clear();
00127                 }
00128         }
00129 
00130 
00131 /*
00132         // the following is not necessary if the tests below are switched off
00133         // because the combination is done in [firstclno;c1-1] only
00134         //
00135         // clear the backwards connections (that were set to -1 in the above process)
00136         for (clno=c1;clno<=c2-1;clno++){
00137                 NUMLIST &neighbours=clstoverlap[clno-firstclno].clusno; 
00138                 if ( neighbours.size() != 0 && *(neighbours.begin()) == -1 )  {
00139                         neighbours.clear();
00140                 }
00141         }
00142 
00143         // only a test (time-consuming!):
00144         // test if all self-references and "-1" have been erased
00145         NUMBER s;
00146         for (clno=firstclno;clno<=c2-1;clno++){
00147                 NUMLIST &neighbours=clstoverlap[clno-firstclno].clusno;
00148                 if ( neighbours.size()!=0 && (*(neighbours.begin()))  == -1)  {
00149                         error("ALARM: -1 left");
00150                         cout << "clno="<<clno<<endl;
00151                         cout << "firstclno="<<firstclno<<" c1="<<c1<<" c2="<<c2<<endl;
00152                         exit(1);
00153                 }
00154                 s=neighbours.size();
00155                 neighbours.remove(clno);
00156                 s=s-neighbours.size();
00157                 if (s !=0) {
00158                         error("still self-references in clusterlist");
00159                         cout << " clno="<<clno<<" # of self references=" <<s<<endl;
00160                         exit(1);
00161                 }
00162         }
00163 
00164         // only a test (time consuming!)
00165         // test if all the clusters have been combined
00166         // by looking for non-empty backwards connection lists
00167         for (clno = c1 ; clno<= c2-1;clno++){
00168                 if (clstoverlap[clno-firstclno].clusno.size()!= 0) {
00169                         error ("not found every connection during combining"); 
00170                         cout <<"clno="<<clno; 
00171                         cout <<" overlap["<<clno<<"].clusno.size = "<<clstoverlap[clno-firstclno].clusno.size()<<endl;
00172                         NUMLIST::iterator cl;
00173                         for (cl=clstoverlap[clno-firstclno].clusno.begin();cl!=clstoverlap[clno-firstclno].clusno.end();cl++){
00174                                 cout <<*cl<< " ";
00175                         }
00176                         cout <<endl; 
00177                         exit(1);
00178                 }
00179         }
00180         
00181   
00182         // show the resulting cluster combination
00183         cout <<"\ncombined clusters are"<<endl;
00184         for (clno=firstclno;clno<=c1-1;clno++){
00185 
00186                 NUMLIST &neighbours=clstoverlap[clno-firstclno].clusno;
00187                 if (! neighbours.empty() ){
00188                         cout <<"{"<< clno<<"+  ";
00189                         for (nneighb=neighbours.begin();nneighb!=neighbours.end();nneighb++){
00190                                 cout <<*nneighb<< " "<<flush;
00191                         }
00192                         cout <<"}\t"<<flush;
00193                 }
00194         }
00195 */
00196   
00197         // now combine the clusters of spheres according to clstoverlap
00198         // and set the right clusternumber to each sphere
00199 
00200         // idea: perhaps renumbering doesn't have to be done here, but below
00201 
00202         for (clno=firstclno;clno<=c1-1;clno++){
00203                 NUMLIST &neighbours=clstoverlap[clno-firstclno].clusno;
00204                 if (! neighbours.empty() ){
00205                         for (nneighb=neighbours.begin();nneighb!=neighbours.end();nneighb++){
00206                                 set_clusternumber (spheres, clst[*nneighb].sphlist,clno);               
00207                                 clst[clno].sphlist.splice(clst[clno].sphlist.end(), clst[*nneighb].sphlist);
00208                         }
00209                 }
00210         }
00211 
00212         delete[] clstoverlap;
00213 
00214 
00215         // clean clustertable of empty clusters
00216         // and set the right clno to each sphere
00217 
00218         NUMBER highest=c2-1;
00219 
00220         for (clno=firstclno;clno<=c2-1;clno++){
00221                 if (! clst[clno].sphlist.empty()) highest=clno;
00222                 else{
00223                         // find first non-empty 
00224                         NUMBER j;
00225                         for (j=clno+1;j<=c2-1;j++) if (! clst[j].sphlist.empty()) break;
00226                         if (j==c2) {clno=c2;break;}       // the rest is also empty
00227 
00228                         else{
00229                                 swapcluson(clst[clno],clst[j]);
00230                                 set_clusternumber (spheres, clst[clno].sphlist,clno);
00231                                 if (!clst[j].sphlist.empty()) {
00232                                         errorout ("error in getting rid of empty clusters (after swap)");
00233                                         cout <<"should be empty: clno j="<<j<<endl;
00234                                         cout <<"was swapped: clno ="<<clno<<endl;
00235                                         exit (1);
00236                                 }
00237                                 highest=clno;
00238                         }
00239                 }
00240         }
00241         c2=highest+1;     // first empty clusternumber
00242 
00243         return (c2);
00244 }

clock_t copy_l_count_and_analyze sphere   spheres,
sphere   copy,
NUMLIST   sphlist,
NUMBER *    histo,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 133 of file counters.h.

References naive_count_and_analyze(), NUMBER, and REAL.

Referenced by starters::listcount(), and starters::test_list().

00138                                                                                   {
00139 
00140         clock_t time=clock();
00141 
00142         NUMLIST::iterator iter;
00143         NUMBER index=0;
00144     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00145                 index++;
00146                 copy[index]=spheres[*iter];
00147         }
00148 
00149         naive_count_and_analyze(copy,1,index,histo,biggestcl,averagecl);
00150 
00151         index=0;
00152     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00153                 index++;
00154                 spheres[*iter]=copy[index];
00155         }
00156 
00157         return (clock()-time);
00158 }

NUMBER count_analyze_and_return_clusters NUMBER    c,
sphere   spheres,
NUMLIST   all,
cluson   clusters,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 910 of file divide_and_conquer.h.

References sphere::c, dividecount(), analyze::erasehisto(), errorout(), getdim(), GRIDSIZE, NUMBER, and REAL.

Referenced by divide_by_c_cuts_count_and_analyze().

00915 {
00916 //      if (c>=1) {
00917                 int dimension=getdim( spheres[*all.begin()].c );
00918 
00919                 NUMBER nextcluster=dividecount(spheres, all, 
00920                                                                                             0,GRIDSIZE,0,GRIDSIZE, 
00921                                                                                                  0, c, 
00922                                                                                             dimension,dimension, 
00923                                                                                             clusters, 1);
00924 
00925                 erasehisto(histogram,1,all.size());
00926                 NUMBER biggestcl_no;
00927                 NUMBER totalnumber= makehistogram ( clusters,
00928                                                                                                         1,nextcluster-1,
00929                                                                                                         histogram, 
00930                                                                                                         biggestcl_no, 
00931                                                                                                         biggestcl,
00932                                                                                                         averagecl);
00933 
00934         if (totalnumber != (NUMBER)all.size()) {
00935                 errorout("not all the spheres are in clusters!");
00936                 cout << "number of spheres: N="<<all.size();
00937                 cout <<"  counted="<<totalnumber<<endl;
00938                 exit(1);
00939         }
00940         else ; // cout <<"N="<<all.size()<<"  counted="<<totalnumber<<endl;
00941 
00942 //      }
00943 //      else exit(1);
00944 
00945         return (nextcluster-1);   // returns the number of clusters (M0)
00946 
00947 }

NUMBER count_clusters_iteratively sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER    first_clno
 

Definition at line 212 of file cellcount.h.

References sphere::clno, getdim(), NUMBER, and overlap2().

Referenced by optimize::compare_recursion_and_Stoddard_iteration(), and optimize::new_vs_old_algo().

00216 {
00217         // the idea to this algorithm can be found in 
00218         // S.D.Stoddard, J.Comp.Phys 27, 291-293 (1978)
00219         // Identifying clusters in computer experiments on systems of particles
00220         
00221         NUMBER i,j,k;
00222         NUMBER N=last-first+1;
00223         NUMBER* neighbour=new NUMBER[N];                // afterwards contains a "list" of linked spheres
00224         for (i=0;i<N;i++) {neighbour[i]=i;}             // initialize link"list"
00225         NUMBER ntemp;                                                   // used for swapping
00226         sphere temp( getdim(array[first].c) );  // used as a temporary distance vector
00227 
00228         for (i=0; i<N-1; i++) {
00229                 if (neighbour[i]==i) {
00230                         j=i;
00231                         do {
00232                                 for (k=i+1; k<N; k++) {
00233                                         if (neighbour[k]==k){
00234                                                 if (overlap2(array[first+j],array[first+k], temp)){
00235                                                         ntemp=neighbour[j];
00236                                                         neighbour[j]=neighbour[k];
00237                                                         neighbour[k]=ntemp;
00238                                                 }
00239                                         }
00240                                 }
00241                                 j=neighbour[j];
00242                         } while (j!=i);
00243                 }
00244         }
00245         // cout<<"\n";
00246         // for (i=0;i<N;i++){cout<<"[L("<<i<<")="<<neighbour[i]<<"] ";}
00247 
00248         NUMBER clusternumber=first_clno;
00249         for (i=0; i<N; i++){
00250                 if (array[first+i].clno==0){
00251                         j=i;
00252                         do {
00253                                 array[first+i].clno=clusternumber;
00254                                 i=neighbour[i];
00255                         } while (i!=j);
00256                         clusternumber++;
00257                 }
00258         }
00259 
00260         delete[] neighbour;
00261         return clusternumber;
00262 }

NUMBER count_clusters_iteratively2 sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER    first_clno
 

Definition at line 264 of file cellcount.h.

References sphere::clno, getdim(), NUMBER, and overlap2().

00268 {
00269         // the idea to this algorithm can be found in 
00270         // S.D.Stoddard, J.Comp.Phys 27, 291-293 (1978)
00271         // Identifying clusters in computer experiments on systems of particles
00272         
00273         NUMBER i,j,k;
00274         NUMBER N=last-first+1;
00275         
00276         NUMBER* neighbour=new NUMBER[N];        // first~ 1 ; last~ last-first+1
00277         for (i=0;i<N;i++) {neighbour[i]=i;}     // initialize linklist
00278 
00279         NUMBER ntemp;                                                   // used for swapping
00280         sphere temp( getdim(array[first].c) );  // used as a temporary distance vector
00281 
00282         NUMBER clusternumber=first_clno;
00283 
00284         for (i=0; i<N-1; i++) {
00285                 if (neighbour[i]==i) {
00286                         array[first+i].clno=clusternumber;
00287                         j=i;
00288                         do {
00289                                 for (k=i+1; k<N; k++) {
00290                                         if (neighbour[k]==k){
00291                                                 if (overlap2(array[first+j],array[first+k], temp)){
00292                                                         array[first+k].clno=clusternumber;
00293                                                         ntemp=neighbour[j];
00294                                                         neighbour[j]=neighbour[k];
00295                                                         neighbour[k]=ntemp;
00296                                                 }
00297                                         }
00298                                 }
00299                                 j=neighbour[j];
00300                         } while (j!=i);
00301                         clusternumber++;
00302                 }
00303         }
00304 
00305         delete [] neighbour;
00306         return clusternumber;
00307 }

NUMBER count_clusters_iteratively_only_selected_spherenumbers sphere   array,
std::vector< NUMBER > &    sphnumber,
NUMBER    N,
NUMBER    first_clno
 

Definition at line 309 of file cellcount.h.

References sphere::clno, getdim(), NUMBER, and overlap2().

Referenced by optimize::compare_recursion_and_Stoddard_iteration(), and optimize::new_vs_old_algo().

00313 {
00314         // the idea to this algorithm can be found in 
00315         // S.D.Stoddard, J.Comp.Phys 27, 291-293 (1978)
00316         // Identifying clusters in computer experiments on systems of particles
00317         
00318         NUMBER i,j,k;
00319         NUMBER* neighbour=new NUMBER[N+1];              // afterwards contains a "list" of linked spheres
00320         for (i=1;i<=N;i++) {neighbour[i]=i;}    // initialize link"list"
00321         NUMBER ntemp;                                                   // used for swapping
00322         sphere temp( getdim(array[sphnumber[N]].c) );  // used as a temporary distance vector
00323 
00324         for (i=1; i<=N-1; i++) {
00325                 if (neighbour[i]==i) {
00326                         j=i;
00327                         do {
00328                                 for (k=i+1; k<=N; k++) {
00329                                         if (neighbour[k]==k){
00330                                                 if (overlap2(array[sphnumber[j]],array[sphnumber[k]], temp)){
00331                                                         ntemp=neighbour[j];
00332                                                         neighbour[j]=neighbour[k];
00333                                                         neighbour[k]=ntemp;
00334                                                 }
00335                                         }
00336                                 }
00337                                 j=neighbour[j];
00338                         } while (j!=i);
00339                 }
00340         }
00341         // cout<<"\n";
00342         // for (i=0;i<N;i++){cout<<"[L("<<i<<")="<<neighbour[i]<<"] ";}
00343 
00344         NUMBER clusternumber=first_clno;
00345         for (i=1; i<=N; i++){
00346                 if (array[sphnumber[i]].clno==0){
00347                         j=i;
00348                         do {
00349                                 array[sphnumber[i]].clno=clusternumber;
00350                                 i=neighbour[i];
00351                         } while (i!=j);
00352                         clusternumber++;
00353                 }
00354         }
00355 
00356         delete[] neighbour;
00357         return clusternumber;
00358 }

NUMBER count_clusters_recursively sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER    first_clno
 

Definition at line 34 of file cellcount.h.

References sphere::clno, neighbour_recursion(), and NUMBER.

Referenced by list_to_given_array_and_find_cluster(), and list_to_temp_array_and_find_cluster().

00038 {
00039         NUMBER clusternumber=first_clno;                                                                                
00040         for (NUMBER k=first; k<=last; k++) {
00041                 if (array[k].clno==0) {                                                                                         // if yet uncounted
00042                         neighbour_recursion(array, k,last, k, clusternumber);   // the actual counting process
00043                         clusternumber++;                                                                                                        // increase cluster-counter
00044                 }
00045         }
00046         return (clusternumber);
00047 }

clock_t countclusters_l sphere   array,
NUMLIST   sphlist,
NUMBER *    clustertable,
NUMBER &    clusternumber
 

Definition at line 164 of file cellcount.h.

References neighbour_l(), and NUMBER.

Referenced by naive_listcount_and_analyze().

00169 {
00170         clock_t start=clock();
00171         
00172         NUMBER size;
00173 
00174         NUMLIST::iterator k;
00175     for (k =  sphlist.begin(); k != sphlist.end(); k++){                // search for neighbours from each sphere
00176 
00177                 if (array[*k].clno==0) {                                                                // if yet uncounted
00178 
00179                         size=neighbour_l(array,sphlist, k, k, clusternumber);   // the actual counting process
00180                         clustertable[clusternumber]=size;                                               // store size to table of all clusters
00181                         clusternumber++;                                                                                // increase cluster-counter
00182                 }
00183         }
00184         clustertable[clusternumber]=0;                  // mark the end in that table by: "last cluster is of size 0"
00185         return (clock()-start);                                 // return the time (and the clustertable and the next clusternumber!)
00186 }

clock_t countclusters_naive sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER *    clustertable
 

Definition at line 106 of file cellcount.h.

References sphere::clno, neighbour_naive(), and NUMBER.

Referenced by naive_arraycount_and_analyze(), and naive_count_and_analyze().

00106                                                                                             {
00107         clock_t start=clock();
00108         
00109         NUMBER size;
00110         NUMBER clusternumber=0;                                                                         // start with # 1
00111                 
00112         for (NUMBER k=first; k<=last; k++) {
00113                 if (array[k].clno==0) {                                                         // if yet uncounted
00114 
00115                         clusternumber++;                                                                        // increase cluster-counter
00116                         size=neighbour_naive(array, k,last, k, clusternumber);  // the actual counting process
00117                         clustertable[clusternumber]=size;                                       // store size to table of all clusters
00118 
00119                 }
00120         }
00121         clustertable[clusternumber+1]=0;                                                        // mark the end in that table by: "last cluster is of size 0"
00122         return (clock()-start);
00123 }

void divide_all_spheres sphere   array,
NUMLIST   original,
NUMLIST   lowerlist,
NUMLIST   upperlist,
COORDFLOAT    border,
int    direction
 

Definition at line 19 of file divide_and_conquer.h.

References COORDFLOAT, and lower().

Referenced by divide_once_count_and_combine(), divide_three_times_count_and_analyze(), divide_two_times_count_and_analyze(), dividecount(), partcount(), and starters::test_list().

00024                                                                {
00025 
00026         NUMLIST::iterator iter1;
00027 
00028         for (iter1 =  original.begin(); iter1 != original.end(); ++iter1){
00029                 if ( lower(array[*iter1].c, border, direction)) 
00030                         lowerlist.insert(lowerlist.end(), *iter1);
00031                 else upperlist.insert(upperlist.end(), *iter1);
00032         }
00033 }

NUMBER divide_by_c_cuts_count_and_analyze sphere   spheres,
NUMLIST   all,
NUMBER    c,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 951 of file divide_and_conquer.h.

References count_analyze_and_return_clusters(), NUMBER, and REAL.

Referenced by optimize::choose_cuts_with_reference_algo(), optimize::double_N_and_run_all_faster_cuts(), optimize::double_N_and_run_specified_cuts(), starters::into_file7_pt1(), reference_test(), optimize::run_different_cuts(), optimize::test_average_time_for_specified_cuts(), starters::test_occuring_clusternumbers(), test_occuring_clusternumbers(), and test_spanningclusters().

00956 {
00957         cluson *clusters=new cluson[all.size()+1];
00958    
00959         NUMBER number_of_clusters= count_analyze_and_return_clusters(c,
00960                                                                                                  spheres, all,
00961                                                                                                  clusters, histogram, 
00962                                                                                                  biggestcl, averagecl);
00963 
00964         delete[] clusters;
00965 
00966         return number_of_clusters;
00967 }

NUMBER divide_count_and_analyze sphere   spheres,
NUMLIST   all,
NUMBER    c,
cluson   clusters,
NUMBER &    biggestcl,
REAL &    mean_clsz
 

Definition at line 975 of file divide_and_conquer.h.

References sphere::c, COORDFLOAT, dividecount(), analyze::erasehisto(), errorout(), exit_out_of_memory(), getdim(), GRIDSIZE, NUMBER, REAL, and waitanykey().

Referenced by setR_count_analyze_step().

00980 {
00981         NUMBER *histogram=new NUMBER[all.size()+1];                     
00982         if (histogram==NULL) exit_out_of_memory("divide_count_and_analyze(...): NUMBER *histogram");
00983         erasehisto(histogram,1,all.size());
00984    
00985         int dimension=getdim( spheres[*all.begin()].c );
00986 
00987         NUMBER numberof_cl=dividecount(spheres, all, 
00988                                                                         0,GRIDSIZE,(COORDFLOAT)0,GRIDSIZE, 
00989                                                                         0, c, 
00990                                                                         dimension,dimension, 
00991                                                                         clusters, 1);
00992 
00993         NUMBER biggestcl_no;
00994         NUMBER totalnumber= makehistogram ( clusters,
00995                                                                                 1,numberof_cl-1,
00996                                                                                 histogram, 
00997                                                                                 biggestcl_no, 
00998                                                                                 biggestcl,
00999                                                                                 mean_clsz);
01000         if (totalnumber != (NUMBER)all.size()) {
01001                 errorout("not all the spheres are in clusters!");
01002                 cout << "number of spheres: N="<<all.size();
01003                 cout <<"  counted="<<totalnumber<<endl;
01004                 waitanykey();
01005         }
01006         
01007         delete[] histogram;
01008 
01009         return numberof_cl-1;
01010 }

NUMBER divide_d_times_count_and_analyze sphere   spheres,
NUMLIST   all,
NUMBER    N,
NUMBER    d,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 708 of file divide_and_conquer.h.

References analyze::analyze_clusters(), sphere::c, COORDFLOAT, getdim(), GRIDSIZE, NUMBER, partcount(), and REAL.

Referenced by optimize::choose_dividings().

00715 {
00716         cluson *clusters=new cluson[N+1];
00717 
00718         int dimension=getdim( spheres[*all.begin()].c );
00719 
00720         NUMBER nextcluster=partcount(spheres, all, 0, GRIDSIZE, (COORDFLOAT)0, GRIDSIZE, 1, d, 1,dimension, clusters, 1);
00721 
00722         NUMBER biggestcl_no=analyze_clusters (clusters, 1, nextcluster-1,histogram,N,biggestcl,averagecl);
00723 
00724         delete[] clusters;
00725 
00726         return (biggestcl_no);
00727 }

NUMBER divide_once_count_and_analyze sphere   spheres,
sphere   temp,
NUMLIST   all,
NUMBER    N,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 516 of file divide_and_conquer.h.

References analyze::analyze_clusters(), divide_once_count_and_combine(), GRIDSIZE, NUMBER, and REAL.

Referenced by optimize::new_vs_old_algo().

00523 {
00524 
00525         cluson *clusters=new cluson[N+1];
00526         NUMBER nextclno;
00527 
00528         nextclno=divide_once_count_and_combine (spheres, temp, all, clusters,1,GRIDSIZE/2, 1);
00529         cout <<" -> combined to: "<<nextclno-1<<" clusters"<<endl;
00530         
00531         NUMBER biggestcl_no=analyze_clusters (clusters, 1, nextclno-1,histogram,N,biggestcl,averagecl);
00532         
00533         delete[] clusters;
00534 
00535         return (biggestcl_no);
00536 }

NUMBER divide_once_count_and_combine sphere   spheres,
sphere   temp,
NUMLIST   all,
cluson   clst,
NUMBER    firstclno,
COORDFLOAT    border,
int    direction
 

Definition at line 491 of file divide_and_conquer.h.

References combine(), COORDFLOAT, divide_all_spheres(), list_to_given_array_and_find_cluster(), make_clusterlist_array(), and NUMBER.

Referenced by divide_once_count_and_analyze(), divide_three_times_count_and_analyze(), and divide_two_times_count_and_analyze().

00498 {
00499 
00500         NUMBER c1,c2;
00501         NUMLIST sph1,sph2;
00502         divide_all_spheres(spheres, all, sph1,sph2,border,direction);
00503 
00504         c1=list_to_given_array_and_find_cluster(spheres, temp, sph1, firstclno);
00505         c2=list_to_given_array_and_find_cluster(spheres, temp, sph2, c1);
00506         cout <<"found "<<c1-firstclno<<" and "<<c2-c1<<" clusters ";
00507         cout <<"(c1="<<c1<<", c2="<<c2<<")";
00508 
00509         make_clusterlist_array (spheres, all, clst);
00510 
00511         c2=combine(spheres,sph1,sph2,clst,firstclno,c1,c2,border,direction);
00512         return (c2);
00513 }

NUMBER divide_three_times_count_and_analyze sphere   spheres,
sphere   temp,
NUMLIST   all,
NUMBER    N,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 577 of file divide_and_conquer.h.

References analyze::analyze_clusters(), combine(), COORDFLOAT, divide_all_spheres(), divide_once_count_and_combine(), GRIDSIZE, NUMBER, and REAL.

00584 {
00585         cluson *clusters=new cluson[N+1];
00586 
00587         NUMBER nextclno1, nextclno2;
00588         NUMBER cl1, cl2;
00589         NUMLIST sph1,sph2,sph3,sph4,sph5,sph6;
00590 
00591         COORDFLOAT border1=GRIDSIZE/2;
00592         COORDFLOAT border2=GRIDSIZE/4;
00593 
00594         divide_all_spheres(spheres, all, sph1,sph2,border1,1);
00595 
00596         divide_all_spheres(spheres, sph1,sph3,sph4,border1,2);
00597         nextclno1=divide_once_count_and_combine (spheres, temp, sph3, clusters,1,border1-border2, 1); cout<<endl;
00598          nextclno2=divide_once_count_and_combine (spheres, temp, sph4, clusters,nextclno1,border1-border2, 1); cout<<endl;
00599         cl1=combine (spheres,sph3,sph4,clusters,1,nextclno1,nextclno2,border1,2);
00600         cout <<" -> combined to: "<<cl1-1<<" clusters"<<endl;
00601         
00602         divide_all_spheres(spheres, sph2,sph5,sph6,border1,2);
00603          nextclno1=divide_once_count_and_combine (spheres, temp, sph5, clusters,cl1,border1+border2, 1); cout <<endl;
00604          nextclno2=divide_once_count_and_combine (spheres, temp, sph6, clusters,nextclno1,border1+border2, 1); cout<<endl;
00605         cl2=combine (spheres,sph5,sph6,clusters,cl1,nextclno1,nextclno2,border1,2);
00606         cout <<" -> combined to: "<<cl2-cl1<<" clusters"<<endl;
00607 
00608         cout <<"Now these two combined to: ";
00609         cl2=combine(spheres,sph1,sph2,clusters,1,cl1,cl2,border1,1);
00610         cout<<cl2-1<<" clusters"<<endl;
00611 
00612         NUMBER biggestcl_no=analyze_clusters (clusters, 1, cl2-1,histogram,N,biggestcl,averagecl);
00613 
00614         delete[] clusters;
00615 
00616         return (biggestcl_no);
00617 }

NUMBER divide_two_times_count_and_analyze sphere   spheres,
sphere   temp,
NUMLIST   all,
NUMBER    N,
NUMBER *    histogram,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 539 of file divide_and_conquer.h.

References analyze::analyze_clusters(), combine(), COORDFLOAT, divide_all_spheres(), divide_once_count_and_combine(), GRIDSIZE, NUMBER, and REAL.

Referenced by optimize::choose_dividings(), and optimize::new_vs_old_algo().

00546 {
00547 
00548         cluson *clusters=new cluson[N+1];
00549 
00550         NUMBER nextclno1, nextclno2;
00551         NUMBER cl2;
00552         NUMLIST sph1,sph2;
00553 
00554         COORDFLOAT border1=GRIDSIZE/2;
00555 
00556         divide_all_spheres(spheres, all,sph1,sph2, border1,1);
00557 
00558          //cout <<"A) count clusters in left part..."<<endl;
00559          nextclno1=divide_once_count_and_combine (spheres, temp, sph1, clusters,1,border1, 2);
00560          cout <<" -> combined to: "<<nextclno1-1<<" clusters"<<endl;
00561 
00562          //cout <<"B) count clusters in right part..."<<endl;
00563          nextclno2=divide_once_count_and_combine (spheres, temp, sph2, clusters,nextclno1,border1, 2);
00564          cout <<" -> combined to: "<<nextclno2-nextclno1<<" clusters"<<endl;
00565         
00566         cout <<"Now combine the two results...";
00567         cl2=combine (spheres,sph1,sph2,clusters,1,nextclno1,nextclno2,border1,1);
00568         cout <<" -> combined to: "<<cl2-1<<" clusters"<<endl;
00569         
00570         NUMBER biggestcl_no=analyze_clusters (clusters, 1, cl2-1,histogram,N,biggestcl,averagecl);
00571         
00572         delete[] clusters;
00573 
00574         return (biggestcl_no);
00575 }

NUMBER dividecount sphere   spheres,
NUMLIST   all,
COORDFLOAT    l,
COORDFLOAT    r,
COORDFLOAT    lm,
COORDFLOAT    rm,
COUNTER    divstep,
COUNTER    divcounter,
int    direction,
int    dimension,
cluson   clusters,
NUMBER    firstclno
 

Definition at line 786 of file divide_and_conquer.h.

References combine(), COORDFLOAT, COUNTER, divide_all_spheres(), list_to_temp_array_and_find_cluster(), make_clusterlist_array(), and NUMBER.

Referenced by count_analyze_and_return_clusters(), divide_count_and_analyze(), and optimize::new_vs_old_algo().

00792 {
00793         NUMBER nextclno;
00794 
00795         if (divstep < divcounter/direction ) {
00796                 NUMLIST s1, s2;
00797                 NUMBER ncl1, ncl2;
00798                 divide_all_spheres (spheres, all, s1,s2,(l+r)/2,direction);
00799                 ncl1=dividecount(spheres, s1,                                                                   // RECURSION!
00800                                                           l,(l+r)/2, lm,rm, 
00801                                                           divstep+1, divcounter, 
00802                                                           direction,dimension, 
00803                                                           clusters, firstclno);
00804                 ncl2=dividecount(spheres, s2,                                                                   // RECURSION!
00805                                                           (l+r)/2,r, lm,rm, 
00806                                                           divstep+1, divcounter, 
00807                                                           direction,dimension, 
00808                                                           clusters, ncl1);
00809                 nextclno=combine(spheres, s1,s2,clusters,firstclno,ncl1,ncl2,(l+r)/2,direction);
00810         }
00811 
00812         else {
00813                 if (direction==1) {
00814                                                                 // the core clusterCounter
00815                                                                 // (naive recursion or iteration with full network)
00816                         nextclno=list_to_temp_array_and_find_cluster(spheres, all, firstclno);   
00817                         make_clusterlist_array (spheres, all, clusters);
00818                 }
00819                 else {
00820                         // continue in next-lower direction (divcounter-divstep cuts left to do)
00821                         nextclno=dividecount(spheres, all, 
00822                                                                                 lm,rm, lm,rm, 
00823                                                                                 0, divcounter-divstep, 
00824                                                                                 direction-1,dimension, 
00825                                                                                 clusters, firstclno);
00826                 }
00827         }
00828         return nextclno;
00829 }

NUMBER list_to_given_array_and_find_cluster sphere   spheres,
sphere   copy,
NUMLIST   sphlist,
NUMBER    first_clno
 

Definition at line 189 of file cellcount.h.

References count_clusters_recursively(), and NUMBER.

Referenced by divide_once_count_and_combine().

00193 {
00194         NUMLIST::iterator iter;
00195         NUMBER index=0;
00196     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00197                 index++;
00198                 copy[index]=spheres[*iter];
00199         }
00200 
00201         NUMBER first_free_clusternumber=count_clusters_recursively(copy,1,index,first_clno);
00202 
00203         index=0;
00204     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00205                 index++;
00206                 spheres[*iter]=copy[index];
00207         }
00208         return (first_free_clusternumber);
00209 }

NUMBER list_to_temp_array_and_find_cluster sphere   spheres,
NUMLIST   sphlist,
NUMBER    first_clno
 

Definition at line 50 of file cellcount.h.

References count_clusters_recursively(), and NUMBER.

Referenced by dividecount(), and partcount().

00053 {
00054 
00055         sphere *copy= new sphere[sphlist.size()+1];
00056 
00057         NUMLIST::iterator iter;
00058         NUMBER index=0;
00059     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00060                 index++;
00061                 copy[index]=spheres[*iter];
00062         }
00063 
00064         NUMBER first_free_clusternumber=count_clusters_recursively(copy,1,index,first_clno);
00065 
00066         index=0;
00067     for (iter =  sphlist.begin(); iter != sphlist.end(); iter++){
00068                 index++;
00069                 spheres[*iter]=copy[index];
00070         }
00071 
00072         delete[] copy;
00073 
00074         return (first_free_clusternumber);
00075 }

COUNTER maximal_dividings_in_one_coordinate COORDFLOAT    spacelength,
REAL    radius
 

Definition at line 635 of file divide_and_conquer.h.

References COORDFLOAT, COUNTER, log(), and REAL.

Referenced by optimize::choose_cuts_with_reference_algo(), optimize::choose_dividings(), optimize::double_N_and_run_all_faster_cuts(), optimize::double_N_and_run_specified_cuts(), and optimize::run_different_cuts().

00635                                                                                  {
00636         REAL boxlength=2*radius;
00637         REAL maximal_boxes_in_one_direction=spacelength/boxlength;
00638         REAL maximal_dividings=log(maximal_boxes_in_one_direction) / log (2);
00639         return ( (int) maximal_dividings );
00640 }

NUMBER naive_arraycount_and_analyze sphere   spheres,
NUMBER    first,
NUMBER    last,
NUMBER *    histo,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 51 of file counters.h.

References countclusters_naive(), analyze::erasehisto(), NUMBER, REAL, and set_clustersize_to_each_sphere().

Referenced by optimize::choose_cuts_with_reference_algo(), optimize::choose_dividings(), optimize::compare_recursion_and_Stoddard_iteration(), optimize::double_N_and_run_all_faster_cuts(), optimize::new_vs_old_algo(), and optimize::run_different_cuts().

00056                                                                    {
00057 
00058         NUMBER *tableofclusters=new NUMBER[(last-first+3)];     // must be one bigger than number of spheres because of ending 0
00059 
00060         countclusters_naive(spheres, first, last, tableofclusters);   //count clusters, vs.1
00061 
00062         averagecl=set_clustersize_to_each_sphere(tableofclusters, spheres, first,last);
00063         erasehisto(histo,first, last);
00064         NUMBER biggestcl_no;
00065         makehistogram(tableofclusters,histo,biggestcl,biggestcl_no);
00066         
00067         delete[] tableofclusters;
00068 
00069         return (biggestcl_no);
00070 }

clock_t naive_count_and_analyze sphere   spheres,
NUMBER    first,
NUMBER    last,
NUMBER *    histo,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 20 of file counters.h.

References countclusters_naive(), analyze::erasehisto(), NUMBER, REAL, and set_clustersize_to_each_sphere().

Referenced by copy_l_count_and_analyze(), starters::listcount(), and sort_naivecount_and_analyze().

00026 {
00027         // returns these results:
00028         // the biggest cluster is of size:                                              << biggestcl
00029         // each sphere is on average part of a cluster of size  << averagecl
00030         // the detailed size-distribution is in                                 << histo[...]
00031 
00032         clock_t time=clock();
00033         NUMBER *tableofclusters=new NUMBER[(last-first+3)];     // must be one bigger than number of spheres because of ending 0
00034 
00035         countclusters_naive(spheres, first, last, tableofclusters);   //count clusters, vs.1
00036 
00037         averagecl=set_clustersize_to_each_sphere(tableofclusters, spheres, first,last);
00038         erasehisto(histo,first, last);
00039 
00040         NUMBER biggestcl_no;
00041         makehistogram(tableofclusters,histo,biggestcl,biggestcl_no);
00042 
00043         delete[] tableofclusters;
00044 
00045         return (clock()-time);
00046 }

clock_t naive_listcount_and_analyze sphere   spheres,
NUMLIST   sphlist,
NUMBER    N,
NUMBER *    histo,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 104 of file counters.h.

References countclusters_l(), analyze::erasehisto(), NUMBER, REAL, and set_clustersize_to_each_sphere_l().

Referenced by starters::listcount(), and starters::test_list().

00110                                                   {
00111         // returns these results:
00112         // the biggest cluster is of size:                                              << biggestcl
00113         // each sphere is on average part of a cluster of size  << averagecl
00114         // the detailed size-distribution is in                                 << histo[...]
00115 
00116         clock_t time=clock();
00117         NUMBER *tableofclusters=new NUMBER[(sphlist.size()+2)]; // must be one bigger than number of spheres because of ending 0
00118         NUMBER clusternumber=1;                                                                 // first cluster is "1"
00119 
00120         countclusters_l(spheres,sphlist, tableofclusters, clusternumber);   
00121 
00122         averagecl=set_clustersize_to_each_sphere_l(tableofclusters, spheres, sphlist);
00123         erasehisto(histo,1, N);
00124         NUMBER biggestcl_no;
00125         makehistogram(tableofclusters,histo,biggestcl, biggestcl_no);
00126 
00127         delete[] tableofclusters;
00128 
00129         return (clock()-time);
00130 }

NUMBER neighbour_l sphere   array,
NUMLIST   sphlist,
NUMLIST::iterator    firstsph,
NUMLIST::iterator    actualsph,
NUMBER    clnumber
 

Definition at line 129 of file cellcount.h.

References sphere::c, sphere::clno, distance(), getdim(), length(), NUMBER, and sphere::r.

Referenced by countclusters_l().

00134 {               
00135         array[*actualsph].clno=clnumber;                        // this sphere is set to be found in this cluster
00136 
00137         myVector distance(getdim(array[*actualsph].c)); 
00138         bool overlapped;
00139 
00140         NUMBER size=1;
00141 
00142         NUMLIST::iterator nextsph;
00143 
00144     for (nextsph =  firstsph; nextsph != sphlist.end(); nextsph++){
00145 
00146                 if ( array[*nextsph].clno==0 ) {
00147 
00148                         //if ( overlap2(array[*actualsph],array[*nextsph])  ) { 
00149                                         // the following 4 lines do the same, but are faster than that:
00150                                         // because of not using operator-(vect1, vect2) which needs a myVector temp;
00151                         
00152                         distance=(array[*nextsph].c);
00153                         distance-=(array[*actualsph].c);
00154                         overlapped=length(distance) < (array[*actualsph].r + array[*nextsph].r) ;
00155                         if (overlapped) {
00156                                 size+=neighbour_l (array, sphlist, firstsph, nextsph, clnumber);        // recursion, now with nextsph
00157                         }
00158                 }
00159         }
00160         return size;
00161 }

NUMBER neighbour_naive sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER    actualsph,
NUMBER    clnumber
 

Definition at line 78 of file cellcount.h.

References sphere::c, sphere::clno, distance(), getdim(), length(), NUMBER, and sphere::r.

Referenced by countclusters_naive().

00078                                                                                                      {          
00079         array[actualsph].clno=clnumber;
00080 
00081         myVector distance(getdim(array[actualsph].c));
00082         bool overlapped;
00083 
00084         NUMBER size=1;
00085 
00086         for (NUMBER nextsph=first;nextsph<=last;nextsph++) {
00087                 if ( array[nextsph].clno==0 ) {
00088 
00089                         // if ( overlap(array[actualsph],array[nextsph])  ) { 
00090                                 // the following 3 lines are faster:
00091                                 // because of not using operator-(vect1, vect2) which needs a vector temp;
00092                         
00093                         distance=(array[nextsph].c);
00094                         distance-=(array[actualsph].c);         // using -= instead of - is much faster (no vector temp)
00095                         overlapped=length(distance) < (array[actualsph].r + array[nextsph].r) ;
00096 
00097                         if (overlapped) {
00098 
00099                                 size+=neighbour_naive (array, first, last, nextsph, clnumber);  // RECURSION!
00100                         }
00101                 }
00102         }
00103         return size;
00104 }

void neighbour_recursion sphere   array,
NUMBER    first,
NUMBER    last,
NUMBER    actualsph,
NUMBER    clnumber
 

Definition at line 14 of file cellcount.h.

References sphere::clno, getdim(), NUMBER, and overlap2().

Referenced by count_clusters_recursively().

00014                                                                                                        {                
00015 
00016         array[actualsph].clno=clnumber;                         // set this sphere as "counted" by assigning clusternumber
00017 
00018         sphere temp( getdim(array[actualsph].c) );  // used as a temporary distance vector
00019 
00020         for (NUMBER nextsph=first;nextsph<=last;nextsph++) {
00021                 if ( array[nextsph].clno==0 ) {
00022                         if ( overlap2(array[actualsph],array[nextsph], temp)  ) {         
00023                                                         // this overlap-function uses a temp-sphere-coordinatevector
00024                                                         // for storing the difference of the two vectors 
00025                                                         // (it is much faster than creating one temporary vector 
00026                                                         // for each overlap-test by using overlap (sphere, sphere) )
00027                                 neighbour_recursion (array, first, last, nextsph, clnumber);
00028                         }
00029                 }
00030         }
00031 }

NUMBER partcount sphere   spheres,
NUMLIST   all,
COORDFLOAT    l,
COORDFLOAT    r,
COORDFLOAT    lm,
COORDFLOAT    rm,
COUNTER    divstep,
COUNTER    divmax,
int    direction,
int    dimension,
cluson   clusters,
NUMBER    firstclno
 

Definition at line 642 of file divide_and_conquer.h.

References combine(), COORDFLOAT, COUNTER, divide_all_spheres(), list_to_temp_array_and_find_cluster(), make_clusterlist_array(), and NUMBER.

Referenced by divide_d_times_count_and_analyze().

00654 {
00655         NUMBER nextclno;
00656 
00657    if (divmax==0) 
00658         {
00659                 nextclno=list_to_temp_array_and_find_cluster(spheres, all, firstclno);
00660                 make_clusterlist_array (spheres, all, clusters);
00661                 return nextclno;
00662         }
00663    
00664         if ( direction==dimension ) {
00665                 if ( divstep==divmax ) {
00666                         NUMLIST s1, s2;
00667                         NUMBER ncl1, ncl2;
00668                         divide_all_spheres (spheres, all, s1,s2,(l+r)/2,direction);
00669                         //cout <<"\ndir="<<direction<<"\tborders l,r=\t"<<l<<"\t"<<r;
00670                         //cout <<"\t# of spheres="<<s1.size()<<" and "<<s2.size()<<endl;
00671                         ncl1=list_to_temp_array_and_find_cluster(spheres, s1, firstclno);
00672                         ncl2=list_to_temp_array_and_find_cluster(spheres, s2, ncl1);
00673                         make_clusterlist_array (spheres, all, clusters);
00674                         nextclno=combine(spheres, s1,s2,clusters,firstclno,ncl1,ncl2,(l+r)/2,direction);
00675                 }
00676                 else {
00677                         NUMLIST s1, s2;
00678                         NUMBER ncl1, ncl2;
00679                         divide_all_spheres (spheres, all, s1,s2,(l+r)/2,direction);
00680                         //cout <<"diV ";
00681                         ncl1=partcount(spheres, s1, l,(l+r)/2, lm,rm, divstep+1, divmax, direction,dimension, clusters, firstclno);
00682                         ncl2=partcount(spheres, s2, (l+r)/2,r, lm,rm, divstep+1, divmax, direction,dimension, clusters, ncl1);
00683                         nextclno=combine(spheres, s1,s2,clusters,firstclno,ncl1,ncl2,(l+r)/2,direction);
00684                 }
00685         }
00686 
00687         else {
00688                 if (divstep <= divmax) {
00689                         NUMLIST s1, s2;
00690                         NUMBER ncl1, ncl2;
00691                         divide_all_spheres (spheres, all, s1,s2,(l+r)/2,direction);
00692                         //cout <<"diV ";
00693                         ncl1=partcount(spheres, s1, l,(l+r)/2, lm,rm, divstep+1, divmax, direction,dimension, clusters, firstclno);
00694                         ncl2=partcount(spheres, s2, (l+r)/2,r, lm,rm, divstep+1, divmax, direction,dimension, clusters, ncl1);
00695                         nextclno=combine(spheres, s1,s2,clusters,firstclno,ncl1,ncl2,(l+r)/2,direction);
00696                 }
00697 
00698                 else {
00699                         //cout <<"diM ";
00700                         nextclno=partcount(spheres, all, lm,rm, lm,rm, 1, divmax, direction+1,dimension, clusters, firstclno);
00701                 }
00702         }
00703                 
00704         return nextclno;
00705 }

bool reference_test NUMBER    N,
int    dim,
COUNTER    cuts
 

Definition at line 164 of file counters.h.

References COUNTER, divide_by_c_cuts_count_and_analyze(), errorout(), GRIDSIZE, increasing_integers(), ms(), NUMBER, R_critical(), R_critical_guessed(), REAL, analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), sort_naivecount_and_analyze(), and throw_spheres().

00164                                                      {    // test if new and old algo's results are the SAME!
00165 
00166         sphere *scatter = new sphere[N+1];
00167         set_dim(scatter,0,N,dim);
00168         throw_spheres(scatter, 1, N);           // randomly throw spheres from 1 to N in array scatter
00169         REAL r=R_critical(N,GRIDSIZE,dim); 
00170          if (r==-1) r=R_critical_guessed(N,GRIDSIZE,dim);  // with _critical_ sphere radius, if known, otherwise r=guess
00171         set_radius(scatter, 1,N,r);
00172 
00173         // new algo
00174         NUMBER *histogram=new NUMBER[(N+1)]; 
00175         NUMBER biggestcl;
00176         REAL averagecl;
00177         NUMLIST all;
00178         increasing_integers (all, N);           // fill the list "all" with the numbers of all spheres
00179 
00180         clock_t speed=clock();
00181         cout <<"\ndivide_by_c_cuts count (new algo):.."<<flush;
00182         set_clusternumber(scatter,1,N,0);   // no sphere is found yet
00183         divide_by_c_cuts_count_and_analyze(scatter, all, cuts,histogram, biggestcl, averagecl);
00184         cout <<"  speed: "<<ms(clock()-speed)<<" ms"<<endl;
00185         cout <<" (biggestcluster: "<<biggestcl<<"\taverage cluster: "<<averagecl<<" )"<<endl;
00186 
00187         // old algo
00188         sphere *copy = new sphere[N+1];
00189         set_dim(copy,0,N,dim);
00190         NUMBER *histogramcontrol=new NUMBER[(N+1)]; 
00191 
00192         speed=clock();
00193         cout <<"\nsorted-array-count (old, naive algo):..            "<<flush;
00194         set_clusternumber(scatter,1,N,0);   // no sphere is found yet
00195         sort_naivecount_and_analyze(scatter, copy, 1, N, histogramcontrol, biggestcl, averagecl);
00196         cout <<"  speed: "<<ms(clock()-speed)<<" ms"<<endl;
00197         cout <<" (biggestcluster: "<<biggestcl<<"\taverage cluster: "<<averagecl<<" )"<<endl;
00198 
00199         if (sameresult(histogram,histogramcontrol,1,biggestcl)) {
00200                 cout <<"\nThe new algorithm was tested. Results are perfect. Let us begin.\n\n"<<endl;
00201                 delete [] scatter, copy, histogram, histogramcontrol;
00202                 all.clear();
00203                 return true;
00204         }
00205                         
00206         else {
00207                 cout <<".\nTERRIBLE !\n";
00208                 errorout("The new algorithm has different results. \nPlease write to cpp__at__AndreasKrueger__dot__de\n");
00209                 cout<<"cuts="<<cuts<<endl;
00210 
00211                 delete [] scatter, copy, histogram, histogramcontrol;
00212                 all.clear();
00213                 return false;
00214         }
00215 }

one_result setR_count_analyze_step NUMBER    N,
int    dim,
sphere   spheres,
NUMLIST   L_sph_numbers,
REAL    radius,
string &    throwtime,
clock_t &    clcount_time,
clock_t &    spclsearch_time
 

Definition at line 220 of file counters.h.

References choose_optimal_cuts(), COUNTER, divide_count_and_analyze(), exit_out_of_memory(), give_short_timestamp(), GRIDSIZE, LONGBITS, analyze::mean_without_lr_spanningcls(), NUMBER, REAL, set_clusternumber(), set_radius(), and spanning_dirs_and_clusters().

Referenced by ff::is_the_biggestcluster_bigger_than_a_ratio(), ff::is_the_incl_meancluster_bigger_than_a_ratio(), ff::is_the_numberofcl_smaller_than_a_ratio(), ff::is_there_a_spanning_cluster(), ff::is_there_only_one_cluster(), and throw_dnc_count_analyze_step().

00222 {
00223         COUNTER cuts=choose_optimal_cuts(dim,N, radius);
00224 
00225         cluson *clusters=new cluson[N+1];
00226         if (clusters==NULL) exit_out_of_memory("radiusstep(...): cluson *clusters");
00227 
00228         NUMBER numberof_cl; NUMBER biggestcl; REAL mean_clsz; REAL mean_clsz_without_spcls; 
00229         LONGBITS spcl_dirs; NUMLIST L_spanningclusters; L_spanningclusters.clear();
00230 
00231         clock_t time_start=clock();
00232          set_radius(spheres, 1,N,radius);
00233          set_clusternumber(spheres,1,N,0);   
00234          numberof_cl=divide_count_and_analyze(spheres, L_sph_numbers, cuts, clusters, biggestcl, mean_clsz);
00235         clcount_time=(clock()-time_start);
00236         
00237         clock_t time_spsearch_start=clock();
00238          spcl_dirs=spanning_dirs_and_clusters(spheres, L_sph_numbers, 0, GRIDSIZE, radius, dim, 
00239                                                                                   clusters, L_spanningclusters);
00240      mean_clsz_without_spcls= mean_without_lr_spanningcls(mean_clsz, N, clusters, 
00241                                                                                                               L_spanningclusters, spcl_dirs);
00242 
00243         spclsearch_time=(clock()-time_spsearch_start);
00244         string counttime=give_short_timestamp(); 
00245 
00246         delete[] clusters;
00247         return one_result(spcl_dirs, numberof_cl, biggestcl, mean_clsz, mean_clsz_without_spcls,
00248                                           clcount_time + spclsearch_time, throwtime, counttime);
00249 }

clock_t sort_naivecount_and_analyze sphere   spheres,
sphere   copy,
NUMBER    first,
NUMBER    last,
NUMBER *    histo,
NUMBER &    biggestcl,
REAL &    averagecl
 

Definition at line 74 of file counters.h.

References copy_array(), naive_count_and_analyze(), NUMBER, quicksort1(), and REAL.

Referenced by starters::into_file(), starters::into_file2(), starters::into_screen(), and reference_test().

00081 {
00082 
00083         // returns these results:
00084         // the biggest cluster is of size:                                              << biggestcl
00085         // each sphere is on average part of a cluster of size  << averagecl
00086         // the most frequent cluster is of size:                                << mostfreqcl
00087         // the detailed size-distribution is in                                 << histo[...]
00088         
00089         clock_t time=clock();
00090 
00091         copy_array(spheres,copy,1,last);                // store it before sorting
00092         quicksort1 (spheres,1,last);                    // sort by length
00093         naive_count_and_analyze(spheres, first, last, histo, biggestcl, averagecl);
00094         copy_array(copy,spheres,1,last);                // copy it back
00095 
00096         return (clock()-time);
00097 }

void test_cuts_function  
 

Definition at line 755 of file divide_and_conquer.h.

References choose_optimal_cuts(), COUNTER, and REAL.

00755                          {
00756         cout<<"type in dim, N"<<endl;
00757         int dim; COUNTER N;
00758         cin>>dim>>N;
00759         REAL R=0;
00760         while (R!=-1){
00761                 cout <<"\ntype in R (-1 for end)";
00762                 cin>>R;
00763                 cout <<choose_optimal_cuts(dim, N, R);
00764         }
00765 }

one_result throw_dnc_count_analyze_step sphere   spheres,
NUMLIST   L_sph_numbers,
REAL    radius,
clock_t &    clcount_time,
clock_t &    spclsearch_time
 

Definition at line 253 of file counters.h.

References getdim(), give_short_timestamp(), NUMBER, REAL, setR_count_analyze_step(), and throw_spheres().

Referenced by starters::into_file8_pt1().

00255 {
00256         NUMBER N=L_sph_numbers.size();
00257         int dim=getdim(spheres[L_sph_numbers.front()]);
00258 
00259         throw_spheres(spheres, 1, N);           
00260         string throwtime=give_short_timestamp(); 
00261         
00262         return setR_count_analyze_step(N,dim, spheres, L_sph_numbers, radius, 
00263                                                   throwtime, clcount_time, spclsearch_time);
00264 }




Diploma Thesis Sourcecode Documentation
check out the text and the executable binaries

www.AndreasKrueger.de/thesis/code