Esempio n. 1
0
        /// <summary>
        /// the senderNode seletes the next hop from the nodes which are active or ON now.
        /// select the higest priority.
        /// we assume that the active nodes will recive the date and send ACK. we assume also that the active nodes recived the pck and the sender node send CTS packet, to let the selected forwarder node to send its packet.
        ///
        /// </summary>
        /// <param name="candidates"></param>
        /// <returns></returns>
        public RoutingMetric SelectedForwarder(Sensor senderNode, Sensor source)
        {
            RoutingMetric        Max    = null;
            List <RoutingMetric> wakUps = new List <Forwarding.RoutingMetric>();

            // check the sink is there. one hop to the sink.
            foreach (RoutingMetric candidate in senderNode.MyForwardersShortedList)
            {
                if (candidate.PotentialForwarder.ID == PublicParamerters.SinkNode.ID)
                {
                    Max = candidate;
                }
            }


            if (Max == null)
            {
                bool isMaxSelected = false;
                if (senderNode.ID != source.ID)
                {
                    // sort the nodes agian prependicual distance
                    ForwardersSelection xx = new Forwarding.ForwardersSelection();
                    xx.UpdateMyForwardersAccordingtoPerpendicaureDistance(senderNode, source);
                }

                // copy.
                List <RoutingMetric> coordernaters = new List <Forwarding.RoutingMetric>();
                coordernaters.AddRange(senderNode.MyForwardersShortedList);

                // candidates are sorted according to heigh pri, then we need to select the first active node " radio ON".
                foreach (RoutingMetric candidate in coordernaters)
                {
                    // check it one of candidate is the sink node.
                    // we asume that the currently Active node, can lsiten and will be the recieve the data.
                    // the heighest active node.
                    if (candidate.PotentialForwarder.CurrentSensorState == Datatypes.SensorStatus.Active)
                    {
                        if (!isMaxSelected)
                        {
                            isMaxSelected = true;
                            Max           = candidate;
                        }
                        else
                        {
                            Logs.Logs.RedundantPackets(senderNode, candidate.PotentialForwarder);
                            PublicParamerters.TotalReduntantTransmission += 1;
                        }
                    }
                }
            }

            return(Max);
        }
