Debian Codegraph @

lib/dotgen/class1.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11
12 /*
13 * Classify edges for rank assignment phase to
14 * create temporary edges.
15 */
16
17 #include "config.h"
18
19 #include <dotgen/dot.h>
20 #include <stdbool.h>
21
22 bool nonconstraint_edge(edge_t *e) {
23 char *constr;
24
25 if (E_constr && (constr = agxget(e, E_constr))) {
26 if (constr[0] && !mapbool(constr))
27 return true;
28 }
29 return false;
30 }
31
32 static void
33 interclust1(graph_t * g, node_t * t, node_t * h, edge_t * e)
34 {
35 node_t *v, *t0, *h0;
36 int offset, t_len, h_len, t_rank, h_rank;
37
38 if (ND_clust(agtail(e)))
39 t_rank = ND_rank(agtail(e)) - ND_rank(GD_leader(ND_clust(agtail(e))));
40 else
41 t_rank = 0;
42 if (ND_clust(aghead(e)))
43 h_rank = ND_rank(aghead(e)) - ND_rank(GD_leader(ND_clust(aghead(e))));
44 else
45 h_rank = 0;
46 offset = ED_minlen(e) + t_rank - h_rank;
47 if (offset > 0) {
48 t_len = 0;
49 h_len = offset;
50 } else {
51 t_len = -offset;
52 h_len = 0;
53 }
54
55 v = virtual_node(g);
56 ND_node_type(v) = SLACKNODE;
57 t0 = UF_find(t);
58 h0 = UF_find(h);
59 edge_t *const rt = make_aux_edge(v, t0, t_len, CL_BACK * ED_weight(e));
60 edge_t *const rh = make_aux_edge(v, h0, h_len, ED_weight(e));
61 ED_to_orig(rt) = ED_to_orig(rh) = e;
62 }
63 void class1(graph_t * g)
64 {
65 node_t *n, *t, *h;
66 edge_t *e, *rep;
67
68 mark_clusters(g);
69 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
70 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
71
72 /* skip edges already processed */
73 if (ED_to_virt(e))
74 continue;
75
76 /* skip edges that we want to ignore in this phase */
77 if (nonconstraint_edge(e))
78 continue;
79
80 t = UF_find(agtail(e));
81 h = UF_find(aghead(e));
82
83 /* skip self, flat, and intra-cluster edges */
84 if (t == h)
85 continue;
86
87
88 /* inter-cluster edges require special treatment */
89 if (ND_clust(t) || ND_clust(h)) {
90 interclust1(g, agtail(e), aghead(e), e);
91 continue;
92 }
93
94 if ((rep = find_fast_edge(t, h)))
95 merge_oneway(e, rep);
96 else
97 virtual_edge(t, h, e);
98 }
99 }
100 }
101