# The traveling salesman problem - Using Space Renormalization

Image attached is where I am at the moment. Blue dots=points/cities, Black x's represent central points in each box that contains at least one city, and pink dots represent the midpoint of these centre points

I am doing a short project using Lab Windows to approximate the minimal path between points on a 2D plane. (Graphically only, I don't need an actual path length)

To do this I am using real space re-normalization.

http://scitation.aip.org/docserver/fulltext/aip/journal/cip/10/6/1.168588.pdf?expires=1387106816&id=id&accname=guest&checksum=350319AE8AA74E9002D87940052A0140 - An article by U. Yoshiyuki - "Solving the Traveling Salesman Problem By a Statistical Physics Method" describes exactly what I am trying to do

So far I have: Plotted random integer valued points on a graph in my user interface

Divided my plotting space evenly into boxes, i.e. a 2x2 graph (Just by plotting lines)

Created a new point in the centre of each box if there was a random point generated in that box

Found the nearest edge point (for the 2x2 graph only)

     /*
* Travelling Salesman Problem
* A Graphical Approximation using Space Re-normalization

* Assuming there are  3 or more cities
*/

#include "toolbox.h"
#include <cvirte.h>
#include <userint.h>
#include "TSP.h"

static int panelHandle;
void draw_borders(int,int,int,int);/*function prototype*/

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1;  /* out of memory */
if ((panelHandle = LoadPanel (0, "TSP.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
return 0;
}

int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}

int CVICALLBACK ClearPlot (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
DeleteGraphPlot(panelHandle,PANEL_2X2GRAPH,-1,1);
DeleteGraphPlot(panelHandle,PANEL_4X4GRAPH,-1,1);
DeleteGraphPlot(panelHandle,PANEL_8X8GRAPH,-1,1);
DeleteGraphPlot(panelHandle,PANEL_16X16GRAPH,-1,1);
DeleteGraphPlot(panelHandle,PANEL_GRAPH_PATH,-1,1);
break;
}
return 0;
}

int CVICALLBACK Go (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

int x[1024],y[1024]; /* City co-ordinates */
int i,j,k,num=10; /* num is the number of cities to be plotted */
int xi=0,xf=1024,yi=0,yf=1024; /* boundary points om graph */
int flag=0;

/* Structures to store central points for each box containing a city*/
typedef struct{
int x,y;
} Segment1;
Segment1 Seg1[100][100];

typedef struct{
int x,y;
} Segment2;
Segment2 Seg2[100][100];

typedef struct{
int x,y;
} Segment3;
Segment3 Seg3[100][100];

typedef struct{
int x,y;
} Segment4;
Segment4 Seg4[100][100];

/*2x2*/
int grid1x2d[2][2],grid1y2d[2][2];/*grid containing x and y coordinate of central point locations in each box which contains a city*/
int grid1xx[4], grid1yy[4];/*same grid stretched to 1d for plotting*/
int mid1x2d, mid1y2d;

/*4x4*/
int grid2x2d[4][4],grid2y2d[4][4];
int grid2xx[16], grid2yy[16];

/*8x8*/
int grid3x2d[8][8],grid3y2d[8][8];
int grid3xx[64], grid3yy[64];

/*16x16*/
int grid4x2d[16][16],grid4y2d[16][16];
int grid4xx[256], grid4yy[256];

draw_borders(xi,xf,yi,yf);/*Draw borders for clarity*/

/* Plot Cities */
for(i=0;i<num;i++){

/*represent each city as a random point*/
x[i] = (int)Random(0,1024);
y[i] = (int)Random(0,1024);
PlotPoint(panelHandle,PANEL_2X2GRAPH,x[i],y[i],VAL_CROSS,VAL_BLUE); /*plot city on each graph*/
PlotPoint(panelHandle,PANEL_4X4GRAPH,x[i],y[i],VAL_CROSS,VAL_BLUE);
PlotPoint(panelHandle,PANEL_8X8GRAPH,x[i],y[i],VAL_CROSS,VAL_BLUE);
PlotPoint(panelHandle,PANEL_16X16GRAPH,x[i],y[i],VAL_CROSS,VAL_BLUE);
PlotPoint(panelHandle,PANEL_GRAPH_PATH,x[i],y[i],VAL_CROSS,VAL_BLUE);

/*Print out city coordinates*/
char resultx[100];
sprintf(resultx,"x co-ordinate of city %d is %d\n",i+1,x[i]);
SetCtrlVal(panelHandle,PANEL_CITYCOORDINATES,resultx);

char resulty[100];
sprintf(resulty,"y co-ordinate of city %d is %d\n",i+1,y[i]);
SetCtrlVal(panelHandle,PANEL_CITYCOORDINATES,resulty);
}

SetCtrlVal(panelHandle,PANEL_MESSAGE,"Cities Plotted");

////////////*2x2 Graph*////////////////////////////////////////////////////////////////////////////
/* First find centre point of each box which contains a city
* Second find midpoint of centre point locations of each box that contains at least one city
*/

/* Set count in all 4 boxes to be zero*/
for (i=0;i<2;i++){ /*x direction*/
for (j=0; j<2; j++) /*y direction*/
}

/* For every city, add 1 to count */
for (i=0;i<num;i++)

/* Set up a grid containing the x,y coordinates of central point locations of each box that contains at least one city*/
for (i=0;i<2;i++){
for (j=0; j<2; j++){
grid1x2d[i][j]=i*512+256;  grid1y2d[i][j] =j*512+256;

/* Assign these values to a structure to call on them later when finding midpoint*/
Seg1[i][j].x = grid1x2d[i][j]; Seg1[i][j].y = grid1y2d[i][j];
}
else{
/* Set up a grid containing dummy x,y coordinates if there are no cities in a particular box */
grid1x2d[i][j]=-1;  grid1y2d[i][j] =-1;

Seg1[i][j].x = grid1x2d[i][j]; Seg1[i][j].y = grid1y2d[i][j];
}
}
}

/* Find edge points which are found if representative points are connected*/
/* If the 2X2 Graph has an empty box then there will be an edgepoint in centre of graph*/
for(i=0;i<2;i++){
for(j=0;j<2;j++){
PlotPoint(panelHandle,PANEL_2X2GRAPH,512,512,VAL_BOLD_X,VAL_DK_GREEN);
PlotPoint(panelHandle,PANEL_4X4GRAPH,512,512,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_8X8GRAPH,512,512,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_16X16GRAPH,512,512,VAL_BOLD_X,VAL_MAGENTA);
}
}
}

