direction NNIEdgeTest(edge e, double[][] A, double[] weight, int wIndex )
	{
		int a,b,c,d;
		edge f;
		double[] lambda;
		double D_LR, D_LU, D_LD, D_RD, D_RU, D_DU;
		double w1,w2,w0;
	  
		if ( e.tail.leaf() || e.head.leaf() )
			return direction.NONE;
		lambda = new double[3];;
		a = e.tail.parentEdge.topsize;
		f = e.siblingEdge();
		b = f.bottomsize;  
		c = e.head.leftEdge.bottomsize;
		d = e.head.rightEdge.bottomsize;

		lambda[0] = ((double) b*c + a*d)/((a + b)*(c+d));
		lambda[1] = ((double) b*c + a*d)/((a + c)*(b+d));    
		lambda[2] = ((double) c*d + a*b)/((a + d)*(b+c));
	  
		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 = wf2(lambda[0],D_RU,D_LD,D_LU,D_RD,D_DU,D_LR);
		w1 = wf2(lambda[1],D_RU,D_LD,D_DU,D_LR,D_LU,D_RD);
		w2 = wf2(lambda[2],D_DU,D_LR,D_LU,D_RD,D_RU,D_LD);
		if (w0 <= w1)
		{
			if (w0 <= w2) //w0 <= w1,w2
			{
				weight[wIndex] = 0.0;
				return direction.NONE;
			}
			else //w2 < w0 <= w1 
			{
				weight[wIndex] = w2 - w0;
				return direction.RIGHT;
			}
		}
		else if (w2 <= w1) //w2 <= w1 < w0
	    {
			weight[wIndex] = w2 - w0;
	      	return direction.RIGHT;
	    }
		else //w1 < w2, w0
	    {
			weight[wIndex] = w1 - w0;
			return direction.LEFT;	
	    }
	}