예제 #1
0
        public static void ChangeRingNode(RingNodes CurrentRN, bool isExpanding)
        {
            //First we find a new node (Expand or Collapse we start with expand)
            //Change this node with the other and change the clockwise and anticlockwise
            //Determine poisition of nodes
            //Sensor oldRingNode = CurrentRN.Node;
            Sensor newRingNode = FindNewRingNodeReplacement(CurrentRN);
            Sensor clock       = CurrentRN.ClockWiseNeighbor;
            Sensor anti        = CurrentRN.AntiClockWiseNeighbor;

            if (newRingNode != null)
            {
                //me,anti,clock
                RingNodes newNo = new RingNodes(newRingNode, CurrentRN.AntiClockWiseNeighbor, CurrentRN.ClockWiseNeighbor);
                //newNo.AnchorNode = CurrentRN.AnchorNode;
                newRingNode.RingNodesRule = newNo;
                ReplaceTwoNodes(CurrentRN, newNo);
                ClearOldRingNodeData(CurrentRN, newNo);
                AddRemoveArrows(CurrentRN, newNo);
                markNeighboringRingNods();
                RingNodesFunctions r = new RingNodesFunctions();
                r.DeterminePositionofAllNodes();
                Console.WriteLine("Change {0} to {1}", CurrentRN.Node.ID, newRingNode.ID);
            }
            else
            {
                Console.WriteLine("Failed to change node {0}", CurrentRN.Node.ID);
                //Failed
            }
        }
예제 #2
0
        private static void populateRingNodes()
        {
            Sensor    point;
            Sensor    clock;
            Sensor    anti;
            RingNodes node;
            int       clockwise     = 0;
            int       antiClockwise = 1;
            int       counter       = 0;

            for (int i = 0; i <= (PublicParamerters.PreRingNodesHolder.Count() - 1); i++)
            {
                counter++;
                if (i == 0)
                {
                    clockwise = PublicParamerters.PreRingNodesHolder.Count - 1;
                }
                else if (i == PublicParamerters.PreRingNodesHolder.Count - 1)
                {
                    antiClockwise = 0;
                }
                point = PublicParamerters.PreRingNodesHolder[i];
                clock = PublicParamerters.PreRingNodesHolder[clockwise];
                anti  = PublicParamerters.PreRingNodesHolder[antiClockwise];
                node  = new RingNodes(point, anti, clock);
                point.RingNodesRule = node;
                PublicParamerters.RingNodes.Add(node);
                antiClockwise = counter + 1;
                clockwise     = counter - 1;
            }
        }
