Esempio n. 1
0
 private List<Double> getUsedArgWeight(Term t, Env env, int useParam) {
   List<Double> res = new ArrayList<Double>();
   for (int i = 0; i < getArity(t, env); i++) {
     Term arg = t.getArg(i);
     if (usingParam(arg, env, useParam, i)) res.add(getFullWeight(arg, t, env));
   }
   return res;
 }
Esempio n. 2
0
 public double getFullWeight(Term t, Term parent, Env env) {
   int type = t.getStartType();
   String symbol = getSymbol(t, env);
   int ind = getInd(symbol, type);
   int typeParent = parent.getStartType();
   String symbolParent = getSymbol(parent, env);
   switch (type) {
     case INTEGER:
     case VARIABLE:
     case CONSTANT:
       return this.getOwnWeight(symbol, type, symbolParent, typeParent);
     case FUNCTION:
     case PREDICATE:
       int aggregator = getAggregator(type).get(ind);
       int useParam = getUseParam(type).get(ind);
       double w = getOwnWeight(symbol, type, symbolParent, typeParent);
       return w * computeAggregatedWeight(t, env, aggregator, useParam);
     default:
       return -1;
   }
 }
Esempio n. 3
0
 private boolean usingParam(Term param, Env env, int useParam, int pos) {
   int typeArg = param.getStartType();
   switch (useParam) {
     case USE_NONVAR:
       return typeArg != VARIABLE;
     case USE_ONLYVAR:
       return typeArg == VARIABLE;
     case USE_ALLPARAM:
     default:
       return true;
   }
 }
Esempio n. 4
0
 public int getArity(Term t, Env env) {
   return env.getSymTable().getArity(t.getStartName(), t.getStartType());
 }
Esempio n. 5
0
 public String getSymbol(Term t, Env env) {
   return env.getSymTable().get(t.getStartName(), t.getStartType());
 }
Esempio n. 6
0
  /**
   * Applies this operator.
   *
   * @return true if the application of this operator succeeds.
   */
  public boolean apply() {
    super.apply();

    // Checks equality constraints.
    Options opt = tableau.getOptions();
    if (opt.useEqConstraint()) {
      if (opt.getEqConstraintType() != CFP.EQ_CONSTRAINTS_ADVANCE) {
        Literal lit = node.getLiteral();
        if (lit.isEqualPred()) {
          stats.incTests(Stats.EQ_CONSTRAINT_GEN);
          TermWeight weight1 = env.getTermWeight1();
          TermWeight weight2 = env.getTermWeight2();
          Term arg1 = lit.getArg(0);
          Term arg2 = lit.getArg(1);
          arg1.calcTermWegiht(weight1);
          arg2.calcTermWegiht(weight2);
          int ret = weight2.isGreaterThan(weight1);
          if (ret == TermWeight.TRUE || ret == TermWeight.SAME) {
            super.cancel();
            stats.incSuccs(Stats.EQ_CONSTRAINT_GEN);
            if (env.dbgNow(DBG_TABLEAUX)) {
              System.out.println();
              System.out.println("FAILED by EQCN [" + arg1 + " > " + arg2 + "].");
            }
            return false;
          } else if (opt.getEqConstraintType() == CFP.EQ_CONSTRAINTS_FULL) {
            GreaterThan gt = new GreaterThan(env, node, Stats.EQ_CONSTRAINT_CHK, arg1, arg2);
            if (tableau.addConstraint(gt)) {
              addGenerated(gt);
              stats.incProds(Stats.EQ_CONSTRAINT_GEN);
            }
          }
        }
      } else { // Checks equality constraints in advance

        Literal lit = node.getLiteral();
        if (lit.isNegEqualPred()) { // changes the constraint >= to >.

          stats.incTests(Stats.EQ_CONSTRAINT_GEN);
          TermWeight weight1 = env.getTermWeight1();
          TermWeight weight2 = env.getTermWeight2();
          Term arg1 = lit.getArg(0);
          Term arg2 = lit.getArg(1);
          arg1.calcTermWegiht(weight1);
          arg2.calcTermWegiht(weight2);
          int ret = weight2.isGreaterThan(weight1);
          if (ret == TermWeight.TRUE || ret == TermWeight.SAME) {
            super.cancel();
            stats.incSuccs(Stats.EQ_CONSTRAINT_GEN);
            if (env.dbgNow(DBG_TABLEAUX)) {
              System.out.println();
              System.out.println("FAILED by EQCN [" + arg1 + " > " + arg2 + "].");
            }
            return false;
          } else {
            GreaterThan gt = new GreaterThan(env, node, Stats.EQ_CONSTRAINT_CHK, arg1, arg2);
            if (tableau.addConstraint(gt)) {
              addGenerated(gt);
              stats.incProds(Stats.EQ_CONSTRAINT_GEN);
            }
          }
        }
      }
    }

    node.setReductionTarget(target);
    node.addTag(REDUCED);
    tableau.stats().incSuccs(Stats.REDUCTION);
    return true;
  }