Esempio n. 2
0
        /// <summary>
        /// within my subzone ONLY
        /// the source and sender node are the same.
        /// </summary>
        /// <param name="senderNode"></param>
        /// <returns></returns>
        public List <RoutingMetric> SelectForwardersSetWithinMySubZone(Sensor senderNode)
        {
            // the routing zone.
            List <Point>  FourCorners = senderNode.MyRoutingZone;
            Parallelogram Zone        = new Computations.Parallelogram();

            if (FourCorners != null)
            {
                Zone.P1 = FourCorners[0];
                Zone.P2 = FourCorners[1];
                Zone.P3 = FourCorners[2];
                Zone.P4 = FourCorners[3];
            }

            Geomtric             Geo        = new Computations.Geomtric();
            List <RoutingMetric> Forwarders = new List <RoutingMetric>();

            if (PublicParamerters.SinkNode == null)
            {
                return(null);
            }
            else
            if (PublicParamerters.SinkNode.ID != senderNode.ID) // for all node but sink node
            {
                List <Sensor> N = senderNode.NeighboreNodes;
                if (N != null)
                {
                    if (N.Count > 0)
                    {
                        // sum:
                        double EnergySum        = 0; // energy
                        double DirectionSum     = 0; // direction
                        double PreDistanceSum   = 0; // prependiculare distance
                        double TransDistanceSum = 0; // transmission distance
                        foreach (Sensor potentialForwarder in N)
                        {
                            if (potentialForwarder.ResidualEnergy > 0)
                            {
                                // if next hop is wthin the zone of the source node then:
                                Point point = potentialForwarder.CenterLocation;
                                if (Geo.PointTestParallelogram(Zone, point))
                                {
                                    double Dij = Operations.DistanceBetweenTwoSensors(senderNode, potentialForwarder);                 // i and j
                                    double Djb = Operations.DistanceBetweenTwoSensors(potentialForwarder, PublicParamerters.SinkNode); // j and b
                                    double Dib = Operations.DistanceBetweenTwoSensors(senderNode, PublicParamerters.SinkNode);         // i and b

                                    RoutingMetric metRic = new RoutingMetric();
                                    metRic.PID                           = PublicParamerters.NumberofGeneratedPackets;
                                    metRic.SenderNode                    = senderNode;
                                    metRic.SourceNode                    = senderNode;
                                    metRic.PotentialForwarder            = potentialForwarder;
                                    metRic.DistanceFromSenderToForwarder = Dij;
                                    metRic.DistanceFromSenderToSink      = Dib;
                                    metRic.DistanceFromFrowarderToSink   = Djb;
                                    metRic.r = senderNode.ComunicationRangeRadius;
                                    metRic.ZoneWidthControl = Settings.Default.ZoneWidth;

                                    // sum's:
                                    EnergySum        += Math.Exp(Math.Pow(metRic.NormalizedEnergy, Settings.Default.EnergyDistCnt));
                                    TransDistanceSum += (1 / (Math.Exp(Math.Pow(metRic.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt))));
                                    DirectionSum     += (1 / (Math.Exp(Math.Pow(metRic.NormalizedDirection, Settings.Default.DirectionDistCnt))));
                                    PreDistanceSum   += (1 / (Math.Exp(Math.Pow(metRic.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt))));

                                    Forwarders.Add(metRic); // keep for each node.
                                }
                                else
                                { // if the sink is a direct neigbore with me
                                    if (PublicParamerters.SinkNode.ID == potentialForwarder.ID)
                                    {
                                        double Dij = Operations.DistanceBetweenTwoSensors(senderNode, potentialForwarder);                 // i and j
                                        double Djb = Operations.DistanceBetweenTwoSensors(potentialForwarder, PublicParamerters.SinkNode); // j and b
                                        double Dib = Operations.DistanceBetweenTwoSensors(senderNode, PublicParamerters.SinkNode);         // i and b

                                        RoutingMetric metRic = new RoutingMetric();
                                        metRic.PID                           = PublicParamerters.NumberofGeneratedPackets;
                                        metRic.SenderNode                    = senderNode;
                                        metRic.SourceNode                    = senderNode;
                                        metRic.PotentialForwarder            = potentialForwarder;
                                        metRic.DistanceFromSenderToForwarder = Dij;
                                        metRic.DistanceFromSenderToSink      = Dib;
                                        metRic.DistanceFromFrowarderToSink   = Djb;
                                        metRic.r = senderNode.ComunicationRangeRadius;
                                        metRic.ZoneWidthControl = Settings.Default.ZoneWidth;

                                        // sum's:
                                        EnergySum        += Math.Exp(Math.Pow(metRic.NormalizedEnergy, Settings.Default.EnergyDistCnt));
                                        TransDistanceSum += (1 / (Math.Exp(Math.Pow(metRic.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt))));
                                        DirectionSum     += (1 / (Math.Exp(Math.Pow(metRic.NormalizedDirection, Settings.Default.DirectionDistCnt))));
                                        PreDistanceSum   += (1 / (Math.Exp(Math.Pow(metRic.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt))));


                                        Forwarders.Add(metRic); // keep for each node.
                                    }
                                }
                            }
                        }


                        double LinkQEstiSum = 0;//  the sum of link quality estimations, for all forwarders.
                        int    k            = 0;
                        foreach (RoutingMetric forwarder in Forwarders)
                        {
                            // propablity distrubution:
                            forwarder.EnPr   = (Math.Exp(Math.Pow(forwarder.NormalizedEnergy, Settings.Default.EnergyDistCnt))) / EnergySum;
                            forwarder.TdPr   = (1 / (Math.Exp(Math.Pow(forwarder.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt)))) / TransDistanceSum;
                            forwarder.DirPr  = (1 / (Math.Exp(Math.Pow(forwarder.NormalizedDirection, Settings.Default.DirectionDistCnt)))) / DirectionSum; // propablity for lemda.
                            forwarder.PerdPr = (1 / (Math.Exp(Math.Pow(forwarder.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt)))) / PreDistanceSum;
                            LinkQEstiSum    += forwarder.LinkEstimation;
                            k++;
                        }

                        foreach (RoutingMetric Potentialforwarder in Forwarders)
                        {
                            Potentialforwarder.LinkEstimationNormalized = Potentialforwarder.LinkEstimation / LinkQEstiSum;
                        } // end lik hoode

                        /*
                         *
                         * //
                         * List<RoutingMetric> selected = new List<Forwarding.RoutingMetric>();
                         * foreach (RoutingMetric or in Forwarders)
                         * {
                         *  if(or.LinkEstimationNormalized>(1/(Convert.ToDouble(Forwarders.Count))))
                         *  {
                         *      selected.Add(or);
                         *  }
                         * }
                         *
                         * if(selected.Count>=1)
                         * {
                         *  Forwarders.Clear();
                         *  Forwarders = selected;
                         * }
                         *
                         * LinkQEstiSum = 0;
                         * foreach (RoutingMetric forwarder in Forwarders)
                         * {
                         *  LinkQEstiSum += forwarder.LinkEstimation;
                         * }
                         *
                         * foreach (RoutingMetric Potentialforwarder in Forwarders)
                         * {
                         *  Potentialforwarder.LinkEstimationNormalized = Potentialforwarder.LinkEstimation / LinkQEstiSum;
                         *
                         * }
                         */
                    }
                }
            }

            Forwarders.Sort(new LinkPrioritySorter());// sort according to Priority.

            return(Forwarders);
        }