예제 #3
0
        /* private static void AddRemoveArrows(RingNodes oldNode, RingNodes newNode)
         * {
         *   Sensor oldSen = oldNode.Node;
         *   Sensor newSen = newNode.Node;
         *
         *   Sensor clockWise = oldNode.ClockWiseNeighbor;
         *   Sensor AnticlockWise = oldNode.AntiClockWiseNeighbor;
         *
         *   Arrow fromClockToNode = clockWise.MyArrows.Where(i => i.To.ID == oldSen.ID).First();
         *
         *   int IndexForClock = clockWise.MyArrows.IndexOf(fromClockToNode);
         *   if (IndexForClock != -1)
         *   {
         *       clockWise.MyArrows[IndexForClock].Stroke = Brushes.Gray;
         *       clockWise.MyArrows[IndexForClock].StrokeThickness = 0.2;
         *       clockWise.MyArrows[IndexForClock].HeadHeight = 0.2;
         *       clockWise.MyArrows[IndexForClock].HeadWidth = 0.2;
         *   }
         *
         *   Arrow fromNodetoAntiClock = oldSen.MyArrows.Where(i => i.To.ID == AnticlockWise.ID).First();
         *   int IndexForOld = oldSen.MyArrows.IndexOf(fromNodetoAntiClock);
         *   if (IndexForOld != -1)
         *   {
         *       oldSen.MyArrows[IndexForOld].Stroke = Brushes.Gray;
         *       oldSen.MyArrows[IndexForOld].StrokeThickness = 0.2;
         *       oldSen.MyArrows[IndexForOld].HeadHeight = 0.2;
         *       oldSen.MyArrows[IndexForOld].HeadWidth = 0.2;
         *   }
         *   //---------
         *
         *   Arrow fromClockToNNode;
         *   Arrow fromNNodetoAntiClock;
         *
         *   try
         *   {
         *       fromClockToNNode = clockWise.MyArrows.Where(i => i.To.ID == newSen.ID).First();
         *       int IndexForNAnti = clockWise.MyArrows.IndexOf(fromClockToNNode);
         *       if (IndexForNAnti != -1)
         *       {
         *           clockWise.MyArrows[IndexForNAnti].Stroke = Brushes.Black;
         *           clockWise.MyArrows[IndexForNAnti].StrokeThickness = 1;
         *           clockWise.MyArrows[IndexForNAnti].HeadHeight = 0.2;
         *           clockWise.MyArrows[IndexForNAnti].HeadWidth = 0.2;
         *       }
         *   }
         *   catch
         *   {
         *       fromClockToNNode = null;
         *       Ring.addNewArrow(clockWise, newSen);
         *   }
         *
         *   try
         *   {
         *       fromNNodetoAntiClock = newSen.MyArrows.Where(i => i.To.ID == AnticlockWise.ID).First();
         *       int IndexForNOld = newSen.MyArrows.IndexOf(fromNNodetoAntiClock);
         *       if (IndexForNOld != -1)
         *       {
         *           newSen.MyArrows[IndexForNOld].Stroke = Brushes.Black;
         *           newSen.MyArrows[IndexForNOld].StrokeThickness = 1;
         *           newSen.MyArrows[IndexForNOld].HeadHeight = 0.2;
         *           newSen.MyArrows[IndexForNOld].HeadWidth = 0.2;
         *       }
         *   }
         *   catch
         *   {
         *       fromNNodetoAntiClock = null;
         *       Ring.addNewArrow(newSen, AnticlockWise);
         *   }
         *
         *
         *
         * }
         */

        private static Sensor FindNewRingNodeReplacement(RingNodes RN)
        {
            if (!RN.Node.isExpanding)
            {
                ShouldNodeExpand(RN.Node);
            }
            Sensor cand = null;

            GetTheSetofClosestNodes(RN);
            for (int i = 0; i < 4; i++)
            {
                if (!RN.Node.isExpanding)
                {
                    i    = 1;
                    cand = GetNewRingNode(RN, i);
                    return(cand);
                }

                cand = GetNewRingNode(RN, i);
                if (cand != null)
                {
                    return(cand);
                }
            }
            return(cand);
        }
예제 #4
0
 private void ReplaceTwoNodes(RingNodes currentRN, List <Sensor> b)
 {
     //  currentRN.AntiClockWiseNeighbor.RingNodesRule.ClockWiseNeighbor = b.Node;
     //   currentRN.ClockWiseNeighbor.RingNodesRule.AntiClockWiseNeighbor = b.Node;
     try
     {
         RingNodes bring = PublicParamerters.RingNodes.Where(i => i.Node.ID == currentRN.Node.ID).First();
         int       index = PublicParamerters.RingNodes.IndexOf(bring);
         PublicParamerters.RingNodes.RemoveAt(index);
         if (index != -1)
         {
             foreach (Sensor rn in b)
             {
                 PublicParamerters.RingNodes.Insert(index, rn.RingNodesRule);
                 //rn.Node.RingNodesRule.AnchorNode = currentRN.AnchorNode;
                 //PublicParameters.RingNodes[index] = rn;
                 index++;
             }
         }
     }
     catch
     {
         Console.WriteLine("Replace Two Nodes returned exception");
     }
 }
