Java Code Examples for kodkod.ast.Formula#or()
The following examples show how to use
kodkod.ast.Formula#or() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Proc.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Override public Formula formula() { return Formula.or(map(disjuncts, new Formula[0], new Func1<Proc,Formula>() { @Override public Formula run(Proc p) { return p.formula(); } })); }
Example 2
Source File: Proc.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Override public Pair<Formula,Bounds> firstOrderProblem() { Formula[] formulas = new Formula[disjuncts.length]; Bounds[] boundss = new Bounds[disjuncts.length]; for (int i = 0; i < disjuncts.length; i++) { Pair<Formula,Bounds> p = disjuncts[i].firstOrderProblem(); formulas[i] = p.a; boundss[i] = p.b; } return new Pair<Formula,Bounds>(Formula.or(formulas), union(boundss)); }
Example 3
Source File: ALG195_1.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns conjecture 1. * * @return co1 */ public final Formula co1() { Formula f = Formula.FALSE; for (int i = 0; i < 7; i++) { f = f.or(co1h(h[i])); } return f; }
Example 4
Source File: Quasigroups7.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns conjecture 1. * * @return co1 */ public final Formula co1() { final List<Formula> formulas = new ArrayList<Formula>(); for (int i = 0; i < 7; i++) { formulas.add(co1h(h[i])); } return Formula.or(formulas); }
Example 5
Source File: DNACuts.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the cutChainLength constraint. (Similar to CutChainsAtMost6BasesLong * fact, but with the cut chain length as specified during construction.) * * @return the cutChainLength constraint */ public Formula cutChainLength() { Formula ret = Formula.FALSE; final Variable c = Variable.unary("c"); for (int i = 0; i < neighbor.length; i++) { ret = ret.or(c.join(neighbor[i]).in(JoinLink)); } return ret.forAll(c.oneOf(CutLink)); }
Example 6
Source File: DNACuts.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the cutLinkUniqueness constraint. * * @return the cutLinkUniqueness constraint. */ public Formula cutLinkUniqueness() { final Variable c1 = Variable.unary("c1"); final Variable c2 = Variable.unary("c2"); final Formula f0 = c1.eq(c2).not().and(next.join(c1).in(JoinLink)).and(next.join(c2).in(JoinLink)); Formula f = c1.join(base).in(c2.join(base).union(c2.join(base).join(partner))).not(); for (int i = 0; i < neighbor.length; i++) { Expression c1n = c1.join(neighbor[i]), c2n = c2.join(neighbor[i]); f = f.or(c1n.in(JoinLink)).or(c2n.in(JoinLink)); f = f.or(c1n.join(base).in(c2n.join(base).union(c2n.join(base).join(partner))).not()); } return f0.implies(f).forAll(c1.oneOf(CutLink).and(c2.oneOf(CutLink))); }
Example 7
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Returns conjecture 1. * @return co1 */ public final Formula co1() { Formula f = Formula.FALSE; for(int i = 0; i < 7; i++) { f = f.or(co1h(h[i])); } return f; }
Example 8
Source File: Quasigroups7.java From kodkod with MIT License | 5 votes |
/** * Returns conjecture 1. * @return co1 */ public final Formula co1() { final List<Formula> formulas = new ArrayList<Formula>(); for(int i = 0; i < 7; i++) { formulas.add(co1h(h[i])); } return Formula.or(formulas); }
Example 9
Source File: DNACuts.java From kodkod with MIT License | 5 votes |
/** * Returns the cutChainLength constraint. (Similar to * CutChainsAtMost6BasesLong fact, but with the cut * chain length as specified during construction.) * @return the cutChainLength constraint */ public Formula cutChainLength() { Formula ret = Formula.FALSE; final Variable c = Variable.unary("c"); for(int i = 0; i < neighbor.length; i++) { ret = ret.or(c.join(neighbor[i]).in(JoinLink)); } return ret.forAll(c.oneOf(CutLink)); }
Example 10
Source File: DNACuts.java From kodkod with MIT License | 5 votes |
/** * Returns the cutLinkUniqueness constraint. * @return the cutLinkUniqueness constraint. */ public Formula cutLinkUniqueness() { final Variable c1 = Variable.unary("c1"); final Variable c2 = Variable.unary("c2"); final Formula f0 = c1.eq(c2).not().and(next.join(c1).in(JoinLink)).and(next.join(c2).in(JoinLink)); Formula f = c1.join(base).in(c2.join(base).union(c2.join(base).join(partner))).not(); for(int i = 0; i < neighbor.length; i++) { Expression c1n = c1.join(neighbor[i]), c2n = c2.join(neighbor[i]); f = f.or(c1n.in(JoinLink)).or(c2n.in(JoinLink)); f = f.or(c1n.join(base).in(c2n.join(base).union(c2n.join(base).join(partner))).not()); } return f0.implies(f).forAll(c1.oneOf(CutLink).and(c2.oneOf(CutLink))); }
Example 11
Source File: SolutionIterator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
/** * Returns the trivial solution corresponding to the trivial translation stored * in {@code this.translation}, and if {@code this.translation.cnf.solve()} is * true, sets {@code this.translation} to a new translation that eliminates the * current trivial solution from the set of possible solutions. The latter has * the effect of forcing either the translator or the solver to come up with the * next solution or return UNSAT. If {@code this.translation.cnf.solve()} is * false, sets {@code this.translation} to null. * * @requires this.translation != null * @ensures this.translation is modified to eliminate the current trivial * solution from the set of possible solutions * @return current solution */ private Solution nextTrivialSolution() { final Translation.Whole transl = this.translation; final Solution sol = Solver.trivial(transl, translTime); // this also // frees up // solver // resources, // if unsat if (sol.instance() == null) { translation = null; // unsat, no more solutions } else { trivial++; final Bounds bounds = transl.bounds(); final Bounds newBounds = bounds.clone(); final List<Formula> changes = new ArrayList<Formula>(); for (Relation r : bounds.relations()) { final TupleSet lower = bounds.lowerBound(r); if (lower != bounds.upperBound(r)) { // r may change if (lower.isEmpty()) { changes.add(r.some()); } else { final Relation rmodel = Relation.nary(r.name() + "_" + trivial, r.arity()); newBounds.boundExactly(rmodel, lower); changes.add(r.eq(rmodel).not()); } } } // nothing can change => there can be no more solutions (besides the // current trivial one). // note that transl.formula simplifies to the constant true with // respect to // transl.bounds, and that newBounds is a superset of transl.bounds. // as a result, finding the next instance, if any, for // transl.formula.and(Formula.or(changes)) // with respect to newBounds is equivalent to finding the next // instance of Formula.or(changes) alone. final Formula formula = changes.isEmpty() ? Formula.FALSE : Formula.or(changes); final long startTransl = System.currentTimeMillis(); translation = Translator.translate(formula, newBounds, transl.options()); translTime += System.currentTimeMillis() - startTransl; } return sol; }
Example 12
Source File: Solver.java From kodkod with MIT License | 4 votes |
/** * Returns the trivial solution corresponding to the trivial translation stored in {@code this.translation}, * and if {@code this.translation.cnf.solve()} is true, sets {@code this.translation} to a new translation * that eliminates the current trivial solution from the set of possible solutions. The latter has the effect * of forcing either the translator or the solver to come up with the next solution or return UNSAT. * If {@code this.translation.cnf.solve()} is false, sets {@code this.translation} to null. * @requires this.translation != null * @ensures this.translation is modified to eliminate the current trivial solution from the set of possible solutions * @return current solution */ private Solution nextTrivialSolution() { final Translation.Whole transl = this.translation; final Solution sol = trivial(transl, translTime); // this also frees up solver resources, if unsat if (sol.instance()==null) { translation = null; // unsat, no more solutions } else { trivial++; final Bounds bounds = transl.bounds(); final Bounds newBounds = bounds.clone(); final List<Formula> changes = new ArrayList<Formula>(); for(Relation r : bounds.relations()) { final TupleSet lower = bounds.lowerBound(r); if (lower != bounds.upperBound(r)) { // r may change if (lower.isEmpty()) { changes.add(r.some()); } else { final Relation rmodel = Relation.nary(r.name()+"_"+trivial, r.arity()); newBounds.boundExactly(rmodel, lower); changes.add(r.eq(rmodel).not()); } } } // nothing can change => there can be no more solutions (besides the current trivial one). // note that transl.formula simplifies to the constant true with respect to // transl.bounds, and that newBounds is a superset of transl.bounds. // as a result, finding the next instance, if any, for transl.formula.and(Formula.or(changes)) // with respect to newBounds is equivalent to finding the next instance of Formula.or(changes) alone. final Formula formula = changes.isEmpty() ? Formula.FALSE : Formula.or(changes); final long startTransl = System.currentTimeMillis(); translation = Translator.translate(formula, newBounds, transl.options()); translTime += System.currentTimeMillis() - startTransl; } return sol; }
Example 13
Source File: JenaTranslator.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(OpTable arg0) { Set<Variable> vars = HashSetFactory.make(); Formula f = null; for(Iterator<Binding> bs = arg0.getTable().rows(); bs.hasNext(); ) { Formula rf = null; Binding b = bs.next(); for(Var jv : arg0.getTable().getVars()) { if (b.get(jv) != null) { Expression value = toTerm(b.get(jv)); Variable var = context.getVars().get(jv.getName()); vars.add(var); Formula ef = var.eq(value); rf = rf==null? ef: rf.and(ef); } } f = f==null? rf: f.or(rf); } context.setCurrentQuery(f==null? Formula.TRUE: f); if (context.getStaticBinding() != null) { context.getStaticBinding().addAll(vars); } else { context.setStaticBinding(vars); } Expression bound = null; for(Variable v : vars) { bound = bound==null? varExpr(v): bound.union(varExpr(v)); } if (bound != null) { if (context.getDynamicBinding() != null) { context.setDynamicBinding(context.getDynamicBinding().union(bound)); } else { context.setDynamicBinding(bound); } } context.getCurrentContinuation().next(context, context.getCurrentQuery()); }
Example 14
Source File: Trees.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Returns the inCycle predicate. * * @return * * <pre> * pred InCycle(v: V, c: V -> V) { * v in v.c or * some v': v.c | v' in v.^(c - v->v' - v'->v) * } * </pre> */ public final Formula inCycle(Expression/* V */ v, Expression/* V->V */ c) { final Formula f0 = v.in(v.join(c)); final Variable vp = Variable.unary("v'"); final Formula f1 = vp.in(v.join((c.difference(v.product(vp)).difference(vp.product(v))).closure())); return f0.or(f1.forSome(vp.oneOf(v.join(c)))); }
Example 15
Source File: Trees.java From kodkod with MIT License | 3 votes |
/** * Returns the inCycle predicate. * @return * <pre> * pred InCycle(v: V, c: V -> V) { * v in v.c or * some v': v.c | v' in v.^(c - v->v' - v'->v) * } * </pre> */ public final Formula inCycle(Expression/*V*/ v, Expression/*V->V*/ c) { final Formula f0 = v.in(v.join(c)); final Variable vp = Variable.unary("v'"); final Formula f1 = vp.in(v.join((c.difference(v.product(vp)).difference(vp.product(v))).closure())); return f0.or(f1.forSome(vp.oneOf(v.join(c)))); }