Exemplo n.º 1
0
        private void findPotentialPointsForAnchor(ConvexHullNodes anchor)
        {
            Point dest = new Point(anchor.node.CenterLocation.X, 10); // x-axis

            foreach (NeighborsTableEntry entry in anchor.node.NeighborsTable)
            {
                foreach (Sensor x in SetofNodes)
                {
                    if (ConvexNodes.Count > 3 && x == PointZero)
                    {
                        ConvexHullNodes nei = new ConvexHullNodes(x, 0);
                        anchor.PotentialNextHop.Add(nei);
                        return;
                    }
                    if (x.ID == entry.NeiNode.ID && !ConvexNodes.Contains(x))
                    {
                        double          angle = Operations.GetDirectionAngle(anchor.node.CenterLocation, dest, x.CenterLocation);
                        ConvexHullNodes nei   = new ConvexHullNodes(x, angle);
                        anchor.PotentialNextHop.Add(nei);
                        //anchor.PotentialNextHop.Add(x);
                    }
                }
            }
            SubsetOfHull.Push(anchor);
        }
Exemplo n.º 2
0
        /*  private void findCommonNeighbor(Sensor s1, Sensor s2)
         * {
         *    double distance = Operations.DistanceBetweenTwoSensors(s1, s2);
         *    bool haveCommon = (distance < 100);
         *    if (haveCommon)
         *    {
         *        // They will have common neighbors
         *        List<Sensor> potentialNeighbors = new List<Sensor>();
         *        List<Sensor> commonNeighbors = new List<Sensor>();
         *        foreach (NeighborsTableEntry entryS1 in s1.NeighborsTable)
         *        {
         *            foreach (NeighborsTableEntry entryS2 in s2.NeighborsTable)
         *            {
         *                if (entryS1.NeiNode.ID == entryS2.NeiNode.ID)
         *                {
         *                    commonNeighbors.Add(entryS1.NeiNode);
         *                    if (SetofNodes.Contains(entryS1.NeiNode))
         *                    {
         *                        potentialNeighbors.Add(entryS1.NeiNode);;
         *                    }
         *                }
         *            }
         *        }
         *    }
         *    else
         *    {
         *
         *    }
         *
         * }
         * private void checkRingNodes()
         * {
         *    //We check if the ring nodes are all one-hop away from each other; if not we choose a common node (from the Set of All Nodes) between the two
         *    //to connect both of them
         *    int holder = 0;
         *    for (int i = ConvexNodes.Count - 2; i >= (0); i--)
         *    {
         *        holder = i;
         *        holder++;
         *        Sensor s1 = ConvexNodes[holder];
         *        Sensor s2 = ConvexNodes[i];
         *        if (!isMyNeighbor(s1, s2))
         *        {
         *            RingNodes node = new RingNodes(s1, s2, false);
         *            PublicParamerters.ringNodeHolder.Add(node);
         *            node.lastCheck();
         *        }
         *        else
         *        {
         *            RingNodes node = new RingNodes(s1, s2,true);
         *            PublicParamerters.ringNodeHolder.Add(node);
         *            node.lastCheck();
         *        }
         *    }
         *
         *
         * }*/

        private void startBuilding()
        {
            bool takeNextPoint = true;

            SubsetOfHull.Push(SortedSetOfConvexNodes.Dequeue());
            do
            {
                if (takeNextPoint)
                {
                    SubsetOfHull.Push(SortedSetOfConvexNodes.Dequeue());
                }

                ConvexHullNodes PointThree = SubsetOfHull.Pop();
                ConvexHullNodes PointTwo   = SubsetOfHull.Pop();
                ConvexHullNodes PointOne   = SubsetOfHull.Pop();

                if (isClockwise(PointOne, PointTwo, PointThree))
                {
                    SubsetOfHull.Push(PointOne);
                    SubsetOfHull.Push(PointTwo);
                    SubsetOfHull.Push(PointThree);
                    takeNextPoint = true;
                }
                else
                {
                    SubsetOfHull.Push(PointOne);
                    SubsetOfHull.Push(PointThree);
                    if (SubsetOfHull.Count >= 3)
                    {
                        takeNextPoint = false;
                    }
                }
            } while (SortedSetOfConvexNodes.Count > 0);

            //  Console.WriteLine("Ending ****");
            int c = SubsetOfHull.Count;

            do
            {
                ConvexHullNodes x = SubsetOfHull.Pop();
                ConvexNodes.Add(x.node);
                PublicParameters.BorderNodes.Add(x.node);

                //   x.node.ShowComunicationRange(true);
                //  Console.WriteLine(x.node.ID);
            } while (SubsetOfHull.Count > 0);



            getBorderNodes();
        }
