public Agent(Sensor sink, Sensor root, Sensor oldagent, Sensor self) { try { sinkNode = sink; OldAgent = oldagent; NewAgent = null; RootNode = root; Node = self; if (AgentBuffer == null) { AgentBuffer = new Queue <Packet>(); } if (SinkOutOfRangeTimer.IsEnabled) { SinkOutOfRangeTimer.Stop(); } self.isSinkAgent = true; NeighborsTableEntry sinkEntry = new NeighborsTableEntry(); sinkEntry.NeiNode = PublicParameters.SinkNode; int index = self.NeighborsTable.FindIndex(item => item.ID == PublicParameters.SinkNode.ID); if (!(index >= 0)) { self.NeighborsTable.Add(sinkEntry); self.Ellipse_HeaderAgent_Mark.Stroke = new SolidColorBrush(Colors.Black); self.MainWindow.Dispatcher.Invoke(() => self.Ellipse_HeaderAgent_Mark.Visibility = Visibility.Visible); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private static void updateNeighborsTable() { PublicParameters.SinkNode.NeighborsTable.Clear(); double offset = PublicParameters.CommunicationRangeRadius; foreach (Sensor sen in PublicParameters.myNetwork) { if (sen.ID != PublicParameters.SinkNode.ID) { double distance = Operations.DistanceBetweenTwoPoints(sen.CenterLocation, PublicParameters.SinkNode.CenterLocation); if (distance <= offset) { NeighborsTableEntry entry = new NeighborsTableEntry(); entry.NeiNode = sen; PublicParameters.SinkNode.NeighborsTable.Add(entry); } } } if (PublicParameters.SinkNode.NeighborsTable.Count > 7) { } if (PublicParameters.SinkNode.NeighborsTable.Count == 0) { isOutOfBound = true; } }
/// <summary> /// only those nodes which follow within the range of i. /// </summary> /// <param name="i"></param> /// <returns></returns> private void DiscoverMyNeighbors(Sensor i) { i.NeighborsTable = new List <NeighborsTableEntry>(); // get the overlapping nodes: if (Network != null) { if (Network.Count > 0) { foreach (Sensor node in Network) { if (i.ID != node.ID && node.ID != PublicParameters.SinkNode.ID) { bool isOverlapped = Operations.isInMyComunicationRange(i, node); if (isOverlapped) { NeighborsTableEntry en = new NeighborsTableEntry(); en.NeiNode = node; i.NeighborsTable.Add(en); } } } } } }
/* private static void checkDistanceWithAgent() * { * if (isOutOfBound) * { * outOfBound(); * } * * if (myAgent != null) * { * * double distance = Operations.DistanceBetweenTwoPoints(PublicParameters.SinkNode.CenterLocation, myAgent.CenterLocation); * double offset = (PublicParameters.SinkNode.ComunicationRangeRadius-5); * if (distance > offset) * { * chooseAgent(); * } * } * else * { * * chooseAgent(); * } * * * * } * */ private static void updateNeighborsTable() { PublicParameters.SinkNode.NeighborsTable.Clear(); double offset = PublicParameters.CommunicationRangeRadius; foreach (Sensor sen in PublicParameters.myNetwork) { if (sen.ID != PublicParameters.SinkNode.ID) { double distance = Operations.DistanceBetweenTwoPoints(sen.CenterLocation, PublicParameters.SinkNode.CenterLocation); int entered = 0; if (distance <= offset) { entered++; NeighborsTableEntry entry = new NeighborsTableEntry(); entry.NeiNode = sen; PublicParameters.SinkNode.NeighborsTable.Add(entry); } if (entered > 10) { Console.WriteLine("Sink has lots of neighbors"); } } } if (PublicParameters.SinkNode.NeighborsTable.Count > 15) { Console.WriteLine("More than 15 neighbors"); } if (PublicParameters.SinkNode.NeighborsTable.Count == 0) { isOutOfBound = true; } }
/// <summary> /// only those nodes which follow within the range of i. /// </summary> /// <param name="i"></param> /// <returns></returns> private void DiscoverMyNeighbors(Sensor i) { i.NeighborsTable = new List <NeighborsTableEntry>(); // get the overlapping nodes: if (Network != null) { if (Network.Count > 0) { foreach (Sensor node in Network) { if (i.ID != node.ID) { bool isOverlapped = Operations.isInMyComunicationRange(i, node); if (isOverlapped) { NeighborsTableEntry en = new NeighborsTableEntry(); en.NeiNode = node; en.R = Operations.DistanceBetweenTwoSensors(i, node);//R表示源节点到某邻居节点的距离 en.angle = Operations.Angle_SenderReceive_TO_SenderSink(i, node, PublicParamerters.SinkNode); i.NeighborsTable.Add(en); } } } } } }
private static void GetSubDistribution(Sensor sender, NeighborsTableEntry neiEntry) { int i = 0; foreach (FunCoef funItem in sender.function) { if (i == 5 && funItem.coef != null) { //if the value is direction, then the coef is needed to modify by density funItem.coef[2] = neiEntry.result[0]; neiEntry.result[i] = SigmoidFunction(neiEntry.value[i], funItem.coef); } else { if (funItem.func == 0) { neiEntry.result[i] = ExpFunction(neiEntry.value[i], funItem.coef); } else if (funItem.func == 1) { neiEntry.result[i] = GaussFunction(neiEntry.value[i], funItem.coef); } else if (funItem.func == 2) { neiEntry.result[i] = SigmoidFunction(neiEntry.value[i], funItem.coef); } else if (funItem.func == 3) { if (neiEntry.value[i] < 0.5) { neiEntry.result[i] = 1; } else { neiEntry.result[i] = 0; } //neiEntry.result[i] = 1.0/ neiEntry.value[i]; } else { neiEntry.result[i] = 0; } } i++; } }
public Agent(Sensor sink, Sensor oldagent, Sensor self) { sinkNode = sink; OldAgent = oldagent; Node = self; if (AgentBuffer == null) { AgentBuffer = new Queue <Packet>(); } if (SinkOutOfRangeTimer.IsEnabled) { SinkOutOfRangeTimer.Stop(); } self.isSinkAgent = true; NeighborsTableEntry sinkEntry = new NeighborsTableEntry(); sinkEntry.NeiNode = PublicParameters.SinkNode; self.NeighborsTable.Add(sinkEntry); self.Ellipse_HeaderAgent_Mark.Stroke = new SolidColorBrush(Colors.Black); self.MainWindow.Dispatcher.Invoke(() => self.Ellipse_HeaderAgent_Mark.Visibility = Visibility.Visible); }
/// <summary> /// only those nodes which follow within the range of i. /// </summary> /// <param name="i"></param> /// <returns></returns> private void DiscoverMyNeighbors(Sensor i) { i.NeighborsTable = new List <NeighborsTableEntry>(); // get the overlapping nodes: if (Network != null) { if (Network.Count > 0) { foreach (Sensor node in Network) { if (i.ID != node.ID) { bool isOverlapped = Operations.isInMyComunicationRange(i, node); if (isOverlapped) { NeighborsTableEntry en = new NeighborsTableEntry(); en.NeiNode = node; en.R = Operations.DistanceBetweenTwoSensors(i, node); en.NeiNode = node; //public double[] value = new double[10]; //den,ds,dn,pd,re,dir en.value[2] = Operations.DistanceBetweenTwoSensors(i, node) / node.ComunicationRangeRadius; en.value[4] = node.ResidualEnergy / node.BatteryIntialEnergy; en.value[1] = (node.ds - i.ds + i.ComunicationRangeRadius) / (2 * i.ComunicationRangeRadius); en.value[5] = GetDirection(i, node) / Math.PI; en.value[6] = node.HopsToSink; i.NeighborsTable.Add(en); } } } } } }