33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
56 #define D_useGrid (fdp_parms->useGrid)
57 #define D_useNew (fdp_parms->useNew)
58 #define D_numIters (fdp_parms->numIters)
59 #define D_unscaled (fdp_parms->unscaled)
60 #define D_C (fdp_parms->C)
61 #define D_Tfact (fdp_parms->Tfact)
62 #define D_K (fdp_parms->K)
63 #define D_T0 (fdp_parms->T0)
93 #define T_useGrid (parms.useGrid)
94 #define T_useNew (parms.useNew)
95 #define T_seed (parms.seed)
96 #define T_numIters (parms.numIters)
97 #define T_maxIters (parms.maxIters)
98 #define T_unscaled (parms.unscaled)
100 #define T_Tfact (parms.Tfact)
101 #define T_K (parms.K)
102 #define T_T0 (parms.T0)
103 #define T_smode (parms.smode)
104 #define T_Cell (parms.Cell)
105 #define T_Cell2 (parms.Cell2)
106 #define T_K2 (parms.K2)
107 #define T_Wd (parms.Wd)
108 #define T_Ht (parms.Ht)
109 #define T_Wd2 (parms.Wd2)
110 #define T_Ht2 (parms.Ht2)
111 #define T_pass1 (parms.pass1)
112 #define T_loopcnt (parms.loopcnt)
114 #define EXPFACTOR 1.2
115 #define DFLT_maxIters 600
117 #define DFLT_Cell 0.0
119 #define DFLT_smode INIT_RANDOM
121 static double cool(
double temp,
int t)
128 static void reset_params(
void)
151 fprintf(stderr,
"tlayout %s",
agnameof(g));
199 agerr(
AGWARN,
"fdp does not support start=self - ignoring\n");
215 "Params %s : K %f T0 %f Tfact %f maxIters %d unscaled %d\n",
228 while (dist2 == 0.0) {
229 xdelta = 5 - rand() % 10;
230 ydelta = 5 - rand() % 10;
231 dist2 = xdelta * xdelta + ydelta * ydelta;
238 if (IS_PORT(p) && IS_PORT(q))
240 DISP(q)[0] += xdelta * force;
241 DISP(q)[1] += ydelta * force;
242 DISP(p)[0] -= xdelta * force;
243 DISP(p)[1] -= ydelta * force;
252 double xdelta, ydelta;
256 doRep(p, q, xdelta, ydelta, xdelta * xdelta + ydelta * ydelta);
259 static void doNeighbor(
Grid * grid,
int i,
int j,
node_list * nodes)
265 double xdelta, ydelta;
272 fprintf(stderr,
" doNeighbor (%d,%d) : %d\n", i, j,
276 for (; nodes != 0; nodes = nodes->
next) {
278 for (qs = cellp->
nodes; qs != 0; qs = qs->
next) {
282 dist2 = xdelta * xdelta + ydelta * ydelta;
284 doRep(p, q, xdelta, ydelta, dist2);
290 static int gridRepulse(
Dt_t * dt,
cell * cellp,
Grid * grid)
302 fprintf(stderr,
"gridRepulse (%d,%d) : %d\n", i, j,
306 for (p = nodes; p != 0; p = p->
next) {
307 for (q = nodes; q != 0; q = q->
next)
312 doNeighbor(grid, i - 1, j - 1, nodes);
313 doNeighbor(grid, i - 1, j, nodes);
314 doNeighbor(grid, i - 1, j + 1, nodes);
315 doNeighbor(grid, i, j - 1, nodes);
316 doNeighbor(grid, i, j + 1, nodes);
317 doNeighbor(grid, i + 1, j - 1, nodes);
318 doNeighbor(grid, i + 1, j, nodes);
319 doNeighbor(grid, i + 1, j + 1, nodes);
330 double xdelta, ydelta;
337 dist2 = xdelta * xdelta + ydelta * ydelta;
338 while (dist2 == 0.0) {
339 xdelta = 5 - rand() % 10;
340 ydelta = 5 - rand() % 10;
341 dist2 = xdelta * xdelta + ydelta * ydelta;
348 DISP(q)[0] -= xdelta * force;
349 DISP(q)[1] -= ydelta * force;
350 DISP(p)[0] += xdelta * force;
351 DISP(p)[1] += ydelta * force;
354 static void updatePos(
Agraph_t * g,
double temp, bport_t * pp)
368 len2 = dx * dx + dy * dy;
375 double fact = temp / (sqrt(len2));
376 x =
ND_pos(n)[0] + dx * fact;
377 y =
ND_pos(n)[1] + dy * fact;
386 }
else if (d >= 1.0) {
387 ND_pos(n)[0] = 0.95 * x / d;
388 ND_pos(n)[1] = 0.95 * y / d;
400 #define FLOOR(d) ((int)floor(d))
404 static void gAdjust(
Agraph_t * g,
double temp, bport_t * pp,
Grid * grid)
415 DISP(n)[0] = DISP(n)[1] = 0;
423 applyAttr(n,
aghead(e), e);
428 updatePos(g, temp, pp);
433 static void adjust(
Agraph_t * g,
double temp, bport_t * pp)
443 DISP(n)[0] = DISP(n)[1] = 0;
452 applyAttr(n,
aghead(e), e);
456 updatePos(g, temp, pp);
471 boxf bb = { {0, 0}, {0, 0} };
474 double PItimes2 =
M_PI * 2.0;
491 size =
T_K * (sqrt((
double) nG) + 1.0);
496 }
else if (n_pos > 1) {
497 double alpha, area, width, height, quot;
498 ctr.
x = (bb.
LL.
x + bb.
UR.
x) / 2.0;
499 ctr.
y = (bb.
LL.
y + bb.
UR.
y) / 2.0;
503 quot = (width * height) / area;
507 }
else if (quot > 0.0) {
508 quot = 2.0 * sqrt(quot);
510 T_Ht = height / quot;
513 height = area / width;
516 }
else if (height > 0) {
517 width = area / height;
527 alpha = atan2(T_Ht,
T_Wd);
529 T_Ht = T_Ht / sin(alpha);
541 local_seed = time(
NULL);
543 local_seed = getpid() ^ time(
NULL);
561 ND_pos(np)[0] = T_Wd * cos(pp->alpha) + ctr.
x;
562 ND_pos(np)[1] = T_Ht * sin(pp->alpha) + ctr.
y;
585 p.
x = (p.
x * cnt +
ND_pos(op)[0]) / (cnt + 1);
586 p.
y = (p.
y * cnt +
ND_pos(op)[1]) / (cnt + 1);
597 }
else if (cnt == 1) {
598 ND_pos(np)[0] = 0.98 * p.
x + 0.1 * ctr.
x;
599 ND_pos(np)[1] = 0.9 * p.
y + 0.1 * ctr.
y;
602 double angle = PItimes2 *
drand48();
603 double radius = 0.9 *
drand48();
604 ND_pos(np)[0] = radius * T_Wd * cos(angle);
605 ND_pos(np)[1] = radius * T_Ht * sin(angle);
636 double l, max2 = 0.0;
642 l = dx * dx + dy * dy;
645 fprintf(stderr,
"%s: (%f,%f) (%f,%f)\n",
agnameof(np),
646 ND_pos(np)[0],
ND_pos(np)[1], DISP(np)[0], DISP(np)[1]);
648 fprintf(stderr,
"max delta = %f\n", sqrt(max2));
653 fprintf(stderr,
" %s -- %s (%f)\n",
agnameof(np),
668 bport_t *pp = PORTS(g);
674 reset = init_params(g, xpms);
677 ctr = initPositions(g, pp);
683 temp = cool(temp, i);
684 gAdjust(g, temp, pp, grid);
689 temp = cool(temp, i);
694 if ((ctr.
x != 0.0) || (ctr.
y != 0.0)) {
Agsym_t * agattr(Agraph_t *g, int kind, char *name, char *value)
CGRAPH_API Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
int agerr(agerrlevel_t level, const char *fmt,...)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
CGRAPH_API char * agnameof(void *)
void addGrid(Grid *g, int i, int j, Agnode_t *n)
Grid * mkGrid(int cellHint)
void fdp_initParams(graph_t *g)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
int late_int(void *obj, attrsym_t *attr, int def, int low)
void dumpstat(graph_t *g)
COORD dist2(Ppoint_t, Ppoint_t)
void walkGrid(Grid *g, int(*walkf)(Dt_t *, cell *, Grid *))
void adjustGrid(Grid *g, int nnodes)
CGRAPH_API Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
double late_double(void *obj, attrsym_t *attr, double def, double low)
EXTERN unsigned char Verbose
CGRAPH_API int agnnodes(Agraph_t *g)
int setSeed(graph_t *G, int dflt, long *seedp)
cell * findGrid(Grid *g, int i, int j)
void fdp_tLayout(graph_t *g, xparams *xpms)
double dist(Site *s, Site *t)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)