hello.
i have a set of 50 points. (array of 50 objects (arrayOfNodes[]) having x, y locations and distance and nearest neighbor and neighbor table ). The points are given X-Y location randomly in a range of 300 X300. and there is a center point called BaseStaion (BS). For every point A, I have a neghbor table (array of int) where if the other point B is in range of 50mts then its a neighbor of A, so value in (arrayOfNodes[A].neighborTable) is set to distance of point B to BS for all other points value is set to 9999. From this neighbor table I want to find a nearest neighbor (any point that is neighbor of A and its distance from BS is minimum). So the code finds that fine. But there are some cases where 2 points are nearest neighbors of each other. I dont want that to happen. so I need to find the next neighbor wich can be closer to the BS amongst teh other points. I wrote a code to find the second min in array but at times even the point at second minimum are neighbore of each other. So i have to look into many neighbors to decide the next nearest one!. I am not able to figure that out.
I am attaching some part of code here. Sorry! my problem description can be weird. Please let me know if i can make myself more clear.
// set the vlaues in nebor table
for (int i = 0; i < noOfNodes; i++)
{
for (int j =0; j<noOfNodes; j++)
{
if(i==j)
arrayOfNodes[i].neighborTable[j] = 9999; //self node
else
if (euclideanDistance(arrayOfNodes[i].xLocation, arrayOfNodes[j].xLocation, arrayOfNodes[i].yLocation,arrayOfNodes[j].yLocation) < txRange)
arrayOfNodes[i].neighborTable[j] = arrayOfNodes[j].distance;
// if neighbor node, save distance from BS
else
arrayOfNodes[i].neighborTable[j] = 9999; // not neighbor
}//end of for j
}//end of for i
//find the neighbor closest to the BS and set it as nearestNeigborNode
for (int i = 0; i < noOfNodes; i++)
{
/* for some nodes wich are in range of 50 from BS, their nearest nebor is set to BS. Did that in some other part of code */
if (arrayOfNodes[i].nearestNeighborNode != baseStation.nodeID)
{
int minValue = arrayOfNodes[i].neighborTable[0];
for (int j =1; j<noOfNodes; j++)
{
if (arrayOfNodes[i].neighborTable[j] < minValue)
{
minValue = arrayOfNodes[i].neighborTable[j];
arrayOfNodes[i].nearestNeighborNode = j;
}
}
} //end of for i
/* I am facing problem here here i want to keep looking recursively for other nebors of A till i find B such that A and B are not nebors of each other. I did only to find second min, but i might have to look beyond second min. */
//for the case when 2 nodes are nearest neighbors of each other
for (int i=0;i<noOfNodes;i++)
for (int j =0 ; j<noOfNodes; j++)
{
if ((arrayOfNodes[i].nearestNeighborNode == j)&& (arrayOfNodes[j].nearestNeighborNode == i))
{ arrayOfNodes[i].neighborTable[j] == 1000;
int minValue2 = arrayOfNodes[i].neighborTable[0];
for (int k =1; k<noOfNodes; k++)
{
if (arrayOfNodes[i].neighborTable[k] < minValue2)
{
minValue2 = arrayOfNodes[i].neighborTable[k];
arrayOfNodes[i].nearestNeighborNode = k;
}
} //end of for k
}//end of if
}
}//end of if (arrayOfNodes[i].nearestNeighborNode = baseStation.nodeID */
} // end of i for nearest neighbor