meditationatae

Just another WordPress.com site

source code of udgraph_solver301a dot c

#include <stdio.h>
#include <math.h>
#define NUMSTEPS 510
#define MAXDIFFAT100 ((long double) 110)/((long double) 1000)
#define MAXDIFFAT50 ((long double) 14)/((long double) 10)
#define MAXDIFFAT25 ((long double) 550)/((long double) 100)
static unsigned long long Q[2097152],carry=0;

unsigned long long B64MWC(void)
{ unsigned long long t,x; static int j=2097151;
j=(j+1)&2097151;
x=Q[j]; t=(x<<28)+carry;
carry=(x>>36)-(t<x);
return (Q[j]=t-x);
}

#define CNG ( cng=6906969069LL*cng+13579 )
#define XS ( xs^=(xs<<13), xs^=(xs>>17), xs^=(xs<<43) )
#define KISS ( B64MWC()+CNG+XS )
/********************* README SECTION *********************

10-point non-singular solutions to the unit
graph problem are found numerically at a rate of
57.9 solutions per second on a dual core Athlon
5000+ processor.

The solutions are expected to be isometric as a
10-point metric space to the soltion depicted in
the graph in my blog post :

Sketch of 10-vertex unit distance graph, 2013
at URL =

meditationatae.wordpress.com/2017/02/06/sketch-of-10-vertex-unit-distance-graph-2013
The sci dot math posts:

mathforum.org/kb/message.jspa?messageID=10081388

and earlier:

mathforum.org/kb/message.jspa?messageID=10074716

This solver for a particular graph has been optimized
to run in as little time as possible for the given graph,
decribed by the 10×10 adjacency matrix.

To compile, I type:

$ gcc -lm -O3 -o udgraph_solver201a.out udgraph_solver201a.c

at the shell command line in Linux.

The executable is then udgraph_solver201a.out .
In C pre-processor terms, if VERBOSE is defined by
a pre-processor directive,
Number-Sign define VERBOSE
say on line 7 above after the other
Number-sign defines,
then the solution count and the 10×10 matrix of vertex to vertex
distances for a solution will be printed.

As above VERBOSE is not defined, the program will run with
minimal output until it finishes after about 9 minutes
with my system.

This README is based on file
Slash home slash david slash graphs slash golomb6
slash udgraph_solver201a dot c,

will serve to write the local file:

Slash home slash david slash graphs slash golomb6
slash udgraph_solver301a dot c ,

and will go by the Moniker or alias
“unit distance graph solver draft 101”

a hexadecimal dump will be posted to my blog

meditationatae.wordpress.com
David Bernier

********************* README END *************************/

