public void Utilize(int limit, TimeSpan Time, out string log) { log = ""; for (int i = 0; i < TimeMessage.Count; i++) { if (Time.Subtract(TimeMessage[i]).TotalSeconds > limit) { for (int f = 0; f < Edges.Count; f++) { if (TimeEdges[i].Equals(Edges[f])) { if (EdgeWeight[f] > 1) { log += "Edge #" + No + " & Edge # " + Edges[f].No + " get low\n"; EdgeWeight[f] -= 1; TimeEdges.RemoveAt(i); TimeMessage.RemoveAt(i); break; } else { log += "Edge #" + No + " & Edge # " + Edges[f].No + " delete\n"; Edges.RemoveAt(f); EdgeWeight.RemoveAt(f); TimeEdges.RemoveAt(i); TimeMessage.RemoveAt(i); break; } } } --i; } } }
// Constructors public Edge(Node <TValue> tail, Node <TValue> head, EdgeKind kind, EdgeWeight weight) { Tail = tail; Head = head; Kind = kind; Weight = weight; }
/// <summary> /// Does the queue contain this node? /// </summary> /// <param name="toCheck"></param> /// <returns></returns> public bool Contains(EdgeWeight toCheck) { //See if there is a key containing this value if (!theDic.TryGetValue(toCheck.weight, out aQueue)) { return false; } //Key exists does its queue contain this node if (aQueue.Contains(toCheck)) { return true; } return false; }
public Edge <TValue> AddEdge(TValue tail, TValue head, EdgeKind kind, EdgeWeight weight) { var tailNode = GetNode(tail); var headNode = GetNode(head); var edge = new Edge <TValue>(tailNode, headNode, kind, weight); tailNode.OutgoingEdges.Add(edge); headNode.IncomingEdges.Add(edge); return(edge); }
public void Enqueue(EdgeWeight toEnqueue) { //no key exists for this value we must create a key and queue if (!theDic.TryGetValue(toEnqueue.weight, out aQueue)) { //came back null create a new Queue for this slot aQueue = new Queue<EdgeWeight>(); aQueue.Enqueue(toEnqueue); theDic.Add(toEnqueue.weight, aQueue); } //queue already exists inside the dictionary append to exisiting key else { aQueue.Enqueue(toEnqueue); } }
protected void Receive(Node sender) { bool found = false; for (int i = 0; i < Edges.Count; i++) { if (Edges[i].Equals(sender)) { found = true; EdgeWeight[i] += 1; } } if (!found) { Edges.Add(sender); EdgeWeight.Add(1); } }
public void SendMessage(Node recipient) { recipient.Receive(this); bool found = false; for (int i = 0; i < Edges.Count; i++) { if (Edges[i].Equals(recipient)) { found = true; EdgeWeight[i] += 1; } } if (!found) { Edges.Add(recipient); EdgeWeight.Add(1); } }