private int GetUniformDirection() { int nd = Convert.ToInt16(Math.Abs(UnformRandomNumberGenerator.GetUniform(8))); //checkTheNewDirection(nd); return(nd); }
private void btn_compute_Click(object sender, RoutedEventArgs e) { PublicParamerters.FinishedRoutedPackets.Clear(); int NOS = Convert.ToInt16(com_nos.Text); int NOP = Convert.ToInt16(com_nop.Text); double dist = Convert.ToDouble(com_distance.Text); List <Sensor> SelectNodesWithinDistanceN = SelectNodesWithinDistance(dist); if (SelectNodesWithinDistanceN != null) { // selecte The Nodes: List <Sensor> SelectedSn = new List <Sensor>(NOS); for (int i = 0; i < NOS; i++) { int ran = Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(SelectNodesWithinDistanceN.Count - 1)); if (ran > 0) { SelectedSn.Add(SelectNodesWithinDistanceN[ran]); } else { SelectedSn.Add(SelectNodesWithinDistanceN[1]); } } foreach (Sensor sen in SelectedSn) { sen.GenerateMultipleDataPackets(NOP); } } }
/// <summary> /// how many sensor to be slected. /// how many packet each sensor will sent. /// </summary> /// <param name="NOS"></param> /// <param name="NOP"></param> public void RandimSelect(List <Sensor> Network, int NOS, int NOP) { // selecte The Nodes: List <Sensor> SelectedSn = new List <Modules.Sensor>(NOS); for (int i = 0; i < NOS; i++) { int ran = Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(Network.Count - 1)); if (ran > 0) { SelectedSn.Add(Network[ran]); } else { SelectedSn.Add(Network[1]); } } // each packet sendt NOP: for (int i = 0; i < NOP; i++) { foreach (Sensor sen in SelectedSn) { sen.GeneratePacketAndSent(false, Settings.Default.EnergyDistCnt, Settings.Default.TransDistanceDistCnt, Settings.Default.DirectionDistCnt, Settings.Default.PrepDistanceDistCnt); } } } // end class random generated.
/// <summary> /// how many sensor to be slected. /// how many packet each sensor will sent. /// </summary> /// <param name="NOS"></param> /// <param name="NOP"></param> public void RandimSelect(List <Sensor> Network, int NOS, int NOP) { // selecte The Nodes: List <Sensor> SelectedSn = new List <Modules.Sensor>(NOS); for (int i = 0; i < NOS; i++) { int ran = Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(Network.Count - 1)); if (ran > 0) { SelectedSn.Add(Network[ran]); } else { SelectedSn.Add(Network[1]); } } // each packet sendt NOP: for (int i = 0; i < NOP; i++) { foreach (Sensor sen in SelectedSn) { sen.GeneratePacekts(); } } } // end class random generated.
/// <summary> /// perform the experment. /// </summary> /// <param name="distance"></param> /// <param name="NOS"></param> /// <param name="NOP"></param> public EnergyConsmption2 DoExperment(double distance, int NOS, int NOP) { List <Sensor> SelectNodesWithinDistanceN = SelectNodesWithinDistance(distance); if (SelectNodesWithinDistanceN != null) { // selecte The Nodes: List <Sensor> SelectedSn = new List <Modules.Sensor>(NOS); for (int i = 0; i < NOS; i++) { int ran = Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(SelectNodesWithinDistanceN.Count - 1)); if (ran > 0) { SelectedSn.Add(SelectNodesWithinDistanceN[ran]); } else { SelectedSn.Add(SelectNodesWithinDistanceN[1]); } } // each packet sendt NOP: for (int i = 0; i < NOP; i++) { foreach (Sensor sen in SelectedSn) { sen.GeneratePacketAndSent(); // sen.GeneratePacketAndSent(false, Settings.Default.EnergyDistCnt, Settings.Default.TransDistanceDistCnt, Settings.Default.DirectionDistCnt, Settings.Default.PrepDistanceDistCnt); } } EnergyConsmption2 re = new ExpermentsResults.EnergyConsmption2(); re.Distance = distance; re.NOP = NOP; re.Nodes = SelectedSn; re.NOS = NOS; re.Number_of_RecievedPackets = PublicParamerters.SinkNode.PacketsList.Count; foreach (DataPacket.Datapacket pa in PublicParamerters.SinkNode.PacketsList) { re.EnergyConsumption += pa.UsedEnergy_Joule; re.SumRoutingEfficiency += pa.RoutingEfficiency; } PublicParamerters.SinkNode.PacketsList.Clear();// clear. return(re); } else { System.Windows.MessageBox.Show("Distance is too short it should be 2*sensang range"); return(null); } }
private void RandomSelectNodes_Tick(object sender, EventArgs e) { // start sending after the nodes are intilized all. if (PublicParamerters.SimulationTime > PublicParamerters.MacStartUp) { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParamerters.NumberofNodes - 2)); if (index != PublicParamerters.SinkNode.ID) { myNetWork[index].GeneratePacketAndSent(); } } }
private void RandomSelectNodes_Tick(object sender, EventArgs e) { // start sending after the nodes are intilized all. if (PublicParamerters.SimulationTime < stopSimlationWhen) { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(myNetWork.Count - 2)); if (index != PublicParamerters.SinkNode.ID) { myNetWork[index].GeneratePacketAndSent(false, Settings.Default.EnergyDistCnt, Settings.Default.TransDistanceDistCnt, Settings.Default.DirectionDistCnt, Settings.Default.PrepDistanceDistCnt); } } }
public void RandomSelectEndNodes(int numOFpACKETS) { if (PublicParamerters.SimulationTime > PublicParamerters.MacStartUp) { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParamerters.NumberofNodes - 2)); if (index != PublicParamerters.SinkNode.ID) { Sensor endNode = MainWindow.myNetWork[index]; GenerateMultipleControlPackets(numOFpACKETS, endNode); } } }
private void UplinkPacketsGenerate_Tirk(object sender, EventArgs e) { UplinkalreadyGeneratedPackets++; if (UplinkalreadyGeneratedPackets <= UplinkTobeGeneratedPackets) { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParamerters.NumberofNodes - 2)); // myNetWork[index].GenerateDataPacket(); } else { RandomSelectSourceNodesTimer.Interval = TimeSpan.FromSeconds(0); RandomSelectSourceNodesTimer.Stop(); UplinkalreadyGeneratedPackets = 0; UplinkTobeGeneratedPackets = 0; } }
private void RandomSelectSourceNodesTimer_Tick(object sender, EventArgs e) { if (PublicParamerters.NumberofGeneratedPackets < xPackets) { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParamerters.NumberofNodes - 2)); myNetWork[index].GeneratePacketAndSent(); Console.WriteLine("Target" + xPackets + ". Generated:" + PublicParamerters.NumberofGeneratedPackets.ToString()); } else { RandomSelectSourceNodesTimer.Interval = TimeSpan.FromSeconds(0); RandomSelectSourceNodesTimer.Stop(); xPackets = 0; Console.WriteLine("Finised"); } }
private void DownLINKRandomSentAnumberofPackets(object sender, EventArgs e) { DownlinkAlreadyGenerated++; if (DownlinkAlreadyGenerated <= DownlinkTobeGenerated) { int index = Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParameters.NumberofNodes - 2)); Sensor EndNode = myNetWork[index]; PublicParameters.SinkNode.GenerateControlPacket(EndNode); } else { RandomSelectSourceNodesTimer.Interval = TimeSpan.FromSeconds(0); RandomSelectSourceNodesTimer.Stop(); DownlinkAlreadyGenerated = 0; DownlinkTobeGenerated = 0; } }
/// <summary> /// how many sensor to be slected. /// how many packet each sensor will sent. /// </summary> /// <param name="NOS"></param> /// <param name="NOP"></param> public void RandimSelect(List <Sensor> Network, int NOS, int NOP) { // selecte The Nodes: List <Sensor> SelectedSn = new List <Dataplane.Sensor>(NOS); for (int i = 0; i < NOS; i++) { int ran = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(Network.Count - 2)); SelectedSn.Add(Network[ran]); } // each packet sendt NOP: for (int i = 0; i < NOP; i++) { foreach (Sensor sen in SelectedSn) { sen.GenerateDataPacket(); } } } // end class random generated.
/// <summary> /// generate packet. start by obtian. /// </summary> private void GenerateRandomPacket() { int index = 1 + Convert.ToInt16(UnformRandomNumberGenerator.GetUniform(PublicParamerters.NumberofNodes - 2)); Sensor sensor = myNetWork[index]; ObtainSinkFreshPositionMessage ob = new ObtainSinkFreshPositionMessage(sensor); }