Search in sources :

Example 6 with FormulaOperator

use of kodkod.ast.operator.FormulaOperator in project org.alloytools.alloy by AlloyTools.

the class FullNegationPropagator method visit.

/**
 * Visits the formula's children with appropriate settings for the negated flag
 * if bf has not been visited before.
 *
 * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.NaryFormula)
 */
@Override
public final void visit(NaryFormula nf) {
    if (visited(nf))
        return;
    final FormulaOperator op = nf.op();
    if (negated && op == AND) {
        List<Formula> formulas = new LinkedList<Formula>();
        for (Formula f : nf) {
            FullNegationPropagator fne = new FullNegationPropagator(shared, annotations);
            f.not().accept(fne);
            formulas.add(Formula.and(fne.conjuncts));
        }
        addConjunct(Formula.or(formulas), false, nf);
        hasChanged = true;
    } else if (!negated && op == OR) {
        List<Formula> formulas = new LinkedList<Formula>();
        boolean changed = false;
        for (Formula f : nf) {
            FullNegationPropagator fne = new FullNegationPropagator(shared, annotations);
            f.accept(fne);
            changed = changed || fne.hasChanged;
            formulas.add(Formula.and(fne.conjuncts));
        }
        if (changed) {
            addConjunct(Formula.or(formulas), false, nf);
            hasChanged = true;
        } else {
            addConjunct(nf);
        }
    } else {
        for (Formula f : nf) {
            f.accept(this);
        }
        hasChanged = negated;
    }
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) FormulaOperator(kodkod.ast.operator.FormulaOperator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 7 with FormulaOperator

use of kodkod.ast.operator.FormulaOperator in project org.alloytools.alloy by AlloyTools.

the class FOL2BoolTranslator method visit.

/**
 * Calls lookup(binFormula) and returns the cached value, if any. If a
 * translation has not been cached, translates the formula, calls cache(...) on
 * it and returns it.
 *
 * @return let t = lookup(binFormula) | some t => t, cache(binFormula,
 *         binFormula.op(binFormula.left.accept(this),
 *         binFormula.right.accept(this))
 */
@Override
public final BooleanValue visit(BinaryFormula binFormula) {
    BooleanValue ret = lookup(binFormula);
    if (ret != null)
        return ret;
    final BooleanValue left = binFormula.left().accept(this);
    final BooleanValue right = binFormula.right().accept(this);
    final FormulaOperator op = binFormula.op();
    final BooleanFactory f = interpreter.factory();
    switch(op) {
        case AND:
            ret = f.and(left, right);
            break;
        case OR:
            ret = f.or(left, right);
            break;
        case IMPLIES:
            ret = f.implies(left, right);
            break;
        case IFF:
            ret = f.iff(left, right);
            break;
        default:
            throw new IllegalArgumentException("Unknown operator: " + op);
    }
    return cache(binFormula, ret);
}
Also used : FormulaOperator(kodkod.ast.operator.FormulaOperator) BooleanValue(kodkod.engine.bool.BooleanValue) BooleanFactory(kodkod.engine.bool.BooleanFactory)

Aggregations

FormulaOperator (kodkod.ast.operator.FormulaOperator)7 BinaryFormula (kodkod.ast.BinaryFormula)5 ComparisonFormula (kodkod.ast.ComparisonFormula)5 Formula (kodkod.ast.Formula)5 IntComparisonFormula (kodkod.ast.IntComparisonFormula)5 MultiplicityFormula (kodkod.ast.MultiplicityFormula)5 NaryFormula (kodkod.ast.NaryFormula)5 NotFormula (kodkod.ast.NotFormula)5 QuantifiedFormula (kodkod.ast.QuantifiedFormula)5 ConstantFormula (kodkod.ast.ConstantFormula)3 FixFormula (kodkod.ast.FixFormula)3 BooleanValue (kodkod.engine.bool.BooleanValue)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExprCompOperator (kodkod.ast.operator.ExprCompOperator)1 ExprOperator (kodkod.ast.operator.ExprOperator)1 BooleanAccumulator (kodkod.engine.bool.BooleanAccumulator)1 BooleanFactory (kodkod.engine.bool.BooleanFactory)1 Operator (kodkod.engine.bool.Operator)1