Пример #1
0
int bNNIEdgeTest(meEdge *e, meTree *T, double **A, double *weight)
{
  meEdge *f;
  double D_LR, D_LU, D_LD, D_RD, D_RU, D_DU;
  double w1,w2,w0;
  /*if (verbose)
    printf("Branch swap: testing edge %s.\n",e->label);*/
  if ((leaf(e->tail)) || (leaf(e->head)))
    return(NONE);

  f = siblingEdge(e);

  D_LR = A[e->head->leftEdge->head->index][e->head->rightEdge->head->index];
  D_LU = A[e->head->leftEdge->head->index][e->tail->index];
  D_LD = A[e->head->leftEdge->head->index][f->head->index];
  D_RU = A[e->head->rightEdge->head->index][e->tail->index];
  D_RD = A[e->head->rightEdge->head->index][f->head->index];
  D_DU = A[e->tail->index][f->head->index];

  w0 = wf5(D_RU,D_LD,D_LU,D_RD,D_DU,D_LR); /*weight of current config*/
  w1 = wf5(D_RU,D_LD,D_DU,D_LR,D_LU,D_RD); /*weight with L<->D switch*/
  w2 = wf5(D_DU,D_LR,D_LU,D_RD,D_RU,D_LD); /*weight with R<->D switch*/
  if (w0 <= w1)
    {
      if (w0 <= w2) /*w0 <= w1,w2*/
	{
	  *weight = 0.0;
	  return(NONE);
	}
      else /*w2 < w0 <= w1 */
	{
	  *weight = w2 - w0;
	  if (verbose)
	    {
	      printf("Possible swap across %s. ",e->label);
	      printf("Weight dropping by %lf.\n",w0 - w2);
	      printf("New weight would be %lf.\n",T->weight + w2 - w0);
	    }
	  return(RIGHT);
	}
    }
  else if (w2 <= w1) /*w2 <= w1 < w0*/
    {
      *weight = w2 - w0;
      if (verbose)
	{
	  printf("Possible swap across %s. ",e->label);
	  printf("Weight dropping by %lf.\n",w0 - w2);
	  printf("New weight should be %lf.\n",T->weight + w2 - w0);
	}
      return(RIGHT);
    }
  else /*w1 < w2, w0*/
    {
      *weight = w1 - w0;
      if (verbose)
	{
	  printf("Possible swap across %s. ",e->label);
	  printf("Weight dropping by %lf.\n",w0 - w1);
	  printf("New weight should be %lf.\n",T->weight + w1 - w0);
	}
      return(LEFT);
    }
}
Пример #2
0
int bNNIEdgeTest (edge *e, tree *T, double **A, double *weight)
{
	edge *f;
	double D_LR, D_LU, D_LD, D_RD, D_RU, D_DU;
	double w1, w2, w0;

	if ((leaf(e->tail)) || (leaf(e->head)))
		return (NONE);

	f = siblingEdge (e);

	D_LR = A[e->head->leftEdge->head->index][e->head->rightEdge->head->index];
	D_LU = A[e->head->leftEdge->head->index][e->tail->index];
	D_LD = A[e->head->leftEdge->head->index][f->head->index];
	D_RU = A[e->head->rightEdge->head->index][e->tail->index];
	D_RD = A[e->head->rightEdge->head->index][f->head->index];
	D_DU = A[e->tail->index][f->head->index];

	w0 = wf5 (D_RU, D_LD, D_LU, D_RD, D_DU, D_LR);	// weight of current config
	w1 = wf5 (D_RU, D_LD, D_DU, D_LR, D_LU, D_RD);	// weight with L<->D switch
	w2 = wf5 (D_DU, D_LR, D_LU, D_RD, D_RU, D_LD);	// weight with R<->D switch

	if (w0 <= w1)
	{
		if (w0 <= w2)	// w0 <= w1,w2
		{
			*weight = 0.0;
			return (NONE);
		}
		else			// w2 < w0 <= w1
		{
			*weight = w2 - w0;
			if (verbose > 2 && !isBoostrap)
			{
				Debug ( (char*)"Possible swap across '%s'. Weight dropping by %f.", e->label, w0 - w2);
				Debug ( (char*)"New tree length should be %f.", T->weight + w2 - w0);
			}
			return (RIGHT);
		}
	}
	else if (w2 <= w1)	// w2 <= w1 < w0
	{
		*weight = w2 - w0;
		if (verbose > 2 && !isBoostrap)
		{
			Debug ( (char*)"Possible swap across '%s'. Weight dropping by %f.", e->label, w0 - w2);
			Debug ( (char*)"New tree length should be %f.", T->weight + w2 - w0);
		}
		return(RIGHT);
	}
	else				// w1 < w2, w0
	{
		*weight = w1 - w0;
		if (verbose > 2 && !isBoostrap)
		{
			Debug ( (char*)"Possible swap across '%s'. Weight dropping by %f.", e->label, w0 - w1);
			Debug ( (char*)"New tree length should be %f.", T->weight + w1 - w0);
		}
		return(LEFT);
	}
}