Shortest Path Algorithm Program Error

Hi,

I have a question on the algorithm below which i copied from shortestPathText.txt - Google Drive

but it doesn't compile correctly due to

dijsktra:104: error: invalid conversion from 'int' to 'const char*'
dijsktra:104: error: initializing argument 1 of 'unsigned char String::operator==(const char*) const'

can anyone help me on this? i can't find the solution...thank you so much...appreciate any help on this thanks

#include <EEPROM.h>

#include<stdio.h>

#define MAXNODES 16
#define ROW 4
#define COL 4
typedef struct node{
	int x;
	int y;
}node;

int grid[ROW][COL];
int costMatrix[MAXNODES][MAXNODES];
String pathMatrix[MAXNODES][MAXNODES];
int nodeMatrix[MAXNODES];
node unsettledNodes[36];
int unsettledNodeCounter = 0;
node settledNodes[36];
int settledNodeCounter = 0;
node startNode;
const int MAXVALUE = 9999;
void setup()
{
	Serial.begin(9600);
        Serial.println();        Serial.println();        Serial.println();
        Serial.println("****************************************");
        getGrid();
	createMap(); //create cost matrix
	printMap();	
	

}

void calculateCost(int i,int row, int col){
	if(row>=0&&col>=0&&row<ROW&&col<COL&&grid[row][col]==1){
		int j = row*ROW+col;
		costMatrix[i][j] = 1;
		pathMatrix[i][j] = String(String(i)+","+String(j));
					     }
	
}
void getGrid(){
	int k=0;
        for(int i=0;i<ROW;i++){
          for(int j=0;j<COL;j++){
            grid[i][j] = EEPROM.read(k++);
         }
        }
        
	
}

String trimString(String path){
  while(path.charAt(path.length()-1)!=',') path = path.substring(0,path.length()-1);
  path = path.substring(0,path.length()-1);
  return path;
}
void createMap(){
	int i=0,j=0;
	int nodeMatrixCounter = 0;	
	//getting the grid to an array
	for(i=0;i<ROW;i++){
		for(j=0;j<COL;j++){
			nodeMatrix[nodeMatrixCounter++] = grid[i][j];
				}
			}
        Serial.println("Nodes");
			
	for(i=0;i<nodeMatrixCounter;i++) {
              Serial.print(nodeMatrix[i]); Serial.print("\t");
                                      }
	Serial.println();Serial.println();
        //initializing the path matrix;
        for(i=0;i<MAXNODES;i++){
          for(j=0;j<MAXNODES;j++)pathMatrix[i][j] = String(-1);
        }
        
	//calculating the cost mar=trix
	for(i=0;i<MAXNODES;i++){
		for(j=0;j<MAXNODES;j++){
			costMatrix[i][j] = MAXVALUE;
					}		
		}

   
	int row,col;
	for(i=0;i<MAXNODES;i++){
		if(nodeMatrix[i]==1){
			row = i/ROW;
			col = i%ROW;
			calculateCost(i,row-1,col);
			calculateCost(i,row+1,col);
			calculateCost(i,row,col-1);
			calculateCost(i,row,col+1);
				    }
				}
	int k=0;
	for (i = 0; i < MAXNODES; i++) {
                for (j = 0; j < MAXNODES; j++) {
                        for (k = 0; k < MAXNODES; k++) {
                                if (costMatrix[j][k] > costMatrix[j][i] + costMatrix[i][k]&&k!=j) {
                                        costMatrix[j][k] = costMatrix[j][i] + costMatrix[i][k];
                                        if(pathMatrix[j][k]==-1) pathMatrix[j][k] = String(trimString(pathMatrix[j][i])+","+pathMatrix[i][k]);
                                        else {
                                          pathMatrix[j][k] = trimString(pathMatrix[j][k]);
                                          pathMatrix[j][k]+= String(pathMatrix[j][i]+","+pathMatrix[i][k]);
                                            }
                                }
                        }
                }
        }
}

void printMap(){
int i=0;
int j=0;
Serial.println("Cost Matrix");
for(i=0;i<MAXNODES;i++){
	for(j=0;j<MAXNODES;j++) {
          Serial.print(costMatrix[i][j]);
          Serial.print("\t");
                                }
	Serial.println();
}
	Serial.println();Serial.println();
Serial.println("Shortest Path Matrix");
for(i=0;i<MAXNODES;i++){
	for(j=0;j<MAXNODES;j++) {
          Serial.print(pathMatrix[i][j]);
          Serial.print("\t");
                                }
	Serial.println();
}
}


void loop(){}

This testif(pathMatrix[j][k]==-1)compares an element of pathmatrix, whose type is String, to the number -1, whose type defaults to int. I got it to compile by changing that test to this:if(pathMatrix[j][k]==String(-1))I've never used String, so I don't know whether that's valid.

What sort of Arduino are you using for this effort?

Thanks tmd3 for ur reply.

I am using arduino pro mini 3.3v 328p for path finding robot...currently just starting to learn arduino. This is my class project to implement path finding algorithm into ultrasonic sensors robot to get from point A to point B. I found this dijsktra algorithm so i try to check the code but i cant seem to understand the error...

Thank again...i will keep trying...

If you get past the error, I think you'll find that the compilation will still fail, because this program requires more memory than the Pro Mini has available. It also exceeds the memory of an Uno.

The "invalid conversion" error arises because the program tries to compare two values whose data types aren't compatible: an element of pathmatrix, type String, and -1, type int. There's no reasonable way to compare those two things, so the compiler complains and gives up.

This posted version of this program doesn't even compile. That suggests that there may be other problems with it - well, there's at least one more problem, it takes too much memory. I'd suggest that you carefully evaluate whether you need Dijkstra's algorithm for your application, and, if you do, learn how to write it yourself, and look for better examples.

Hi tmd3,

Ya u're probably rite...i will try to write myself cuz the program above has really eaten up whole bunch of memory....

thanks again...

best regards.