for(i=0;i<2;i++){
j=0;
mid1x2d= (Seg1[i][j].x + Seg1[i][j+1].x) /2 ;
mid1y2d= (Seg1[i][j].y + Seg1[i][j+1].y) /2 ;
PlotPoint(panelHandle,PANEL_2X2GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_DK_GREEN);
PlotPoint(panelHandle,PANEL_4X4GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_8X8GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_16X16GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
}
}
for(j=0;j<2;j++){
i=0;
mid1x2d= (Seg1[i][j].x + Seg1[i+1][j].x) /2 ;
mid1y2d= (Seg1[i][j].y + Seg1[i+1][j].y) /2 ;
PlotPoint(panelHandle,PANEL_2X2GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_DK_GREEN);
PlotPoint(panelHandle,PANEL_4X4GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_8X8GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
PlotPoint(panelHandle,PANEL_16X16GRAPH,mid1x2d,mid1y2d,VAL_BOLD_X,VAL_MAGENTA);
}
}

/*stretch into 1d array for plotting*/
for (k=0;k<4;k++){
grid1xx[k]=grid1x2d[k%2][(int)k/2];
}
for (k=0;k<4;k++){
grid1yy[k]=grid1y2d[k%2][(int)k/2];
}

PlotXY (panelHandle, PANEL_2X2GRAPH, grid1xx , grid1yy ,4, VAL_INTEGER, VAL_INTEGER, VAL_SCATTER,VAL_BOLD_X, VAL_THIN_LINE, 1, VAL_BLACK);
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////*Optimal Paths*////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////

////////////*4x4 Graph*////////////////////////////////////////////////////////////////////////////
/* Set count in all 4 boxes to be zero*/
for (i=0;i<4;i++){ /*x direction*/
for (j=0; j<4; j++) /*y direction*/
}

