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


C# NodeList.GetNodeById方法代码示例

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


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

示例1: CenterOfMass_algorithm

 /// <summary>
 /// 质心算法
 /// </summary>
 /// <param name="nodeList"></param>
 /// <param name="j">质心算法中取j跳范围内的信标节点帮助计算</param>
 public static void CenterOfMass_algorithm(NodeList nodeList, int j)
 {
     List<Node> generalNodeList = nodeList.GetAllGeneralNode();
     foreach (GeneralNode gn in generalNodeList)
     {
         //循环,进行定位
         List<Node> AssistLocateNodeList = new List<Node>();
         //将信标节点加入到协助定位的节点列表中
         foreach (int nodeId in gn.HopCountTable.Keys)
         {
             if (nodeList.GetNodeById(nodeId).IsBeaconNode && gn.HopCountTable[nodeId] <= j)
             {
                 AssistLocateNodeList.Add(nodeList.GetNodeById(nodeId));
             }
         }
         if (AssistLocateNodeList.Count >= 1)
         {
             double sumEstimatedX = 0d;
             double sumEstimatedY = 0d;
             foreach (BeaconNode bn in AssistLocateNodeList)
             {
                 sumEstimatedX += bn.RealX;
                 sumEstimatedY += bn.RealY;
             }
             gn.IsLocatable = true;
             gn.IsAlreadyLocated = true;
             gn.EstimatedX = sumEstimatedX / AssistLocateNodeList.Count;
             gn.EstimatedY = sumEstimatedY / AssistLocateNodeList.Count;
         }
     }
 }
开发者ID:unclechao,项目名称:Revised-DV-Hop-algorithm,代码行数:36,代码来源:AlgorithmFunction.cs

示例2: DV_Hop_algorithm

        /// <summary>
        /// 传统DV-Hop算法计算hopSize
        /// </summary>
        /// <param name="nodeList"></param>
        public static void DV_Hop_algorithm(NodeList nodeList)
        {
            List<Node> generalNodeList = nodeList.GetAllGeneralNode();
            foreach (GeneralNode gn in generalNodeList)
            {
                //遍历每个未知节点,求跳距
                Dictionary<int, int> beaconNodeDic = new Dictionary<int, int>();
                //取得所有与未知节点可以通信的信标节点
                foreach (int key in gn.HopCountTable.Keys)
                {
                    if (nodeList.GetNodeById(key).IsBeaconNode)
                    {
                        beaconNodeDic.Add(key, gn.HopCountTable[key]);
                    }
                }
                //找到beaconNodeDic中与未知节点跳数最小的信标节点
                int shortestHop = int.MaxValue;
                int shortestHopNodeId = -1;
                foreach (int key in beaconNodeDic.Keys)
                {
                    if (beaconNodeDic[key] < shortestHop)
                    {
                        shortestHop = beaconNodeDic[key];
                        shortestHopNodeId = key;
                    }
                }
                Node nearestBeaconNode = nodeList.GetNodeById(shortestHopNodeId);
                //找出能与nearestBeaconNode信标节点通信的其他信标节点
                Dictionary<int, int> assistLocateBeaconNodeDic = new Dictionary<int, int>();
                if (nearestBeaconNode == null)
                {
                    //如果没有能与其通信的信标节点
                    gn.IsLocatable = false;
                    gn.IsAlreadyLocated = false;
                }
                else
                {
                    foreach (int id in nearestBeaconNode.HopCountTable.Keys)
                    {
                        if (nodeList.GetNodeById(id).IsBeaconNode)
                        {
                            assistLocateBeaconNodeDic.Add(id, nearestBeaconNode.HopCountTable[id]);
                        }
                    }
                    //计算hopsize
                    double sumDistance = 0d;
                    int sumHop = 0;
                    foreach (int nodeId in assistLocateBeaconNodeDic.Keys)
                    {
                        sumDistance += CalculateNodeDistance(nearestBeaconNode, nodeList.GetNodeById(nodeId));
                        sumHop += CalculateNodeHop(nearestBeaconNode, nodeList.GetNodeById(nodeId));
                    }
                    gn.DV_Hop_Hopsize = sumDistance / sumHop;
                    //利用三边测量法定位
                    List<Node> assistLocateBeaconNode = new List<Node>();
                    foreach (int key in gn.HopCountTable.Keys)
                    {
                        if (nodeList.GetNodeById(key).IsBeaconNode && assistLocateBeaconNode.Count < 3)
                        {
                            assistLocateBeaconNode.Add(nodeList.GetNodeById(key));
                        }
                    }
                    //判断信标节点数量,若小于3,则无法进行定位
                    if (assistLocateBeaconNode.Count < 3)
                    {
                        gn.IsLocatable = false;
                    }
                    else
                    {
                        //三边测量法定位
                        double[] pos = Three_edge_measurement.trilateration(assistLocateBeaconNode[0].RealX, assistLocateBeaconNode[0].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[0]), assistLocateBeaconNode[1].RealX, assistLocateBeaconNode[1].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[1]), assistLocateBeaconNode[2].RealX, assistLocateBeaconNode[2].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[2]));
                        gn.EstimatedX = pos[0];
                        gn.EstimatedY = pos[1];
                        if (gn.EstimatedX < 0)
                        {
                            gn.EstimatedX = 0;
                        }
                        if (gn.EstimatedY < 0)
                        {
                            gn.EstimatedY = 0;
                        }
                        if (gn.EstimatedX > 100)
                        {
                            gn.EstimatedX = 100;
                        }
                        if (gn.EstimatedY > 100)
                        {
                            gn.EstimatedY = 100;
                        }
                        gn.IsLocatable = true;
                        gn.IsAlreadyLocated = true;
                    }
                }

            }
        }
