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);
        }
 public static double?calculateTransition(GridSpace grid, int[] direction, int cr, int cc, double pt)
 {
     if (grid.isBoundary(direction[0], direction[1]) || grid.isNoGo(direction[0], direction[1]))
     {
         return(pt * grid.Value(cr, cc));
     }
     else
     {
         return(pt * grid.Value(direction[0], direction[1]));
     }
 }
Exemple #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);
 }