Debian Codegraph @

lib/order/add-subgraph-constraints.js

raw symbols SCIP
1 var _ = require("../lodash");
2
3 module.exports = addSubgraphConstraints;
4
5 function addSubgraphConstraints(g, cg, vs) {
6 var prev = {},
7 rootPrev;
8
9 _.forEach(vs, function(v) {
10 var child = g.parent(v),
11 parent,
12 prevChild;
13 while (child) {
14 parent = g.parent(child);
15 if (parent) {
16 prevChild = prev[parent];
17 prev[parent] = child;
18 } else {
19 prevChild = rootPrev;
20 rootPrev = child;
21 }
22 if (prevChild && prevChild !== child) {
23 cg.setEdge(prevChild, child);
24 return;
25 }
26 child = parent;
27 }
28 });
29
30 /*
31 function dfs(v) {
32 var children = v ? g.children(v) : g.children();
33 if (children.length) {
34 var min = Number.POSITIVE_INFINITY,
35 subgraphs = [];
36 _.each(children, function(child) {
37 var childMin = dfs(child);
38 if (g.children(child).length) {
39 subgraphs.push({ v: child, order: childMin });
40 }
41 min = Math.min(min, childMin);
42 });
43 _.reduce(_.sortBy(subgraphs, "order"), function(prev, curr) {
44 cg.setEdge(prev.v, curr.v);
45 return curr;
46 });
47 return min;
48 }
49 return g.node(v).order;
50 }
51 dfs(undefined);
52 */
53 }