public void start(object obj) { int length = NodeList.Nodes.Count; int WakeUpRange = NodeActivator.WakeUpNodeList.Count(); bool equilibrium = false; NodeActivator.TotalWakeUpCalls = 0; Random random = new Random(); NodeActivator.StartTime = DateTime.Now; int rand = 0, i = 0; CancellationToken token = (CancellationToken)obj; //initialize data for each node before simulation loop starts for (i = 0; i < length; i++) { NodeList.Nodes[i].FlowReciever(); if (NodeActivator.Cancel) { break; } } //this loop only breaks if equilibium reached or all nodes get failed while (true) { if (NodeActivator.Cancel) { break; } WakeUpRange = NodeActivator.WakeUpNodeList.Count(); if (WakeUpRange <= 1) { AdHocNetSimulation.SimWindow.WriteOutput("\nAll nodes have been failed\n"); break; } rand = random.Next(0, WakeUpRange); equilibrium = NodeActivator.loopWakeUpCall(rand); if (equilibrium) { break; } if (token.IsCancellationRequested) { break; } } }
public void FlowReciever() { double failure = _Random.NextDouble(); if (!this._initialized) { this._initialized = true; this._intializeCombinations(); } if (failure < this._FailureRate && NodeActivator.FailNum > 0 && this._failed == false) { this._KillMySelf(); NodeActivator.RemoveNode(this.ID); NodeActivator.FailNum = NodeActivator.FailNum - 1; this._failed = true; } if (!this._failed) { this._SourceNum = this.Sources.Count; int i = 0; string key = null; for (int j = 0; j < this._SourceNum; j++) { i = this.Sources.ElementAt(j); for (int x = 0; x < this.InFlow[i].Count; x++) { if (this.InFlow[i].ElementAt(x).Value.OriginID != -1) { if (this.InFlow[i].ElementAt(x).Value.DestinationID == this.ID) { this._ConsumeFlow(this.InFlow[i].ElementAt(x).Value.OriginID, this.InFlow[i].ElementAt(x).Value.CurrFlow, i); } else { key = this.InFlow[i].ElementAt(x).Key; this._ForwardFlow(key, i); } key = this.InFlow[i].ElementAt(x).Key; this.InFlow[i][key].OriginID = -1; } } } this._SendMyOwnFlow(); } }