Esempio n. 1
0
  public static void main(String[] args) {
    // AI a = new AI();
    String input = "exampleinput.txt";
    /*
     * try{ BufferedReader br = new BufferedReader(new
     * InputStreamReader(System.in));
     * System.out.println("Please enter an input filename location: ");
     * input = br.readLine(); }catch(IOException io){ io.printStackTrace();
     * }
     */

    GUI.Threes.readFile(input);
    GUI.Threes.set();
    Moves.storeNext();
    Moves.resetNext();
    ArrayDeque<String> Res = AStar(GUI.Threes.board, 400);
    System.out.println(Res.removeFirst());
    System.out.println(Res.removeFirst());

    Moves.doMove(GUI.Threes.board, Res, true);
    System.out.println("Final board is");
    // GUI.Threes.finalBoard();

    while (!Res.isEmpty()) {
      System.out.print(Res.removeLast());
    }
    System.out.println();
    GUI.Threes.readFile(input);
    GUI.Threes.set();
    Moves.resetNext();
    recur(GUI.Threes.board, 10);
  }
Esempio n. 2
0
  private void checkEnum(EnumDataSchema older, EnumDataSchema newer) {
    checkName(older, newer);

    _path.addLast(DataSchemaConstants.SYMBOLS_KEY);

    // using list to preserve symbol order
    List<String> newerOnlySymbols = new CheckerArrayList<String>(newer.getSymbols());
    newerOnlySymbols.removeAll(older.getSymbols());

    List<String> olderOnlySymbols = new CheckerArrayList<String>(older.getSymbols());
    olderOnlySymbols.removeAll(newer.getSymbols());

    if (newerOnlySymbols.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_OLD_READER,
          "new enum added symbols %s",
          newerOnlySymbols);
    }

    if (olderOnlySymbols.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_NEW_READER,
          "new enum removed symbols %s",
          olderOnlySymbols);
    }

    _path.removeLast();
  }
Esempio n. 3
0
  public void run() {
    super.run();

    long currentTime = this.bh.getTime();
    if (!auctionSubmissionTimes.isEmpty() && currentTime >= auctionSubmissionTimes.peekLast()) {
      auctionSubmissionTimes.removeLast();
      submitAuction();
    }
  }
Esempio n. 4
0
 @Override
 public Item removeItem() throws Exception {
   if (!itemList.isEmpty()) {
     maxItemCnt -= 1;
     return itemList.removeLast();
   } else {
     throw new ItemStoreException("Стопка пуста");
   }
 }
Esempio n. 5
0
 /**
  * Add a sub-annotation to the current LAAnnotation and explain it.
  *
  * @param reason The reason for which a sub-annotation is created.
  * @param coeff The Farkas coefficient of the sub-annotation.
  */
 public void addAnnotation(LAReason reason, Rational coeff) {
   assert ((coeff.signum() > 0) == reason.isUpper());
   Rational sign = Rational.valueOf(coeff.signum(), 1);
   LAAnnotation annot = mSubReasons.get(reason);
   if (annot == null) {
     annot = new LAAnnotation(reason);
     mSubReasons.put(reason, annot);
     if (mAnnotationStack != null) mAnnotationStack.addLast(annot);
     reason.explain(this, reason.getVar().getEpsilon(), sign);
     if (mAnnotationStack != null) mAnnotationStack.removeLast();
   }
   if (mAnnotationStack != null) mAnnotationStack.getLast().addFarkas(annot, coeff);
 }
Esempio n. 6
0
  private void checkFixed(FixedDataSchema older, FixedDataSchema newer) {
    checkName(older, newer);

    _path.addLast(DataSchemaConstants.SIZE_KEY);

    int olderSize = older.getSize();
    int newerSize = newer.getSize();
    if (olderSize != newerSize) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_NEW_AND_OLD_READERS,
          "fixed size changed from %d to %d",
          olderSize,
          newerSize);
    }

    _path.removeLast();
  }
Esempio n. 7
0
 public void addEQAnnotation(LiteralReason reason, Rational coeff) {
   // FIXME: make a special annotation for disequalities
   assert ((coeff.signum() > 0) == reason.isUpper());
   Rational sign = Rational.valueOf(coeff.signum(), 1);
   LAAnnotation annot = mSubReasons.get(reason);
   if (annot == null) {
     annot = new LAAnnotation(reason);
     mSubReasons.put(reason, annot);
     mAnnotationStack.addLast(annot);
     if (reason.getOldReason() instanceof LiteralReason)
       reason.getOldReason().explain(this, reason.getVar().getEpsilon(), sign);
     else addAnnotation(reason.getOldReason(), sign);
     addLiteral(reason.getLiteral().negate(), sign);
     mAnnotationStack.removeLast();
   }
   mAnnotationStack.getLast().addFarkas(annot, coeff);
 }
