/* initGraphAttrs: * Set attributes based on original root graph. * This is obtained by taking a node of g, finding its node * in the original graph, and finding that node's graph. */ static void initGraphAttrs(Agraph_t * g, circ_state * state) { static Agraph_t *rootg; static attrsym_t *N_artpos; static attrsym_t *N_root; static attrsym_t *G_mindist; static char *rootname; Agraph_t *rg; node_t *n = agfstnode(g); rg = agraphof(ORIGN(n)); if (rg != rootg) { /* new root graph */ state->blockCount = 0; rootg = rg; G_mindist = agattr(rootg,AGRAPH, "mindist", NULL); N_artpos = agattr(rootg,AGNODE, "articulation_pos", NULL); N_root = agattr(rootg,AGNODE, "root", NULL); } rootname = agget(rootg, "root"); initBlocklist(&state->bl); state->orderCount = 1; state->min_dist = late_double(rootg, G_mindist, MINDIST, 0.0); state->N_artpos = N_artpos; state->N_root = N_root; state->rootname = rootname; }
block_t *mkBlock(Agraph_t * g) { block_t *sn; sn = NEW(block_t); initBlocklist(&sn->children); sn->sub_graph = g; return sn; }
/* create_block_tree: * Construct block tree by peeling nodes from block list in state. * When done, return root. The block list is empty * FIX: use largest block as root */ block_t *createBlocktree(Agraph_t * g, circ_state * state) { block_t *bp; block_t *next; block_t *root; int min; /* int ordercnt; */ find_blocks(g, state); bp = state->bl.first; /* if root chosen, will be first */ /* Otherwise, just pick first as root */ root = bp; /* Find node with minimum VAL value to find parent block */ /* FIX: Should be some way to avoid search below. */ /* ordercnt = state->orderCount; */ for (bp = bp->next; bp; bp = next) { Agnode_t *n; Agnode_t *parent; Agnode_t *child; Agraph_t *subg = bp->sub_graph; child = n = agfstnode(subg); min = VAL(n); parent = PARENT(n); for (n = agnxtnode(subg, n); n; n = agnxtnode(subg, n)) { if (VAL(n) < min) { child = n; min = VAL(n); parent = PARENT(n); } } SET_PARENT(parent); CHILD(bp) = child; next = bp->next; /* save next since list insertion destroys it */ appendBlock(&(BLOCK(parent)->children), bp); } initBlocklist(&state->bl); /* zero out list */ return root; }
/* find_blocks: */ static void find_blocks(Agraph_t * g, circ_state * state) { Agnode_t *n; Agnode_t *root = NULL; block_t *rootBlock = NULL; blocklist_t ublks; #ifdef USER_BLOCKS graph_t *clust_subg; graph_t *mg; edge_t *me; node_t *mm; int isRoot; #endif initBlocklist(&ublks); /* check to see if there is a node which is set to be the root */ if (state->rootname) { root = agfindnode(g, state->rootname); } if (!root && state->N_root) { for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (late_bool(ORIGN(n), state->N_root, 0)) { root = n; break; } } } #ifdef USER_BLOCKS /* process clusters first */ /* by construction, all subgraphs are blocks and are non-empty */ mm = g->meta_node; mg = mm->graph; for (me = agfstout(mg, mm); me; me = agnxtout(mg, me)) { block_t *block; clust_subg = agusergraph(me->head); isRoot = 0; block = mkBlock(clust_subg); /* block = makeBlock(g, state); */ for (n = agfstnode(clust_subg); n; n = agnxtnode(clust_subg, n)) { if (!BCDONE(n)) { /* test not necessary if blocks disjoint */ SET_BCDONE(n); BLOCK(n) = block; if (n == root) isRoot = 1; } } if (isRoot) { /* Assume blocks are disjoint, so don't check if rootBlock is * already assigned. */ rootBlock = block; insertBlock(&state->bl, block); } else { appendBlock(&state->bl, block); } } ublks.first = state->bl.first; ublks.last = state->bl.last; #endif if (!root) root = agfstnode(g); dfs(g, root, state, !rootBlock); #ifdef USER_BLOCKS /* If g has user-supplied blocks, it may be disconnected. * We then fall into the following ugly loop. * We are guaranteed !VISITED(n) and PARENT(n) has been * set to a visited node. */ if (ublks.first) { while (n = findUnvisited(&ublks)) { dfs(g, n, state, 0); } } #endif }