/// <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 max_hop_count = int.MinValue; int selectNode = scope_net_topo.Nodes[0].ID; while (max_hop_count < K) { neighbor.Remove(selectNode); neighbor.AddRange(src_net_topo.GetNeighborNodeIDs(selectNode).Except(scope_net_topo.Nodes.Select(n => n.ID))); neighbor = neighbor.Distinct().ToList(); selectNode = -1; int minD = int.MaxValue; foreach (int id in neighbor) { int tmpD = src_net_topo.Nodes.Find(n => n.ID == id).Degree; 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; } // 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)); 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 <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); }
/// <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="K">The K-diameter cut value</param> /// <param name="scope_net_topo">This round process that generte scope topology</param> /// <param name="deployNodes">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, int K, ref NetworkTopology scope_net_topo, ref List <int> deployNodes) { double max_hop_count = double.MinValue; while (max_hop_count < K) { int minDegree = int.MaxValue; int selectNode = -1; // to finding the neighbor node with minimum degree foreach (var scopeNode in scope_net_topo.Nodes) { foreach (int neighbor in src_net_topo.GetNeighborNodeIDs(scopeNode.ID)) { if (!scope_net_topo.Nodes.Exists(x => x.ID == neighbor)) { if (minDegree > src_net_topo.Nodes.Find(n => n.ID == neighbor).Degree) { minDegree = src_net_topo.Nodes.Find(n => n.ID == neighbor).Degree; selectNode = neighbor; } } } } // 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.Nodes.Add(src_net_topo.Nodes.Find(n => n.ID == selectNode)); foreach (var scopeNode in scope_net_topo.Nodes) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(e => e.Node1 == scopeNode.ID && e.Node2 == selectNode || e.Node1 == selectNode && e.Node2 == scopeNode.ID) .ToList()); } scope_net_topo.ComputingShortestPath(); foreach (var node1 in scope_net_topo.Nodes) { foreach (var node2 in scope_net_topo.Nodes) { int hop_count = scope_net_topo.GetShortestPath(node1.ID, node2.ID).Count; if (max_hop_count < hop_count) { max_hop_count = hop_count; } } } } } List <int> tmp = new List <int>(); NetworkTopology remain_topo; // Handling the neighbor nodes of each node in the scope network topology. foreach (var scopeNode in scope_net_topo.Nodes) { tmp.AddRange(src_net_topo.GetNeighborNodeIDs(scopeNode.ID).Except(scope_net_topo.Nodes.Select(x => x.ID))); } tmp = tmp.Distinct().ToList(); // During above process the tmp list will be deployment nodes, and add to deployNodes list. deployNodes.AddRange(tmp); // Adding deploy nodes to the scope network topology. foreach (int id in tmp) { scope_net_topo.Nodes.AddRange(src_net_topo.Nodes.Where(x => x.ID == id).ToList()); } // Adding deploy nodes's edge to the scope network topology. foreach (var scopeNode in scope_net_topo.Nodes) { scope_net_topo.Edges.AddRange(src_net_topo.Edges.Where(x => x.Node1 == scopeNode.ID || x.Node2 == scopeNode.ID).ToList()); } scope_net_topo.Edges = scope_net_topo.Edges.Distinct().ToList(); // Computing the complement set between source and scope network topology. remain_topo = src_net_topo - scope_net_topo; // Computing the complement set's shortest path. //remain_topo.ComputingShortestPath(); // Removing deployment nodes and edges from scope network topology. foreach (int id in tmp) { 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); }