Hello,
I need help with Lee algorithm. Just a quick reminder of what it is: Start at a point, assign the cost of 0 to that point, and expand vertically and horizontally until target is hit. See below:
______3
____3 2 3
__3 2 1 2 3
3 2 1 0 1 2 3
__3 2 1 2 3
___3 2 3
_____3
Let's assume pin 1 (row_pin1 and column_pin1) and pin 2 (row_pin2 and column_pin2) definitions are correct. Also, please ignore all printf statements, I use them just to see where my program is going.
Where I am lost is at the logic of the expansion from point 0 to the target. Can someone please help me with that?
Also, if you look at Lee algorithm, I think with the current values, "while" loop should never be exited, because even though row_pin1=row_pin2, column_pin1!=column_pint. But the loop exits anyway, rather than getting stuck.
/* --- The following code comes from C:\lcc\lib\wizard\textmode.tpl. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
int x=5;
int array[6];
array[0]=0;
array[1]=2;
array[2]=1;
array[3]=3;
array[4]=4;
array[5]=1;
int column_pin1;
int row_pin1;
int column_pin2;
int row_pin2;
int column_pin1_top;
int column_pin1_bottom;
int cost=0;
//-Pin 1
if (array[2]==0 && (array[1]!=0 && array[1]!=x-1))
{
column_pin1=array[0];
row_pin1=array[1]+1;
printf("%3i", column_pin1);
}
if (array[2]==0 && (array[1]==0 || array[1]==x-1))
{
column_pin1=array[0];
row_pin1=array[1]+1;
printf("%3i", column_pin1);
}
if (array[2]==1)
{
column_pin1=array[0];
row_pin1=array[1];
printf("%3i", column_pin1);
}
if (array[2]==2)
{
column_pin1=array[0];
row_pin1=array[1];
printf("%3i", column_pin1);
}
if (array[2]==3)
{
column_pin1=array[0]+1;
row_pin1=array[1];
printf("%3i", column_pin1);
}
if (array[2]==4)
{
column_pin1=array[0]+1;
row_pin1=array[1];
printf("%3i", column_pin1);
}
//-Pin 2
if (array[5]==0 && (array[4]!=0 && array[4]!=x-1))
{
column_pin2=array[3];
row_pin2=array[4]+1;
printf("%3i", column_pin2);
}
if (array[5]==0 && (array[4]==0 || array[4]==x-1))
{
column_pin2=array[3];
row_pin2=array[4]+1;
printf("%3i", column_pin2);
}
if (array[5]==1)
{
column_pin2=array[3];
row_pin2=array[4];
printf("%3i", column_pin2);
}
if (array[5]==2)
{
column_pin2=array[3];
row_pin2=array[4];
printf("%3i", column_pin2);
}
if (array[5]==3)
{
column_pin2=array[3]+1;
row_pin2=array[4];
printf("%3i", column_pin2);
}
if (array[5]==4)
{
column_pin2=array[3]+1;
row_pin2=array[4];
printf("%3i", column_pin2);
}
//- Lee algorithm
while (((row_pin1)!=(row_pin2)) && ((column_pin1)!=(column_pin2)))
{
column_pin1_top=column_pin1;
printf("%3i", column_pin1_top);
column_pin1_bottom=column_pin1;
printf("kk");
printf("%3i", cost);
//- going to the right
for (row_pin1=row_pin1;row_pin1!=row_pin2;row_pin1++)
{
printf("%3i", cost);
column_pin1_top=column_pin1_top+1;
printf("%3i", column_pin1_top);
column_pin1_bottom=column_pin1_bottom-1;
cost=cost+1;
if (column_pin1_top==column_pin2)
{
column_pin1=column_pin1_top;
}
if (column_pin1_bottom==column_pin2)
{
column_pin1=column_pin1_bottom;
}
printf("%3i", cost);
printf("%3i", column_pin1_top);
printf("%3i", column_pin1_bottom);
printf("%3i", column_pin1);
}
}
}
Thank You.