本文整理汇总了TypeScript中graphlib.alg.tarjan方法的典型用法代码示例。如果您正苦于以下问题:TypeScript alg.tarjan方法的具体用法?TypeScript alg.tarjan怎么用?TypeScript alg.tarjan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphlib.alg
的用法示例。
在下文中一共展示了alg.tarjan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateOrder
export function generateOrder(proj: project.Project) {
const inputGraph = new Graph<FileInput, {}>({ directed: true });
for (const file of proj.files) {
inputGraph.setNode(file.filename, {
file,
groupName: undefined
});
}
for (const file of proj.files) {
for (const dependency of file.dependencies) {
inputGraph.setEdge(file.filename, dependency.filename);
}
}
const acyclicGraph = new Graph<FileGroup, {}>({ directed: true });
for (const group of alg.tarjan(inputGraph)) {
acyclicGraph.setNode(group[0], {
filenames: group
});
for (const member of group) {
inputGraph.node(member).groupName = group[0];
}
}
for (const filename of inputGraph.nodes()) {
const groupName = inputGraph.node(filename).groupName;
for (const edge of inputGraph.inEdges(filename)) {
const otherGroup = inputGraph.node(edge.w).groupName;
if (groupName !== otherGroup) acyclicGraph.setEdge(groupName, otherGroup);
}
}
const order = alg.topsort(acyclicGraph);
let index = 0;
for (const groupName of order) {
const group = acyclicGraph.node(groupName);
const component: file.SourceFile[] = [];
const cyclic = group.filenames.length !== 1;
for (const filename of group.filenames) {
const file = inputGraph.node(filename).file;
if (cyclic) {
file.hasCircularDependencies = true;
file.connectedComponent = component;
component.push(file);
} else {
file.hasCircularDependencies = false;
}
file.orderIndex = index++;
proj.orderFiles.push(file);
}
}
}
示例2: test_graph
function test_graph() {
var g = new graphlib.Graph({
compound: true,
directed: true,
multigraph: true
});
g.setEdge('a', 'b');
g.setEdge('a', 'b', 1.023, 'test');
g.setEdge({ v: 'a', w: 'b', name: 'test' }, 1.023);
g.hasEdge('a', 'b', 'test');
g.hasEdge({ v: 'a', w: 'b', name: 'test' });
g.removeEdge('a', 'b', 'test');
g.removeEdge({ v: 'a', w: 'b', name: 'test' });
g.edge('a', 'b', 'test');
g.edge({v: 'a', w: 'b', name: 'test'});
g.setDefaultNodeLabel({});
g.setDefaultNodeLabel(() => 42);
g.setDefaultEdgeLabel({});
g.setDefaultEdgeLabel(() => 'e42');
g.setNodes(['a', 'b', 'c'], 42);
g.setParent('d', 'a');
g.setParent('d');
g.parent('d');
g.children('a');
g.filterNodes(v => true);
g.setPath(['a', 'b', 'c'], 42);
graphlib.json.read(graphlib.json.write(g));
graphlib.alg.dijkstra(g, 'a', e => g.edge(e));
graphlib.alg.dijkstraAll(g, e => g.edge(e));
graphlib.alg.dijkstraAll(g);
graphlib.alg.findCycles(g);
graphlib.alg.isAcyclic(g);
graphlib.alg.prim(g, e => g.edge(e));
graphlib.alg.tarjan(g);
graphlib.alg.topsort(g);
graphlib.alg.preorder(g, g.nodes());
graphlib.alg.postorder(g, g.nodes());
}
示例3: test_graph
function test_graph() {
var g = new graphlib.Graph();
g.setEdge('a', 'b');
g.setEdge('a', 'b', 1.023);
g.edge('a', 'b');
g.edge({v: 'a', w: 'b'});
graphlib.json.read(graphlib.json.write(g));
graphlib.alg.dijkstra(g, 'a', e => g.edge(e));
graphlib.alg.dijkstraAll(g, e => g.edge(e));
graphlib.alg.dijkstraAll(g);
graphlib.alg.findCycles(g);
graphlib.alg.isAcyclic(g);
graphlib.alg.prim(g, e => g.edge(e));
graphlib.alg.tarjan(g);
graphlib.alg.topsort(g);
}