Package aima.core.util.math

Examples of aima.core.util.math.MixedRadixNumber


      for (Literal tl : thisToTry.get(literalName)) {
        thisTerms.addAll(tl.getAtomicSentence().getArgs());
      }
    }

    MixedRadixNumber permutation = null;
    long numPermutations = 1L;
    if (radices.size() > 0) {
      permutation = new MixedRadixNumber(0, radices);
      numPermutations = permutation.getMaxAllowedValue() + 1;
    }
    // Want to ensure none of the othCVariables are
    // part of the key set of a unification as
    // this indicates it is not a legal subsumption.
    Set<Variable> othCVariables = _variableCollector
        .collectAllVariables(othC);
    Map<Variable, Term> theta = new LinkedHashMap<Variable, Term>();
    List<Literal> literalPermuations = new ArrayList<Literal>();
    for (long l = 0L; l < numPermutations; l++) {
      // Track the other clause's terms for this
      // permutation.
      othCTerms.clear();
      int radixIdx = 0;
      for (String literalName : thisToTry.keySet()) {
        int sizeT = thisToTry.get(literalName).size();
        literalPermuations.clear();
        literalPermuations.addAll(othCToTry.get(literalName));
        int sizeO = literalPermuations.size();

        if (sizeO > 1) {
          for (int i = 0; i < sizeT; i++) {
            int r = sizeO - i;
            if (r > 1) {
              // If not a 1 to 1 mapping then you need
              // to use the correct permuation
              int numPos = permutation
                  .getCurrentNumeralValue(radixIdx);
              othCTerms.addAll(literalPermuations.remove(numPos)
                  .getAtomicSentence().getArgs());
              radixIdx++;
            } else {
              // is the last mapping, therefore
              // won't be on the radix
              othCTerms.addAll(literalPermuations.get(0)
                  .getAtomicSentence().getArgs());
            }
          }
        } else {
          // a 1 to 1 mapping
          othCTerms.addAll(literalPermuations.get(0)
              .getAtomicSentence().getArgs());
        }
      }

      // Note: on unifier
      // unifier.unify(P(w, x), P(y, z)))={w=y, x=z}
      // unifier.unify(P(y, z), P(w, x)))={y=w, z=x}
      // Therefore want this clause to be the first
      // so can do the othCVariables check for an invalid
      // subsumes.
      theta.clear();
      if (null != _unifier.unify(thisTerms, othCTerms, theta)) {
        boolean containsAny = false;
        for (Variable v : theta.keySet()) {
          if (othCVariables.contains(v)) {
            containsAny = true;
            break;
          }
        }
        if (!containsAny) {
          subsumes = true;
          break;
        }
      }

      // If there is more than 1 mapping
      // keep track of where I am in the
      // possible number of mapping permutations.
      if (null != permutation) {
        permutation.increment();
      }
    }

    return subsumes;
  }
View Full Code Here

TOP

Related Classes of aima.core.util.math.MixedRadixNumber

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.