Esempio n. 8
0
 private void run(Appendable appender) throws IOException {
   while (!mTodo.isEmpty()) {
     final Object next = mTodo.removeLast();
     if (next instanceof Term) {
       ((Term) next).toStringHelper(mTodo);
     } else if (next instanceof Sort) {
       ((Sort) next).toStringHelper(mTodo);
     } else if (next instanceof Object[]) {
       final Object[] arr = (Object[]) next;
       mTodo.addLast(")");
       for (int i = arr.length - 1; i >= 0; i--) {
         mTodo.addLast(arr[i]);
         if (i > 0) {
           mTodo.addLast(" ");
         }
       }
       appender.append('(');
     } else {
       appender.append(next.toString());
     }
   }
 }
Esempio n. 9
0
  public void dump() {
    ArrayDeque<Integer> framePointersCopy = framePointers.clone();
    ArrayList<Integer> framePointersList = new ArrayList<Integer>();

    // Since ArrayDeque does not inherit from ArrayList like Stack
    // inherits from Vector, we must copy the ArrayDeque's contents
    // into an ArrayList.
    while (!framePointersCopy.isEmpty()) {
      framePointersList.add(framePointersCopy.removeLast());
    }

    int first = framePointersList.remove(0);

    // Makes printing frames a lot easier by grouping each frame together by separating
    // the frames in runStack using the subList method in List which ArrayList inherits
    // from.
    while (!framePointersList.isEmpty()) {
      System.out.print(runStack.subList(first, framePointersList.get(0)) + " ");
      first = framePointersList.remove(0);
    }

    System.out.println(runStack.subList(first, runStack.size()));
  }
Esempio n. 10
0
  private void check(DataSchema older, DataSchema newer) {
    Checked toCheck = new Checked(older, newer);
    if (_checked.contains(toCheck)) {
      return;
    }
    _checked.add(toCheck);

    if (older == newer) {
      return;
    }

    int pathCount = 1;
    if (_options.getMode() == CompatibilityOptions.Mode.DATA) {
      older = older.getDereferencedDataSchema();
      while (newer.getType() == DataSchema.Type.TYPEREF) {
        TyperefDataSchema typerefDataSchema = ((TyperefDataSchema) newer);
        _path.addLast(typerefDataSchema.getFullName());
        _path.addLast(DataSchemaConstants.REF_KEY);
        pathCount++;
        newer = typerefDataSchema.getRef();
      }
    }
    if (newer.getType() == DataSchema.Type.TYPEREF) {
      _path.addLast(((TyperefDataSchema) newer).getFullName());
    } else {
      _path.addLast(newer.getUnionMemberKey());
    }

    switch (newer.getType()) {
      case TYPEREF:
        if (isSameType(older, newer))
          checkTyperef((TyperefDataSchema) older, (TyperefDataSchema) newer);
        break;
      case RECORD:
        if (isSameType(older, newer))
          checkRecord((RecordDataSchema) older, (RecordDataSchema) newer);
        break;
      case ARRAY:
        if (isSameType(older, newer)) checkArray((ArrayDataSchema) older, (ArrayDataSchema) newer);
        break;
      case MAP:
        if (isSameType(older, newer)) checkMap((MapDataSchema) older, (MapDataSchema) newer);
        break;
      case ENUM:
        if (isSameType(older, newer)) checkEnum((EnumDataSchema) older, (EnumDataSchema) newer);
        break;
      case FIXED:
        if (isSameType(older, newer)) checkFixed((FixedDataSchema) older, (FixedDataSchema) newer);
        break;
      case UNION:
        if (isSameType(older, newer)) checkUnion((UnionDataSchema) older, (UnionDataSchema) newer);
        break;
      default:
        if (newer instanceof PrimitiveDataSchema) checkPrimitive(older, newer);
        else
          throw new IllegalStateException(
              "Unknown schema type "
                  + newer.getType()
                  + ", checking old schema "
                  + older
                  + ", new schema "
                  + newer);
        break;
    }

    for (; pathCount > 0; pathCount--) {
      _path.removeLast();
    }
    return;
  }
Esempio n. 11
0
 private void checkMap(MapDataSchema older, MapDataSchema newer) {
   _path.addLast(DataSchemaConstants.VALUES_KEY);
   check(older.getValues(), newer.getValues());
   _path.removeLast();
 }
Esempio n. 12
0
 private void checkArray(ArrayDataSchema older, ArrayDataSchema newer) {
   _path.addLast(DataSchemaConstants.ITEMS_KEY);
   check(older.getItems(), newer.getItems());
   _path.removeLast();
 }
Esempio n. 13
0
 private void checkTyperef(TyperefDataSchema older, TyperefDataSchema newer) {
   checkName(older, newer);
   _path.addLast(DataSchemaConstants.REF_KEY);
   check(older.getDereferencedDataSchema(), newer.getDereferencedDataSchema());
   _path.removeLast();
 }
Esempio n. 14
0
  private void checkRecord(RecordDataSchema older, RecordDataSchema newer) {
    checkName(older, newer);

    List<RecordDataSchema.Field> commonFields =
        new ArrayList<RecordDataSchema.Field>(newer.getFields().size());
    List<String> newerRequiredAdded = new CheckerArrayList<String>();
    List<String> newerOptionalAdded = new CheckerArrayList<String>();
    List<String> requiredToOptional = new CheckerArrayList<String>();
    List<String> optionalToRequired = new CheckerArrayList<String>();
    List<String> newerRequiredRemoved = new CheckerArrayList<String>();
    List<String> newerOptionalRemoved = new CheckerArrayList<String>();

    for (RecordDataSchema.Field newerField : newer.getFields()) {
      String fieldName = newerField.getName();
      RecordDataSchema.Field olderField = older.getField(fieldName);
      if (olderField == null) {
        (newerField.getOptional() ? newerOptionalAdded : newerRequiredAdded).add(fieldName);
      } else {
        commonFields.add(newerField);
        boolean newerFieldOptional = newerField.getOptional();
        if (newerFieldOptional != olderField.getOptional()) {
          (newerFieldOptional ? requiredToOptional : optionalToRequired).add(fieldName);
        }
      }
    }
    for (RecordDataSchema.Field olderField : older.getFields()) {
      String fieldName = olderField.getName();
      RecordDataSchema.Field newerField = newer.getField(fieldName);
      if (newerField == null) {
        (olderField.getOptional() ? newerOptionalRemoved : newerRequiredRemoved).add(fieldName);
      }
    }

    if (newerRequiredAdded.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_NEW_READER,
          "new record added required fields %s",
          newerRequiredAdded);
    }

    if (newerRequiredRemoved.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_OLD_READER,
          "new record removed required fields %s",
          newerRequiredRemoved);
    }

    if (optionalToRequired.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_NEW_READER,
          "new record changed optional fields to required fields %s",
          optionalToRequired);
    }

    if (requiredToOptional.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.BREAKS_OLD_READER,
          "new record changed required fields to optional fields %s",
          requiredToOptional);
    }

    if (newerOptionalAdded.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.OLD_READER_IGNORES_DATA,
          "new record added optional fields %s",
          newerOptionalAdded);
    }

    if (newerOptionalRemoved.isEmpty() == false) {
      appendMessage(
          CompatibilityMessage.Impact.NEW_READER_IGNORES_DATA,
          "new record removed optional fields %s",
          newerOptionalRemoved);
    }

    for (RecordDataSchema.Field newerField : commonFields) {
      String fieldName = newerField.getName();

      _path.addLast(fieldName);

      RecordDataSchema.Field olderField = older.getField(fieldName);
      assert (olderField != null);
      check(olderField.getType(), newerField.getType());

      _path.removeLast();
    }
  }
Esempio n. 15
0
  protected void loadLogFile() {
    fileChooser.setMultiSelectionEnabled(true);
    if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;
    File[] files = fileChooser.getSelectedFiles();
    for (File file : files) {
      BufferedReader br = null;
      ArrayDeque<String[]> buffer = new ArrayDeque<String[]>();
      try {
        br = new BufferedReader(new FileReader(file.getAbsoluteFile()));
        String line = br.readLine();
        if (line != null) {
          String[] elements = line.split("(\\s*)?,(\\s*)?", -1);
          getColumnsFilters(elements);

          boolean resetColumns = false;
          if (logThrottleAngleColIdx >= 0
              || logFfbColIdx >= 0
              || logSdColIdx >= 0
              || (logWbAfrColIdx >= 0 && isOl)
              || (logStockAfrColIdx >= 0 && !isOl)
              || (logAfLearningColIdx >= 0 && !isOl)
              || (logAfCorrectionColIdx >= 0 && !isOl)
              || logRpmColIdx >= 0
              || logMafColIdx >= 0
              || logIatColIdx >= 0
              || logMpColIdx >= 0) {
            if (JOptionPane.YES_OPTION
                == JOptionPane.showConfirmDialog(
                    null,
                    "Would you like to reset column names or filter values?",
                    "Columns/Filters Reset",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.PLAIN_MESSAGE)) resetColumns = true;
          }

          if (resetColumns
              || logThrottleAngleColIdx < 0
              || logFfbColIdx < 0
              || logSdColIdx < 0
              || (logWbAfrColIdx < 0 && isOl)
              || (logStockAfrColIdx < 0 && !isOl)
              || (logAfLearningColIdx < 0 && !isOl)
              || (logAfCorrectionColIdx < 0 && !isOl)
              || logRpmColIdx < 0
              || logMafColIdx < 0
              || logIatColIdx < 0
              || logMpColIdx < 0) {
            ColumnsFiltersSelection selectionWindow = new VEColumnsFiltersSelection(false);
            if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements)) return;
          }

          if (logClOlStatusColIdx == -1) clValue = -1;

          String[] flds;
          String[] afrflds;
          boolean removed = false;
          int i = 2;
          int clol = -1;
          int row = getLogTableEmptyRow();
          double thrtlMaxChange2 = thrtlMaxChange + thrtlMaxChange / 2.0;
          double throttle = 0;
          double pThrottle = 0;
          double ppThrottle = 0;
          double afr = 0;
          double rpm;
          double ffb;
          double iat;
          clearRunTables();
          setCursor(new Cursor(Cursor.WAIT_CURSOR));
          for (int k = 0; k <= afrRowOffset && line != null; ++k) {
            line = br.readLine();
            if (line != null) buffer.addFirst(line.split(",", -1));
          }
          try {
            while (line != null && buffer.size() > afrRowOffset) {
              afrflds = buffer.getFirst();
              flds = buffer.removeLast();
              line = br.readLine();
              if (line != null) buffer.addFirst(line.split(",", -1));
              ppThrottle = pThrottle;
              pThrottle = throttle;
              throttle = Double.valueOf(flds[logThrottleAngleColIdx]);
              try {
                if (row > 0 && Math.abs(pThrottle - throttle) > thrtlMaxChange) {
                  if (!removed) Utils.removeRow(row--, logDataTable);
                  removed = true;
                } else if (row <= 0 || Math.abs(ppThrottle - throttle) <= thrtlMaxChange2) {
                  // Filters
                  afr =
                      (isOl
                          ? Double.valueOf(afrflds[logWbAfrColIdx])
                          : Double.valueOf(afrflds[logStockAfrColIdx]));
                  rpm = Double.valueOf(flds[logRpmColIdx]);
                  ffb = Double.valueOf(flds[logFfbColIdx]);
                  iat = Double.valueOf(flds[logIatColIdx]);
                  if (clValue != -1) clol = Integer.valueOf(flds[logClOlStatusColIdx]);
                  boolean flag =
                      isOl
                          ? ((afr <= afrMax || throttle >= thrtlMin) && afr <= afrMax)
                          : (afrMin <= afr);
                  if (flag
                      && clol == clValue
                      && rpmMin <= rpm
                      && ffbMin <= ffb
                      && ffb <= ffbMax
                      && iat <= iatMax) {
                    removed = false;
                    if (!isOl)
                      trims.add(
                          Double.valueOf(flds[logAfLearningColIdx])
                              + Double.valueOf(flds[logAfCorrectionColIdx]));
                    Utils.ensureRowCount(row + 1, logDataTable);
                    logDataTable.setValueAt(rpm, row, 0);
                    logDataTable.setValueAt(iat, row, 1);
                    logDataTable.setValueAt(Double.valueOf(flds[logMpColIdx]), row, 2);
                    logDataTable.setValueAt(ffb, row, 3);
                    logDataTable.setValueAt(afr, row, 4);
                    logDataTable.setValueAt(Double.valueOf(flds[logMafColIdx]), row, 5);
                    logDataTable.setValueAt(Double.valueOf(flds[logSdColIdx]), row, 6);
                    row += 1;
                  } else removed = true;
                } else removed = true;
              } catch (NumberFormatException e) {
                logger.error(e);
                JOptionPane.showMessageDialog(
                    null,
                    "Error parsing number at " + file.getName() + " line " + i + ": " + e,
                    "Error processing file",
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
              i += 1;
            }
          } finally {
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
          }
        }
      } catch (Exception e) {
        logger.error(e);
        JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE);
      } finally {
        if (br != null) {
          try {
            br.close();
          } catch (IOException e) {
            logger.error(e);
          }
        }
      }
    }
  }
Esempio n. 16
0
 /** Close the current {@link Doc.Level}. */
 void close() {
   Doc.Level top = stack.removeLast();
   stack.peekLast().add(top);
 }