Example #1
0
 private void Dfs(Node node, NetworkSegment netWorkSegment)
 {
     _visited[node.Name]       = node;
     netWorkSegment[node.Name] = node;
     _notVisited.Remove(node.Name);
     foreach (var neighbor in node.Neighbors)
     {
         if (_visited.ContainsKey(neighbor.Key))
         {
             continue;
         }
         Dfs(neighbor.Value, netWorkSegment);
     }
 }
Example #2
0
        public Network Analyze(string filePath)
        {
            var network = _fileParser.Parse(filePath);

            _visited    = new Dictionary <string, Node>();
            _notVisited = new Dictionary <string, Node>();
            foreach (var item in network.Nodes)
            {
                _notVisited[item.Key] = item.Value;
            }

            while (_notVisited.Any())
            {
                var node           = _notVisited.First().Value;
                var netWorkSegment = new NetworkSegment();
                Dfs(node, netWorkSegment);
                network.NetworkSegments.Add(netWorkSegment);
            }

            _visited.Clear();
            _notVisited.Clear();
            return(network);
        }