Example #1
0
  private static void printOptimal(
      int xdim,
      int ydim,
      Map<Block<Double>, BlockAction> optimalAction,
      Map<Block<Double>, BlockAction> optimalAction1,
      BufferedWriter out) {
    try {
      //  List<CellAction> values1 = new ArrayList<CellAction>(optimalAction.values());
      //   List<CellAction> values2 = new ArrayList<CellAction>(optimalAction1.values());
      // Iterate through each cell and get the optimal policy for that cell(state)
      for (int j = ydim; j > 0; j--) {
        for (int i = 1; i <= xdim; i++) {
          Block<Double> c = table.getCellAt(i, j);

          String toWrite = "";
          if (c != null) {
            BlockAction ca = getCellAction(i, j, optimalAction);

            if (ca != null) {
              toWrite = ca.toString();
              toWrite = printactionMap.get(toWrite);
            }
            if (optimalAction1 != null) {
              BlockAction ca1 = getCellAction(i, j, optimalAction1);
              if (ca != null && ca1 != null) {
                if (ca1.equals(ca) == false) {
                  toWrite = toWrite + "*";
                }
              }
            }

            if (ca != null) {

              out.write(toWrite + "\t");

            } else {
              out.write(c.getContent().toString() + "\t");
            }
          } else {
            out.write("X\t");
          }
        }

        out.write(System.getProperty("line.separator"));
      }
      out.write(System.getProperty("line.separator"));
      out.write(System.getProperty("line.separator"));

    } catch (IOException ex) {
      Logger.getLogger(A3Main.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Example #2
0
  private static boolean compareMaps(
      Map<Block<Double>, BlockAction> a, Map<Block<Double>, BlockAction> b) {
    List<BlockAction> values1 = new ArrayList<BlockAction>(a.values());
    List<BlockAction> values2 = new ArrayList<BlockAction>(b.values());
    // boolean equals = true;
    for (int i = 0; i < values1.size(); i++) {
      BlockAction a1 = values1.get(i);
      BlockAction b1 = values2.get(i);

      if (a1.equals(b1) == false) {

        return false;
      }
    }

    return true;
  }