Exemplo n.º 3
0
        private ConvexHullNodes getLowestAngle(List <ConvexHullNodes> set)
        {
            double          lowest = 10;
            ConvexHullNodes holder = null;

            foreach (ConvexHullNodes compare in set)
            {
                if (compare.polarAngle < lowest)
                {
                    lowest = compare.polarAngle;
                    holder = compare;
                }
            }

            return(holder);
        }
Exemplo n.º 4
0
        /*private void getNextNode(ConvexHullNodes from)
         * {
         *  Console.WriteLine("Getting next node for {0}", from.node.ID);
         *
         *  if (from.SortedConvexHullSet.Count == 1)
         *  {
         *      ConvexHullNodes entry = from.SortedConvexHullSet.Dequeue();
         *      if (entry == null)
         *      {
         *          Console.WriteLine();
         *      }
         *      else
         *      {
         *          SubsetOfHull.Push(entry);
         *          ConvexNodes.Add(entry.node);
         *      }
         *
         *
         *  }
         *  if (from.SortedConvexHullSet.Count == 0)
         *  {
         *      Console.WriteLine();
         *      return;
         *
         *  }
         *  else
         *  {
         *
         *      // we take the first two in the potential next hops and check if they make a right turn (ClockWise)
         *      ConvexHullNodes second = from.SortedConvexHullSet.Dequeue();
         *      ConvexHullNodes third = from.SortedConvexHullSet.Dequeue();
         *      do
         *      {
         *
         *          if (!isCounterClockWise(from, second, third))
         *          {
         *              SubsetOfHull.Push(third);
         *              ConvexNodes.Add(third.node);
         *              if (from.SortedConvexHullSet.Count >= 1)
         *              {
         *                  ConvexHullNodes fourth = from.SortedConvexHullSet.Dequeue();
         *                  ConvexHullNodes lastIn = SubsetOfHull.Pop();
         *                  if (!isCounterClockWise(from, fourth, lastIn))
         *                  {
         *                      ConvexNodes.Remove(lastIn.node);
         *                      SubsetOfHull.Push(fourth);
         *                      ConvexNodes.Add(fourth.node);
         *                  }
         *                  else
         *                  {
         *                      SubsetOfHull.Push(lastIn);
         *                      SubsetOfHull.Push(fourth);
         *                      ConvexNodes.Add(fourth.node);
         *
         *                  }
         *              }
         *
         *          }
         *          else
         *          {
         *              SubsetOfHull.Push(second);
         *              SubsetOfHull.Push(third);
         *              ConvexNodes.Add(second.node);
         *              ConvexNodes.Add(third.node);
         *
         *              if (from.SortedConvexHullSet.Count >= 1)
         *              {
         *                  ConvexHullNodes fourth = from.SortedConvexHullSet.Dequeue();
         *                  ConvexHullNodes lastIn = SubsetOfHull.Pop();
         *                  if (!isCounterClockWise(from, fourth, lastIn))
         *                  {
         *                      ConvexNodes.Remove(lastIn.node);
         *                      SubsetOfHull.Push(fourth);
         *                      ConvexNodes.Add(fourth.node);
         *                      lastIn = SubsetOfHull.Pop();
         *                      if (!isCounterClockWise(from, fourth, lastIn))
         *                      {
         *                          SubsetOfHull.Push(fourth);
         *                          ConvexNodes.Remove(lastIn.node);
         *                      }
         *                      else
         *                      {
         *                          SubsetOfHull.Push(lastIn);
         *                          SubsetOfHull.Push(fourth);
         *                          ConvexNodes.Add(fourth.node);
         *                      }
         *                  }
         *                  else
         *                  {
         *                      SubsetOfHull.Push(lastIn);
         *                      SubsetOfHull.Push(fourth);
         *                      ConvexNodes.Add(fourth.node);
         *
         *                  }
         *              }
         *
         *
         *          }
         *
         *
         *      } while (from.SortedConvexHullSet.Count >=1);
         *
         *
         *
         *
         *
         *
         *
         *
         *
         *  }
         *  }
         *
         *
         *
         *
         * public static bool isFinished = false;
         *
         * private void startFromPointZero()
         * {
         *  Sensor anchor = PointZero;
         *  ConvexHullNodes anc = new ConvexHullNodes(anchor, 0);
         *  findPotentialPointsForAnchor(anc);
         *  ConvexNodes.Add(anchor);
         *
         *  do
         *  {
         *      if (SubsetOfHull.Count > 0)
         *      {
         *          ConvexHullNodes from = SubsetOfHull.Pop();
         *          if (from.node != PointZero)
         *          {
         *              findPotentialPointsForAnchor(from);
         *          }
         *          else if (from.node == PointZero && RingNodes.Count > 3)
         *          {
         *              Console.WriteLine("Finished");
         *              isFinished = true;
         *              return;
         *          }
         *
         *          sortMyPotentialNextHop(from);
         *          getNextNode(from);
         *      }
         *      else
         *      {
         *          isFinished = true;
         *      }
         *
         *
         *
         *
         *
         *
         *  } while (!isFinished);
         *
         *  Console.WriteLine("****");
         *  foreach (Sensor sen in ConvexNodes)
         *  {
         *      Console.WriteLine(sen.ID);
         *  }
         *  Console.WriteLine();
         *
         * }
         */


        private void getPolarAngleToPointsFromAnchor(Sensor anchor)
        {
            // according to the direction they make with P0 and the X-Axis
            Point dest = new Point(anchor.CenterLocation.X + InitialRadius + ThreshHold, anchor.CenterLocation.Y); // x-axis

            foreach (Sensor px in SetofNodes)
            {
                if (px.ID != anchor.ID)
                {
                    double          angle = Operations.GetDirectionAngle(anchor.CenterLocation, dest, px.CenterLocation);
                    ConvexHullNodes node  = new ConvexHullNodes(px, angle);
                    ConvexHullSet.Add(node);
                    //Console.WriteLine("Node {0} , has Angle {1}", node.node.ID, node.polarAngle);
                    // Console.WriteLine("Node {0} , has Angle {1}", px.ID, angle);
                }
            }
        }