/* For every city, add 1 to count */
for (i=0;i<num;i++)

/* Set up a grid containing the x,y coordinates of central point locations of each box that contains at least one city*/
for (i=0;i<4;i++){
for (j=0; j<4; j++){
grid2x2d[i][j]=i*256+128;  grid2y2d[i][j] =j*256+128;

/* Assign these values to a structure to call on them later when finding midpoint*/
Seg2[i][j].x = grid2x2d[i][j]; Seg2[i][j].y = grid2y2d[i][j];
}
else{
/* Set up a grid containing dummy x,y coordinates if there are no cities in a particular box */
grid2x2d[i][j]=-1;  grid2y2d[i][j] =-1;

Seg2[i][j].x = grid2x2d[i][j]; Seg2[i][j].y = grid2y2d[i][j];
}
}
}

/*stretch into 1d array for plotting*/
for (k=0;k<16;k++)
grid2xx[k]=grid2x2d[k%4][(int)k/4];

for (k=0;k<16;k++)
grid2yy[k]=grid2y2d[k%4][(int)k/4];

PlotXY (panelHandle, PANEL_4X4GRAPH, grid2xx , grid2yy ,16, VAL_INTEGER, VAL_INTEGER, VAL_SCATTER, VAL_BOLD_X, VAL_THIN_LINE, 1, VAL_BLACK);
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////*8x8 Graph*////////////////////////////////////////////////////////////////////////////
/* Set count in all 4 boxes to be zero*/
for (i=0;i<8;i++){ /*x direction*/
for (j=0; j<8; j++) /*y direction*/
}

/* For every city, add 1 to count */
for (i=0;i<num;i++)

/* Set up a grid containing the x,y coordinates of central point locations of each box that contains at least one city*/
for (i=0;i<8;i++){
for (j=0; j<8; j++){
grid3x2d[i][j]=i*128+64;  grid3y2d[i][j] =j*128+64;

/* Assign these values to a structure to call on them later when finding midpoint*/
Seg3[i][j].x = grid3x2d[i][j]; Seg3[i][j].y = grid3y2d[i][j];
}
else{
/* Set up a grid containing dummy x,y coordinates if there are no cities in a particular box */
grid3x2d[i][j]=-1;  grid3y2d[i][j] =-1;

Seg3[i][j].x = grid3x2d[i][j]; Seg3[i][j].y = grid3y2d[i][j];
}
}
}

/*stretch into 1d array for plotting*/
for (k=0;k<64;k++)
grid3xx[k]=grid3x2d[k%8][(int)k/8];

for (k=0;k<64;k++)
grid3yy[k]=grid3y2d[k%8][(int)k/8];

PlotXY (panelHandle, PANEL_8X8GRAPH, grid3xx , grid3yy ,64, VAL_INTEGER, VAL_INTEGER, VAL_SCATTER, VAL_BOLD_X, VAL_THIN_LINE, 1, VAL_BLACK);
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////*16x16 Graph*////////////////////////////////////////////////////////////////////////////
/* Set count in all 4 boxes to be zero*/
for (i=0;i<16;i++){ /*x direction*/
for (j=0; j<16; j++) /*y direction*/
}

/* For every city, add 1 to count */
for (i=0;i<num;i++)

/* Set up a grid containing the x,y coordinates of central point locations of each box that contains at least one city*/
for (i=0;i<16;i++){
for (j=0; j<16; j++){
grid4x2d[i][j]=i*64+32;  grid4y2d[i][j] =j*64+32;

/* Assign these values to a structure to call on them later when finding midpoint*/
Seg4[i][j].x = grid4x2d[i][j]; Seg4[i][j].y = grid4y2d[i][j];
}
else{
/* Set up a grid containing dummy x,y coordinates if there are no cities in a particular box */
grid4x2d[i][j]=-1;  grid4y2d[i][j] =-1;

Seg4[i][j].x = grid4x2d[i][j]; Seg4[i][j].y = grid4y2d[i][j];
}
}
}

