Example #1
0
 @Override
 public double getIncompatibility() {
   assert setAtom.getNumberOfValues() == 1;
   if (NumericUtilities.equals(setAtom.getSoftValue(0), getAggregateValue())) {
     return 0.0;
   } else return Double.POSITIVE_INFINITY;
 }
Example #2
0
 public List<VariableAssignment> traceAtomEvent(Atom atom) {
   Collection<Atom> atoms = dependence.get(atom.getPredicate());
   List<VariableAssignment> vars = new ArrayList<VariableAssignment>(atoms.size());
   for (Atom entry : atoms) {
     // Check whether arguments match
     VariableAssignment var = new VariableAssignment();
     Term[] argsGround = atom.getArguments();
     Term[] argsTemplate = entry.getArguments();
     assert argsGround.length == argsTemplate.length;
     for (int i = 0; i < argsGround.length; i++) {
       if (argsTemplate[i] instanceof Variable) {
         // Add mapping
         assert argsGround[i] instanceof GroundTerm;
         var.assign((Variable) argsTemplate[i], (GroundTerm) argsGround[i]);
       } else {
         // They must be the same
         if (!argsTemplate[i].equals(argsGround[i])) {
           var = null;
           break;
         }
       }
     }
     if (var != null) vars.add(var);
   }
   return vars;
 }
Example #3
0
 @Override
 public BindingMode getBinding(Atom atom) {
   if (referencedAtoms.contains(atom)) {
     if (setAtom.isActive()) return BindingMode.StrongRV;
     else return BindingMode.WeakRV;
   } else if (setAtom.equals(atom)) {
     if (definitionType.getAggregator().enoughSupport(set1, set2, referencedAtoms))
       return BindingMode.StrongRV;
     else return BindingMode.WeakRV;
   } else return BindingMode.NoBinding;
 }
Example #4
0
    public DNFClause(List<Atom> posLiterals, List<Atom> negLiterals) {
      this.posLiterals = new ArrayList<Atom>(posLiterals);
      this.negLiterals = new ArrayList<Atom>(negLiterals);
      dependence = ArrayListMultimap.create();
      Set<Variable> allowedVariables = new HashSet<Variable>();
      Set<Variable> variablesToCheck = new HashSet<Variable>();
      boolean tempAllVariablesBound = true;

      /*
       * Checks if all Variables in the clause appear in a positive literal
       * with a StandardPredicate.
       */
      Set<Variable> setToAdd;

      for (Atom atom : posLiterals) {
        if (atom.getPredicate() instanceof StandardPredicate) setToAdd = allowedVariables;
        else setToAdd = variablesToCheck;

        for (Term t : atom.getArguments()) {
          if (t instanceof Variable) setToAdd.add((Variable) t);
        }
      }

      for (Atom atom : negLiterals)
        for (Term t : atom.getArguments())
          if (t instanceof Variable) variablesToCheck.add((Variable) t);

      isGround = (allowedVariables.size() + variablesToCheck.size() == 0) ? true : false;

      for (Variable v : variablesToCheck)
        if (!allowedVariables.contains(v)) tempAllVariablesBound = false;

      allVariablesBound = tempAllVariablesBound;

      /*
       * Processes the positive literals with StandardPredicates further
       */
      for (int i = 0; i < posLiterals.size(); i++)
        if (posLiterals.get(i).getPredicate() instanceof StandardPredicate)
          dependence.put(posLiterals.get(i).getPredicate(), posLiterals.get(i));

      if (posLiterals.size() == 0) query = null;
      else if (posLiterals.size() == 1) query = (allVariablesBound) ? posLiterals.get(0) : null;
      else
        query =
            (allVariablesBound)
                ? new Conjunction(posLiterals.toArray(new Formula[posLiterals.size()]))
                : null;
    }
Example #5
0
 @Override
 public boolean equals(Object oth) {
   if (oth == this) return true;
   if (oth == null || !(getClass().isInstance(oth))) return false;
   GroundSetDefinition p = (GroundSetDefinition) oth;
   return setAtom.equals(p.setAtom);
 }
Example #6
0
  GroundSetDefinition(
      SetDefinitionKernel s, Atom atom, TermMembership s1, TermMembership s2, Set<Atom> refAtoms) {
    assert s != null;
    definitionType = s;
    setAtom = atom;
    set1 = s1;
    set2 = s2;
    referencedAtoms = refAtoms;
    setAtom.setSoftValue(0, getAggregateValue());

    hashcode = new HashCodeBuilder().append(setAtom).toHashCode();
  }