Exemplo n.º 1
0
        public static PolicySpace IP(GridSpace g)
        {
            PolicySpace ps = new PolicySpace(g.Rows(), g.Cols());

            for (int c = 0; c < g.Rows(); c++)
            {
                for (int c1 = 0; c1 < g.Cols(); c1++)
                {
                    if (g.isNoGo(c, c1))
                    {
                        ps.matrix[c, c1] = "X";
                    }
                    else if (g.isRestricted(c, c1))
                    {
                        ps.matrix[c, c1] = g.Value(c, c1).ToString();
                    }
                    else
                    {
                        int[] n = new int[] { c - 1, c1 };
                        int[] s = new int[] { c + 1, c1 };
                        int[] e = new int[] { c, c1 + 1 };
                        int[] w = new int[] { c, c1 - 1 };

                        double?val_n = 0, val_s = 0, val_e = 0, val_w = 0;

                        val_n = g.Value(n[0], n[1]);
                        val_s = g.Value(s[0], s[1]);
                        val_e = g.Value(e[0], e[1]);
                        val_w = g.Value(w[0], w[1]);

                        if (compareVal_for_PS(val_n, val_s, val_w, val_e))
                        {
                            ps.matrix[c, c1] = "N";
                        }
                        else if (compareVal_for_PS(val_s, val_n, val_w, val_e))
                        {
                            ps.matrix[c, c1] = "S";
                        }
                        else if (compareVal_for_PS(val_w, val_s, val_n, val_e))
                        {
                            ps.matrix[c, c1] = "W";
                        }
                        else if (compareVal_for_PS(val_e, val_s, val_w, val_n))
                        {
                            ps.matrix[c, c1] = "E";
                        }
                        else
                        {
                            ps.matrix[c, c1] = "C";
                        }
                    }
                }
            }
            return(ps);
        }
Exemplo n.º 2
0
 public void Process()
 {
     for (int c = 0; c < grid.Rows(); c++)
     {
         for (int c1 = 0; c1 < grid.Cols(); c1++)
         {
             if (!grid.isRestricted(c, c1))
             {
                 double?[] temp = new double?[actions.Length];
                 for (int c2 = 0; c2 < actions.Length; c2++)
                 {
                     temp[c2] = CF(grid, actions[c2], c, c1, living_reward, discount_factor);
                 }
                 grid.Value(c, c1, temp.Max());
                 //grid.Print();
             }
         }
     }
 }