Package aima.core.logic.propositional.parsing.ast

Examples of aima.core.logic.propositional.parsing.ast.Symbol


        List<Sentence> pair = pairs.get(i);
        // System.out.println("pair number" + i+" of "+pairs.size());
        Set<Sentence> resolvents = plResolve(pair.get(0), pair.get(1));
        resolvents = filterOutClausesWithTwoComplementaryLiterals(resolvents);

        if (resolvents.contains(new Symbol("EMPTY_CLAUSE"))) {
          return true;
        }
        newClauses = SetOps.union(newClauses, resolvents);
        // System.out.println("clauseslist size = " +clauses.size());
View Full Code Here


  public Set<Sentence> plResolve(Sentence clause1, Sentence clause2) {
    Set<Sentence> resolvents = new HashSet<Sentence>();
    ClauseSymbols cs = new ClauseSymbols(clause1, clause2);
    Iterator<Symbol> iter = cs.getComplementedSymbols().iterator();
    while (iter.hasNext()) {
      Symbol symbol = iter.next();
      resolvents.add(createResolventClause(cs, symbol));
    }

    return resolvents;
  }
View Full Code Here

    }
    for (int i = 0; i < negativeSymbols.size(); i++) {
      sentences.add(new UnarySentence(negativeSymbols.get(i)));
    }
    if (sentences.size() == 0) {
      return new Symbol("EMPTY_CLAUSE"); // == empty clause
    } else {
      return LogicUtils.chainWith("OR", sentences);
    }

  }
View Full Code Here

    if ((purePositiveSymbols.size() == 0)
        && (pureNegativeSymbols.size() == 0)) {
      return new SymbolValuePair();// automatically set to null values
    } else {
      if (purePositiveSymbols.size() > 0) {
        Symbol symbol = new Symbol(
            (purePositiveSymbols.get(0)).getValue());
        if (pureNegativeSymbols.contains(symbol)) {
          throw new RuntimeException("Symbol " + symbol.getValue()
              + "misclassified");
        }
        return new SymbolValuePair(symbol, true);
      } else {
        Symbol symbol = new Symbol(
            (pureNegativeSymbols.get(0)).getValue());
        if (purePositiveSymbols.contains(symbol)) {
          throw new RuntimeException("Symbol " + symbol.getValue()
              + "misclassified");
        }
        return new SymbolValuePair(symbol, false);
      }
    }
View Full Code Here

    // try to find a unit clause
    SymbolValuePair svp = findPureSymbolValuePair(clauseList, model,
        symbols);
    if (svp.notNull()) {
      List<Symbol> newSymbols = new ArrayList<Symbol>(symbols);
      newSymbols.remove(new Symbol(svp.symbol.getValue()));
      Model newModel = model.extend(new Symbol(svp.symbol.getValue()),
          svp.value.booleanValue());
      return dpll(clauses, newSymbols, newModel);
    }

    SymbolValuePair svp2 = findUnitClause(clauseList, model, symbols);
    if (svp2.notNull()) {
      List<Symbol> newSymbols = new ArrayList<Symbol>(symbols);
      newSymbols.remove(new Symbol(svp2.symbol.getValue()));
      Model newModel = model.extend(new Symbol(svp2.symbol.getValue()),
          svp2.value.booleanValue());
      return dpll(clauses, newSymbols, newModel);
    }

    Symbol symbol = (Symbol) symbols.get(0);
    // System.out.println("default behaviour selecting " + symbol);
    List<Symbol> newSymbols = new ArrayList<Symbol>(symbols);
    newSymbols.remove(0);
    return (dpll(clauses, newSymbols, model.extend(symbol, true)) || dpll(
        clauses, newSymbols, model.extend(symbol, false)));
View Full Code Here

    for (int i = 0; i < clauseList.size(); i++) {
      Sentence clause = (Sentence) clauseList.get(i);
      if ((clause instanceof Symbol)
          && (!(model.getAssignedSymbols().contains(clause)))) {
        // System.out.println("found unit clause - assigning");
        return new SymbolValuePair(new Symbol(
            ((Symbol) clause).getValue()), true);
      }

      if (clause instanceof UnarySentence) {
        UnarySentence sentence = (UnarySentence) clause;
        Sentence negated = sentence.getNegated();
        if ((negated instanceof Symbol)
            && (!(model.getAssignedSymbols().contains(negated)))) {
          // System.out.println("found unit clause type 2 -
          // assigning");
          return new SymbolValuePair(new Symbol(
              ((Symbol) negated).getValue()), false);
        }
      }

    }
View Full Code Here

   *
   * @return the answer to the specified question using the PL-FC-Entails
   *         algorithm
   */
  public boolean plfcEntails(KnowledgeBase kb, String s) {
    return plfcEntails(kb, new Symbol(s));
  }
View Full Code Here

   *         algorithm
   */
  public boolean plfcEntails(KnowledgeBase kb, Symbol q) {
    List<HornClause> hornClauses = asHornClauses(kb.getSentences());
    while (agenda.size() != 0) {
      Symbol p = agenda.pop();
      while (!inferred(p)) {
        inferred.put(p, Boolean.TRUE);

        for (int i = 0; i < hornClauses.size(); i++) {
          HornClause hornClause = hornClauses.get(i);
View Full Code Here

    SymbolCollector sc = new SymbolCollector();

    List<Symbol> symbols = new Converter<Symbol>().setToList(sc
        .getSymbolsIn(s));
    for (int i = 0; i < symbols.size(); i++) {
      Symbol sym = (Symbol) symbols.get(i);
      myModel = myModel.extend(sym, Util.randomBoolean());
    }
    List<Sentence> clauses = new Converter<Sentence>()
        .setToList(clauseGatherer.getClausesFrom(transformer
            .transform(s)));

    for (int i = 0; i < numberOfFlips; i++) {
      if (getNumberOfClausesSatisfiedIn(
          new Converter<Sentence>().listToSet(clauses), myModel) == clauses
          .size()) {
        return myModel;
      }
      Sentence clause = clauses.get(random.nextInt(clauses.size()));

      List<Symbol> symbolsInClause = new Converter<Symbol>().setToList(sc
          .getSymbolsIn(clause));
      if (random.nextDouble() >= probabilityOfRandomWalk) {
        Symbol randomSymbol = symbolsInClause.get(random
            .nextInt(symbolsInClause.size()));
        myModel = myModel.flip(randomSymbol);
      } else {
        Symbol symbolToFlip = getSymbolWhoseFlipMaximisesSatisfiedClauses(
            new Converter<Sentence>().listToSet(clauses),
            symbolsInClause, myModel);
        myModel = myModel.flip(symbolToFlip);
      }
View Full Code Here

  }

  private Symbol getSymbolWhoseFlipMaximisesSatisfiedClauses(
      Set<Sentence> clauses, List<Symbol> symbols, Model model) {
    if (symbols.size() > 0) {
      Symbol retVal = symbols.get(0);
      int maxClausesSatisfied = 0;
      for (int i = 0; i < symbols.size(); i++) {
        Symbol sym = symbols.get(i);
        if (getNumberOfClausesSatisfiedIn(clauses, model.flip(sym)) > maxClausesSatisfied) {
          retVal = sym;
          maxClausesSatisfied = getNumberOfClausesSatisfiedIn(
              clauses, model.flip(sym));
        }
View Full Code Here

TOP

Related Classes of aima.core.logic.propositional.parsing.ast.Symbol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.