int main(void)
{
unsigned long long i,cng=123456789987654321LL,
xs=362436069362436069LL;
unsigned long long randx;
int B;
int j;
int k;
int quit;
int l, m;
int count;
int solution_found;
char alphabet[10];
unsigned long long maxi_ull;
long double xcoord[10];
long double diff;
long double diff_record;
long double maxdiffat400;
long double one;
long double ycoord[10];
long double forces[10][2];
long double C;
long double vector[2];
long double xgood[10];
long double ygood[10];
int has_converged_flag;
int has_converged_step;
int max_has_converged_step;
long double scaling;
long double dmatrix[10][10];
int adjmat[10][10] = {{0,0,0,0,0,1,1,0,1,1},{0,0,0,1,0,0,0,1,1,1},{0,0,0,0,1,0,1,1,0,1},{0,1,0,0,0,1,0,1,0,0},{0,0,1,0,0,0,1,1,1,0},{1,0,0,1,0,0,1,0,0,0},{1,0,1,0,1,1,0,0,0,0},{0,1,1,1,1,0,0,0,0,0},{1,1,0,0,1,0,0,0,0,1},{1,1,1,0,0,0,0,0,1,0}};
/************************************************************************
newtestz746a.out 345 : 8m 34.631s for 30k solns. , using -O3
newtestz745a.out 340 : 8m 35s for 30000 solutions, with -O3
newtestz585a.c: 8m 51s for 30000 solutions, using -O3 optimization
newtest83a.c: 9m 57s for 30000 solutions, using -O3 optimization option
newtest81a.c: 9m 57s for 30000 solutions, using -O3 optimization option
newtest73a.c: 8m 49s for 30000 solutions, using -O3 optimization option
newtest66a.c: 10m 25s for 30000 solutions, using -O3 optimization option
newtest65a.c: 11m 30s for 30000 solutions
newtest64a.c: 11m 30s for 30000 solutions
newtest63a.c: 11m 33s for 30000 solutions
newtest62a.c: 11m 33s for 30000 solutions
newtest61a.c: 3m 51s for 10000 solutions
newtest57a.c: 6m 27s for 10000 solutions
newtest56a.c: 6m 37s for 10000 solutions
newtest55a.c: 6m 43s for 10000 solutions
newtest54a.c: 6m 48s for 10000 solutions
newtest53a.c: 6m 46s for 10000 solutions
newtest48a.c: 62 seconds for 1600 solutions
newtest47a.c: 14 seconds for 400 solutions
newtest46a.c: 66 seconds for 400 solutions
newtest39a.c: 67 seconds for 400 solutions
newtest37a.c: 70 seconds for 400 solutions
newtest35a.c: 79 seconds for 400 solutions
newtest34a.c: 72 seconds for 400 solutions
newtest33a.c: 91 seconds for 400 solutions
newtest30a.c: 16 seconds for 100 solutions
newtest29a.c: 18 seconds for 100 solutions
newtest28a.c: 25 seconds for 100 solutions
newtest27a.c: 50 seconds for 100 solutions
newtest26a.c: 99 seconds for 100 solutions
newtest25a.c: 3000 solutions per hour
for 100 solutions, 2 minutes …
808 solutions per minute for 4-point diamond shape.
gtest230a.c :
2600 solutions per minute for 7-point 4-colour
graph
gtest980a.c :
98000 solutions per minute for 7-point 4-colour
graph, Mosers’ spindle.
en.wikipedia.org slash wiki slash Moser_spindle
*************************************************/
B = 340;

maxi_ull = ((unsigned long long)6700417)*((unsigned long
long)2753074036095);
scaling = ((long double) 34)/((long double) 10);
one = (long double) 1;
diff_record = ((long double) 2100)/((long double) 100);
maxdiffat400 = ((long double)1)/((long double)100000);
maxdiffat400 = (((long double)1)/((long double)100000))*maxdiffat400;
maxdiffat400 = (((long double)1)/((long double)100000))*maxdiffat400;
count = 0;
max_has_converged_step = 0;

alphabet[0] = ‘A’;
alphabet[1] = ‘B’;
alphabet[2] = ‘C’;
alphabet[3] = ‘D’;
alphabet[4] = ‘E’;
alphabet[5] = ‘F’;
alphabet[6] = ‘G’;
alphabet[7] = ‘H’;
alphabet[8] = ‘I’;
alphabet[9] = ‘J’;

/* First seed Q[] with CNG+XS: */
for(i=0;i<2097152;i++) Q[i]=CNG+XS;

for(l=0; l< 10 ; l++)
{
dmatrix[l][l] = (long double) 0;
}

printf(“B = %d\n\n”, B);
while( count < 30000 )
{
solution_found = 0;

while( 0 == solution_found )
{
for( j=0; j< 10 ; j++)
{
randx = KISS;
xcoord[j] = ((long double) randx)/((long double) maxi_ull);
xcoord[j] = scaling*xcoord[j];
randx = KISS;
ycoord[j] = ((long double) randx)/((long double) maxi_ull);
ycoord[j] = scaling*ycoord[j];
}
for(l=0; l< 10 ; l++)
{
for(m=0; m< l ; m++)
{
dmatrix[l][m] = (xcoord[l]-xcoord[m])*(xcoord[l]-xcoord[m]);
dmatrix[l][m] = dmatrix[l][m] +
(ycoord[l]-ycoord[m])*(ycoord[l]-ycoord[m]);
dmatrix[l][m] = sqrtl(dmatrix[l][m]);
}
for(m= l+1 ; m< 10 ; m++)
{
dmatrix[l][m] = dmatrix[m][l];
}
}
diff = (long double) 0;
for(l=0; l< 10 ; l++)
{
for(m=0; m< l; m++)
{
if( 1 == adjmat[l][m] )
{
diff = diff + fabsl(one-dmatrix[l][m]);
}
}
}
if(diff < diff_record)
{
solution_found = 1;

for( j =0; j< 10 ; j++)
{
xgood[j] = xcoord[j];
ygood[j] = ycoord[j];
}
}
}

/*****************************************************************

have solution …

*****************************************************************/
has_converged_flag = 0;
quit = 0;
/*************** BEGIN ITERATIONS TO CONVERGE **************/
for( k = 0; k < NUMSTEPS ; k++)
{
if( quit == 1)
{
break;
}

if( (k+1) < 100)
{
C = ((long double) 345)/((long double) 1000);
}
else
{
C = ((long double) B )/((long double) 1000);
}

for(l=0; l< 10 ; l++)
{
for(m=0; m< l ; m++)
{
dmatrix[l][m] = (xgood[l]-xgood[m])*(xgood[l]-xgood[m]);
dmatrix[l][m] = dmatrix[l][m] +
(ygood[l]-ygood[m])*(ygood[l]-ygood[m]);
dmatrix[l][m] = sqrtl(dmatrix[l][m]);
}
for(m= l+1 ; m< 10 ; m++)
{
dmatrix[l][m] = dmatrix[m][l];
}
}
if( (k+1) == 25 )
{
diff = (long double) 0;
for(l=0; l< 10 ; l++)
{
for(m=0; m< l; m++)
{
if( 1 == adjmat[l][m] )
{
diff = diff + fabsl(one-dmatrix[l][m]);
}
}
}

if( diff > MAXDIFFAT25 )
{
quit = 1;
}
}
if( (k+1) == 50 )
{
diff = (long double) 0;
for(l=0; l< 10 ; l++)
{
for(m=0; m< l; m++)
{
if( 1 == adjmat[l][m] )
{
diff = diff + fabsl(one-dmatrix[l][m]);
}
}
}

if( diff > MAXDIFFAT50 )
{
quit = 1;
}
}
if( (k+1) == 100 )
{
diff = (long double) 0;
for(l=0; l< 10 ; l++)
{
for(m=0; m< l; m++)
{
if( 1 == adjmat[l][m] )
{
diff = diff + fabsl(one-dmatrix[l][m]);
}
}
}

if( diff > MAXDIFFAT100 )
{
quit = 1;
}
}
diff = (long double) 0;

for(l=0; l< 10 ; l++)
{
for(m=0; m< l; m++)
{
if( 1 == adjmat[l][m] )
{
diff = diff + fabsl(one-dmatrix[l][m]);
}
}
}

if( (diff < maxdiffat400) && (has_converged_flag == 0) )
{
has_converged_flag = 1;
has_converged_step = k+1;

if( has_converged_step > max_has_converged_step )
{
max_has_converged_step = has_converged_step;
}

quit = 1;

if((dmatrix[0][2]<(((long double)14)/((long double)10)))&& dmatrix[0][2]>one)
{
count = count + 1;
#ifdef VERBOSE
printf(“Solutions count = %d “, count);
printf(“has_converged_step = %d “, has_converged_step);
printf(“max_has_converged_step = %d\n”, max_has_converged_step);
printf(“Matrix of distances vertex to vertex:\n”);
printf(” “);
for(m=0; m<10; m++)
{
printf(” %c “, alphabet[m]);
}
printf(“\n”);
for(l=0; l< 10 ; l++)
{
printf(“%c “, alphabet[l]);
for(m=0; m< 10 ; m++)
{
printf(“%.4Lf “, dmatrix[l][m]);
}
printf(“\n”);
}

printf(“\n”);
#endif

}
}
for(l=0; l< 10 ; l++)
{
forces[l][0] = (long double) 0;
forces[l][1] = (long double) 0;

for(m=0; m< 10 ; m++)
{
if( 1 == adjmat[l][m] )
{
vector[0] = xgood[m]-xgood[l];
vector[1] = ygood[m]-ygood[l];
vector[0] = vector[0]/dmatrix[l][m];
vector[1] = vector[1]/dmatrix[l][m];
vector[0] = vector[0]*C;
vector[1] = vector[1]*C;
vector[0] = vector[0]*(dmatrix[l][m]-one);
vector[1] = vector[1]*(dmatrix[l][m]-one);

forces[l][0] = forces[l][0] + vector[0];
forces[l][1] = forces[l][1] + vector[1];
}
}
}

for( j =0; j< 10 ; j++)
{
xgood[j] = xgood[j] + forces[j][0];
ygood[j] = ygood[j] + forces[j][1];
}
}
/******************************************************
Below, post-convergence algorithm or heuristic:
******************************************************/
}
/*****************************************
while( count < 30000 ) end Block
*****************************************/

return 0;
}

Advertisements

Written by meditationatae

February 10, 2017 at 5:24 pm

Posted in History

%d bloggers like this: