Exemple #1
0
        /**
         * Searches a file for the best path using three algorithms. The solutions
         * can be shown on screen.
         * @param filename The file (without extension) to be searched.
         * @param showSolutions Indicates if solutions should be shown on screen.
         * @return All relevant statistics for the three experiments.
         */
        public static ExperimentResults search(eTileType[,] map, String filename)
        {
            ExperimentResults info = new ExperimentResults();

            // Dijkstra
            Dijkstra         dijkstraAlgorithm = new Algorithm.Dijkstra(new TileWorld.TileWorld(map));
            AlgorithmResults dijkstra          = dijkstraAlgorithm.run();

            info.setDijkstra(dijkstra);
            saveImage(filename + "_dijkstra", dijkstraAlgorithm.getMap());

            // A*
            AStar            aStarAlgorithm = new AStar(new TileWorld.TileWorld(map));
            AlgorithmResults aStar          = aStarAlgorithm.run();

            info.setaStar(aStar);
            saveImage(filename + "_aStar", aStarAlgorithm.getMap());

            // BFS Search
            BFS bfsAlgorithm           = new BFS(new TileWorld.TileWorld(map));
            AlgorithmResults bfsSearch = bfsAlgorithm.run();

            info.setBFSSearch(bfsSearch);
            saveImage(filename + "_bfs", bfsAlgorithm.getMap());

            return(info);
        }
Exemple #2
0
 /**
  * Prints the results for all three algorithms on System.out.
  *
  * @param filename Filename containing the world that has been searched.
  * @param info Results of the experiments for all three algorithms for that file.
  */
 public static void printAllResults(String filename, ExperimentResults info)
 {
     Console.WriteLine("#######################");
     Console.WriteLine("Testcase: " + filename);
     Console.WriteLine("#######################");
     printAlgorithmResult("A*", info.getaStar());
     Console.WriteLine("-------------------------------------");
     printAlgorithmResult("Dijkstra", info.getDijkstra());
     Console.WriteLine("-------------------------------------");
     printAlgorithmResult("BFS", info.getBFSSearch());
 }
Exemple #3
0
        public static void start(int howMany)
        {
            String filename;

            eTileType[,] map;
            // search all files
            for (int fileNr = 1; fileNr <= howMany; fileNr++)
            {
                // determine file to search
                filename = "i" + fileNr;
                Image rawmap;
                try
                {
                    rawmap = Image.FromFile(@"..\..\" + filename + ".png");
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    Console.WriteLine("FILE NOT FOUND!");
                    Console.WriteLine(ex);
                    System.Threading.Thread.Sleep(5000);
                    return;
                }

                Bitmap bm = (Bitmap)rawmap;
                map = new eTileType[rawmap.Width, rawmap.Height];
                for (int i = 0; i < rawmap.Width; i++)
                {
                    for (int i2 = 0; i2 < rawmap.Height; i2++)
                    {
                        Color     pixel     = bm.GetPixel(i, i2);
                        eTileType pixelType = eTileType.UNKNOWN;
                        switch (pixel.Name)
                        {
                        case "ffffff00"://yellow
                            pixelType = eTileType.SAND;
                            break;

                        case "ff000000"://black
                            pixelType = eTileType.NONWALKABLE;
                            break;

                        case "ffffffff"://white
                            pixelType = eTileType.ROAD;
                            break;

                        case "ffff0000"://red
                            pixelType = eTileType.START;
                            break;

                        case "ff00ff00"://green
                            pixelType = eTileType.END;
                            break;

                        case "ff0000ff"://blue
                            pixelType = eTileType.WATER;
                            break;

                        case "ff808080"://gray
                            pixelType = eTileType.MOUNTAIN;
                            break;

                        case "ff00ffff"://cyan
                            pixelType = eTileType.PATH;
                            break;
                        }
                        map[i, i2] = pixelType;
                    }
                }


                // search tile world
                ExperimentResults info = search(map, filename);

                // print the results to System.out
                printAllResults(filename, info);
            }
            Console.WriteLine("Press Enter to close the application.");
            Console.ReadLine();
        }