/*stretch into 1d array for plotting*/
for (k=0;k<256;k++)
grid4xx[k]=grid4x2d[k%16][(int)k/16];

for (k=0;k<256;k++)
grid4yy[k]=grid4y2d[k%16][(int)k/16];

PlotXY (panelHandle, PANEL_16X16GRAPH, grid4xx , grid4yy ,256, VAL_INTEGER, VAL_INTEGER, VAL_SCATTER,VAL_BOLD_X, VAL_THIN_LINE, 1, VAL_BLACK);
////////////////////////////////////////////////////////////////////////////////////////////////////

break;
}
return 0;


}

     void draw_borders(int xi,int xf,int yi,int yf){ /*function definition*/

/*Draw borders for clarity*/

/*2x2*/
PlotLine(panelHandle,PANEL_2X2GRAPH,xi,(yf+yi)/2,xf,(yf+yi)/2,VAL_RED);
PlotLine(panelHandle,PANEL_2X2GRAPH,(xf+xi)/2,yi,(xf+xi)/2,yf,VAL_RED);

/*4x4*/
PlotLine(panelHandle,PANEL_4X4GRAPH,xi,(yf+yi)/2,xf,(yf+yi)/2,VAL_RED);
PlotLine(panelHandle,PANEL_4X4GRAPH,(xf+xi)/2,yi,(xf+xi)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_4X4GRAPH,(xi+(xf+xi)/2)/2,yi,(xi+(xf+xi)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_4X4GRAPH,(xf+(xf+xi)/2)/2,yi,(xf+(xf+xi)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_4X4GRAPH,xi,(yf+(yf+yi)/2)/2,xf,(yf+(yf+yi)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_4X4GRAPH,xi,(yi+(yf+yi)/2)/2,xf,(yi+(yf+yi)/2)/2,VAL_RED);

/*8x8*/
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yf+yi)/2,xf,(yf+yi)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xf+xi)/2,yi,(xf+xi)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xi+(xf+xi)/2)/2,yi,(xi+(xf+xi)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xf+(xf+xi)/2)/2,yi,(xf+(xf+xi)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yf+(yf+yi)/2)/2,xf,(yf+(yf+yi)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yi+(yf+yi)/2)/2,xf,(yi+(yf+yi)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xi+(xi+(xf+xi)/2)/2)/2,yi,(xi+(xi+(xf+xi)/2)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xf+(xi+(xf+xi)/2)/2)/2,yi,(xf+(xi+(xf+xi)/2)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xf+(xf+(xf+xi)/2)/2)/2,yi,(xf+(xf+(xf+xi)/2)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,(xi+(xf+(xf+xi)/2)/2)/2,yi,(xi+(xf+(xf+xi)/2)/2)/2,yf,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yi+(yi+(yf+yi)/2)/2)/2,xf,(yi+(yi+(yf+yi)/2)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yi+(yf+(yf+yi)/2)/2)/2,xf,(yi+(yf+(yf+yi)/2)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yf+(yf+(yf+yi)/2)/2)/2,xf,(yf+(yf+(yf+yi)/2)/2)/2,VAL_RED);
PlotLine(panelHandle,PANEL_8X8GRAPH,xi,(yf+(yi+(yf+yi)/2)/2)/2,xf,(yf+(yi+(yf+yi)/2)/2)/2,VAL_RED);

