Esempio n. 1
0
 private void ReplaceTwoNodes(RingNodes currentRN, List <Sensor> b)
 {
     //  currentRN.AntiClockWiseNeighbor.RingNodesRule.ClockWiseNeighbor = b.Node;
     //   currentRN.ClockWiseNeighbor.RingNodesRule.AntiClockWiseNeighbor = b.Node;
     try
     {
         RingNodes bring = PublicParameters.RingNodes.Where(i => i.Node.ID == currentRN.Node.ID).First();
         int       index = PublicParameters.RingNodes.IndexOf(bring);
         PublicParameters.RingNodes.RemoveAt(index);
         if (index != -1)
         {
             foreach (Sensor rn in b)
             {
                 PublicParameters.RingNodes.Insert(index, rn.RingNodesRule);
                 //rn.Node.RingNodesRule.AnchorNode = currentRN.AnchorNode;
                 //PublicParameters.RingNodes[index] = rn;
                 index++;
             }
         }
     }
     catch
     {
         Console.WriteLine("Replace Two Nodes returned exception");
     }
 }
Esempio n. 2
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
            }
        }
Esempio n. 3
0
        private void GetTheSetofClosestNodes(RingNodes RN)
        {
            ClosestNodestoRN.Clear();
            List <RingNodeCandidates> holder = new List <RingNodeCandidates>();
            Sensor anti  = RN.AntiClockWiseNeighbor;
            Sensor clock = RN.ClockWiseNeighbor;

            foreach (NeighborsTableEntry nei in RN.Node.NeighborsTable)
            {
                Sensor node     = nei.NeiNode;
                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.NeiNode, RN.AntiClockWiseNeighbor);
                    distance += Operations.DistanceBetweenTwoSensors(nei.NeiNode, RN.ClockWiseNeighbor);
                }
                RingNodeCandidates cand = new RingNodeCandidates(nei.NeiNode, distance);
                holder.Add(cand);
            }
            ClosestNodestoRN = holder.OrderBy(i => i.Distance).ToList();
            //Console.WriteLine("ASd");
        }
Esempio n. 4
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);
        }
Esempio n. 5
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 <= (PublicParameters.PreRingNodesHolder.Count() - 1); i++)
            {
                counter++;
                if (i == 0)
                {
                    clockwise = PublicParameters.PreRingNodesHolder.Count - 1;
                }
                else if (i == PublicParameters.PreRingNodesHolder.Count - 1)
                {
                    antiClockwise = 0;
                }
                point = PublicParameters.PreRingNodesHolder[i];
                clock = PublicParameters.PreRingNodesHolder[clockwise];
                anti  = PublicParameters.PreRingNodesHolder[antiClockwise];
                node  = new RingNodes(point, anti, clock);
                point.RingNodesRule = node;
                PublicParameters.RingNodes.Add(node);
                antiClockwise = counter + 1;
                clockwise     = counter - 1;
            }
        }
Esempio n. 6
0
        private void ClearOldRingNodeData(RingNodes node)
        {
            Sensor sen = node.Node;

            sen.RingNodesRule = new RingNodes();

            RemoveArrow(node);
        }
Esempio n. 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);
        }
Esempio n. 8
0
        private static void ClearOldRingNodeData(RingNodes node, RingNodes newNode)
        {
            Sensor sen = node.Node;

            sen.RingNodesRule = new RingNodes();
            foreach (NeighborsTableEntry neighbor in node.Node.NeighborsTable)
            {
                neighbor.NeiNode.RingNeighborRule = new RingNeighbor(neighbor.NeiNode);
            }
            //  AddRemoveArrows(node, newNode);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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))
            {
            }
        }
Esempio n. 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, PublicParameters.networkCenter);

            foreach (RingNodeCandidates nei in ClosestNodestoRN)
            {
                double candiDistance = Operations.DistanceBetweenTwoPoints(nei.Node.CenterLocation, PublicParameters.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);
        }
Esempio n. 12
0
        private static void GetTheSetofClosestNodes(RingNodes RN)
        {
            ClosestNodestoRN.Clear();
            List <RingNodeCandidates> holder = new List <RingNodeCandidates>();

            foreach (NeighborsTableEntry nei in RN.Node.NeighborsTable)
            {
                double distance = Operations.DistanceBetweenTwoSensors(nei.NeiNode, RN.AntiClockWiseNeighbor);
                distance += Operations.DistanceBetweenTwoSensors(nei.NeiNode, RN.ClockWiseNeighbor);
                RingNodeCandidates cand = new RingNodeCandidates(nei.NeiNode, distance);
                holder.Add(cand);
            }
            ClosestNodestoRN = holder.OrderBy(i => i.Distance).ToList();
        }
Esempio n. 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();
        }
Esempio n. 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 = PublicParameters.RingNodes.Where(i => i.Node.ID == currentRN.Node.ID).First();
         int       index = PublicParameters.RingNodes.IndexOf(bring);
         if (index != -1)
         {
             PublicParameters.RingNodes[index] = b;
         }
     }
     catch
     {
         Console.WriteLine("Replace Two Nodes returned exception");
     }
 }
Esempio n. 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 (!PublicParameters.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);
        }
Esempio n. 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 (PublicParameters.IsExanding)
                {
                    double distance = Operations.DistanceBetweenTwoPoints(newRingNode.CenterLocation, PublicParameters.networkCenter);
                    if (distance >= (PublicParameters.clusterRadius * 1.6))
                    {
                        PublicParameters.IsExanding = false;
                    }
                }
                else
                {
                    double distance = Operations.DistanceBetweenTwoPoints(newRingNode.CenterLocation, PublicParameters.networkCenter);
                    if (distance <= (PublicParameters.clusterRadius))
                    {
                        PublicParameters.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.AnchorNode = CurrentRN.AnchorNode;
                }
                // 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();
                blah();
                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
            }
        }