Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Usage: Skiing.exe Source_heightMap [Target_processedMap]");
            string sourceFile = null, destFile = "processedMap.txt";

            VertexMap map = null;

            if (args.Length == 1 || args.Length == 2)
            {
                sourceFile = args[0];
                map = new VertexMap(new StreamReader(sourceFile));

                if (args.Length == 2)
                {
                    destFile = args[1];
                }
            }
            else
            {
                map = new VertexMap(new int[,]{
                                            {4, 8, 7, 3},
                                            {2, 5, 9, 3},
                                            {6, 3, 2, 5},
                                            {4, 4, 1, 6}
                                        }
                                    );
            }

            Route bestRoute = map.BestRoute;

            WriteResult(map, destFile);
        }
Esempio n. 2
0
 public Vertex(VertexMap map, int i, int j, int height)
 {
     Map = map;
     LongestRoute = new Route(this);
     I = i;
     J = j;
     Height = height;
 }
Esempio n. 3
0
        public static void WriteResult(VertexMap map, string destLPDFile)
        {
            int iMax = map.DimY, jMax = map.DimX;
            bool outputToConcole = iMax < 10 && jMax < 10;

            if (outputToConcole) Console.WriteLine("Processed Map:");

            using (StreamWriter writer = new StreamWriter(destLPDFile))
            {
                for (int i = 0; i < iMax; i++)
                {
                    for (int j = 0; j < jMax; j++)
                    {
                        Vertex v = map[i, j];

                        string partOfBestRoute = (map.BestRoute.Vertexes.Contains(v)) ? "*" : " ";
                        string text = string.Format("{0,5} [{1,3}/{2,4}]", partOfBestRoute+v.Height, v.LongestRoute.Length, v.LongestRoute.HeightDiff);

                        text = string.Format("{0,-20}", text);

                        if (outputToConcole) Console.Write(text);

                        writer.Write(text);
                        Vertex vertex = v;
                    }

                    if (outputToConcole) Console.WriteLine();
                    writer.WriteLine();
                }
            }

            if (outputToConcole) Console.WriteLine();

            Console.WriteLine("BestRoute: [{0}]", map.BestRoute);
            foreach (var v in map.BestRoute.Vertexes)
            {
                Console.WriteLine("    [{0},{1}]={2}", v.I, v.J, v.Height);
            }
        }