예제 #5
0
        private void GetTheSetofClosestNodes(RingNodes RN)
        {
            ClosestNodestoRN.Clear();
            List <RingNodeCandidates> holder = new List <RingNodeCandidates>();
            Sensor anti  = RN.AntiClockWiseNeighbor;
            Sensor clock = RN.ClockWiseNeighbor;

            foreach (Sensor nei in RN.Node.NeighborsTable)
            {
                Sensor node     = nei;
                double distance = 0;
                if (Operations.isInMyComunicationRange(node, anti))
                {
                    distance += Operations.DistanceBetweenTwoSensors(node, clock);
                }
                else if (Operations.isInMyComunicationRange(node, clock))
                {
                    distance += Operations.DistanceBetweenTwoSensors(node, anti);
                }
                else
                {
                    distance  = Operations.DistanceBetweenTwoSensors(nei, RN.AntiClockWiseNeighbor);
                    distance += Operations.DistanceBetweenTwoSensors(nei, RN.ClockWiseNeighbor);
                }
                RingNodeCandidates cand = new RingNodeCandidates(nei, distance);
                holder.Add(cand);
            }
            ClosestNodestoRN = holder.OrderBy(i => i.Distance).ToList();
            //Console.WriteLine("ASd");
        }
예제 #6
0
        private void ClearOldRingNodeData(RingNodes node)
        {
            Sensor sen = node.Node;

            sen.RingNodesRule = new RingNodes();
            sen.NotHighTierNode();
            RemoveArrow(node);
        }
예제 #7
0
        private static void RemoveArrow(RingNodes oldNode)
        {
            Sensor oldSen       = oldNode.Node;
            Sensor clockSen     = oldNode.ClockWiseNeighbor;
            Sensor antiClockSen = oldNode.AntiClockWiseNeighbor;

            Ring.removeOldLine(clockSen, oldSen);
            Ring.removeOldLine(oldSen, antiClockSen);
        }
예제 #8
0
        private static void ClearOldRingNodeData(RingNodes node, RingNodes newNode)
        {
            Sensor sen = node.Node;

            sen.RingNodesRule  = new RingNodes();
            sen.IsHightierNode = false;
            foreach (Sensor neighbor in node.Node.NeighborsTable)
            {
                neighbor.RingNeighborRule = new RingNeighbor(neighbor);
            }
            //  AddRemoveArrows(node, newNode);
        }
예제 #9
0
        private static void CheckNewRingNode(RingNodes newNode)
        {
            Sensor me        = newNode.Node;
            Sensor clock     = newNode.ClockWiseNeighbor;
            Sensor antiClock = newNode.AntiClockWiseNeighbor;

            if (!Operations.isInMyComunicationRange(me, clock))
            {
            }
            if (!Operations.isInMyComunicationRange(me, antiClock))
            {
            }
        }
예제 #10
0
        private static void AddRemoveArrows(RingNodes oldNode, RingNodes newNode)
        {
            Sensor newSen       = newNode.Node;
            Sensor oldSen       = oldNode.Node;
            Sensor clockSen     = oldNode.ClockWiseNeighbor;
            Sensor antiClockSen = oldNode.AntiClockWiseNeighbor;

            Ring.removeOldLine(clockSen, oldSen);
            Ring.removeOldLine(oldSen, antiClockSen);

            Ring.addNewLine(newSen, antiClockSen);
            Ring.addNewLine(clockSen, newSen);
        }
