24 static double Epsilon2;
33 double distvec(
double *p0,
double *p1,
double *vec)
38 for (k = 0; k <
Ndim; k++) {
39 vec[k] = p0[k] - p1[k];
40 dist += (vec[k] * vec[k]);
52 rv =
N_NEW(m,
double *);
53 mem =
N_NEW(m * n,
double);
54 for (i = 0; i < m; i++) {
57 for (j = 0; j < n; j++)
72 static double ***new_3array(
int m,
int n,
int p,
double ival)
77 rv =
N_NEW(m + 1,
double **);
78 for (i = 0; i < m; i++) {
79 rv[i] =
N_NEW(n + 1,
double *);
80 for (j = 0; j < n; j++) {
81 rv[i][j] =
N_NEW(p,
double);
82 for (k = 0; k < p; k++)
91 static void free_3array(
double ***rv)
96 for (i = 0; rv[i]; i++) {
97 for (j = 0; rv[i][j]; j++)
118 if (*s ==
'\0')
return 1;
120 if ((sscanf(s,
"%lf", val) < 1) || (*val < 0) || ((*val == 0) && !
Nop)) {
176 deg = degreeKind(G, np, &other);
182 }
else if (deg == 1) {
197 double total_len = 0.0;
202 if ((err = lenattr(ep, lenx, &len))) {
223 double total_len = 0.0;
224 double dfltlen = 1.0;
228 fprintf(stderr,
"Scanning graph %s, %d nodes\n",
agnameof(G),
236 deg = degreeKind(G, np, &other);
239 }
else if (deg == 1) {
241 xp = prune(G, other, xp);
262 total_len += setEdgeLen(G, np, lenx, dfltlen);
269 total_len += setEdgeLen(G, np, lenx, dfltlen);
273 str =
agget(G,
"defaultdist");
277 Initial_dist = total_len / (nE > 0 ? nE : 1) * sqrt(nV) + 1;
283 GD_t(G) = new_3array(nV, nV,
Ndim, 0.0);
301 free_3array(
GD_t(g));
309 for (k = n; k <
Ndim; k++)
333 fprintf(stderr,
"Setting initial positions\n");
338 if ((init ==
INIT_SELF) && (once == 0)) {
339 agerr(
AGWARN,
"start=%s not supported with mode=self - ignored\n");
358 fprintf(stderr,
"Setting up spring model: ");
364 for (i = 0; i < nG; i++) {
365 for (j = 0; j < i; j++) {
369 K[i][j] = K[j][i] = f;
374 for (i = 0; i < nG; i++)
375 for (k = 0; k <
Ndim; k++)
379 for (j = 0; j < nG; j++) {
384 for (k = 0; k <
Ndim; k++) {
401 static double total_e(
graph_t * G,
int nG)
409 for (i = 0; i < nG - 1; i++) {
411 for (j = i + 1; j < nG; j++) {
413 for (t0 = 0.0, d = 0; d <
Ndim; d++) {
419 - 2.0 *
GD_dist(G)[i][j] * sqrt(t0));
435 fprintf(stderr,
"\nfinal e = %f", total_e(G, nG));
436 fprintf(stderr,
" %d%s iterations %.2f sec\n",
441 agerr(
AGWARN,
"Max. iterations (%d) reached on graph %s\n",
452 for (k = 0; k <
Ndim; k++)
454 for (j = 0; j < nG; j++) {
459 for (k = 0; k <
Ndim; k++) {
460 old =
GD_t(G)[i][j][k];
465 old =
GD_t(G)[j][i][k];
466 GD_t(G)[j][i][k] = -
GD_t(G)[i][j][k];
472 #define Msub(i,j) M[(i)*Ndim+(j)]
477 double scale, sq, t[
MAXDIM];
482 for (l = 0; l <
Ndim; l++)
483 for (k = 0; k <
Ndim; k++)
485 for (i = 0; i < nG; i++) {
490 for (k = 0; k <
Ndim; k++) {
495 for (k = 0; k <
Ndim; k++) {
496 for (l = 0; l < k; l++)
497 Msub(l, k) += K[n][i] * D[n][i] * t[k] * t[l] * scale;
499 K[n][i] * (1.0 - D[n][i] * (sq - (t[k] * t[k])) * scale);
502 for (k = 1; k <
Ndim; k++)
503 for (l = 0; l < k; l++)
509 fprintf(stderr,
"iterations = %d final e = %f\n",
GD_move(G),
528 if ((cnt % 100) == 0) {
537 for (i = 0; i < nG; i++) {
541 for (m = 0.0, k = 0; k <
Ndim; k++)
552 if (
Verbose && (cnt % 100 == 0)) {
553 fprintf(stderr,
"%.3f ", sqrt(max));
555 fprintf(stderr,
"\n");
559 if (fabs((e - save_e) / save_e) < 1e-5) {
575 for (i = 0; i <
Ndim; i++)
577 solve(a, b, c, Ndim);
578 for (i = 0; i <
Ndim; i++) {
586 for (i = 0; i <
Ndim; i++) {
590 fprintf(stderr,
"%s %.3f\n",
agnameof(n), sum);
621 while ((left = 2 * i + 1) < Heapsize) {
623 if ((right < Heapsize)
675 fprintf(stderr,
"Calculating shortest paths: ");
void neato_enqueue(node_t *)
void s1(graph_t *, node_t *)
void shortest_path(graph_t *, int)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, char *value)
void initial_positions(graph_t *, int)
int scan_graph(graph_t *)
#define ALLOC(size, ptr, type)
void jitter3d(Agnode_t *, int)
int scan_graph_mode(graph_t *G, int mode)
void heapdown(Agnode_t *)
void solve(double *, double *, double *, int)
EXTERN double Initial_dist
CGRAPH_API Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
CGRAPH_API int agdelete(Agraph_t *g, void *obj)
int agerr(agerrlevel_t level, const char *fmt,...)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
void final_energy(graph_t *, int)
char * agget(void *obj, char *name)
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
double distvec(double *, double *, double *)
void update_arrays(graph_t *G, int nG, int i)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
void free_array(double **rv)
CGRAPH_API char * agnameof(void *)
double ** new_array(int i, int j, double val)
void move_node(graph_t *, int, Agnode_t *)
void free_scan_graph(graph_t *)
void solve_model(graph_t *, int)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
void D2E(Agraph_t *, int, int, double *)
EXTERN unsigned char Reduce
void make_spring(graph_t *, Agnode_t *, Agnode_t *, double)
CGRAPH_API Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
EXTERN unsigned char Verbose
CGRAPH_API int agnnodes(Agraph_t *g)
Agnode_t * node(Agraph_t *g, char *name)
void randompos(Agnode_t *, int)
#define agfindedge(g, t, h)
node_t * neato_dequeue(void)
CGRAPH_API int agnedges(Agraph_t *g)
int checkStart(graph_t *G, int nG, int dflt)
char * agxget(void *obj, Agsym_t *sym)
double dist(Site *s, Site *t)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Agnode_t * choose_node(graph_t *, int)
void diffeq_model(graph_t *, int)
void jitter_d(Agnode_t *, int, int)
#define GD_neato_nlist(g)