Example #1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine(
                    "Please specify input file path, source vertex id and " +
                    "coma-separated list of destination verticies ids.");
            }
            else
            {
                try
                {
                    var inputGraphFileContent = ArgumentsParser.GetFileContent(args[0]);
                    var sourceVertexId = ArgumentsParser.ParseSourceVertexId(args[1]);
                    var destinationVerticesIds = ArgumentsParser.ParseDestinationVerticesIds(args[2]);

                    var algorithmRunner = new AlgorithmRunner();
                    var shortestPaths = algorithmRunner.FindShortestPaths(
                        inputGraphFileContent,
                        sourceVertexId);

                    var result = OutputFormatter.Format(shortestPaths, destinationVerticesIds);

                    Console.WriteLine("Result is {0}", result);
                }
                catch (Exception ex)
                {
                    PrintError(ex);
                }
            }

            Console.WriteLine("Press any key to exit ...");
            Console.ReadKey();
        }
        public void FindShortestPaths()
        {
            var inputGraph = @"1 2,10 3,20".Replace(" ", "\t");
            var sourceVertexId = 1;

            var algorithmRunner = new AlgorithmRunner();

            List<ShortestPath> actual = algorithmRunner.FindShortestPaths(
                                            inputGraph, sourceVertexId);

            var expected = new List<ShortestPath> { 
                new ShortestPath{ From = new Vertex(1), To = new Vertex(1), Length = 0},
                new ShortestPath{ From = new Vertex(1), To = new Vertex(2), Length = 10},
                new ShortestPath{ From = new Vertex(1), To = new Vertex(3), Length = 20},
            };

            AssertionHelper.AssertAreEqual(expected, actual);
        }