Exemplo n.º 5
0
        private bool isClockwise(ConvexHullNodes one, ConvexHullNodes two, ConvexHullNodes three)
        {
            Point a = one.node.CenterLocation;
            Point b = two.node.CenterLocation;
            Point c = three.node.CenterLocation;

            double value = ((b.X - a.X) * (c.Y - a.Y) - (c.X - a.X) * (b.Y - a.Y));

            if (value >= 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 6
0
        private static void ConvexHullBuildMethod()
        {
            ConvexHullRing constructor = new ConvexHullRing();

            // showVirtualRadius();
            constructor.findTheSetofNodes();
            constructor.findPointZero();
            constructor.getPolarAngleToPointsFromAnchor(PointZero);
            ConvexHullNodes AnchorPoint = new ConvexHullNodes(PointZero, 0);

            AnchorPoint.PotentialNextHop = ConvexHullSet;
            PointZeroConvex = AnchorPoint;
            constructor.sortConvexHullSet(PointZero);
            SubsetOfHull.Push(AnchorPoint);
            constructor.startBuilding();

            //constructor.startFromPointZero();
        }
Exemplo n.º 7
0
        private void sortConvexHullSet(Sensor anchor)
        {
            List <ConvexHullNodes> beforeSort = ConvexHullSet;
            ConvexHullNodes        small      = null;

            do
            {
                try
                {
                    small = getLowestAngle(beforeSort);
                    SortedSetOfConvexNodes.Enqueue(small);
                    beforeSort.Remove(small);
                    //Console.WriteLine("Node {0} has angle {1}", small.node.ID, small.polarAngle);
                }
                catch
                {
                    small = null;
                    MessageBox.Show("Just returned a null");
                }
            } while (beforeSort.Count > 0);
        }
Exemplo n.º 8
0
        private void sortMyPotentialNextHop(ConvexHullNodes from)
        {
            List <ConvexHullNodes> beforeSort = from.PotentialNextHop;

            ConvexHullNodes small = null;

            do
            {
                try
                {
                    small = getLowestAngle(beforeSort);
                    from.SortedConvexHullSet.Enqueue(small);
                    beforeSort.Remove(small);
                    // Console.WriteLine("Node {0} has angle {1}", small.node.ID, small.polarAngle);
                }
                catch
                {
                    small = null;
                    MessageBox.Show("Just returned a null");
                }
            } while (beforeSort.Count > 0);
        }