private bool selectStartNode(NetworkTopology topo, out int selectNode, bool isNeedRecompute) { int eccentricity; int diameter = int.MinValue; int minDegree = int.MaxValue; bool isSelected = false; // If find center point. if (topo.FindCenterNodeID(out selectNode, out eccentricity, isNeedRecompute)) { foreach (var node in topo.Nodes) { if (diameter < node.Eccentricity) { diameter = node.Eccentricity; } } // Check whether the diameter is greater than 2 * K, then select the point from center. if (diameter > 2 * K) { isSelected = true; } // Select the point from minimum degree. else { foreach (var n in topo.Nodes) { if (minDegree > topo.Degree(n.ID)) { minDegree = topo.Degree(n.ID); selectNode = n.ID; isSelected = true; } } } } // Select the point from minimum degree. else { foreach (var n in topo.Nodes) { if (minDegree > topo.Degree(n.ID)) { minDegree = topo.Degree(n.ID); selectNode = n.ID; isSelected = true; } } } return(isSelected); }
private bool selectStartNode(NetworkTopology topo, out int selectNode, bool isNeedRecompute) { int minDegree = int.MaxValue; bool isSelected = false; selectNode = -1; foreach (var n in topo.Nodes) { if (minDegree > topo.Degree(n.ID)) { minDegree = topo.Degree(n.ID); selectNode = n.ID; isSelected = true; } } return(isSelected); }
/// <summary> /// Starting run algorithm with specific source topology and K-diameter cut, /// and this round process will generate scope topology to scop_net_topo, /// and will add the deployment node to deployNodes structure. /// Finally, it will return the remain network topology with this process. /// </summary> /// <param name="src_net_topo">The source network topology</param> /// <param name="scope_net_topo">This round process that generte scope topology</param> /// <param name="nowDeployNodes">The result of the deployment node id</param> /// <returns>The remain network topology after process the algorithm.</returns> private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes) { List <int> neighbor = new List <int>(); int selectNode = scope_net_topo.Nodes[0].ID; while (true) { neighbor.Remove(selectNode); neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.Distinct().ToList(); NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes); concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix; concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID))); concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2))); foreach (int id in neighbor) { concentrate_topo.Edges.Add(new NetworkTopology.Edge() { Node1 = id, Node2 = scope_net_topo.Nodes[0].ID }); } selectNode = -1; List <int> tmp = new List <int>(neighbor); //neighbor.Sort((x, y) => concentrate_topo.Degree(x).CompareTo(concentrate_topo.Degree(y))); for (int i = 0; i < neighbor.Count; i++) { int max_hop_count = int.MinValue; int minD = int.MaxValue; foreach (int id in tmp) { int tmpD = concentrate_topo.Degree(id); if (minD > tmpD) { minD = tmpD; selectNode = id; } } tmp.Remove(selectNode); foreach (var scopeNode in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } if (max_hop_count <= K - 1) { break; } else { selectNode = -1; } } //int minD = int.MaxValue; //foreach (int id in neighbor) //{ // int tmpD = concentrate_topo.Degree(id); // if (minD > tmpD) // { // minD = tmpD; // selectNode = id; // } //} //if (scope_net_topo.Nodes.Count >= N) // selectNode = -1; // if nothing found, break the loop. if (selectNode == -1) { break; } // Computing the max hop counts with adding the select node. else { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode)); //foreach (var scopeNode in scope_net_topo.Nodes) //{ // int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode); // if (max_hop_count < hop_count) // max_hop_count = hop_count; //} } } NetworkTopology remain_topo; // Handling the neighbor nodes of each node in the scope network topology. if (selectNode != -1) { neighbor.Remove(selectNode); neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.Distinct().ToList(); } // During above process the tmp list will be deployment nodes, and add to deployNodes list. nowDeployNodes.AddRange(neighbor); // Adding deploy nodes to the scope network topology. foreach (int id in neighbor) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id)); } // Computing the complement set between source and scope network topology. remain_topo = src_net_topo - scope_net_topo; // Removing deployment nodes and edges from scope network topology. foreach (int id in neighbor) { scope_net_topo.Nodes.RemoveAll(x => x.ID == id); scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id); } return(remain_topo); }
/// <summary> /// Starting run algorithm with specific source topology and K-diameter cut, /// and this round process will generate scope topology to scop_net_topo, /// and will add the deployment node to deployNodes structure. /// Finally, it will return the remain network topology with this process. /// </summary> /// <param name="src_net_topo">The source network topology</param> /// <param name="scope_net_topo">This round process that generte scope topology</param> /// <param name="nowDeployNodes">The result of the deployment node id</param> /// <returns>The remain network topology after process the algorithm.</returns> private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes) { List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>(); int selectNode = scope_net_topo.Nodes[0].ID; int now_hop_count = 0; while (true) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes); concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix; concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID))); concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2))); foreach (int id in neighbor.Select(n => n.NodeID)) { concentrate_topo.Edges.Add(new NetworkTopology.Edge() { Node1 = id, Node2 = scope_net_topo.Nodes[0].ID }); } selectNode = -1; //neighbor.Sort((x, y) => concentrate_topo.ClusteringCoefficient(x).CompareTo(concentrate_topo.ClusteringCoefficient(y))); if (now_hop_count < K / 2) { Dictionary <int, double> tmp = new Dictionary <int, double>(); foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID)) { tmp.Add(id, concentrate_topo.ClusteringCoefficient(id)); } for (int i = 0; i < tmp.Count;) { int max_hop_count = int.MinValue; selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value >= kvp2.Value ? kvp1 : kvp2).Key; tmp.Remove(selectNode); NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode); if (nowNode.HopCount == int.MinValue) { foreach (var scopeNode in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } nowNode.HopCount = max_hop_count; } else { max_hop_count = nowNode.HopCount; } now_hop_count = max_hop_count; if (now_hop_count <= K - 1) { break; } else { selectNode = -1; } } } else { Dictionary <int, int> tmp = new Dictionary <int, int>(); foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID)) { tmp.Add(id, src_net_topo.Degree(id)); } for (int i = 0; i < tmp.Count;) { int max_hop_count = int.MinValue; selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value <= kvp2.Value ? kvp1 : kvp2).Key; tmp.Remove(selectNode); NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode); if (nowNode.HopCount == int.MinValue) { foreach (var scopeNode in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } nowNode.HopCount = max_hop_count; } else { max_hop_count = nowNode.HopCount; } now_hop_count = max_hop_count; if (now_hop_count <= K - 1) { break; } else { selectNode = -1; } } } // if nothing found, break the loop. if (selectNode == -1) { break; } // adding the node to the scope set, and computing the max hop count. else { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode)); } } NetworkTopology remain_topo; // Handling the neighbor nodes of each node in the scope network topology. if (selectNode != -1) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); } // During above process the tmp list will be deployment nodes, and add to deployNodes list. nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID)); // Adding deploy nodes to the scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id)); } // Computing the complement set between source and scope network topology. remain_topo = src_net_topo - scope_net_topo; // Removing deployment nodes and edges from scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Nodes.RemoveAll(x => x.ID == id); scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id); } return(remain_topo); }
protected override void doDeploy(NetworkTopology networkTopology) { if (checkHaveRunned(networkTopology)) { isNeedWriteing2SQLite = false; isNeedReset = false; } else { NetworkTopology process_topo = networkTopology; NetworkTopology center_tmp_topo = null; NetworkTopology side_tmp_topo = null; int centerNode; int sideNode; int eccentricity; int minDegree; isNeedRecompute = false; lastDeployCount = 0; allLevelDeploy = new List <List <int> >(); while (process_topo.Nodes.Count > 0) { centerNode = -1; sideNode = -1; minDegree = int.MaxValue; process_topo.FindCenterNodeID(out centerNode, out eccentricity, isNeedRecompute); foreach (var n in process_topo.Nodes) { if (minDegree > process_topo.Degree(n.ID)) { minDegree = process_topo.Degree(n.ID); sideNode = n.ID; } } NetworkTopology center_scope_net_topo = new NetworkTopology(networkTopology.Nodes); NetworkTopology side_scope_net_topo = new NetworkTopology(networkTopology.Nodes); List <int> center_deploy = new List <int>(); List <int> side_deploy = new List <int>(); center_scope_net_topo.AdjacentMatrix = networkTopology.AdjacentMatrix; side_scope_net_topo.AdjacentMatrix = networkTopology.AdjacentMatrix; if (centerNode != -1) { center_scope_net_topo.Nodes.Add(process_topo.Nodes.Find(n => n.ID == centerNode)); center_tmp_topo = startAlgorithm(process_topo, center_scope_net_topo, center_deploy); } if (sideNode != -1) { side_scope_net_topo.Nodes.Add(process_topo.Nodes.Find(n => n.ID == sideNode)); side_tmp_topo = startAlgorithm(process_topo, side_scope_net_topo, side_deploy); } if (center_deploy.Count < side_deploy.Count) { process_topo = center_tmp_topo; allRoundScopeList.Add(center_scope_net_topo); deployNodes.AddRange(center_deploy); allLevelDeploy.Add(center_deploy); DataUtility.Log(string.Format("================= Level {0} ==================\n", allRoundScopeList.Count)); DataUtility.Log(string.Format("Start From Center Node:\t{0}\n", center_scope_net_topo.Nodes[0].ID)); DataUtility.Log(string.Format("Scope Node Count:\t{0}\n", center_scope_net_topo.Nodes.Count)); DataUtility.Log(string.Format("Deploy Count/Node Count:\t{0}/{1} = {2:0.0000}\n", deployNodes.Count, networkTopology.Nodes.Count, (float)deployNodes.Count / (float)networkTopology.Nodes.Count)); } else { process_topo = side_tmp_topo; allRoundScopeList.Add(side_scope_net_topo); deployNodes.AddRange(side_deploy); allLevelDeploy.Add(side_deploy); DataUtility.Log(string.Format("================= Level {0} ==================\n", allRoundScopeList.Count)); DataUtility.Log(string.Format("Start From Side Node:\t{0}\n", side_scope_net_topo.Nodes[0].ID)); DataUtility.Log(string.Format("Scope Node Count:\t{0}\n", side_scope_net_topo.Nodes.Count)); DataUtility.Log(string.Format("Deploy Count/Node Count:\t{0}/{1} = {2:0.0000}\n", deployNodes.Count, networkTopology.Nodes.Count, (float)deployNodes.Count / (float)networkTopology.Nodes.Count)); } isNeedRecompute = deployNodes.Count != lastDeployCount; lastDeployCount = deployNodes.Count; } if (process_topo.Nodes.Count != 0) { allRoundScopeList.Add(process_topo); } } // Modifying actual tracer type on network topology depend on computed deployment node. foreach (int id in deployNodes) { networkTopology.Nodes.Find(n => n.ID == id).Tracer = NetworkTopology.TracerType.Tunneling; } }
/// <summary> /// Starting run algorithm with specific source topology and K-diameter cut, /// and this round process will generate scope topology to scop_net_topo, /// and will add the deployment node to deployNodes structure. /// Finally, it will return the remain network topology with this process. /// </summary> /// <param name="src_net_topo">The source network topology</param> /// <param name="scope_net_topo">This round process that generte scope topology</param> /// <param name="nowDeployNodes">The result of the deployment node id</param> /// <returns>The remain network topology after process the algorithm.</returns> private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes) { List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>(); int selectNode = scope_net_topo.Nodes[0].ID; while (true) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); selectNode = -1; Dictionary <int, int> tmp = new Dictionary <int, int>(); foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID)) { tmp.Add(id, src_net_topo.Degree(id)); } for (int i = 0; i < tmp.Count;) { int max_hop_count = int.MinValue; selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value <= kvp2.Value ? kvp1 : kvp2).Key; tmp.Remove(selectNode); NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode); if (nowNode.HopCount == int.MinValue) { foreach (var scopeNode in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } nowNode.HopCount = max_hop_count; } else { max_hop_count = nowNode.HopCount; } if (max_hop_count <= K - 1) { break; } else { selectNode = -1; } } //int minD = int.MaxValue; //foreach (int id in neighbor) //{ // int tmpD = src_net_topo.Degree(id); // if (minD > tmpD) // { // minD = tmpD; // selectNode = id; // } //} //if (scope_net_topo.Nodes.Count >= N) // selectNode = -1; // if nothing found, break the loop. if (selectNode == -1) { break; } // Computing the max hop counts with adding the select node. else { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode)); //foreach (var scopeNode in scope_net_topo.Nodes) //{ // int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode); // if (max_hop_count < hop_count) // max_hop_count = hop_count; //} } } NetworkTopology remain_topo; // Handling the neighbor nodes of each node in the scope network topology. if (selectNode != -1) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); } // During above process the tmp list will be deployment nodes, and add to deployNodes list. nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID)); // Adding deploy nodes to the scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id)); } // Computing the complement set between source and scope network topology. remain_topo = src_net_topo - scope_net_topo; // Removing deployment nodes and edges from scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Nodes.RemoveAll(x => x.ID == id); scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id); } return(remain_topo); }
/// <summary> /// Starting run algorithm with specific source topology and K-diameter cut, /// and this round process will generate scope topology to scop_net_topo, /// and will add the deployment node to deployNodes structure. /// Finally, it will return the remain network topology with this process. /// </summary> /// <param name="src_net_topo">The source network topology</param> /// <param name="scope_net_topo">This round process that generte scope topology</param> /// <param name="nowDeployNodes">The result of the deployment node id</param> /// <returns>The remain network topology after process the algorithm.</returns> private NetworkTopology startAlgorithm(NetworkTopology src_net_topo, NetworkTopology scope_net_topo, List <int> nowDeployNodes) { List <NeighborIDWithMaxHopCount> neighbor = new List <NeighborIDWithMaxHopCount>(); int selectNode = scope_net_topo.Nodes[0].ID; while (true) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); NetworkTopology concentrate_topo = new NetworkTopology(src_net_topo.Nodes); concentrate_topo.AdjacentMatrix = src_net_topo.AdjacentMatrix; concentrate_topo.Nodes.AddRange(src_net_topo.Nodes.Except(scope_net_topo.Nodes.Where(n => n.ID != scope_net_topo.Nodes[0].ID))); concentrate_topo.Edges.AddRange(src_net_topo.Edges.Where(e => !scope_net_topo.Nodes.Exists(n => n.ID == e.Node1 || n.ID == e.Node2))); foreach (int id in neighbor.Select(n => n.NodeID)) { concentrate_topo.Edges.Add(new NetworkTopology.Edge() { Node1 = id, Node2 = scope_net_topo.Nodes[0].ID }); } selectNode = -1; Dictionary <int, double> tmp = new Dictionary <int, double>(); foreach (int id in neighbor.Where(n => n.HopCount == int.MinValue).Select(n => n.NodeID)) { tmp.Add(id, concentrate_topo.ClusteringCoefficient(id)); } //neighbor.Sort((x, y) => concentrate_topo.ClusteringCoefficient(x).CompareTo(concentrate_topo.ClusteringCoefficient(y))); for (int i = 0; i < tmp.Count;) { int max_hop_count = int.MinValue; selectNode = tmp.Aggregate((kvp1, kvp2) => kvp1.Value >= kvp2.Value ? kvp1 : kvp2).Key; tmp.Remove(selectNode); NeighborIDWithMaxHopCount nowNode = neighbor.Find(n => n.NodeID == selectNode); if (nowNode.HopCount == int.MinValue) { foreach (var scopeNode in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPathCount(scopeNode.ID, selectNode) - 1; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } nowNode.HopCount = max_hop_count; } else { max_hop_count = nowNode.HopCount; } if (max_hop_count <= K - 1) { break; } else { selectNode = -1; } } // if nothing found, break the loop. if (selectNode == -1) { break; } // if K <= Diameter/2, checking the degree of selected node wether or not greater than threshold. else if (K <= Math.Ceiling(src_net_topo.Diameter / 2.0)) { List <NetworkTopology.Node> remain_nodes = src_net_topo.Nodes.Except(scope_net_topo.Nodes).ToList(); double avg = remain_nodes.Average(n => src_net_topo.Degree(n.ID)); double std = Math.Sqrt(remain_nodes.Sum(n => Math.Pow(src_net_topo.Degree(n.ID) - avg, 2)) / (double)remain_nodes.Count); double ratio_k = (double)K / (double)src_net_topo.Diameter; int threshold = Convert.ToInt32(Math.Round(avg + std * ratio_k, MidpointRounding.AwayFromZero)); //if (src_net_topo.Degree(selectNode) >= src_net_topo.Nodes.Except(scope_net_topo.Nodes).Average(n => src_net_topo.Degree(n.ID)) + K / 2) if (src_net_topo.Degree(selectNode) > threshold) { selectNode = -1; break; } } // adding the node to the scope set, and computing the max hop count. scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == selectNode && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode)); } NetworkTopology remain_topo; // Handling the neighbor nodes of each node in the scope network topology. if (selectNode != -1) { neighbor.RemoveAll(n => n.NodeID == selectNode); foreach (int id in src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))) { neighbor.Add(new NeighborIDWithMaxHopCount() { NodeID = id, HopCount = int.MinValue }); } //neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.GroupBy(n => n.NodeID).Select(n => n.First()).ToList(); } // During above process the tmp list will be deployment nodes, and add to deployNodes list. nowDeployNodes.AddRange(neighbor.Select(n => n.NodeID)); // Adding deploy nodes to the scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node2) || e.Node2 == id && scope_net_topo.Nodes.Exists(n => n.ID == e.Node1) )); scope_net_topo.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == id)); } // Computing the complement set between source and scope network topology. remain_topo = src_net_topo - scope_net_topo; // Removing deployment nodes and edges from scope network topology. foreach (int id in neighbor.Select(n => n.NodeID)) { scope_net_topo.Nodes.RemoveAll(x => x.ID == id); scope_net_topo.Edges.RemoveAll(x => x.Node1 == id || x.Node2 == id); } return(remain_topo); }