kodkod.instance.TupleSet Java Examples
The following examples show how to use
kodkod.instance.TupleSet.
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: GRA013_026.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns the bounds. * * @return the bounds */ public final Bounds bounds() { final List<String> atoms = new ArrayList<String>(graphSize); for (int i = 1; i <= graphSize; i++) atoms.add("n" + i); atoms.add("goal"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.bound(goal, f.setOf("goal")); final TupleSet ns = f.range(f.tuple("n1"), f.tuple("n" + graphSize)); b.boundExactly(node, ns); final TupleSet s = f.noneOf(2); for (int i = 1; i < graphSize; i++) { for (int j = i + 1; j < graphSize; j++) s.add(f.tuple("n" + i, "n" + j)); } b.boundExactly(lessThan, s); b.bound(red, s); b.bound(green, s); return b; }
Example #2
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 #3
Source File: TranslateKodkodToJava.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** Print the tupleset using the name n. */ private void printTupleset(String n, TupleSet ts, Map<Object,String> atomMap) { file.printf("TupleSet %s = factory.noneOf(%d);%n", n, ts.arity()); for (Tuple t : ts) { file.printf("%s.add(", n); for (int i = 0; i < ts.arity(); i++) { if (i != 0) file.printf(".product("); Object a = t.atom(i); String b = atomMap == null ? null : atomMap.get(a); file.printf("factory.tuple(\"%s\")", (b == null ? a.toString() : b)); if (i != 0) file.printf(")"); } file.printf(");%n"); } }
Example #4
Source File: Sudoku.java From kodkod with MIT License | 6 votes |
/** * Solves the given puzzle using MiniSatProver and translation logging * if core is true; otherwise solves it using MiniSat. Solution is * printed to standard output. */ private void solve(TupleSet clues, SudokuCoreExtractor extractor) { final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSatProver); solver.options().setLogTranslation(1); final Solution sol = solver.solve(rules(), bounds(clues)); if (sol.instance()!=null) { System.out.println(sol.stats()); System.out.println(SudokuParser.prettyPrint(sol.instance().tuples(grid))); } else { System.out.println(sol.stats()); final Proof proof = sol.proof(); final long[] coreData = extractor.extract(proof); System.out.println("Core (strategy="+extractor.name().toLowerCase()+", size="+coreData[0]+", ms="+coreData[1]+"):"); for(Node n : proof.highLevelCore().values()) { System.out.println(n); } } }
Example #5
Source File: TrivialProof.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * * @see kodkod.engine.Proof#core() */ @Override public final Iterator<TranslationRecord> core() { if (coreFilter == null) { coreFilter = new RecordFilter() { final Set<Node> coreNodes = NodePruner.relevantNodes(log(), coreRoots == null ? log().roots() : coreRoots.keySet()); @Override public boolean accept(Node node, Formula translated, int literal, Map<Variable,TupleSet> env) { return coreNodes.contains(translated); } }; } return log().replay(coreFilter); }
Example #6
Source File: Drivers.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public static TupleSet check(UniverseFactory uf, Pair<Formula, Pair<Formula, Formula>> answer, String relation) throws URISyntaxException { Instance rels = check(uf, answer); if (rels != null) { for(Relation r : rels.relations()) { if (r.toString().equals(relation)) { return rels.tuples(r); } } return null; } else { return null; } }
Example #7
Source File: BoundsComputer.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Computes the lowerbound from bottom-up; it will also set a suitable initial * value for each sig's upperbound. Precondition: sig is not a builtin sig */ private TupleSet computeLowerBound(List<Tuple> atoms, final PrimSig sig) throws Err { int n = sc.sig2scope(sig); TupleSet lower = factory.noneOf(1); for (PrimSig c : sig.children()) lower.addAll(computeLowerBound(atoms, c)); TupleSet upper = lower.clone(); boolean isExact = sc.isExact(sig); if (isExact || sig.isTopLevel()) for (n = n - upper.size(); n > 0; n--) { Tuple atom = atoms.remove(atoms.size() - 1); // If MUST<SCOPE and s is exact, then add fresh atoms to both // LOWERBOUND and UPPERBOUND. // If MUST<SCOPE and s is inexact but toplevel, then add fresh // atoms to the UPPERBOUND. if (isExact) lower.add(atom); upper.add(atom); } lb.put(sig, lower); ub.put(sig, upper); return lower; }
Example #8
Source File: A4Solution.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Add a new relation with the given label and the given lower and upper bound. * * @param label - the label for the new relation; need not be unique * @param lower - the lowerbound; can be null if you want it to be the empty set * @param upper - the upperbound; cannot be null; must contain everything in * lowerbound */ Relation addRel(String label, TupleSet lower, TupleSet upper) throws ErrorFatal { if (solved) throw new ErrorFatal("Cannot add a Kodkod relation since solve() has completed."); Relation rel = Relation.nary(label, upper.arity()); if (lower == upper) { bounds.boundExactly(rel, upper); } else if (lower == null) { bounds.bound(rel, upper); } else { if (lower.arity() != upper.arity()) throw new ErrorFatal("Relation " + label + " must have same arity for lowerbound and upperbound."); bounds.bound(rel, lower, upper); } return rel; }
Example #9
Source File: A4TupleSet.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Construct a new tupleset as the intersection of this and that; this and that * must be come from the same solution. */ public A4TupleSet intersect(A4TupleSet that) throws ErrorAPI { if (sol != that.sol) throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets from the same A4Solution."); if (arity() != that.arity()) throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets with the same arity."); if (this.tuples.size() == 0) return this; // special short cut if (that.tuples.size() == 0) return that; // special short cut TupleSet ts = tuples.clone(); ts.retainAll(that.tuples); if (tuples.size() != ts.size()) return new A4TupleSet(ts, sol); else return this; }
Example #10
Source File: BoundedUniverse.java From quetzal with Eclipse Public License 2.0 | 6 votes |
@Override protected void boundLanguages(Set<Relation> liveRelations, TupleFactory tf, Bounds b, Set<Object> liveAtoms) throws URISyntaxException { LazyTupleSet base = super.languageTableBound(tf); bound(liveRelations, liveAtoms, b, QuadTableRelations.literalLanguages, base, new LazyTupleSet() { @Override public TupleSet tuples() throws URISyntaxException { TupleSet ts = tf.noneOf(2); ts.addAll(base.tuples()); ts.addAll(anyLanguageTableBound(tf).tuples()); return ts; } }); }
Example #11
Source File: A4TupleSet.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Construct a new tupleset as the union of this and that; this and that must be * come from the same solution. Note: if that==null, then the method returns * this A4TupleSet as-is. */ public A4TupleSet plus(A4TupleSet that) throws ErrorAPI { if (that == null) return this; if (sol != that.sol) throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets from the same A4Solution."); if (arity() != that.arity()) throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets with the same arity."); if (this == that || tuples.size() == 0) return that; else if (that.tuples.size() == 0) return this; // special short cut TupleSet ts = tuples.clone(); ts.addAll(that.tuples); if (tuples.size() == ts.size()) return this; if (that.tuples.size() == ts.size()) return that; return new A4TupleSet(ts, sol); }
Example #12
Source File: A4SolutionReader.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** Parse skolem. */ private ExprVar parseSkolem(String id) throws IOException, Err { final XMLNode node = nmap.get(id); if (node == null) throw new IOException("Unknown ID " + id + " encountered."); if (!node.is("skolem")) throw new IOException("ID " + id + " is not a skolem."); String label = label(node); Expr type = null; for (XMLNode sub : node) if (sub.is("types")) { Expr t = parseType(sub); if (type == null) type = t; else type = type.plus(t); } int arity; if (type == null || (arity = type.type().arity()) < 1) throw new IOException("Skolem " + label + " is maltyped."); ExprVar var = ExprVar.make(Pos.UNKNOWN, label, type.type()); TupleSet ts = parseTuples(node, arity); expr2ts.put(var, ts); return var; }
Example #13
Source File: ResolutionBasedProof.java From kodkod with MIT License | 6 votes |
/** * {@inheritDoc} * @see kodkod.engine.Proof#highLevelCore() */ public final Map<Formula, Node> highLevelCore() { if (coreRoots == null) { final RecordFilter unitFilter = new RecordFilter() { final IntSet coreUnits = StrategyUtils.coreUnits(solver.proof()); final Set<Formula> roots = log().roots(); public boolean accept(Node node, Formula translated, int literal, Map<Variable, TupleSet> env) { return roots.contains(translated) && coreUnits.contains(Math.abs(literal)); } }; coreRoots = new LinkedHashMap<Formula, Node>(); final IntSet seenUnits = new IntTreeSet(); for(Iterator<TranslationRecord> itr = log().replay(unitFilter); itr.hasNext(); ) { // it is possible that two top-level formulas have identical meaning, // and are represented with the same core unit; in that case, we want only // one of them in the core. final TranslationRecord rec = itr.next(); if (seenUnits.add(rec.literal())) { coreRoots.put(rec.translated(), rec.node()); } } coreRoots = Collections.unmodifiableMap(coreRoots); } return coreRoots; }
Example #14
Source File: BoundedUniverse.java From quetzal with Eclipse Public License 2.0 | 6 votes |
@Override protected void boundNumbers(Set<Relation> liveRelations, TupleFactory tf, Bounds b, Set<Object> liveAtoms) throws URISyntaxException { LazyTupleSet base = super.numericTableBound(tf); bound(liveRelations, liveAtoms, b, QuadTableRelations.literalValues, base, new LazyTupleSet() { @Override public TupleSet tuples() throws URISyntaxException { TupleSet ts = tf.noneOf(2); ts.addAll(base.tuples()); ts.addAll(anyNumberTableBound(tf).tuples()); return ts; } }); }
Example #15
Source File: NUM378.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns bounds for the problem. * * @return bounds for the problem. */ public final Bounds bounds() { final int n = 21; final List<String> atoms = new ArrayList<String>(n); atoms.add("goal"); for (int i = 0; i < n; i++) atoms.add("n" + i); final Universe u = new Universe(atoms); final Bounds bound = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet succBound = f.noneOf(2); for (int i = 0; i < n; i++) { succBound.add(f.tuple("n" + i, "n" + ((i + 1) % n))); } bound.boundExactly(succ, succBound); final TupleSet sumBound = f.noneOf(3); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { sumBound.add(f.tuple("n" + i, "n" + j, "n" + ((i + j) % n))); } } bound.boundExactly(sum, sumBound); return bound; }
Example #16
Source File: Viktor.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns the bounds for the problem. * * @return bounds */ public final Bounds bounds() { List<String> atoms = new ArrayList<String>(cols + 1); for (int i = 0; i < cols; i++) { atoms.add(String.valueOf(i)); } atoms.add("a"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet abound = f.setOf("a"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { b.bound(a[i][j], abound); } } final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols - 1))); for (int j = 0; j < cols; j++) { b.bound(x[j], xbound); b.boundExactly(j, f.setOf(String.valueOf(j))); } return b; }
Example #17
Source File: Viktor.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the problem. * @return bounds */ public final Bounds bounds() { List<String> atoms = new ArrayList<String>(cols+1); for(int i = 0; i < cols; i++) { atoms.add(String.valueOf(i)); } atoms.add("a"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet abound = f.setOf("a"); for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { b.bound(a[i][j], abound); } } final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols-1))); for(int j = 0; j < cols; j++) { b.bound(x[j], xbound); b.boundExactly(j, f.setOf(String.valueOf(j))); } return b; }
Example #18
Source File: BasicUniverse.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public TupleSet predicatesTableTuples(final TupleFactory tf) { TupleSet tuples = tf.noneOf(1); for(URI bn : predicates) { tuples.add(tf.tuple(bn)); } return tuples; }
Example #19
Source File: SudokuDatabase.java From kodkod with MIT License | 5 votes |
/** * Loads the puzzles from the given file into a fresh database. * This method assumes that each line of the file represents * an individual puzzle. The puzzle should be given as a string of * N*N numbers, where each subsequence of N numbers represents one row * of the grid and zeros stand for blanks. If N > 9, the numbers should * be separated by spaces or tabs. If N <= 9, the spaces may be omitted. * @requires the file is formatted as described above * @return a sudoku database with the puzzles from the given file * @throws IOException */ public static SudokuDatabase load(String file) throws IOException { final List<TupleSet> puzzles = new ArrayList<TupleSet>(100); final BufferedReader reader = new BufferedReader(new FileReader(file)); String puzzle = reader.readLine(); if (puzzle!=null) { puzzles.add(SudokuParser.parse(puzzle)); final Universe univ = puzzles.get(0).universe(); while((puzzle=reader.readLine())!=null) { puzzles.add(SudokuParser.parse(puzzle, univ)); } } reader.close(); return new SudokuDatabase(puzzles); }
Example #20
Source File: BasicUniverse.java From quetzal with Eclipse Public License 2.0 | 5 votes |
private void collectAtoms(Set<Object> liveAtoms, TupleSet bound) { for(Tuple t : bound) { for(int i = 0; i < t.arity(); i++) { Object atom = t.atom(i); liveAtoms.add(atom); } } }
Example #21
Source File: NQueens.java From kodkod with MIT License | 5 votes |
/** * Returns the bounds for relational encoding of the problem. * @return the bounds for relational encoding of the problem. */ public Bounds bounds() { final List<Object> atoms = new ArrayList<Object>(n*2); for(int i =0; i < n; i++) { atoms.add("Q"+i); } for(int i =0; i < n; i++) { atoms.add(Integer.valueOf(i)); } final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet qbound = f.range(f.tuple("Q0"), f.tuple("Q"+(n-1))); final TupleSet nbound = f.range(f.tuple(Integer.valueOf(0)), f.tuple(Integer.valueOf(n-1))); b.boundExactly(queen, qbound); b.boundExactly(num, nbound); b.bound(x, qbound.product(nbound)); b.bound(y, qbound.product(nbound)); final TupleSet obound = f.noneOf(2); for(int i = 1; i < n; i++) { obound.add(f.tuple((Object)Integer.valueOf(i-1), Integer.valueOf(i))); } b.boundExactly(ord, obound); for(int i = 0; i < n; i++) { b.boundExactly(i, f.setOf(Integer.valueOf(i))); } return b; }
Example #22
Source File: SymmetryBreakingTest.java From kodkod with MIT License | 5 votes |
@Test public final void testAcyclic() { bounds.bound(ac1, factory.area(factory.tuple("0","0"), factory.tuple("4","4"))); assertNotNull(solve(ac1.some().and(ac1.acyclic()))); assertPrimVarNum(10); bounds.bound(r1, factory.range(factory.tuple("0"), factory.tuple("4"))); assertNotNull(solve(ac1.join(r1).some().and(ac1.acyclic()))); assertPrimVarNum(10 + bounds.upperBound(r1).size()); TupleSet ac2b = factory.setOf("5","6","7","8"); ac2b = ac2b.product(ac2b); bounds.bound(ac2, ac2b); assertNotNull(solve(ac1.difference(ac2).some().and(ac1.acyclic()).and(ac2.acyclic()))); assertPrimVarNum(10 + 6); bounds.boundExactly(r2, factory.setOf(factory.tuple("5", "6"))); assertNotNull(solve(ac2.join(r2).some().and(ac2.acyclic()))); final TupleSet ac3Bound = factory.allOf(2); ac3Bound.remove(factory.tuple("9", "9")); bounds.bound(ac3, ac3Bound); assertNotNull(solve(ac1.difference(ac2).union(ac3).some().and(ac1.acyclic()).and(ac2.acyclic()))); assertPrimVarNum(ac3Bound.size() + 10 + 6); bounds.bound(to3, factory.allOf(2)); bounds.bound(ord3, factory.setOf("0","1","2")); bounds.bound(first3, bounds.upperBound(ord3)); bounds.bound(last3, bounds.upperBound(ord3)); assertNotNull(solve(to3.product(ac1).some().and(ac1.acyclic()).and(to3.totalOrder(ord3,first3,last3)))); assertPrimVarNum(bounds.upperBound(ac1).size()); }
Example #23
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_01032007() { List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8"))); bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7"))); bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6"))); bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5"))); bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4"))); bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3"))); bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2"))); bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1"))); bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0"))); bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1"))); bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2"))); bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3"))); bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4"))); bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5"))); bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6"))); bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7"))); Expression set = IntConstant.constant(8).toExpression(); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(set.some(), bounds); assertNotNull("expected SATISFIABLE but was " + sol.outcome(), sol.instance()); Evaluator eval = new Evaluator(sol.instance(), solver.options()); TupleSet ts = eval.evaluate(set); assertFalse(ts.size() == 0); }
Example #24
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_05152007_2() { Relation x5 = Relation.nary("A", 1); List<String> atomlist = Arrays.asList("A0", "A1", "A2"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("A2")); x5_upper.add(factory.tuple("A1")); x5_upper.add(factory.tuple("A0")); bounds.bound(x5, x5_upper); Formula x7 = x5.eq(x5).not(); Solver solver = new Solver(); solver.options().setLogTranslation(1); solver.options().setSolver(SATFactory.MiniSatProver); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(x7, bounds); Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values()); assertEquals(1, core.size()); assertTrue(core.contains(x7)); }
Example #25
Source File: BenchmarkSymmStats2.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the size of the partial model (in bits) */ private static int pmBits(Bounds bounds) { int pm = 0; for (TupleSet lower : bounds.lowerBounds().values()) { pm += lower.size(); } return pm; }
Example #26
Source File: Dijkstra.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the bounds corresponding to the given scopes. * * @return bounds */ public Bounds bounds(int states, int processes, int mutexes) { final List<String> atoms = new ArrayList<String>(states + processes + mutexes); for (int i = 0; i < states; i++) { atoms.add("State" + i); } for (int i = 0; i < processes; i++) { atoms.add("Process" + i); } for (int i = 0; i < mutexes; i++) { atoms.add("Mutex" + i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet sb = f.range(f.tuple("State0"), f.tuple("State" + (states - 1))); final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process" + (processes - 1))); final TupleSet mb = f.range(f.tuple("Mutex0"), f.tuple("Mutex" + (mutexes - 1))); b.bound(State, sb); b.bound(holds, sb.product(pb).product(mb)); b.bound(waits, sb.product(pb).product(mb)); b.bound(sfirst, sb); b.bound(slast, sb); b.bound(sord, sb.product(sb)); b.bound(Process, pb); b.bound(Mutex, mb); b.bound(mfirst, mb); b.bound(mlast, mb); b.bound(mord, mb.product(mb)); return b; }
Example #27
Source File: A4SolutionReader.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** Parse tuples. */ private TupleSet parseTuples(XMLNode tuples, int arity) throws Err { TupleSet ans = factory.noneOf(arity); for (XMLNode sub : tuples) if (sub.is("tuple")) ans.add(parseTuple(sub, arity)); return ans; }
Example #28
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_05152007_1() { Relation x5 = Relation.nary("A", 1); List<String> atomlist = Arrays.asList("A0", "A1", "A2"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("A2")); x5_upper.add(factory.tuple("A1")); x5_upper.add(factory.tuple("A0")); bounds.bound(x5, x5_upper); Formula x7 = x5.some(); Formula x8 = x5.no(); Formula x6 = x7.and(x8); Solver solver = new Solver(); solver.options().setLogTranslation(1); solver.options().setSolver(SATFactory.MiniSatProver); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(x6, bounds); // System.out.println("Sol="+sol); Set<Formula> core = Nodes.minRoots(x6, sol.proof().highLevelCore().values()); assertEquals(2, core.size()); assertTrue(core.contains(x7)); assertTrue(core.contains(x8)); }
Example #29
Source File: Quasigroups7.java From kodkod with MIT License | 5 votes |
/** * Returns the partial bounds the problem (axioms 1, 4, 9-11). * @return the partial bounds for the problem */ public Bounds bounds() { final List<String> atoms = new ArrayList<String>(14); for(int i = 0; i < 7; i++) atoms.add("e1"+i); for(int i = 0; i < 7; i++) atoms.add("e2"+i); final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); b.boundExactly(s1, f.range(f.tuple("e10"), f.tuple("e16"))); b.boundExactly(s2, f.range(f.tuple("e20"), f.tuple("e26"))); // axioms 9, 10, 11 for(int i = 0; i < 7; i++) { b.boundExactly(e1[i], f.setOf("e1"+i)); b.boundExactly(e2[i], f.setOf("e2"+i)); } // axom 1 final TupleSet op1h = f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16")); // axiom 4 final TupleSet op2h = f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26")); b.bound(op1, op1h); b.bound(op2, op2h); return b; }
Example #30
Source File: IntTest.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public void testIntCast() { solver.options().setBitwidth(6); TupleSet r1b = factory.setOf("1", "5", "9"); bounds.bound(r1, r1b, r1b); Formula f = r1.sum().toExpression().eq(Expression.NONE); Solution s = solve(f); assertNotNull(s.instance()); bounds.boundExactly(5, factory.setOf(factory.tuple("5"))); f = r1.sum().toExpression().eq(IntConstant.constant(5).toExpression()); s = solve(f); assertNotNull(s.instance()); bounds.boundExactly(1, factory.setOf(factory.tuple("1"))); bounds.boundExactly(6, factory.setOf(factory.tuple("6"))); f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression()); s = solve(f); assertNotNull(s.instance()); bounds.bound(r1, r1b); f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression()); s = solve(f); assertNotNull(s.instance()); bounds.boundExactly(6, factory.setOf(factory.tuple("1"))); f = r1.sum().toExpression().eq(IntConstant.constant(6).toExpression()); s = solve(f); assertNull(s.instance()); }