/// <summary> /// This method does all the job before calling the simulation window. /// </summary> private void _generate() { //initiate all the data including NodeActivator static variables int i = 0, j = 0; NodeList.Nodes = null; NodeActivator.MaxFlow = 0; NodeActivator.TotalNumberOfEdges = 0; Dictionary <int, int> GraphIDtoID = new Dictionary <int, int>(); SimWindow = new SimulationWin(); NodeActivator.NodeNums = this._Vertexes.Count(); NodeActivator.EdgeNums = this._Edges.GetLength(0); NodeActivator.CommNums = this._Commodities.GetLength(0); NodeActivator.SimWindow = SimWindow; NodeActivator.TotalNumberOfEdges = (float)this._Edges.GetLength(0); NodeActivator.WakeUpNodeList = new HashSet <int>(); NodeActivator.NodeSplitBySourceLog = new Dictionary <int, int>(); NodeActivator.NodeSplitByTargetLog = new Dictionary <int, int>(); NodeActivator.FailNum = 0; NodeActivator.Cancel = false; this._MaxThreshold = this._Vertexes.Length * this._MaxDemand; //set up poision style probability if failure probability is greater than zero if (this._FaiureRate > 0) { this._setNodeFailureNode(); this._FaiureRate = this._FaiureRate / 100000; } j = 0; //add nodes to the static nodelist dictionary // The node IDs for simulation may be different than GUI ids foreach (int id in _Vertexes) { GraphIDtoID.Add(id, j); NodeList.Nodes.GetOrAdd(j, new AdHocNode(j++, id, this._ProfitVal, this._FaiureRate)); } try { //set up node data structures according to the edges in the network int to, from; for (i = 0; i < _Edges.GetLength(0); i++) { from = this._Edges[i, 0]; to = this._Edges[i, 1]; from = GraphIDtoID[from]; to = GraphIDtoID[to]; NodeList.Nodes[from].Targets.GetOrAdd(NodeList.Nodes[to].ID, true); NodeList.Nodes[from].MyTargetThresholds.GetOrAdd(NodeList.Nodes[to].ID, this._MaxThreshold); NodeList.Nodes[from].TargetsAndFlowReached.GetOrAdd(NodeList.Nodes[to].ID, 0); NodeList.Nodes[from].TargetsAndMyFlowSent.GetOrAdd(NodeList.Nodes[to].ID, new ConcurrentDictionary <int, float>()); NodeList.Nodes[from].TargetsAndFlowForwarded.GetOrAdd(NodeList.Nodes[to].ID, new ConcurrentDictionary <string, float>()); NodeList.Nodes[to].Sources.Add(NodeList.Nodes[from].ID); NodeList.Nodes[to].SourcesAndFlowConsumed.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary <int, float>()); NodeList.Nodes[to].SourcesAndFlowForwarded.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary <string, float []>()); NodeList.Nodes[to].FlowBlockValueForSources.GetOrAdd(NodeList.Nodes[from].ID, 0); NodeList.Nodes[to].InFlow.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary <string, AdHocFlow>()); } //update commodities according to the simulation ndoe ids for (i = 0; i < this._Commodities.GetLength(0); i++) { NodeActivator.MaxFlow += this._Commodities[i, 2]; from = (int)this._Commodities[i, 0]; to = (int)this._Commodities[i, 1]; this._Commodities[i, 0] = GraphIDtoID[from]; this._Commodities[i, 1] = GraphIDtoID[to]; } this._SplitNodes(); this._SplitCommodities(); this._TableFillAlgo(); this._TotalSingleFlow = this._CalculateSingleEdgeFlow(); NodeActivator.SingleEdgeFlow = this._TotalSingleFlow; } catch (Exception e) { ExceptionMessage.Show("There was a problem with Data provided to simulation: " + e.ToString()); } SimWindow.Show(); SimWindow.StartSim(this._TotalSingleFlow); }
/// <summary> /// This method does all the job before calling the simulation window. /// </summary> private void _generate() { //initiate all the data including NodeActivator static variables int i = 0,j = 0; NodeList.Nodes = null; NodeActivator.MaxFlow = 0; NodeActivator.TotalNumberOfEdges = 0; Dictionary<int, int> GraphIDtoID = new Dictionary<int, int>(); SimWindow = new SimulationWin(); NodeActivator.NodeNums = this._Vertexes.Count(); NodeActivator.EdgeNums = this._Edges.GetLength(0); NodeActivator.CommNums = this._Commodities.GetLength(0); NodeActivator.SimWindow = SimWindow; NodeActivator.TotalNumberOfEdges = (float) this._Edges.GetLength(0); NodeActivator.WakeUpNodeList = new HashSet<int>(); NodeActivator.NodeSplitBySourceLog = new Dictionary<int, int>(); NodeActivator.NodeSplitByTargetLog = new Dictionary<int, int>(); NodeActivator.FailNum = 0; NodeActivator.Cancel = false; this._MaxThreshold = this._Vertexes.Length * this._MaxDemand; //set up poision style probability if failure probability is greater than zero if (this._FaiureRate > 0) { this._setNodeFailureNode(); this._FaiureRate = this._FaiureRate / 100000; } j = 0; //add nodes to the static nodelist dictionary // The node IDs for simulation may be different than GUI ids foreach (int id in _Vertexes) { GraphIDtoID.Add(id, j); NodeList.Nodes.GetOrAdd(j, new AdHocNode(j++, id, this._ProfitVal, this._FaiureRate)); } try { //set up node data structures according to the edges in the network int to, from; for (i = 0; i < _Edges.GetLength(0); i++) { from = this._Edges[i, 0]; to = this._Edges[i,1]; from = GraphIDtoID[from]; to = GraphIDtoID[to]; NodeList.Nodes[from].Targets.GetOrAdd(NodeList.Nodes[to].ID,true); NodeList.Nodes[from].MyTargetThresholds.GetOrAdd(NodeList.Nodes[to].ID, this._MaxThreshold); NodeList.Nodes[from].TargetsAndFlowReached.GetOrAdd(NodeList.Nodes[to].ID, 0); NodeList.Nodes[from].TargetsAndMyFlowSent.GetOrAdd(NodeList.Nodes[to].ID, new ConcurrentDictionary<int, float>()); NodeList.Nodes[from].TargetsAndFlowForwarded.GetOrAdd(NodeList.Nodes[to].ID, new ConcurrentDictionary<string, float>()); NodeList.Nodes[to].Sources.Add(NodeList.Nodes[from].ID); NodeList.Nodes[to].SourcesAndFlowConsumed.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary<int, float>()); NodeList.Nodes[to].SourcesAndFlowForwarded.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary<string, float []>()); NodeList.Nodes[to].FlowBlockValueForSources.GetOrAdd(NodeList.Nodes[from].ID, 0); NodeList.Nodes[to].InFlow.GetOrAdd(NodeList.Nodes[from].ID, new ConcurrentDictionary<string, AdHocFlow>()); } //update commodities according to the simulation ndoe ids for (i = 0; i < this._Commodities.GetLength(0); i++) { NodeActivator.MaxFlow += this._Commodities[i, 2]; from = (int) this._Commodities[i, 0]; to = (int) this._Commodities[i, 1]; this._Commodities[i, 0] = GraphIDtoID[from]; this._Commodities[i, 1] = GraphIDtoID[to]; } this._SplitNodes(); this._SplitCommodities(); this._TableFillAlgo(); this._TotalSingleFlow = this._CalculateSingleEdgeFlow(); NodeActivator.SingleEdgeFlow = this._TotalSingleFlow; } catch (Exception e) { ExceptionMessage.Show("There was a problem with Data provided to simulation: " + e.ToString()); } SimWindow.Show(); SimWindow.StartSim(this._TotalSingleFlow); }