/*16x16*/
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yf+yi)/2,xf,(yf+yi)/2,VAL_RED);//y=midline
PlotLine(panelHandle,PANEL_16X16GRAPH,(xf+xi)/2,yi,(xf+xi)/2,yf,VAL_RED);//x=midline
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+(xf+xi)/2)/2,yi,(xi+(xf+xi)/2)/2,yf,VAL_RED);//x=1/4 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xf+(xf+xi)/2)/2,yi,(xf+(xf+xi)/2)/2,yf,VAL_RED);//x=3/4 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yf+(yf+yi)/2)/2,xf,(yf+(yf+yi)/2)/2,VAL_RED);//y=3/4 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yi+(yf+yi)/2)/2,xf,(yi+(yf+yi)/2)/2,VAL_RED);//y=1/4 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+(xi+(xf+xi)/2)/2)/2,yi,(xi+(xi+(xf+xi)/2)/2)/2,yf,VAL_RED);//x=1/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xf+(xi+(xf+xi)/2)/2)/2,yi,(xf+(xi+(xf+xi)/2)/2)/2,yf,VAL_RED);//x=5/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xf+(xf+(xf+xi)/2)/2)/2,yi,(xf+(xf+(xf+xi)/2)/2)/2,yf,VAL_RED);//x=7/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+(xf+(xf+xi)/2)/2)/2,yi,(xi+(xf+(xf+xi)/2)/2)/2,yf,VAL_RED);//x=3/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yi+(yi+(yf+yi)/2)/2)/2,xf,(yi+(yi+(yf+yi)/2)/2)/2,VAL_RED);//y=1/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yi+(yf+(yf+yi)/2)/2)/2,xf,(yi+(yf+(yf+yi)/2)/2)/2,VAL_RED);//y=3/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yf+(yf+(yf+yi)/2)/2)/2,xf,(yf+(yf+(yf+yi)/2)/2)/2,VAL_RED);//y=7/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,(yf+(yi+(yf+yi)/2)/2)/2,xf,(yf+(yi+(yf+yi)/2)/2)/2,VAL_RED);//y=3/8 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi+((xi+(xi+(xf+xi)/2)/2)/2)/2,yi,xi+((xi+(xi+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=1/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi+((xi+(xf+(xf+xi)/2)/2)/2)/2,yi,xi+((xi+(xf+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=3/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi+((xf+(xi+(xf+xi)/2)/2)/2)/2,yi,xi+((xf+(xi+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=5/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi+((xf+(xf+(xf+xi)/2)/2)/2)/2,yi,xi+((xf+(xf+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=7/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+xf)/2+((xi+(xi+(xf+xi)/2)/2)/2)/2,yi,(xi+xf)/2+((xi+(xi+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=9/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+xf)/2+((xi+(xf+(xf+xi)/2)/2)/2)/2,yi,(xi+xf)/2+((xi+(xf+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=11/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+xf)/2+((xf+(xi+(xf+xi)/2)/2)/2)/2,yi,(xi+xf)/2+((xf+(xi+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=13/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,(xi+xf)/2+((xf+(xf+(xf+xi)/2)/2)/2)/2,yi,(xi+xf)/2+((xf+(xf+(xf+xi)/2)/2)/2)/2,yf,VAL_RED);//x=15/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,yi+((yi+(yi+(yf+yi)/2)/2)/2)/2,xf,yi+((yi+(yi+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=1/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,yi+((yi+(yf+(yf+yi)/2)/2)/2)/2,xf,yi+((yi+(yf+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=3/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,yi+((yf+(yf+(yf+yi)/2)/2)/2)/2,xf,yi+((yf+(yf+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=7/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,yi+((yf+(yi+(yf+yi)/2)/2)/2)/2,xf,yi+((yf+(yi+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=5/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,((yi+yf)/2)+((yf+(yi+(yf+yi)/2)/2)/2)/2,xf,((yi+yf)/2)+((yf+(yi+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=13/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,((yi+yf)/2)+((yf+(yf+(yf+yi)/2)/2)/2)/2,xf,((yi+yf)/2)+((yf+(yf+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=15/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,((yi+yf)/2)+((yi+(yf+(yf+yi)/2)/2)/2)/2,xf,((yi+yf)/2)+((yi+(yf+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=11/16 line
PlotLine(panelHandle,PANEL_16X16GRAPH,xi,((yi+yf)/2)+((yi+(yi+(yf+yi)/2)/2)/2)/2,xf,((yi+yf)/2)+((yi+(yi+(yf+yi)/2)/2)/2)/2,VAL_RED);//y=9/16 line


}

Now I need to code up the following:

Save the optimal paths for any 2x2 box as a look up table

Draw the optimal path for each graph, and save where it hits the edge of its box. This edge point must then be used in the next step (when I make the graph 8x8, then 16x16, etc. until I have found minimum path to a good approximation)

And how can I pass through the graph in an ordered way to do this, and how can I save the optimal paths?

Thanks