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 GridSpace(GridSpace g)
 {
     matrix = new double?[g.Rows(), g.Cols()];
     r_mask = new bool[g.Rows(), g.Cols()];
     R      = g.R;
     C      = g.C;
     for (int c = 0; c < R; c++)
     {
         for (int c1 = 0; c1 < C; c1++)
         {
             this.matrix[c, c1] = g.Value(c, c1);
             this.r_mask[c, c1] = g.r_mask[c, c1];
         }
     }
 }
Exemplo n.º 3
0
 public static bool compareAtThreshold(GridSpace g1, GridSpace g2, double threshold)
 {
     if (g1.Rows() == g2.Rows() && g1.Cols() == g2.Cols())
     {
         for (int c = 0; c < g1.Rows(); c++)
         {
             for (int c1 = 0; c1 < g2.Cols(); c1++)
             {
                 if (!g1.isNoGo(c, c1) && !g2.isNoGo(c, c1))
                 {
                     if (Math.Abs((double)g1.Value(c, c1) - (double)g2.Value(c, c1)) > threshold)
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     else
     {
         throw new Exception("Grid sizes do not match");
     }
     return(true);
 }
Exemplo n.º 4
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();
             }
         }
     }
 }