コード例 #1
0
        /// <summary>
        /// Calculates the position
        /// </summary>
        /// <param name="BlindNode">The BlindNode to be positioned</param>
        /// <param name="filterMethod">The filter to use on the RSS values</param>
        /// <param name="RangingMethod">The ranging method</param>
        /// <param name="multihop">use multihop or not</param>
        /// <returns>The position of the blind node</returns>
        public static Point CalculatePosition(Node BlindNode, Node.FilterMethod filterMethod, Node.RangingMethod rangingMethod, bool multihop)
        {
            List <Point> intersectionPoints = new List <Point>();

            Point         position      = new Point();
            List <string> StatusCircles = new List <string>();

            List <int> ListOfCounts = new List <int>();
            int        count;
            bool       AllCirclesIntersected = false;

            foreach (AnchorNode an in BlindNode.Anchors)
            {
                an.fRSS  = filterMethod(an.RSS);
                an.range = rangingMethod(an.fRSS);
            }

            if (!multihop)
            {
                if (BlindNode.Anchors.Count >= 3)
                {
                    // This lus will continue with expanding and narrowing the range of the anchors
                    // until all circles cut in one or two points
                    while (!AllCirclesIntersected)
                    {
                        for (int i = 0; i < BlindNode.Anchors.Count; i++)
                        {
                            count = 0;

                            for (int j = 0; j < BlindNode.Anchors.Count; j++)
                            {
                                StatusCircles.Add(GeometryHelper.InOrOut(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range));
                            }
                            if (StatusCircles.Contains("Overlap") && !(StatusCircles.Contains("In") || StatusCircles.Contains("Separated")))
                            {
                                BlindNode.Anchors[i].range *= 0.9;
                            }
                            else if ((StatusCircles.Contains("In") || StatusCircles.Contains("Separated")) && !StatusCircles.Contains("Overlap"))
                            {
                                BlindNode.Anchors[i].range *= 1.1;
                            }
                            StatusCircles.Clear();
                        }

                        // Check if all nodes intersect
                        ListOfCounts.Clear();
                        for (int i = 0; i < BlindNode.Anchors.Count; i++)
                        {
                            count = 0;
                            for (int j = 0; j < BlindNode.Anchors.Count; j++)
                            {
                                if (GeometryHelper.BelongTo(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range))
                                {
                                    count++;
                                }
                            }
                            ListOfCounts.Add(count);
                        }
                        if (ListOfCounts.Average() == BlindNode.Anchors.Count)
                        {
                            AllCirclesIntersected = true;
                        }
                    }

                    // Determine crossings
                    for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                        {
                            //returns 0, 1 or 2 Pointss
                            List <Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                {
                                    intersectionPoints.Add(crossing);
                                }
                            }
                        }
                    }

                    // Calculate BN position with clustering
                    if (intersectionPoints.Count >= 3)
                    {
                        position = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                    }
                    else
                    {
                        position = null;
                    }
                }
                else
                {
                    position = null;
                }
            }
            return(position);
        }
コード例 #2
0
        /// <summary>
        /// Calculates the position
        /// </summary>
        /// <param name="BlindNode">The BlindNode to be positioned</param>
        /// <param name="filterMethod">The filter to use on the RSS values</param>
        /// <param name="RangingMethod">The ranging method</param>
        /// <param name="multihop">use multihop or not</param>
        /// <returns>The position of the blind node</returns>
        public static Point CalculatePosition(Node BlindNode, Node.FilterMethod filterMethod, Node.RangingMethod rangingMethod, bool multihop)
        {
            List <Point>              intersectionPoints = new List <Point>();
            List <AnchorNode>         AllAnchors         = new List <AnchorNode>();
            List <IntersectedAnchors> anchors            = new List <IntersectedAnchors>();
            IntersectedAnchors        anchor             = new IntersectedAnchors();
            List <int> CountOfCircles = new List <int>();

            Point center          = new Point();
            int   numberOfCircles = 0;

            foreach (AnchorNode AN in BlindNode.Anchors)
            {
                AN.fRSS  = filterMethod(AN.RSS);
                AN.range = rangingMethod(AN.fRSS);
            }
            foreach (AnchorNode VAN in BlindNode.VirtualAnchors)
            {
                VAN.fRSS  = filterMethod(VAN.RSS);
                VAN.range = rangingMethod(VAN.fRSS);
            }

            if (!multihop)
            {
                if (BlindNode.Anchors.Count >= 3)
                {
                    for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                        {
                            List <Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                {
                                    intersectionPoints.Add(crossing);
                                }
                            }
                        }
                    }
                    if (intersectionPoints.Count >= 3)
                    {
                        center = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                    }
                    else
                    {
                        center = null;
                    }
                }
                else
                {
                    center = null;
                }
            }
            else
            {
                for (int i = 0; i < BlindNode.Anchors.Count - 1; i++)
                {
                    for (int j = i + 1; j < BlindNode.Anchors.Count; j++)
                    {
                        List <Point> crossingPoints = GeometryHelper.Intersect(BlindNode.Anchors[i].posx, BlindNode.Anchors[i].posy, BlindNode.Anchors[i].range, BlindNode.Anchors[j].posx, BlindNode.Anchors[j].posy, BlindNode.Anchors[j].range);
                        if (crossingPoints != null)
                        {
                            foreach (Point crossing in crossingPoints)
                            {
                                intersectionPoints.Add(crossing);
                            }
                        }
                    }
                }
                if (intersectionPoints.Count < 3)
                {
                    intersectionPoints.Clear();

                    foreach (AnchorNode an in BlindNode.Anchors)
                    {
                        AllAnchors.Add(an);
                    }
                    foreach (AnchorNode van in BlindNode.VirtualAnchors)
                    {
                        AllAnchors.Add(van);
                    }

                    for (int i = 0; i < AllAnchors.Count - 1; i++)
                    {
                        for (int j = i + 1; j < AllAnchors.Count; j++)
                        {
                            List <Point> crossingPoints = GeometryHelper.Intersect(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range);
                            if (crossingPoints != null)
                            {
                                foreach (Point crossing in crossingPoints)
                                {
                                    intersectionPoints.Add(crossing);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < AllAnchors.Count; i++)
                    {
                        numberOfCircles = 0;
                        for (int j = 0; j < AllAnchors.Count; j++)
                        {
                            if (GeometryHelper.BelongTo(AllAnchors[i].posx, AllAnchors[i].posy, AllAnchors[i].range, AllAnchors[j].posx, AllAnchors[j].posy, AllAnchors[j].range))
                            {
                                numberOfCircles++;
                            }
                        }
                        CountOfCircles.Add(numberOfCircles);
                    }
                    List <int> anchorss = CountOfCircles.FindAll(number => number == 1);

                    if (intersectionPoints.Count >= 3)
                    {
                        center = Cluster(intersectionPoints, (AllAnchors.Count - anchorss.Count));
                    }
                    else
                    {
                        center = null;
                    }
                }
                else
                {
                    center = Cluster(intersectionPoints, BlindNode.Anchors.Count);
                }
            }
            return(center);
        }