/** * Transforms this first order constraint into a propositional constraint. * * @return The propositionalized constraint. */ public PropositionalConstraint propositionalize() { Score[] leftScores = left.getScores().toArray(); boolean found = false; for (int i = 0; i < leftScores.length && !found; ++i) found = leftScores[i].value.equals(right); PropositionalConstraint result = null; if (!found) result = new PropositionalConstant(false); else result = new PropositionalVariable(left.getClassifier(), left.getExample(), right); if (!equality) result = new PropositionalNegation(result); return result; }
/** * This method sets the given quantification variables to the given object references and * evaluates the expressions involving those variables in this constraint's <code> * FirstOrderEquality</code> children. * * @param o The new object references for the enclosing quantification variables, in order of * nesting. */ public void setQuantificationVariables(Vector o) { if (replacer == null) { System.err.println( "LBJava ERROR: Attempting to set quantification variable in " + "FirstOrderEqualityWithValue with no variable setter " + "implementation provided."); System.exit(1); } replacer.setQuantificationVariables(o); if (!replacer.leftConstant) { left = new FirstOrderVariable(left.getClassifier(), replacer.getLeftObject()); if (variableMap != null && variableMap.containsKey(left)) left = (FirstOrderVariable) variableMap.get(left); } if (!replacer.rightConstant) right = replacer.getRightValue(); }
/** Determines whether the constraint is satisfied. */ public boolean evaluate() { return equality == left.getValue().equals(right); }
/** * Two <code>FirstOrderEqualityWithValue</code>s are equivalent when their children are * equivalent. * * @return <code>true</code> iff the argument is a <code>FirstOrderEqualityWithValue</code> * involving the same children. */ public boolean equals(Object o) { if (!(o instanceof FirstOrderEqualityWithValue)) return false; FirstOrderEqualityWithValue n = (FirstOrderEqualityWithValue) o; return replacer == n.replacer && (replacer != null || replacer == null && left.equals(n.left) && right.equals(n.right)); }
/** * The hash code of a <code>FirstOrderEqualityWithValue</code> is the sum of the hash codes of its * children plus 1. * * @return The hash code for this <code>FirstOrderEqualityWithValue</code>. */ public int hashCode() { if (replacer != null) return replacer.hashCode(); return left.hashCode() + right.hashCode() + 1; }