internal DVNode(IMNodeInternal node, ForwardDelegate forwardMethod, IAsynchQueue queue, IKeyTableFactory tableFactory, int TTL, IConfigSource config) : base(node, tableFactory, config) { _queue = queue; _forwardMethod = forwardMethod; this.TTL = TTL; distanceVector = new DistanceVector(); neighbourVectors = tableFactory.MakeKeyTable <DistanceVector>(); highlightParameters = new Parameters(new object[] { "HColour", node.Colour }); IConfig dvConfig = config.Configs["DV"]; if (dvConfig == null) { dvConfig = config.Configs["DistanceVector"]; } if (dvConfig == null) { dvConfig = config.Configs["Algorithm"]; } if (dvConfig == null) { dvConfig = config.Configs[0]; } _poison = dvConfig.GetBoolean("PoisonReverse", true); _everPrint = dvConfig.GetBoolean("EverPrint", false); _alwaysPrint = dvConfig.GetBoolean("AlwaysPrint", false); highlightPrintText = dvConfig.GetBoolean("HighlightPrint", false); }
private void BroadcastUpdate(int TTL, string msg, bool visualise) { if (ShouldPrint(visualise)) { Logger.Info(Name + " DV broadcasting update after '" + msg + "'."); } if (Model.IsPaused && IsCurrentAlgorithm && visualise) { Say("Broadcasting update after " + msg + "."); } foreach (IMNode n in Neighbours) { IMLink l = Links[n.ID]; //Poisoned reverse, don't pass back routes which route via the destination node var v = new DistanceVector(); lock (distanceVector) { foreach (Distance d in distanceVector) { if (!_poison || !d.Link.Equals(l)) //No Poison reverse { v.Add(d.Target.ID, new Distance(d.Target, d.Hop, d.Link, d.Dist)); } else //Poison reverse { v.Add(d.Target.ID, new Distance(d.Target, d.Hop, d.Link, -1f)); } } } v.Add(ID, new Distance(Node, Node, l, 0f)); _forwardMethod(ID, l.ID, new DVPacket(Node, n, v, visualise, TTL)); } }
internal DVNode(IMNodeInternal node, ForwardDelegate forwardMethod, IAsynchQueue queue, IKeyTableFactory tableFactory, int TTL, IConfigSource config) : base(node, tableFactory, config) { _queue = queue; _forwardMethod = forwardMethod; this.TTL = TTL; distanceVector = new DistanceVector(); neighbourVectors = tableFactory.MakeKeyTable<DistanceVector>(); highlightParameters = new Parameters(new object[] { "HColour", node.Colour }); IConfig dvConfig = config.Configs["DV"]; if (dvConfig == null) dvConfig = config.Configs["DistanceVector"]; if (dvConfig == null) dvConfig = config.Configs["Algorithm"]; if (dvConfig == null) dvConfig = config.Configs[0]; _poison = dvConfig.GetBoolean("PoisonReverse", true); _everPrint = dvConfig.GetBoolean("EverPrint", false); _alwaysPrint = dvConfig.GetBoolean("AlwaysPrint", false); highlightPrintText = dvConfig.GetBoolean("HighlightPrint", false); }
public void SetupDistanceVector() { Network network = Network.singleton; int dvWidth = network.nodes.Count; dv = new DistanceVector(this, new int[dvWidth, dvWidth]); }
/// <summary> /// Return the distance from me to another face. Distances are computed /// by the backend and stored by the UI /// </summary> /// <param name="otherFace">Other face</param> /// <returns>Distance</returns> public double GetDistanceToFace(Face otherFace) { if (DistanceVector.ContainsKey(otherFace)) { return(DistanceVector[otherFace]); } return(_mainCanvas.OptionDialog.DefaultMaxDistance); }
public DVPacket(IMNodeInternal from, INode to, DistanceVector distanceVector, bool visualise = false, int TTL = 51) : base(from, to, from, new Parameters("Visualise", visualise), DV.DV_NAME, visualise) { _distanceVector = distanceVector; _highlighting = false; _ttl = TTL - 1; Name = "Distance Vector " + Name; Selected = 1d; }
public GameObject TestPlayer;//for testing purposes only void LookAtTestPlayer() { if (TestPlayer != null) { if (TestPlayer.transform != null) { Vector3 DistanceVector; DistanceVector.x = Mathf.Abs(transform.position.x - TestPlayer.transform.position.x); DistanceVector.y = Mathf.Abs(transform.position.y - TestPlayer.transform.position.y); DistanceVector.z = Mathf.Abs(transform.position.z - TestPlayer.transform.position.z); float Distance = DistanceVector.magnitude; print("Distance = " + Distance.ToString()); print("DistanceVector = " + DistanceVector.ToString()); if (Distance < NoticeDistance) { transform.LookAt(TestPlayer.transform); print("looky!"); } } } }
static void Main(string[] args) { DistanceVector distanceVector = new DistanceVector(); Console.WriteLine("1. Start the simulation \n2. Add new router \n3. Remove router \n4. Remove link \n5. Add link \n6. Print \n7. Send message \n8. Exit"); string key = ""; bool run = true; while (run) { Console.WriteLine("Input: "); key = Console.ReadLine(); switch (key) { case "1": distanceVector.CopyDataFromFile(); distanceVector.Start(); break; case "2": int port = int.Parse(Console.ReadLine()); int numberOfPairs = int.Parse(Console.ReadLine()); int[] indexes = new int[numberOfPairs]; int[] weights = new int[numberOfPairs]; for (int i = 0; i < numberOfPairs; i++) { indexes[i] = int.Parse(Console.ReadLine()); weights[i] = int.Parse(Console.ReadLine()); } distanceVector.AddNewRouter(port, indexes, weights); break; case "3": int index = int.Parse(Console.ReadLine()); distanceVector.RemoveRouter(index); break; case "4": int first = int.Parse(Console.ReadLine()); int second = int.Parse(Console.ReadLine()); distanceVector.RemoveLink(first, second); break; case "5": first = int.Parse(Console.ReadLine()); second = int.Parse(Console.ReadLine()); int weight = int.Parse(Console.ReadLine()); distanceVector.AddLink(first, second, weight); distanceVector.AddLink(second, first, weight); break; case "6": index = int.Parse(Console.ReadLine()); distanceVector.Print(index); break; case "7": break; case "8": run = false; distanceVector.Clean(); break; default: break; } } }
private void BroadcastUpdate(int TTL, string msg, bool visualise) { if (ShouldPrint(visualise)) Logger.Info(Name + " DV broadcasting update after '" + msg + "'."); if (Model.IsPaused && IsCurrentAlgorithm && visualise) Say("Broadcasting update after " + msg + "."); foreach (IMNode n in Neighbours) { IMLink l = Links[n.ID]; //Poisoned reverse, don't pass back routes which route via the destination node var v = new DistanceVector(); lock (distanceVector) { foreach (Distance d in distanceVector) if (!_poison || !d.Link.Equals(l)) //No Poison reverse v.Add(d.Target.ID, new Distance(d.Target, d.Hop, d.Link, d.Dist)); else //Poison reverse v.Add(d.Target.ID, new Distance(d.Target, d.Hop, d.Link, -1f)); } v.Add(ID, new Distance(Node, Node, l, 0f)); _forwardMethod(ID, l.ID, new DVPacket(Node, n, v, visualise, TTL)); } }