コード例 #1
0
        public void ShortestPathSanFierroToWhetstone_Success()
        {
            InitializeNodes();

            var path = _shortestPathFinder.FindShortestPath(_sanFierro, _whetstone);

            Assert.True(path.Length == 2);
            Assert.Equal("SF", path[0].Id);
            Assert.Equal("WS", path[1].Id);
            Assert.Equal(1, path[0].Edges.First(x => x.Node2.Id == "WS").Value);
        }
コード例 #2
0
        public static string GeneratePathsText(string encomendas, IShortestPathFinderService shortestPathFinder)

        {
            var lines = new List <string>();

            lock (lockObj)
            {
                foreach (var line in encomendas.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries))
                {
                    var nodeIds = line.Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                  .Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();

                    var node1Id = nodeIds[0];
                    var node2Id = nodeIds[1];

                    var nodesPath = shortestPathFinder.FindShortestPath(nodes[node1Id], nodes[node2Id]);

                    lines.Add(GeneratePathTextLine(nodesPath));
                }
            }

            return(string.Join(Environment.NewLine, lines));
        }