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


C# GraphNode.addNeighbour方法代码示例

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


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

示例1: connectNodeNeighbourhood

    /*
     * Connects a single node to the graph using the neighbourhood method. If the arrays passed are null,
     * the method will create them. If the arrays have already been allocated, they should be passed in in
     * order to reduce the time spent on creating and destroying objects.
     */
    private void connectNodeNeighbourhood(GraphNode<StateConfig> node, Tuple<int,float>[] distances, List<GraphNode<StateConfig>> neighbourhoodNodes)
    {
        if (distances == null){
            distances = new Tuple<int, float>[graph.nodes.Count];
        }
        if (neighbourhoodNodes == null){
            neighbourhoodNodes = new List<GraphNode<StateConfig>>(graph.nodes.Count);
        }
        GraphNode<StateConfig> comp;
        // initialise tuples in the distances array
        for (int i = 0; i < distances.Length; i++) {
            distances[i] = new Tuple<int, float>();
        }
        // Compute distances from the node we are currently looking at to
        // all other nodes in the graph
        for (int otherIndex = 0; otherIndex < graph.nodes.Count; otherIndex++) {
            distances[otherIndex].first = otherIndex;
            distances[otherIndex].second = node.content.computeDistanceEuclidean(graph.nodes[otherIndex].content);
        }

        // Sort the distances in ascending order so the closest nodes
        // are at the front of the array
        Array.Sort(distances, ((x,y)=> x.second.CompareTo(y.second)));

        // clear the neighbourhod nodes from the previous node.
        neighbourhoodNodes.Clear();
        // add nodes to the neighbourhood list until the nodes are no longer
        // in the neighbourhood
        for (int i = 0; i < distances.Length; i++) {
            if (distances[i].second > radius){
                break;
            }
            neighbourhoodNodes.Add(graph.nodes[distances[i].first]);
        }

        // Connect the node to its closest N neighbours, to which it is not already
        // connected via nodes in its neighbourhood.
        int connected = 0;
        for (int j = 0; connected < neighbours && j < distances.Length; j++) {
            comp = graph.nodes[distances[j].first];
            if (!neighbourConnected(node, comp, neighbourhoodNodes, radius)
                && occupancy.obstacleFreeStraightPath(node.getPosition(), comp.getPosition())){
                node.addNeighbour(ref comp);
                comp.addNeighbour(ref node);
                connected++;
            }
        }
    }
开发者ID:heuristicus,项目名称:DD2438,代码行数:53,代码来源:PRM.cs

示例2: connectNodeRadius

 /*
  * Connects a single node to the graph using the threshold method.
  */
 private void connectNodeRadius(GraphNode<StateConfig> node)
 {
     GraphNode<StateConfig> comp;
     // store distances to other nodes from the node currently
     // being checked
     for (int j = 0; j < graph.nodes.Count; j++) {
         comp = graph.nodes[j];
         if (node.content.computeDistanceEuclidean(comp.content) < radius
             && occupancy.obstacleFreeStraightPath(comp.content.getPosition(), node.content.getPosition())){
             node.addNeighbour(ref comp);
             comp.addNeighbour(ref node);
         }
     }
 }
开发者ID:heuristicus,项目名称:DD2438,代码行数:17,代码来源:PRM.cs

示例3: connectNodeKNN

    /*
     * Connects a single node to the graph. The distances array should be passed in if
     * already allocated to reduce the time spent creating and destroying objects. If the
     * array is null, one is created.
     */
    private void connectNodeKNN(GraphNode<StateConfig> node, Tuple<int,float>[] distances)
    {
        GraphNode<StateConfig> comp;
        // store distances to other nodes from the node currently
        // being checked
        if (distances == null){
            distances = new Tuple<int, float>[graph.nodes.Count];
            // initialise tuples in the distances array
            for (int i = 0; i < distances.Length; i++) {
                distances[i] = new Tuple<int, float>();
            }
        }
        // Compute distances from the node we are currently looking at to
        // all other nodes in the graph
        for (int k = 0; k < graph.nodes.Count; k++) {
            // self as max distance so that we don't connect to self
            distances[k].first = k;
            // TODO: might be quicker to use an approximate distance and then recompute
            distances[k].second = node.content.computeDistanceEuclidean(graph.nodes[k].content);
        }

        Array.Sort(distances, ((x,y)=> x.second.CompareTo(y.second)));

        // Connect the node to its closest N neighbours, if possible. If it is not possible
        // to make a connection, skip the node and attempt to connect the next closest.
        int connected = 0;
        for (int j = 0; connected < neighbours && j < distances.Length; j++) {
            comp = graph.nodes[distances[j].first];
            if (occupancy.obstacleFreeStraightPath(node.content.getPosition(), comp.content.getPosition())){
                node.addNeighbour(ref comp);
                comp.addNeighbour(ref node);
                connected++;
            }
        }
    }
开发者ID:heuristicus,项目名称:DD2438,代码行数:40,代码来源:PRM.cs


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