38 for (i = L->
size; i >= 0; i--)
50 for (c = 0; c <
GD_comp(g).size; c++) {
72 if (f1 && (f == f1)) {
150 static char *name[] = {
"same",
"min",
"source",
"max",
"sink",
NULL };
225 cluster_leader(
graph_t * clust)
265 make_new_cluster(g, subg);
268 cluster_leader(subg);
284 c = rank_set_class(subg);
287 collapse_cluster(rg, subg);
289 collapse_rankset(rg, subg, c);
291 else collapse_sets(rg, subg);
294 Collapsing leaves is currently obsolete
297 if (
agget(subg,
"ordering"))
310 collapse_cluster(g, subg);
345 while ((e =
ND_out(n).list[0])) {
352 while ((e =
ND_in(n).list[0])) {
392 if ((s =
agget(g,
"nslimit1")))
394 for (c = 0; c <
GD_comp(g).size; c++) {
419 if ((leader != n) && (!asp || (
ND_rank(n) == 0)))
455 v = strtol (s, &ep, 10);
466 static int nVirtualEdges = 0;
476 if (virtualEdgeHeadList !=
NULL) {
477 free(virtualEdgeHeadList);
479 if (virtualEdgeTailList !=
NULL) {
480 free(virtualEdgeTailList);
485 for (lc = 0; lc <
ND_in(n).size; lc++) {
486 e =
ND_in(n).list[lc];
496 for (lc = 0, cnt = 0; lc <
ND_in(n).size; lc++) {
497 e =
ND_in(n).list[lc];
499 virtualEdgeHeadList[cnt] = e->head;
500 virtualEdgeTailList[cnt] = e->tail;
502 printf(
"saved virtual edge: %s->%s\n",
503 virtualEdgeTailList[cnt]->name,
504 virtualEdgeHeadList[cnt]->name);
512 restoreVirtualEdges(
graph_t *g)
517 for (i = 0; i < nVirtualEdges; i++) {
518 if (virtualEdgeTailList[i] && virtualEdgeHeadList[i]) {
520 printf(
"restoring virtual edge: %s->%s\n",
521 virtualEdgeTailList[i]->name, virtualEdgeHeadList[i]->name);
526 printf(
"restored %d virt edges\n", nVirtualEdges);
556 if (minmax_edges2(g, p))
560 setRanks(g, N_level);
569 expand_ranksets(g, asp);
575 if (
agget (g,
"newrank")) {
587 return (strncmp(
agnameof(g),
"cluster", 7) == 0);
637 potential_leaf(g,
AGMKOUT(e), n);
643 potential_leaf(g, e, n);
657 #define BACKWARD_PENALTY 1000
658 #define STRONG_CLUSTER_WEIGHT 1000
660 #define ROOT "\177root"
661 #define TOPNODE "\177top"
662 #define BOTNODE "\177bot"
667 #define ND_comp(n) ND_hops(n)
674 make_new_cluster(p, g);
678 static int is_empty(
graph_t * g)
683 static int is_a_strong_cluster(
graph_t * g)
692 static int rankset_kind(
graph_t * g)
694 char *str =
agget(g,
"rank");
697 if (!strcmp(str,
"min"))
699 if (!strcmp(str,
"source"))
701 if (!strcmp(str,
"max"))
703 if (!strcmp(str,
"sink"))
705 if (!strcmp(str,
"same"))
711 static int is_nonconstraint(
edge_t * e)
727 set =
ND_set(n) = find(set);
736 return (
ND_set(find(n)) = find(leader));
750 union_one(leader, n);
754 static void compile_samerank(
graph_t * ug,
graph_t * parent_clust)
766 set_parent(ug, parent_clust);
771 clust = parent_clust;
775 compile_samerank(s, clust);
790 switch (rankset_kind(ug)) {
794 leader = union_all(ug);
800 leader = union_all(ug);
804 leader = union_all(ug);
817 node_t *up = union_all(ug);
835 static int is_internal_to_cluster(
edge_t * e)
842 par = dot_lca(ct, ch);
845 if ((par == ct) || (par == ch))
885 static void merge(
edge_t * e,
int minlen,
int weight)
898 agerr(
AGERR,
"ranking: failure to create strong constraint edge between nodes %s and %s\n",
917 sprintf (buf,
"_weak_%d",
id++);
918 v = makeXnode(g, buf);
919 e =
agedge(g, v, t, 0, 1);
920 f =
agedge(g, v, h, 0, 1);
939 if (is_nonconstraint(e))
948 if (is_internal_to_cluster(e)) {
956 strong(Xg, Xt, Xh, e);
958 if (is_a_strong_cluster(tc) || is_a_strong_cluster(hc))
961 strong(Xg, Xt, Xh, e);
978 if (!top) top = makeXnode(Xg,
TOPNODE);
979 agedge(Xg, top, rep, 0, 1);
983 if (!bot) bot = makeXnode(Xg,
BOTNODE);
984 agedge(Xg, rep, bot, 0, 1);
988 e =
agedge(Xg, top, bot, 0, 1);
993 compile_clusters(sub, Xg, top, bot);
1016 for (e =
agfstout(g, v); e; e = f) {
1020 reverse_edge2(g, e);
1029 static void break_cycles(
graph_t * g)
1043 static void setMinMax (
graph_t* g,
int doRoot)
1088 minrk =
N_NEW(ncc+1,
int);
1089 for (i = 1; i <= ncc; i++)
1118 setMinMax(g, doRoot);
1146 static int connect_components(
graph_t * g)
1161 (void)
agedge(g, root, n, 0, 1);
1169 static void add_fast_edges (
graph_t * g)
1182 {
int *sz = arg;
agbindrec(graph,
"level graph rec",sz[0],
TRUE); }
1184 {
int *sz = arg;
agbindrec(node,
"level node rec",sz[1],
TRUE); }
1186 {
int *sz = arg;
agbindrec(edge,
"level edge rec",sz[2],
TRUE); }
1187 static Agcbdisc_t mydisc = { {my_init_graph,0,0}, {my_init_node,0,0}, {my_init_edge,0,0} };
1209 if ((s =
agget(g,
"nslimit1")))
1214 compile_samerank(g, 0);
1215 compile_nodes(g, Xg);
1216 compile_edges(g, Xg);
1217 compile_clusters(g, Xg, 0, 0);
1219 ncc = connect_components(Xg);
1220 add_fast_edges (Xg);
1227 if ((s =
agget(g,
"searchsize")))
1231 rank2(Xg, 1, maxiter, ssize);
1233 readout_levels(g, Xg, ncc);
CGRAPH_API Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
CGRAPH_API Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, char *value)
#define elist_append(item, L)
CGRAPH_API Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
void dot_scan_ranks(graph_t *g)
#define GD_has_sinkrank(g)
void decompose(graph_t *g, int pass)
CGRAPH_API void agpushdisc(Agraph_t *g, Agcbdisc_t *disc, void *state)
CGRAPH_API int agdelete(Agraph_t *g, void *obj)
void initEdgeTypes(graph_t *g)
#define alloc_elist(n, L)
int agerr(agerrlevel_t level, const char *fmt,...)
CGRAPH_API Agraph_t * agfstsubg(Agraph_t *g)
CGRAPH_API int agcontains(Agraph_t *, void *)
EXTERN Agsym_t * E_constr
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
int node_induce(Agraph_t *g, Agraph_t *eg)
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
int is_cluster(Agraph_t *)
#define ZALLOC(size, ptr, type, osize)
char * agget(void *obj, char *name)
node_t * UF_find(node_t *n)
CGRAPH_API Agraph_t * agnxtsubg(Agraph_t *subg)
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 dot_rank(Agraph_t *, aspect_t *)
CGRAPH_API Agedge_t * agsubedge(Agraph_t *g, Agedge_t *e, int createflag)
boolean mapBool(char *p, boolean dflt)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
Agraph_t * graph(char *name)
#define STRONG_CLUSTER_WEIGHT
Agraph_t * dot_root(void *p)
void UF_singleton(node_t *u)
#define GD_has_sourcerank(g)
EXTERN unsigned char Verbose
CGRAPH_API int agnnodes(Agraph_t *g)
void init_UF_size(graph_t *g)
int is_a_cluster(Agraph_t *g)
Agnode_t * node(Agraph_t *g, char *name)
struct Agedgeinfo_t Agedgeinfo_t
int rank2(graph_t *g, int balance, int maxiter, int search_size)
CGRAPH_API Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
struct Agraphinfo_t Agraphinfo_t
void reverse_edge(edge_t *e)
CGRAPH_API void * agbindrec(void *obj, char *name, unsigned int size, int move_to_front)
CGRAPH_API Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
#define agfindedge(g, t, h)
CGRAPH_API int agnedges(Agraph_t *g)
char * agxget(void *obj, Agsym_t *sym)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
int maptoken(char *p, char **name, int *val)
void rank3(graph_t *g, aspect_t *asp)
node_t * UF_union(node_t *u, node_t *v)
Agedge_t * edge(Agraph_t *g, Agnode_t *t, Agnode_t *h)