コード例 #1
0
        public Sensor SelectNextHop(Sensor ni, Packet packet)
        {
            List <CoordinationEntry> coordinationEntries = new List <CoordinationEntry>();
            double sum = 0;
            Sensor sj  = null;

            foreach (Sensor nj in ni.NeighborsTable)
            {
                double pj   = Operations.Perpendiculardistance(nj.CenterLocation, packet.Source.CenterLocation, packet.Destination.CenterLocation);
                double pi   = Operations.Perpendiculardistance(ni.CenterLocation, packet.Source.CenterLocation, packet.Destination.CenterLocation);
                double npj  = pj / (pi + PublicParamerters.CommunicationRangeRadius);
                double Edis = 1;
                if (Settings.Default.ConsiderEnergy)
                {
                    Edis = MeredPathDistributions.EnergyDistribution(nj.ResidualEnergyPercentage, 100);
                }
                double disPij   = Math.Exp(-npj);
                double Norangle = Operations.AngleDotProdection(ni.CenterLocation, nj.CenterLocation, packet.Destination.CenterLocation);



                if (Norangle < 0.5 || Double.IsNaN(Norangle))
                {
                    double disAngij;
                    if (Double.IsNaN(Norangle))
                    {
                        disAngij = Math.Exp(-0);
                    }
                    else
                    {
                        disAngij = Math.Exp(-Norangle);
                    }
                    double aggregatedValue = disAngij * (disPij + Edis);
                    sum += aggregatedValue;
                    coordinationEntries.Add(new CoordinationEntry()
                    {
                        Priority = aggregatedValue, Sensor = nj
                    });                                                                                           // candidaite
                }
            }

            if (Settings.Default.CoordinationType == CoordinationType.Random.ToString())
            {
                // random coordinate:
                sj = counter.RandomCoordinate(coordinationEntries, packet, sum);
            }
            else if (Settings.Default.CoordinationType == CoordinationType.Mixed.ToString())
            {
                sj = counter.MaximalCoordinate(coordinationEntries, packet, sum);
            }
            else
            {
                sj = counter.MaximalCoordinate(coordinationEntries, packet, sum);
            }

            return(sj);
        }
コード例 #2
0
ファイル: MergedPathsMessages.cs プロジェクト: howbani/mp
        /// <summary>
        /// get the max value
        /// </summary>
        /// <param name="ni"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public Sensor SelectNextHop(Sensor ni, Packet packet)
        {
            if (packet.Branch != null)
            {
                List <CoordinationEntry> coordinationEntries = new List <CoordinationEntry>();
                double sum = 0;
                Sensor sj  = null;
                foreach (Sensor nj in ni.NeighborsTable)
                {
                    if (nj.ResidualEnergyPercentage > 0)
                    {
                        if (packet.isRecovery)
                        {
                        }

                        double Norangle;
                        if (packet.Destination != null)
                        {
                            if (nj.ID == packet.Destination.ID)
                            {
                                return(nj);
                            }
                        }
                        else
                        {
                            Norangle = Operations.AngleDotProdection(ni.CenterLocation, nj.CenterLocation, packet.Branch.EndPoint);
                            if (Double.IsNaN(Norangle) || Norangle == 0 || Norangle < 0.0001)
                            {
                                // for none-recovery we had the destination.
                                return(nj);
                            }
                            else
                            {
                                if (Norangle < 0.5)
                                {
                                    double ij_ψ = MeredPathDistributions.PerpendicularDistanceDistribution(ni.CenterLocation, nj.CenterLocation, packet.Branch.StartPoint, packet.Branch.EndPoint);
                                    double ij_ω = MeredPathDistributions.ProximityToBranchEndPoint(ni.CenterLocation, nj.CenterLocation, packet.Branch.EndPoint);
                                    double ij_σ = MeredPathDistributions.EnergyDistribution(nj.ResidualEnergyPercentage, 100);
                                    double ij_d = MeredPathDistributions.TransDistDistribution(ni.CenterLocation, nj.CenterLocation);

                                    // double agg1 = Math.Pow(ij_ω, (1 - Norangle)) * (ij_ψ + ij_d + ij_σ); // this needs to be try when lifetime.

                                    double defual = ij_ω * (ij_ψ + ij_d + ij_σ);

                                    double aggregatedValue = defual;
                                    sum += aggregatedValue;
                                    coordinationEntries.Add(new CoordinationEntry()
                                    {
                                        Priority = aggregatedValue, Sensor = nj
                                    });
                                }
                            }
                        }
                    }
                }


                if (Settings.Default.CoordinationType == CoordinationType.Random.ToString())
                {
                    // random coordinate:
                    sj = counter.RandomCoordinate(coordinationEntries, packet, sum);
                }
                else if (Settings.Default.CoordinationType == CoordinationType.Mixed.ToString())
                {
                    sj = counter.RandomCoordinate(coordinationEntries, packet, sum);
                }
                else
                {
                    sj = counter.MaximalCoordinate(coordinationEntries, packet, sum);
                }
                return(sj);
            }
            else
            {
                return(null);
            }
        }