当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript alg.dijkstra方法代码示例

本文整理汇总了TypeScript中graphlib.alg.dijkstra方法的典型用法代码示例。如果您正苦于以下问题:TypeScript alg.dijkstra方法的具体用法?TypeScript alg.dijkstra怎么用?TypeScript alg.dijkstra使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphlib.alg的用法示例。


在下文中一共展示了alg.dijkstra方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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());
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:42,代码来源:graphlib-tests.ts

示例2: 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);
}
开发者ID:HawkHouseIntegration,项目名称:DefinitelyTyped,代码行数:20,代码来源:graphlib-tests.ts

示例3: nodesSortedByDistance

    private nodesSortedByDistance(graph : Graphlib.Graph<any, any>, source : any) : Array<any> {
        let distances = Graphlib.alg.dijkstra(graph, source);
        let nodes:Array<any> = [];

        for (var prop in distances) {
            if (distances.hasOwnProperty(prop)) {
                let distanceToSource = distances[prop].distance;
                if(distanceToSource == Number.POSITIVE_INFINITY) {
                    throw new Error('pipeline graph contains unconnected nodes: ' + Graphlib.Json.write(graph));
                }
                nodes.push({nodeId : prop, distance: distanceToSource})
            }
        }

        let sortByDistance = (node1, node2) => { return node1.distance - node2.distance };

        let sortedNodes = nodes.sort(sortByDistance);

        return sortedNodes.map((item) => {return item.nodeId});
    }
开发者ID:mserranom,项目名称:lean-ci,代码行数:20,代码来源:PipelineGraph.ts

示例4: createSubgraph

    createSubgraph(repo : model.RepositorySchema) : DependencyGraph {

        let newGraph = cloneGraph(this._graph);

        let dijkstraAlgResult = Graphlib.alg.dijkstra(this._graph, repo.name); // or floydWarshall might be faster

        let isValidNode = node => {return dijkstraAlgResult.hasOwnProperty(node) && dijkstraAlgResult[node].distance  != "Infinity"};

        this._graph.nodes().forEach((node) => {
            if(!isValidNode(node)) {
                newGraph.removeNode(node);
            }
        });

        let newDependencyGraph = new DependencyGraph();
        newDependencyGraph._graph = newGraph;
        newDependencyGraph._repos = newGraph.nodes().map(repoId => {return newGraph.node(repoId)});
        newDependencyGraph._dependencies = newGraph.edges().map((edge) => { return {up : edge.v, down : edge.w} });

        return newDependencyGraph;
    }
开发者ID:mserranom,项目名称:lean-ci,代码行数:21,代码来源:DependencyGraph.ts


注:本文中的graphlib.alg.dijkstra方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。