Esempio n. 3
0
        /// <summary>
        /// a mong all neighbors.
        /// </summary>
        /// <param name="senderNode"></param>
        /// <returns></returns>
        private List <RoutingMetric> SelectForwardersSetWithinMyNeighbors(Sensor senderNode)
        {
            List <RoutingMetric> Forwarders = new List <RoutingMetric>();
            List <Sensor>        N          = senderNode.NeighboreNodes;

            if (N != null)
            {
                if (N.Count > 0)
                {
                    // sum:
                    double EnergySum        = 0; // energy
                    double DirectionSum     = 0; // direction
                    double PreDistanceSum   = 0; // prependiculare distance
                    double TransDistanceSum = 0; // transmission distance
                    foreach (Sensor potentialForwarder in N)
                    {
                        if (potentialForwarder.ResidualEnergy > 0)
                        {
                            if (PublicParamerters.SinkNode.ID == potentialForwarder.ID)
                            {
                                double Dij = Operations.DistanceBetweenTwoSensors(senderNode, potentialForwarder);                 // i and j
                                double Djb = Operations.DistanceBetweenTwoSensors(potentialForwarder, PublicParamerters.SinkNode); // j and b
                                double Dib = Operations.DistanceBetweenTwoSensors(senderNode, PublicParamerters.SinkNode);         // i and b

                                RoutingMetric metRic = new RoutingMetric();
                                metRic.PID                           = PublicParamerters.NumberofGeneratedPackets;
                                metRic.SenderNode                    = senderNode;
                                metRic.SourceNode                    = senderNode;
                                metRic.PotentialForwarder            = potentialForwarder;
                                metRic.DistanceFromSenderToForwarder = Dij;
                                metRic.DistanceFromSenderToSink      = Dib;
                                metRic.DistanceFromFrowarderToSink   = Djb;
                                metRic.r = senderNode.ComunicationRangeRadius;
                                metRic.ZoneWidthControl = Settings.Default.ZoneWidth;

                                // sum's:
                                EnergySum        += Math.Exp(Math.Pow(metRic.NormalizedEnergy, Settings.Default.EnergyDistCnt));
                                TransDistanceSum += (1 / (Math.Exp(Math.Pow(metRic.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt))));
                                DirectionSum     += (1 / (Math.Exp(Math.Pow(metRic.NormalizedDirection, Settings.Default.DirectionDistCnt))));
                                PreDistanceSum   += (1 / (Math.Exp(Math.Pow(metRic.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt))));

                                Forwarders.Add(metRic); // keep for each node.
                            }
                            else
                            {
                                double Dij = Operations.DistanceBetweenTwoSensors(senderNode, potentialForwarder);                 // i and j
                                double Djb = Operations.DistanceBetweenTwoSensors(potentialForwarder, PublicParamerters.SinkNode); // j and b
                                double Dib = Operations.DistanceBetweenTwoSensors(senderNode, PublicParamerters.SinkNode);         // i and b

                                RoutingMetric metRic = new RoutingMetric();
                                metRic.PID                           = PublicParamerters.NumberofGeneratedPackets;
                                metRic.SenderNode                    = senderNode;
                                metRic.SourceNode                    = senderNode;
                                metRic.PotentialForwarder            = potentialForwarder;
                                metRic.DistanceFromSenderToForwarder = Dij;
                                metRic.DistanceFromSenderToSink      = Dib;
                                metRic.DistanceFromFrowarderToSink   = Djb;
                                metRic.r = senderNode.ComunicationRangeRadius;
                                metRic.ZoneWidthControl = Settings.Default.ZoneWidth;

                                // sum's:
                                EnergySum        += Math.Exp(Math.Pow(metRic.NormalizedEnergy, Settings.Default.EnergyDistCnt));
                                TransDistanceSum += (1 / (Math.Exp(Math.Pow(metRic.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt))));
                                DirectionSum     += (1 / (Math.Exp(Math.Pow(metRic.NormalizedDirection, Settings.Default.DirectionDistCnt))));
                                PreDistanceSum   += (1 / (Math.Exp(Math.Pow(metRic.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt))));

                                Forwarders.Add(metRic); // keep for each node.
                            }
                        }
                    }

                    //
                    double LinkQEstiSum = 0;//  the sum of link quality estimations, for all forwarders.
                    int    k            = 0;
                    foreach (RoutingMetric forwarder in Forwarders)
                    {
                        // propablity distrubution:
                        forwarder.EnPr   = (Math.Exp(Math.Pow(forwarder.NormalizedEnergy, Settings.Default.EnergyDistCnt))) / EnergySum;
                        forwarder.TdPr   = (1 / (Math.Exp(Math.Pow(forwarder.NormalizedTransDistance, Settings.Default.TransDistanceDistCnt)))) / TransDistanceSum;
                        forwarder.DirPr  = (1 / (Math.Exp(Math.Pow(forwarder.NormalizedDirection, Settings.Default.DirectionDistCnt)))) / DirectionSum; // propablity for lemda.
                        forwarder.PerdPr = (1 / (Math.Exp(Math.Pow(forwarder.NormalizePerpendicularDistance, Settings.Default.PrepDistanceDistCnt)))) / PreDistanceSum;
                        LinkQEstiSum    += forwarder.LinkEstimation;
                        k++;
                    }

                    foreach (RoutingMetric Potentialforwarder in Forwarders)
                    {
                        Potentialforwarder.LinkEstimationNormalized = Potentialforwarder.LinkEstimation / LinkQEstiSum;
                    } // e
                }
            }

            Forwarders.Sort(new LinkPrioritySorter());// sort according to Priority.
            return(Forwarders);
        }