예제 #11
0
        private static Sensor GetNewRingNode(RingNodes RN, int i)
        {
            Sensor clockWiseNei     = RN.ClockWiseNeighbor;
            Sensor AntiClockWiseNei = RN.AntiClockWiseNeighbor;
            Sensor candi            = null;
            double oldDistance      = Operations.DistanceBetweenTwoPoints(RN.Node.CenterLocation, PublicParamerters.networkCenter);

            foreach (RingNodeCandidates nei in ClosestNodestoRN)
            {
                double candiDistance = Operations.DistanceBetweenTwoPoints(nei.Node.CenterLocation, PublicParamerters.networkCenter);
                bool   conditionOne  = (Operations.Orientation(AntiClockWiseNei.CenterLocation, nei.Node.CenterLocation, clockWiseNei.CenterLocation) > 1);
                //int  orientMe = (Operations.Orientation(RN.AntiClockWiseNeighbor.CenterLocation, RN.Node.CenterLocation, RN.ClockWiseNeighbor.CenterLocation));
                int  orientCandi = (Operations.Orientation(AntiClockWiseNei.CenterLocation, nei.Node.CenterLocation, clockWiseNei.CenterLocation));
                bool conditionTwo;//= false;
                bool notRingNode  = (!nei.Node.RingNodesRule.isRingNode);
                bool notAgentNode = (!nei.Node.isSinkAgent);
                if (i == 0)
                {
                    conditionTwo = (candiDistance) > (oldDistance);
                }
                else if (i == 1)
                {
                    conditionOne = true;
                    conditionTwo = (candiDistance) < (oldDistance);
                }
                else if (i == 2)
                {
                    conditionTwo = (candiDistance) > (oldDistance);
                    conditionOne = !(nei.Node.RingNodesRule.isRingNode);
                }
                else
                {
                    conditionTwo = true;
                }

                if (conditionOne && conditionTwo && notRingNode && notAgentNode)
                {
                    candi = nei.Node;
                    if (i == 1)
                    {
                        candi.isExpanding = false;
                    }

                    return(candi);
                }
            }


            return(candi);
        }
예제 #12
0
        private static void GetTheSetofClosestNodes(RingNodes RN)
        {
            ClosestNodestoRN.Clear();
            List <RingNodeCandidates> holder = new List <RingNodeCandidates>();

            foreach (Sensor nei in RN.Node.NeighborsTable)
            {
                double distance = Operations.DistanceBetweenTwoSensors(nei, RN.AntiClockWiseNeighbor);
                distance += Operations.DistanceBetweenTwoSensors(nei, RN.ClockWiseNeighbor);
                RingNodeCandidates cand = new RingNodeCandidates(nei, distance);
                holder.Add(cand);
            }
            ClosestNodestoRN = holder.OrderBy(i => i.Distance).ToList();
        }
예제 #13
0
        private void CheckNewRingNode(RingNodes newNode)
        {
            // AntiNeighbors.Clear();
            Neighbors.Clear();
            Candidates.Clear();

            Sensor me        = newNode.Node;
            Sensor clock     = newNode.ClockWiseNeighbor;
            Sensor antiClock = newNode.AntiClockWiseNeighbor;

            Neighbors.Push(antiClock);

            /*if (!Operations.isInMyComunicationRange(me, antiClock))
             * {
             *  if (findPottentialNeighbors(me, antiClock))
             *  {
             *      totalNumberOfNewNodes = Candidates.Count;
             *      //Neighbors.Push(antiClock);
             *      foreach (Sensor sen in Candidates)
             *      {
             *          Neighbors.Push(sen);
             *          myNewRingNodes.Add(sen);
             *      }
             *      Candidates.Clear();
             *  }
             * }*/
            Neighbors.Push(me);

            /* if (!Operations.isInMyComunicationRange(me, clock))
             * {
             *   if (findPottentialNeighbors(me,clock))
             *   {
             *       totalNumberOfNewNodes += Candidates.Count;
             *       foreach (Sensor sen in Candidates)
             *       {
             *           Neighbors.Push(sen);
             *           myNewRingNodes.Add(sen);
             *       }
             *      // Neighbors.Push(clock);
             *       Candidates.Clear();
             *   }
             * }*/
            Neighbors.Push(clock);
            AggregateNewInfo();
        }
예제 #14
0
 private static void ReplaceTwoNodes(RingNodes currentRN, RingNodes b)
 {
     currentRN.AntiClockWiseNeighbor.RingNodesRule.ClockWiseNeighbor = b.Node;
     currentRN.ClockWiseNeighbor.RingNodesRule.AntiClockWiseNeighbor = b.Node;
     try
     {
         RingNodes bring = PublicParamerters.RingNodes.Where(i => i.Node.ID == currentRN.Node.ID).First();
         int       index = PublicParamerters.RingNodes.IndexOf(bring);
         if (index != -1)
         {
             PublicParamerters.RingNodes[index] = b;
         }
     }
     catch
     {
         Console.WriteLine("Replace Two Nodes returned exception");
     }
 }
