Exemple #1
0
        static void Main(string[] args)
        {
            // Programatic way of calling the MDP
            // MDPGrid grid = new MDPGrid(20,20);
            // Position[] goalPositions = new Position[4]{new Position(9,9),new Position(0,14),new Position(15,14),new Position(19,19)};
            // Position[] wallPositions = new Position[13]{new Position(1,2),new Position(3,2),new Position(5,2),new Position(7,2),new Position(9,2),new Position(0,5),new Position(2,5),new Position(4,5),new Position(6,5),new Position(8,5),new Position(1,9),new Position(3,9),new Position(5,9)};
            // int[] goalValues = new int[4]{10,20,20,30};
            // grid.setWalls(wallPositions);
            // grid.setGoals(goalPositions, goalValues);
            Console.WriteLine("Initial State");
            // MDPGrid grid =new MDPGrid(15,10, "/Users/anak/Desktop/MDP-Excersise/input.csv");
            MDPGrid grid = new MDPGrid(100, 100, "input_unity.csv");

            Console.WriteLine(grid.drawGrid());
            Console.WriteLine(grid.drawGridDirection());
            int iter = 0;

            grid.evalGrid();
            while (!convergence(grid))
            {
                grid.evalGrid();
                iter++;
                Console.WriteLine("iter: " + iter);
                // Console.WriteLine(grid.drawGrid());
                // Console.WriteLine(grid.drawGridDirection());
                // Console.WriteLine(convergence(grid));
            }
            Console.WriteLine("Final iter: " + iter);

            //                '''''''''''''Takes a lot to write
            // File.WriteAllText("valuedata.csv", makeCSV(grid));
            // File.WriteAllText("directiondata.csv", makeCSVDirs(grid));
            File.WriteAllText("policy.csv", grid.createPolicy());
        }
Exemple #2
0
        static String makeCSVDirs(MDPGrid grid)
        {
            string csv = "";

            foreach (var row in grid.directionHistory)
            {
                foreach (var cell in row)
                {
                    csv += cell + ",";
                }
                csv.Remove(csv.Length - 1);
                csv += "\n";
            }
            return(csv);
        }
Exemple #3
0
 public static bool convergence(MDPGrid MDPgrid)
 {
     Node[,] grid     = MDPgrid.grid;
     Node[,] Prevgrid = MDPgrid.prevGrid;
     for (int i = 0; i < MDPgrid.grid.GetLength(0); i++)
     {
         for (int j = 0; j < MDPgrid.grid.GetLength(1); j++)
         {
             // Console.WriteLine(grid[i,j].direction+"ooooow"+ Prevgrid[i,j].direction);
             if (grid[i, j].direction != Prevgrid[i, j].direction)
             {
                 return(false);
             }
         }
     }
     return(true);
 }