22 #define SCALE2 (SCALE/2)
37 static int cmpitem(
Dt_t * d,
int *p1,
int *p2,
Dtdisc_t * disc)
48 offsetof(
nitem, link),
57 static int distY(
box * b1,
box * b2)
59 return ((b1->
UR.
y - b1->
LL.
y) + (b2->
UR.
y - b2->
LL.
y)) / 2;
62 static int distX(
box * b1,
box * b2)
64 return ((b1->
UR.
x - b1->
LL.
x) + (b2->
UR.
x - b2->
LL.
x)) / 2;
86 return (ydelta <= xdelta);
108 return (xdelta <= ydelta);
184 for (i = 0; (e =
ND_out(n).list[i]); i++) {
189 for (i = 0; (e =
ND_in(n).list[i]); i++) {
206 sprintf(buf,
"n%d",
id++);
251 double delta =
dist(&p->
bb, &nxp->
bb);
319 if (oldval != p->
val) {
330 if (oldval != p->
val) {
382 if (oldval != p->
val) {
386 if (nxt->
val != oldval)
403 mapGraphs(vg, cg, dist);
413 if ((n == root) || (!p))
426 e =
agedge(cg, root, an, 1);
431 e =
agedge(cg, an, vn, 1);
444 static void closeGraph(
graph_t * cg)
467 for (i = 0; i < nnodes; i++) {
473 cg = mkConstraintG(g, list, ifn, distX);
475 cg = mkNConstraintG(g, list, ifn, distX);
479 for (i = 0; i < nnodes; i++) {
480 int newpos, oldpos, delta;
483 delta = newpos - oldpos;
505 for (i = 0; i < nnodes; i++) {
511 cg = mkConstraintG(g, list, ifn, distY);
513 cg = mkNConstraintG(g, list, ifn, distY);
523 sprintf(buf,
"%d",
ND_rank(n));
534 for (i = 0; i < nnodes; i++) {
535 int newpos, oldpos, delta;
538 delta = newpos - oldpos;
549 #define overlap(pb,qb) \
550 ((pb.LL.x <= qb.UR.x) && (qb.LL.x <= pb.UR.x) && \
551 (pb.LL.y <= qb.UR.y) && (qb.LL.y <= pb.UR.y))
555 static int overlaps(
nitem * p,
int cnt)
561 for (i = 0; i < cnt - 1; i++) {
563 for (j = i + 1; j < cnt; j++) {
646 initItem(n, p, margin);
650 if (overlaps(nlist, nnodes)) {
655 constrainX(g, nlist, nnodes, intersectY, 1);
656 constrainY(g, nlist, nnodes, intersectX, 1);
659 constrainY(g, nlist, nnodes, intersectX, 1);
660 constrainX(g, nlist, nnodes, intersectY, 1);
663 constrainX(g, nlist, nnodes, intersectY0, 1);
664 constrainY(g, nlist, nnodes, intersectX, 1);
666 constrainY(g, nlist, nnodes, intersectX0, 1);
667 constrainX(g, nlist, nnodes, intersectY, 1);
669 constrainX(g, nlist, nnodes, intersectY, 0);
670 constrainY(g, nlist, nnodes, intersectX, 0);
673 constrainY(g, nlist, nnodes, intersectX, 0);
674 constrainX(g, nlist, nnodes, intersectY, 0);
677 constrainY(g, nlist, nnodes, intersectX0, 0);
678 constrainX(g, nlist, nnodes, intersectY, 0);
682 constrainX(g, nlist, nnodes, intersectY0, 0);
683 constrainY(g, nlist, nnodes, intersectX, 0);
687 for (i = 0; i < nnodes; i++) {
715 else if (p->
x > q->
x)
717 else if (p->
y < q->
y)
719 else if (p->
y > q->
y)
725 static double compress(
info * nl,
int nn)
733 for (i = 0; i < nn; i++) {
735 for (j = i + 1; j < nn; j++) {
761 static pointf *mkOverlapSet(
info * nl,
int nn,
int *cntp)
770 for (i = 0; i < nn; i++) {
772 for (j = i + 1; j < nn; j++) {
808 double cost, bestcost;
813 aarr[0].
y = HUGE_VAL;
817 barr[m].
x = aarr[m].
x;
819 for (k = m - 1; k >= 0; k--) {
820 barr[k].
x = aarr[k].
x;
821 barr[k].
y =
MAX(aarr[k + 1].y, barr[k + 1].y);
825 for (k = 0; k <= m; k++) {
826 cost = barr[k].
x * barr[k].
y;
827 if (cost < bestcost) {
832 assert(bestcost < HUGE_VAL);
833 scale.
x = barr[best].
x;
834 scale.
y = barr[best].
y;
843 static double computeScale(
pointf * aarr,
int m)
851 for (i = 1; i <= m; i++) {
912 s.
x = s.
y = compress(nlist, nnodes);
917 if (
Verbose) fprintf(stderr,
"compress %g \n", s.
x);
919 aarr = mkOverlapSet(nlist, nnodes, &m);
928 s.
x = s.
y = computeScale(aarr, m);
930 s = computeScaleXY(aarr, m);
933 if (
Verbose) fprintf(stderr,
"scale by %g,%g \n", s.
x, s.
y);
937 for (i = 0; i < nnodes; i++) {
int(* Dtcompar_f)(Dt_t *, void *, void *, Dtdisc_t *)
unsigned int(* Dthash_f)(Dt_t *, void *, Dtdisc_t *)
CGRAPH_API Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
#define RALLOC(size, ptr, type)
int(* intersectfn)(nitem *, nitem *)
CGRAPH_API Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
CDT_API int dtclose(Dt_t *)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, char *value)
#define elist_append(item, L)
void *(* Dtmake_f)(Dt_t *, void *, Dtdisc_t *)
expand_t sepFactor(graph_t *g)
CDT_API Dtlink_t * dtflatten(Dt_t *)
CGRAPH_API Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
int agxset(void *obj, Agsym_t *sym, char *value)
int(* sortfn_t)(const void *, const void *)
int cAdjust(graph_t *, int)
CGRAPH_API Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
#define alloc_elist(n, L)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
int intersect(Ppoint_t a, Ppoint_t b, Ppoint_t c, Ppoint_t d)
int scAdjust(graph_t *, int)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
#define PS2INCH(a_points)
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
CGRAPH_API Agdesc_t Agstrictdirected
int rank(graph_t *g, int balance, int maxiter)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
CGRAPH_API int agclose(Agraph_t *g)
CGRAPH_API char * agnameof(void *)
void *(* Dtmemory_f)(Dt_t *, void *, size_t, Dtdisc_t *)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
real cg(Operator Ax, Operator precond, int n, int dim, real *x0, real *rhs, real tol, int maxit, int *flag)
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)
CGRAPH_API Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
int(* Dtevent_f)(Dt_t *, int, void *, Dtdisc_t *)
CGRAPH_API void * agbindrec(void *obj, char *name, unsigned int size, int move_to_front)
int(* distfn)(box *, box *)
void(* Dtfree_f)(Dt_t *, void *, Dtdisc_t *)
CGRAPH_API Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
#define agfindedge(g, t, h)
double dist(Site *s, Site *t)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
CDT_API Dtmethod_t * Dtobag