예제 #15
0
        private Sensor FindNewRingNodeReplacement(RingNodes RN)
        {
            Sensor cand = null;

            /*   if (!RN.Node.isExpanding)
             * {
             *     ShouldNodeExpand(RN.Node);
             * }*/
            GetTheSetofClosestNodes(RN);
            for (int i = 0; i < 4; i++)
            {
                if (!PublicParamerters.IsExanding)
                {
                    i    = 1;
                    cand = GetNewRingNode(RN, i);
                    if (cand != null)
                    {
                        return(cand);
                    }
                    else
                    {
                        i++;
                        cand = GetNewRingNode(RN, i);
                        return(cand);
                    }
                }
                else
                {
                    cand = GetNewRingNode(RN, i);
                    if (cand != null)
                    {
                        return(cand);
                    }
                }
            }

            return(cand);
        }
예제 #16
0
        public void ChangeRingNode(RingNodes CurrentRN)
        {
            MainCounter++;
            //First we find a new node (Expand or Collapse we start with expand)
            //Change this node with the other and change the clockwise and anticlockwise
            //Determine poisition of nodes
            //Sensor oldRingNode = CurrentRN.Node;
            myNewRingNodes.Clear();
            Sensor newRingNode = FindNewRingNodeReplacement(CurrentRN);
            Sensor clock       = CurrentRN.ClockWiseNeighbor;
            Sensor anti        = CurrentRN.AntiClockWiseNeighbor;

            if (newRingNode != null)
            {
                if (PublicParamerters.IsExanding)
                {
                    double distance = Operations.DistanceBetweenTwoPoints(newRingNode.CenterLocation, PublicParamerters.networkCenter);
                    if (distance >= (PublicParamerters.clusterRadius * 1.6))
                    {
                        PublicParamerters.IsExanding = false;
                    }
                }
                else
                {
                    double distance = Operations.DistanceBetweenTwoPoints(newRingNode.CenterLocation, PublicParamerters.networkCenter);
                    if (distance <= (PublicParamerters.clusterRadius))
                    {
                        PublicParamerters.IsExanding = true;
                    }
                }
                //me,anti,clock
                //Now i have myNewRingNodes loop through there and fix everything
                RingNodes newNo = new RingNodes(newRingNode, CurrentRN.AntiClockWiseNeighbor, CurrentRN.ClockWiseNeighbor);
                myNewRingNodes.Add(newRingNode);
                CheckNewRingNode(newNo);
                ReplaceTwoNodes(CurrentRN, myNewRingNodes);
                foreach (Sensor newRN in myNewRingNodes)
                {
                    if (newRN.RingNodesRule.AntiClockWiseNeighbor.ID == newRN.RingNodesRule.ClockWiseNeighbor.ID)
                    {
                        Console.WriteLine("Error in Change RingNode");
                    }

                    newRN.RingNodesRule.AnchorNodes = CurrentRN.AnchorNodes;
                    newRingNode.IsHightierNode      = true;
                    newRingNode.SetSinksAgentsForNewHighTierNode(CurrentRN.Node.GetAnchorNodesFromHighTierNodes);
                }
                // RingNodes newNo = new RingNodes(newRingNode, CurrentRN.AntiClockWiseNeighbor, CurrentRN.ClockWiseNeighbor);
                // newNo.AnchorNode = CurrentRN.AnchorNode;
                // newRingNode.RingNodesRule = newNo;
                //   ReplaceTwoNodes(CurrentRN, newNo);
                if (!myNewRingNodes.Contains(CurrentRN.Node))
                {
                    ClearOldRingNodeData(CurrentRN);
                }

                //AddRemoveArrows(CurrentRN, newNo);
                RingNodesFunctions r = new RingNodesFunctions();
                //markNeighboringRingNods();
                UpdateInformation();
                r.DeterminePositionofAllNodes();
                // Console.WriteLine("Change {0} to {1}",CurrentRN.Node.ID,newRingNode.ID);
            }
            else
            {
                Console.WriteLine("Failed to change node {0}", CurrentRN.Node.ID);
                //Failed
            }
        }