开发者ID:unclechao,项目名称:Revised-DV-Hop-algorithm,代码行数:100,代码来源:AlgorithmFunction.cs

示例3: LocateGeneralNode

 /// <summary>
 /// 定位未知节点
 /// </summary>
 /// <param name="nodeList"></param>
 private static void LocateGeneralNode(NodeList nodeList, int k)
 {
     //取得所有未知节点,遍历并定位
     List<Node> generalNodeList = nodeList.GetAllGeneralNode();
     foreach (GeneralNode gn in generalNodeList)
     {
         //辅助DV-Hop算法定位节点集合
         List<Node> assistLocateBeaconNode = new List<Node>();
         //辅助质心算法定位节点集合
         List<Node> assistCOMLocateNodeList = new List<Node>();
         foreach (int key in gn.HopCountTable.Keys)
         {
             if (nodeList.GetNodeById(key).IsBeaconNode && assistLocateBeaconNode.Count < 3)
             {
                 assistLocateBeaconNode.Add(nodeList.GetNodeById(key));
             }
             if (nodeList.GetNodeById(key).IsBeaconNode && gn.HopCountTable[key] == 1)
             {
                 assistCOMLocateNodeList.Add(nodeList.GetNodeById(key));
             }
         }
         if (assistCOMLocateNodeList.Count >= k)
         {
             //信标节点数量大于事先设定阈值,使用质心算法定位
             double sumEstimatedX = 0d;
             double sumEstimatedY = 0d;
             foreach (BeaconNode bn in assistCOMLocateNodeList)
             {
                 sumEstimatedX += bn.RealX;
                 sumEstimatedY += bn.RealY;
             }
             gn.IsLocatable = true;
             gn.IsAlreadyLocated = true;
             gn.EstimatedX = sumEstimatedX / assistCOMLocateNodeList.Count;
             gn.EstimatedY = sumEstimatedY / assistCOMLocateNodeList.Count;
         }
         //判断信标节点数量,若小于3,则无法进行定位
         else if (assistLocateBeaconNode.Count < 3)
         {
             gn.IsLocatable = false;
         }
         else
         {
             //三边测量法定位
             double[] pos = Three_edge_measurement.trilateration(assistLocateBeaconNode[0].RealX, assistLocateBeaconNode[0].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[0]), assistLocateBeaconNode[1].RealX, assistLocateBeaconNode[1].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[1]), assistLocateBeaconNode[2].RealX, assistLocateBeaconNode[2].RealY, nodeList.FinalHopSize * CalculateNodeHop(gn, assistLocateBeaconNode[2]));
             gn.EstimatedX = pos[0];
             gn.EstimatedY = pos[1];
             if (gn.EstimatedX < 0)
             {
                 gn.EstimatedX = 0;
             }
             if (gn.EstimatedY < 0)
             {
                 gn.EstimatedY = 0;
             }
             if (gn.EstimatedX > 100)
             {
                 gn.EstimatedX = 100;
             }
             if (gn.EstimatedY > 100)
             {
                 gn.EstimatedY = 100;
             }
             gn.IsLocatable = true;
             gn.IsAlreadyLocated = true;
         }
     }
 }
开发者ID:unclechao,项目名称:Revised-DV-Hop-algorithm,代码行数:72,代码来源:AlgorithmFunction.cs

示例4: CalculateNodeHopSize

 /// <summary>
 /// 计算未知节点加权平均每跳距离
 /// </summary>
 /// <param name="nodeList"></param>
 private static void CalculateNodeHopSize(NodeList nodeList)
 {
     List<Node> beaconNodeList = nodeList.GetAllBeaconNode();
     List<Node> generalNodeList = nodeList.GetAllGeneralNode();
     //对各个未知节点求加权平均每跳距离
     foreach (GeneralNode gn in generalNodeList)
     {
         List<Node> tempBeaconNodeList = new List<Node>();
         int sumHop = 0;
         foreach (int beaconNodeId in gn.HopCountTable.Keys)
         {
             //将gn节点HopCountTable中所有beaconNode取出放入tempBeaconNodeList中,并保存gn到所有beaconNode的跳数和
             if (nodeList.GetNodeById(beaconNodeId).IsBeaconNode == true)
             {
                 tempBeaconNodeList.Add(nodeList.GetNodeById(beaconNodeId));
                 sumHop += gn.HopCountTable[beaconNodeId];
             }
         }
         double temp = 0d;
         int tempHop = 0;
         //将tempBeaconNodeList中AvgHopDistance属性为0的节点去除
         for (int i = 0; i < tempBeaconNodeList.Count; i++)
         {
             if (((BeaconNode)tempBeaconNodeList[i]).AvgHopSize <= 0)
             {
                 tempBeaconNodeList.Remove(tempBeaconNodeList[i]);
             }
         }
         foreach (BeaconNode bn in tempBeaconNodeList)
         {
             tempHop += sumHop - CalculateNodeHop(bn, gn);
             temp += bn.AvgHopSize * (sumHop - CalculateNodeHop(bn, gn));
         }
         if (tempHop != 0)
         {
             gn.AvgHopSize = temp / tempHop;
         }
     }
 }
开发者ID:unclechao,项目名称:Revised-DV-Hop-algorithm,代码行数:43,代码来源:AlgorithmFunction.cs


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