Exemple #1
0
        public static void sortTable(Sensor sender)
        {
            List <FlowTableEntry> beforeSort = sender.TuftFlowTable;
            List <FlowTableEntry> afterSort  = new List <FlowTableEntry>();

            do
            {
                FlowTableEntry big = getBiggest(beforeSort);
                if (big != null)
                {
                    afterSort.Add(big);
                    beforeSort.Remove(big);
                }
                else
                {
                    beforeSort.Clear();
                    return;
                }
                if (afterSort.Count > 20)
                {
                    beforeSort.Clear();
                    return;
                }
            } while (beforeSort.Count > 0);
            sender.TuftFlowTable.Clear();
            sender.TuftFlowTable = afterSort;
        }
Exemple #2
0
        public static FlowTableEntry getBiggest(List <FlowTableEntry> table)
        {
            double         offset  = -10;
            FlowTableEntry biggest = null;

            foreach (FlowTableEntry entry in table)
            {
                if (entry.DownLinkPriority > offset)
                {
                    offset  = entry.DownLinkPriority;
                    biggest = entry;
                }
            }
            return(biggest);
        }
Exemple #3
0
        public static FlowTableEntry getSmallest(List <FlowTableEntry> table)
        {
            double         offset  = table[0].DownLinkPriority + PublicParameters.CommunicationRangeRadius;
            FlowTableEntry biggest = null;

            foreach (FlowTableEntry entry in table)
            {
                if (entry.DownLinkPriority < offset)
                {
                    offset  = entry.DownLinkPriority;
                    biggest = entry;
                }
            }
            return(biggest);
        }
Exemple #4
0
        public static void sortTable(Sensor sender)
        {
            List <FlowTableEntry> beforeSort = sender.TuftFlowTable;
            List <FlowTableEntry> afterSort  = new List <FlowTableEntry>();

            do
            {
                FlowTableEntry big = null;
                try
                {
                    big = getSmallest(beforeSort);
                    afterSort.Add(big);
                    beforeSort.Remove(big);
                }
                catch
                {
                    big = null;
                    Console.WriteLine();
                }
            } while (beforeSort.Count > 0);
            sender.TuftFlowTable.Clear();
            sender.TuftFlowTable = afterSort;
        }
