示例#1
0
        private void FindRoutes(NetworkNode currentNode,
                                Stack <NetworkChannel> channelStack, List <Route> routesFound, NetworkChannel receiverNetworkChannel, int depth)
        {
            var nextChannels = currentNode.GetAllChannels().ToList();

            if (depth == channelStack.Count && nextChannels.Contains(receiverNetworkChannel))
            {
                var path = channelStack.ToList();
                path.Add(receiverNetworkChannel);
                routesFound.Add(new Route(path));
                return;
            }

            if (channelStack.Count < depth)
            {
                foreach (var nextChannel in nextChannels)
                {
                    var nextNode = nextChannel.Node1 == currentNode ? nextChannel.Node2 : nextChannel.Node1;

                    channelStack.Push(nextChannel);
                    FindRoutes(nextNode, channelStack, routesFound, receiverNetworkChannel, depth);
                    channelStack.Pop();

                    if (routesFound.Count >= _maxRoutes)
                    {
                        return;
                    }
                }
            }
        }