Java Code Examples for kodkod.instance.Bounds#upperBound()
The following examples show how to use
kodkod.instance.Bounds#upperBound() .
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: SymmetryDetector.java From kodkod with MIT License | 6 votes |
/** * Returns an array that contains unique non-empty tuplesets in the given bounds, * sorted in the order of increasing size. * @return unique non-empty tuplesets in the given bounds, * sorted in the order of increasing size. */ private static TupleSet[] sort(Bounds bounds) { final List<TupleSet> sets = new ArrayList<TupleSet>(bounds.relations().size()); for(Relation r : bounds.relations()) { final TupleSet lower = bounds.lowerBound(r); final TupleSet upper = bounds.upperBound(r); if (!lower.isEmpty() && lower.size()<upper.size()) { sets.add(lower); } if (!upper.isEmpty()) { sets.add(upper); } } final TupleSet[] sorted = sets.toArray(new TupleSet[sets.size()]); Arrays.sort(sorted, new Comparator<TupleSet>(){ public int compare(TupleSet o1, TupleSet o2) { return o1.size() - o2.size(); } }); return sorted; }
Example 2
Source File: SymmetryDetector.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns an array that contains unique non-empty tuplesets in the given * bounds, sorted in the order of increasing size. * * @return unique non-empty tuplesets in the given bounds, sorted in the order * of increasing size. */ private TupleSet[] sort(Bounds bounds) { final List<TupleSet> sets = new ArrayList<TupleSet>(bounds.relations().size()); for (Relation r : bounds.relations()) { if (r.isAtom() && ignoreAllAtomRelsExcept != null && !ignoreAllAtomRelsExcept.contains(r)) continue; if (ignoreRels != null && ignoreRels.contains(r)) continue; final TupleSet lower = bounds.lowerBound(r); final TupleSet upper = bounds.upperBound(r); if (!lower.isEmpty() && lower.size() < upper.size()) { sets.add(lower); } if (!upper.isEmpty()) { sets.add(upper); } } final TupleSet[] sorted = sets.toArray(new TupleSet[sets.size()]); Arrays.sort(sorted, new Comparator<TupleSet>() { @Override public int compare(TupleSet o1, TupleSet o2) { return o1.size() - o2.size(); } }); return sorted; }
Example 3
Source File: GEO159.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns a bounds with the given number of maximum curves and points * * @return a bounds with the given number of maximum curves and points */ @Override public Bounds bounds(int scope) { final Bounds b = super.bounds(scope); final TupleSet c = b.upperBound(curve); final TupleSet p = b.upperBound(point); b.bound(between, c.product(p).product(p).product(p)); return b; }
Example 4
Source File: GEO159.java From kodkod with MIT License | 5 votes |
/** * Returns a bounds with the given number of maximum curves and points * @return a bounds with the given number of maximum curves and points */ public Bounds bounds(int scope) { final Bounds b = super.bounds(scope); final TupleSet c = b.upperBound(curve); final TupleSet p = b.upperBound(point); b.bound(between, c.product(p).product(p).product(p)); return b; }
Example 5
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 6
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; }