Exemple #5
0
        /// <summary>
        /// This will be change per sender.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="endNode"></param>


        public static void GetD_Distribution(Sensor sender, Packet packet)
        {
            List <int> path = Operations.PacketPathToIDS(packet.Path);

            sender.TuftFlowTable.Clear();
            List <int> PacketPath = Operations.PacketPathToIDS(packet.Path);

            Sensor sourceNode;// = packet.Source;
            Point  endNodePosition;

            if (packet.PacketType == PacketType.QReq)
            {
                if (packet.isQreqRouted)
                {
                    sourceNode = packet.ReRouteSource;
                }
                else
                {
                    sourceNode = packet.Source;
                }
            }
            else
            {
                sourceNode = packet.Source;
            }
            if (packet.PacketType == PacketType.Data || packet.PacketType == PacketType.Control)
            {
                endNodePosition = packet.Destination.CenterLocation;
            }

            else if (packet.PacketType == PacketType.QReq)
            {
                if (packet.isQreqInsideCell)
                {
                    endNodePosition = packet.Destination.CenterLocation;
                }
                else
                {
                    endNodePosition = packet.DestinationAddress;
                }
            }
            else
            {
                if (packet.Destination != null)
                {
                    endNodePosition = packet.Destination.CenterLocation;
                }
                else
                {
                    return;
                }
            }

            double distSrcToEnd = Operations.DistanceBetweenTwoPoints(sender.CenterLocation, endNodePosition);
            double ENDifference = distSrcToEnd - sender.ComunicationRangeRadius;

            double n = Convert.ToDouble(sender.NeighborsTable.Count) + 1;

            foreach (NeighborsTableEntry neiEntry in sender.NeighborsTable)
            {
                if (neiEntry.NeiNode.ResidualEnergyPercentage > 0)
                {
                    if (neiEntry.ID != PublicParameters.SinkNode.ID)
                    {
                        FlowTableEntry MiniEntry = new FlowTableEntry();
                        MiniEntry.SID           = sender.ID;
                        MiniEntry.NeighborEntry = neiEntry;

                        // MiniEntry.NeighborEntry.Direction = Operations.GetDirectionAngle(sender.CenterLocation, MiniEntry.NeighborEntry.CenterLocation, endNodePosition);

                        MiniEntry.NeighborEntry.DirProb = Operations.GetAngleDotProduction(sender.CenterLocation, MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                        if (MiniEntry.NeighborEntry.DirProb < 0)
                        {
                            MiniEntry.NeighborEntry.DirProb = 0;
                        }
                        MiniEntry.NeighborEntry.pirDisProb    = Operations.GetPerpendicularProbability(sourceNode.CenterLocation, MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                        MiniEntry.NeighborEntry.TransDisProb  = Operations.GetTransmissionDistanceProbability(MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                        MiniEntry.NeighborEntry.ResEnergyProb = Operations.GetResidualEnergyProbability(MiniEntry.NeighborEntry.NeiNode.ResidualEnergy);

                        MiniEntry.NeighborEntry.pirDis = Operations.GetPerpindicularDistance(sourceNode.CenterLocation, MiniEntry.NeighborEntry.CenterLocation, endNodePosition);

                        MiniEntry.NeighborEntry.pirDisNorm = (MiniEntry.NeighborEntry.pirDis / PublicParameters.CommunicationRangeRadius);
                        MiniEntry.NeighborEntry.RE         = MiniEntry.NeighborEntry.ResEnergyProb;
                        MiniEntry.NeighborEntry.EDNorm     = MiniEntry.NeighborEntry.TransDisProb;
                        MiniEntry.NeighborEntry.Direction  = MiniEntry.NeighborEntry.DirProb;

                        sender.TuftFlowTable.Add(MiniEntry);
                    }
                }
            }

            double RESum  = 0;
            double TDSum  = 0;
            double DirSum = 0;
            double PirSum = 0;

            sender.CW.getDynamicWeight(packet, sender);
            foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
            {
                MiniEntry.NeighborEntry.TransDisProb *= sender.CW.TDWeight;
                if (MiniEntry.NeighborEntry.DirProb < 0)
                {
                    MiniEntry.NeighborEntry.DirProb = 0;
                }
                else
                {
                    MiniEntry.NeighborEntry.DirProb *= sender.CW.DirWeight;
                }


                MiniEntry.NeighborEntry.pirDisProb    *= sender.CW.PirpWeight;
                MiniEntry.NeighborEntry.ResEnergyProb *= sender.CW.EnergyWeight;
            }


            foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
            {
                if (MiniEntry.NID != PublicParameters.SinkNode.ID)
                {
                    RESum  += MiniEntry.NeighborEntry.ResEnergyProb;
                    TDSum  += MiniEntry.NeighborEntry.TransDisProb;
                    DirSum += MiniEntry.NeighborEntry.DirProb;
                    PirSum += MiniEntry.NeighborEntry.pirDisProb;
                }
            }

            double downLinkSum = 0;

            foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
            {
                if (MiniEntry.NID != PublicParameters.SinkNode.ID)
                {
                    MiniEntry.NeighborEntry.TransDisProb /= TDSum;
                    if (MiniEntry.NeighborEntry.DirProb < 0)
                    {
                        MiniEntry.NeighborEntry.DirProb = 0;
                    }
                    else if (DirSum != 0)
                    {
                        MiniEntry.NeighborEntry.DirProb /= DirSum;
                    }

                    MiniEntry.NeighborEntry.ResEnergyProb /= RESum;
                    MiniEntry.NeighborEntry.pirDisProb    /= PirSum;

                    /*  if (packet.PacketType == PacketType.QReq || packet.PacketType == PacketType.QResp)
                     * {
                     *    MiniEntry.NeighborEntry.pirDisProb = 0;
                     * }
                     */
                    if (endNodePosition != packet.Source.CenterLocation)
                    {
                        MiniEntry.DownLinkPriority = (MiniEntry.NeighborEntry.TransDisProb + MiniEntry.NeighborEntry.DirProb + MiniEntry.NeighborEntry.ResEnergyProb + MiniEntry.NeighborEntry.pirDisProb) / 4;
                    }
                    else
                    {
                        MiniEntry.DownLinkPriority = (MiniEntry.NeighborEntry.TransDisProb + MiniEntry.NeighborEntry.DirProb + MiniEntry.NeighborEntry.ResEnergyProb) / 3;
                    }
                    downLinkSum += MiniEntry.DownLinkPriority;
                }
            }



            sortTable(sender);

            //int a = packet.Hops;
            //a ++;

            double average         = 1 / Convert.ToDouble(sender.TuftFlowTable.Count);
            int    Ftheashoeld     = Convert.ToInt16(Math.Ceiling(Math.Sqrt(Math.Sqrt(n)))); // theshold.
            int    forwardersCount = 0;
            int    minus;

            if (path.Count < 2)
            {
                minus = 1;
            }
            else
            {
                minus = 2;
            }
            int lastForwarder = path[path.Count - minus];


            foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
            {
                double dir      = Operations.GetDirectionAngle(sender.CenterLocation, MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                double dist     = Operations.DistanceBetweenTwoPoints(sender.CenterLocation, endNodePosition);
                double distCand = Operations.DistanceBetweenTwoPoints(MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                if (MiniEntry.DownLinkPriority >= average && forwardersCount <= Ftheashoeld)// && MiniEntry.NID != lastForwarder)

                {
                    if (!path.Contains(MiniEntry.NID))
                    {
                        MiniEntry.DownLinkAction = FlowAction.Forward;
                        forwardersCount++;
                    }
                    else if (dir < 0.2 && (distCand < dist))
                    {
                        MiniEntry.DownLinkAction = FlowAction.Forward;
                        forwardersCount++;
                    }
                    else
                    {
                        MiniEntry.DownLinkAction = FlowAction.Drop;
                    }
                }
                else
                {
                    MiniEntry.DownLinkAction = FlowAction.Drop;
                }
            }

            if (forwardersCount == 0)
            {
                foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
                {
                    double srcEnd  = Operations.DistanceBetweenTwoPoints(sender.CenterLocation, endNodePosition);
                    double candEnd = Operations.DistanceBetweenTwoPoints(MiniEntry.NeighborEntry.CenterLocation, endNodePosition);
                    if (MiniEntry.DownLinkPriority >= average && forwardersCount <= Ftheashoeld)
                    {
                        MiniEntry.DownLinkAction = FlowAction.Forward;
                        forwardersCount++;
                    }
                    else
                    {
                        MiniEntry.DownLinkAction = FlowAction.Drop;
                    }
                }
            }
        }
Exemple #6
0
        public static void GetD_Distribution(Sensor sender, Packet packet)
        {
            List <int> path = Operations.PacketPathToIDS(packet.Path);

            sender.TuftFlowTable.Clear();
            List <int> PacketPath = Operations.PacketPathToIDS(packet.Path);

            Sensor sourceNode;// = packet.Source;
            Point  endNodePosition = packet.Destination.CenterLocation;

            double distSrcToEnd = Operations.DistanceBetweenTwoPoints(sender.CenterLocation, endNodePosition);


            double n = Convert.ToDouble(sender.NeighborsTable.Count) + 1;

            foreach (NeighborsTableEntry neiEntry in sender.NeighborsTable)
            {
                if (neiEntry.NeiNode.ResidualEnergyPercentage > 0)
                {
                    if (neiEntry.ID != PublicParameters.SinkNode.ID)
                    {
                        FlowTableEntry MiniEntry = new FlowTableEntry();
                        MiniEntry.SID              = sender.ID;
                        MiniEntry.NeighborEntry    = neiEntry;
                        MiniEntry.DownLinkPriority = Operations.DistanceBetweenTwoPoints(endNodePosition, MiniEntry.NeighborEntry.CenterLocation);
                        sender.TuftFlowTable.Add(MiniEntry);
                    }
                }
            }



            sortTable(sender);

            //int a = packet.Hops;
            //a ++;

            int minus = 0;

            if (path.Count < 2)
            {
                minus = 1;
            }
            else
            {
                minus = 2;
            }

            int lastForwarder = path[path.Count - minus];

            foreach (FlowTableEntry MiniEntry in sender.TuftFlowTable)
            {
                if (MiniEntry.NID != PublicParameters.SinkNode.ID)
                {
                    double srcEnd  = Operations.DistanceBetweenTwoPoints(sender.CenterLocation, endNodePosition);
                    double candEnd = Operations.DistanceBetweenTwoPoints(MiniEntry.NeighborEntry.CenterLocation, endNodePosition);

                    if ((path.Contains(MiniEntry.NID) && (candEnd < srcEnd)))
                    {
                        MiniEntry.DownLinkAction = FlowAction.Forward;
                    }
                    else
                    {
                        if (!(path.Contains(MiniEntry.NID)))
                        {
                            MiniEntry.DownLinkAction = FlowAction.Forward;
                        }
                        else
                        {
                            MiniEntry.DownLinkAction = FlowAction.Drop;
                        }
                    }
                }
            }
        }
Exemple #7
0
        private static Sensor groupNeighbors()
        {
            //MobileModel model = new MobileModel();
            Sensor sink = PublicParameters.SinkNode;
            Point  currentSinkLocation = sink.CenterLocation;
            double smallest            = 0;
            Sensor cand        = null;
            Point  destination = getDirection(sinkDirection);
            double futureMoves = sinkInterval + 5;

            destination.X *= futureMoves;
            destination.Y *= futureMoves;
            Point futureSinkLocation = new Point(currentSinkLocation.X + destination.X, currentSinkLocation.Y + destination.Y); // If sink is going up the location will decrease

            if (sink.NeighborsTable.Count == 0)
            {
                //Sink is out of bound send to the CurrentSinkAgent to buffer
                outOfBound();
                Console.WriteLine("Out of bound");
                cand = null;
                return(cand);
            }
            else
            {
                Point  RootCellHeader = CellGroup.getClusterWithID(rootTreeID).CellTable.CellHeader.CenterLocation;
                double dirSum         = 0;
                double enerSum        = 0;
                double eucSum         = 0;
                Sensor CellHeader     = CellGroup.getClusterWithID(rootTreeID).CellTable.CellHeader;
                foreach (NeighborsTableEntry neiEntry in sink.NeighborsTable)
                {
                    if (neiEntry.ID != CellHeader.ID)
                    {
                        FlowTableEntry MiniEntry = new FlowTableEntry();
                        MiniEntry.NeighborEntry = neiEntry;
                        //    MiniEntry.NeighborEntry.EuclidieanDistance = Operations.DistanceBetweenTwoPoints(futureSinkLocation, MiniEntry.NeighborEntry.CenterLocation);
                        MiniEntry.NeighborEntry.EDNorm = Operations.GetTransmissionDistanceProbability(futureSinkLocation, MiniEntry.NeighborEntry.CenterLocation);
                        eucSum += MiniEntry.NeighborEntry.EDNorm;
                        // MiniEntry.NeighborEntry.Direction = Operations.DistanceBetweenTwoPoints(currentSinkLocation, MiniEntry.NeighborEntry.CenterLocation);
                        MiniEntry.NeighborEntry.DirNorm = Operations.GetTransmissionDistanceProbability(CellHeader.CenterLocation, MiniEntry.NeighborEntry.CenterLocation);
                        dirSum += MiniEntry.NeighborEntry.DirNorm;
                        MiniEntry.NeighborEntry.ResidualEnegNorm = Operations.GetResidualEnergyProbability(MiniEntry.NeighborEntry.NeiNode.ResidualEnergyPercentage);
                        enerSum += MiniEntry.NeighborEntry.ResidualEnegNorm;
                        sink.TuftFlowTable.Add(MiniEntry);
                    }
                }
                foreach (FlowTableEntry entry in sink.TuftFlowTable)
                {
                    entry.NeighborEntry.EDNorm            /= eucSum;
                    entry.NeighborEntry.DirNorm           /= dirSum;
                    entry.NeighborEntry.ResidualEnegNorm  /= enerSum;
                    entry.NeighborEntry.EuclidieanDistance = (entry.NeighborEntry.EDNorm + entry.NeighborEntry.DirNorm) * 0.5 + entry.NeighborEntry.ResidualEnegNorm;
                    if (entry.NeighborEntry.EuclidieanDistance > smallest && !(entry.NeighborEntry.NeiNode.TuftNodeTable.CellHeaderTable.isHeader))
                    {
                        smallest = entry.NeighborEntry.EuclidieanDistance;
                        cand     = entry.NeighborEntry.NeiNode;
                    }
                }
            }
            sink.TuftFlowTable.Clear();
            if (cand == null)
            {
                Console.WriteLine("cand is null");
            }
            return(cand);
        }