Example #1
0
 public void SendRandTwoPoints()
 {
     int    indexSource      = UniformRandomVariable.GetIntValue(0, PublicParamerters.MainWindow.myNetWork.Count - 1);
     int    indexDestination = UniformRandomVariable.GetIntValue(0, PublicParamerters.MainWindow.myNetWork.Count - 1);
     Sensor source           = PublicParamerters.MainWindow.myNetWork[indexSource];
     Sensor dest             = PublicParamerters.MainWindow.myNetWork[indexDestination];
     TestSendPacketsBetweenTwoNodesRandomlySelected c = new TestSendPacketsBetweenTwoNodesRandomlySelected(source, dest);
 }
Example #2
0
        public Sensor RandomCoordinate(List <CoordinationEntry> coordinationEntries, Packet packet, double sum)
        {
            // normalized:
            foreach (CoordinationEntry neiEntry in coordinationEntries)
            {
                if (neiEntry.Sensor.ResidualEnergy > 0)
                {
                    double val        = neiEntry.Priority;
                    double normalized = val / sum;
                    neiEntry.Priority = normalized;
                }
                else
                {
                    neiEntry.Priority = 0;
                }
            }

            List <CoordinationEntry> Forwarders = new List <CoordinationEntry>();
            int    n                  = coordinationEntries.Count;
            double average            = 1 / Convert.ToDouble(n);                                  // this needs to be considered
            int    maxForwarders      = Convert.ToInt16(Math.Floor(Math.Sqrt(Math.Sqrt(n)))) - 1; // theshold.
            int    MaxforwardersCount = 0;

            foreach (CoordinationEntry neiEntry in coordinationEntries)
            {
                if (neiEntry.Priority >= average && MaxforwardersCount <= maxForwarders && neiEntry.Sensor.CurrentSensorState == SensorState.Active)
                {
                    if (neiEntry.Sensor.ResidualEnergy > 0)
                    {
                        Forwarders.Add(neiEntry);
                        MaxforwardersCount++;
                    }
                }
            }

            double dsum = 0;

            for (int i = 0; i < Forwarders.Count; i++)
            {
                dsum += Forwarders[i].Priority;
            }

            foreach (CoordinationEntry neiEntry in Forwarders)
            {
                double val        = neiEntry.Priority;
                double normalized = val / dsum;
                neiEntry.Priority = normalized;
            }



            // range:
            for (int i = 0; i < Forwarders.Count; i++)
            {
                if (i == 0)
                {
                    Forwarders[0].MinRange = 0;
                    Forwarders[0].MaxRange = Forwarders[i].Priority;
                }
                else
                {
                    Forwarders[i].MinRange = Forwarders[i - 1].MaxRange;                          // min
                    Forwarders[i].MaxRange = Forwarders[i - 1].MaxRange + Forwarders[i].Priority; // max
                }
            }

            // one forwarder:
            // forward:
            Sensor forwarder = null;

            double random = UniformRandomVariable.GetDoubleValue(0, 1);

            CoordinationEntry neiEntry1 = null;

            foreach (CoordinationEntry neiEntry in Forwarders)
            {
                if (random >= neiEntry.MinRange && random <= neiEntry.MaxRange)
                {
                    forwarder = neiEntry.Sensor;
                    neiEntry1 = neiEntry;

                    break;
                }
            }


            bool isRemoved = Forwarders.Remove(neiEntry1);

            if (isRemoved)
            {
                foreach (CoordinationEntry neiEntry in Forwarders)
                {
                    RedundantTransmisionCost(packet, neiEntry.Sensor);
                }
            }


            return(forwarder);
        }
Example #3
0
 public void SendToDiagonal()
 {
     int    index = UniformRandomVariable.GetIntValue(0, PublicParamerters.MainWindow.myNetWork.Count - 1);
     Sensor sen   = PublicParamerters.MainWindow.myNetWork[index];
     ObtainSinkFreshPositionMessage ob = new ObtainSinkFreshPositionMessage(sen);
 }