Hi all,
I have written recurisve pathfinding fuction from matrix[j] to matrix[x][y].
however, it's not returning the right values. It is supposed to return the minimal cost from 2 points using any possible path.
all ".value" are the cost to use this Node
all ".bestFromStart" are the max of long int field.
all ".status" are "CLOSED"
any help would be appriciated!!

the function all first called with

/* a brief breakdown of this algorithm:
We have defined a high value (currently the limit of "long int") as the "error"
We start searching the matrix. If at any point it we find that the way we are
trying is longer allredy that the best existing way through specific node, we
return LARGE, meaning do not continue searching throuh this node.
We make sure we dont recourse though a node that has allready been included in
the current path by setting it's status to OPEN upon enterting the recusrive
part of the program. If we now will reach any node which is OPEN, we return 
LARGE- an ending value.
We then search in all derections for any result that doesnt return large and 
return to the main fuction the smallest of all directions.
This way is not entirely fault tolerent because it does not deal with the case
of value=LARGE, but on the other hand it's not meant to deal with value>LARGE
long int GetMin(Node** matrix,int currentR,int currentC,int endR,int endC,
				int rows,int columns,Node* father)
	long int result;

	//if out of bounds return max of field
	if (currentR==rows || currentC==columns || currentR<0 || currentC<0)
		return LARGE;

	//if reached end
	if (currentC==endC && currentR==endR)
		return (matrix[currentR][currentC].value);

	//if already checked here
	if (matrix[currentR][currentC].status==OPEN)
		return LARGE;

/*record distance from beggining*/
	//if first node
	if (father==NULL)
		//assign first value as best value
	//if not first node
		//if bestFromStart old value higher than current value 
		if ( (matrix[currentR][currentC].value +
			father->bestFromStart ) <
			matrix[currentR][currentC].bestFromStart )
			/*this is a bad path - 
			this way is not shorter than previously found way*/
			return LARGE;
	//if not reached end	

	//set current status to closes- can try here again	
	//if was blocked all directions
	if (result==LARGE)
		return LARGE;

	return matrix[currentR][currentC].value+result;

Your GetMin algorithm looks okay. You should post more code. The problem could be in Smallest4 or with the initialization of your matrix.

This article has been dead for over six months. Start a new discussion instead.