示例#1
0
int findDiameter(struct tree *root)
{
	int lheight,rheight,ldia,rdia;
	if(root==NULL) return 0;
	lheight = printMaxHeight(root->left);
	rheight = printMaxHeight(root->right);
	ldia=findDiameter(root->left);
	rdia=findDiameter(root->right);
	return std::max(lheight+rheight+1,std::max(ldia,rdia));
}
示例#2
0
void findStatistics(){
	float sumInCluster=0, sumBetweenCluster=0;
	int countInCluster=0, countBetweenCluster=0, temp=0;
	edge TempEdge;
	while(temp<(vertexNum)){ /*iterating on all the vertices*/
	findDiameter(temp);
	TempEdge = vertices[temp]->edges->head;
		while(TempEdge!=NULL){ /*iterating on all the edges bounded to this vertex*/
			/*in the following sections weight is divided by 2 because each edge is added twice*/
			if((TempEdge->inCluster==1)){
				sumInCluster+=(TempEdge->weight);
				(clusters[vertices[temp]->ClusterBelonging-1]->score)+=(TempEdge->weight/2);
				countInCluster++;
			}
			else if((TempEdge->inCluster==3)){
				sumBetweenCluster+=(TempEdge->weight);
				countBetweenCluster++;
			}
			TempEdge=TempEdge->next;
		}
		temp++;
	}
	if(countInCluster!=0){
		avgInClusters = Calculate(sumInCluster,countInCluster);
	}
	if(countBetweenCluster!=0){
		avgBetweenClusters = Calculate(sumBetweenCluster,countBetweenCluster);
	}
	sort();
	setClusters();
}
示例#3
0
void sampleCavities()
{
  int i=0;
  double energy;

  r_convergence_ratio = 1/c_convergence_ratio;

  while (i<number_of_samples)
  {
    double dx, dy, dz;
    double shift_x, shift_y, shift_z;
    int valid = 0;

    center_x = sample_x = box_x * rnd();
    center_y = sample_y = box_y * rnd();
    center_z = sample_z = box_z * rnd();
    findCenter();
    findDiameter();

    valid = 1;
    if (volume_sampling)
    {
      valid = 0;
      for (shift_x = -box_x; shift_x < box_x; shift_x += box_x)
      for (shift_y = -box_y; shift_y < box_y; shift_y += box_y)
      for (shift_z = -box_z; shift_z < box_z; shift_z += box_z)
      {
        dx = shift_x + sample_x - center_x;
        dy = shift_y + sample_y - center_y;
        dz = shift_z + sample_z - center_z;
        if ((dx*dx + dy*dy + dz*dz) < (.25*diameter*diameter)) valid = 1;
      }
    }

    if (valid)
    {
       printf("%lf\t%lf\t%lf\t%lf\n", center_x, center_y, center_z, diameter);
       i++;
    }
  }
}