kodkod.ast.Relation Java Examples
The following examples show how to use
kodkod.ast.Relation.
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: 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 #2
Source File: JenaTranslator.java From quetzal with Eclipse Public License 2.0 | 6 votes |
private Pair<Relation,List<Pair<Variable,Domain>>> reifyOpAsRelation(Op rhs, TranslatorContext context) { List<Variable> rvs = getVariables(rhs, context); if (DEBUG) System.err.println(rhs + " -- " + context.top()); Set<String> privateNames = privateVariableNames(rhs, context.top()); for(Iterator<Variable> vs = rvs.iterator(); vs.hasNext(); ) { if (privateNames.contains(vs.next().name())) { vs.remove(); } } Set<String> constants = context.constants().keySet(); for(Iterator<Variable> vs = rvs.iterator(); vs.hasNext(); ) { if (constants.contains(vs.next().name())) { vs.remove(); } } rvs = sortVars(rvs); Pair<Relation, List<Pair<Variable, Domain>>> ret = reifyOpAsRelation(rhs, rvs); assert ret != null; return ret; }
Example #3
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 #4
Source File: ListDebug.java From kodkod with MIT License | 6 votes |
ListDebug() { // introduce extra degrees of freedom at potential repair points. // we consider everything except phi nodes as potential repair points. nearNode0 = Relation.unary("nearNode0"); midNode0 = Relation.unary("midNode0"); farNode0 = Relation.unary("farNode0"); next0 = Relation.binary("next0"); next1 = Relation.binary("next1"); nearNode1= Relation.unary("nearNode1"); midNode1 = Relation.unary("midNode1"); farNode1 = Relation.unary("farNode1"); next3 = Relation.binary("next3"); head0 = Relation.binary("head0"); }
Example #5
Source File: SymmetryBreaker.java From kodkod with MIT License | 6 votes |
/** * If all columns of the upper bound of r are symmetric partitions, * those partitions are returned. Otherwise null is returned. * @return (all i: [0..r.arity) | some s: symmetries[int] | * bounds.upperBound[r].project(i).indexView() = s) => * {colParts: [0..r.arity)->IntSet | * all i: [0..r.arity()) | colParts[i] = bounds.upperBound[r].project(i).indexView() }, * null */ private final IntSet[] symmetricColumnPartitions(Relation r) { final IntSet upper = bounds.upperBound(r).indexView(); if (upper.isEmpty()) return null; final IntSet[] colParts = new IntSet[r.arity()]; for(int i = r.arity()-1, min = upper.min(); i >= 0; i--, min /= usize) { for(IntSet part : symmetries) { if (part.contains(min%usize)) { colParts[i] = part; break; } } if (colParts[i]==null) return null; } for(IntIterator tuples = upper.iterator(); tuples.hasNext(); ) { for(int i = r.arity()-1, tuple = tuples.next(); i >= 0; i--, tuple /= usize) { if (!colParts[i].contains(tuple%usize)) return null; } } return colParts; }
Example #6
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 #7
Source File: PrettyPrinter.java From quetzal with Eclipse Public License 2.0 | 6 votes |
/** @effects appends the tokenization of the given node to this.tokens */ public void visit(BinaryExpression node) { if (displayed(node)) return; final boolean oldTop = notTop(); final ExprOperator op = node.op(); final Expression left = node.left(), right = node.right(); if (op==ExprOperator.JOIN && left.arity()==1 && right.arity()==2 && right instanceof Relation) { append(right); append("["); visitChild(left, false); append("]"); } else { visitChild(left, parenthesize(op, left)); infix(op); visitChild(right, parenthesize(op, right)); } top = oldTop; }
Example #8
Source File: OverflowNumTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public OverflowNumTest() { this.ret = Relation.unary("ret"); int min = min(); int max = max(); List<String> atoms = new ArrayList<String>(max - min + 1); for (int i = min; i <= max; i++) { atoms.add(String.valueOf(i)); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); this.bounds = new Bounds(factory.universe()); for (int i = min; i <= max; i++) { bounds.boundExactly(i, factory.setOf(String.valueOf(i))); } bounds.bound(ret, factory.noneOf(1), factory.allOf(1)); }
Example #9
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 #10
Source File: ALG195.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Parametrization of axioms 14 and 15. * * @requires e's are unary, op is ternary */ @Override Formula ax14and15(Relation[] e, Relation op) { final Expression expr0 = e[5].join(op); // op(e5,...) final Expression expr1 = e[5].join(expr0); // op(e5,e5) final Expression expr2 = expr1.join(expr0); // op(e5,op(e5,e5)) final Expression expr3 = expr2.join(expr2.join(op)); // op(op(e5,op(e5,e5)),op(e5,op(e5,e5))) final Expression expr3a = expr3.join(op); // op(op(op(e5,op(e5,e5)),op(e5,op(e5,e5))),...) final Expression expr4 = e[5].join(expr3a); // op(op(op(e5,op(e5,e5)),op(e5,op(e5,e5))),e5) // e0 = op(op(op(e5,op(e5,e5)),op(e5,op(e5,e5))),op(e5,op(e5,e5))) final Formula f0 = e[0].eq(expr2.join(expr3a)); // e2 = op(op(e5,op(e5,e5)),op(e5,op(e5,e5))) final Formula f2 = e[2].eq(expr3); // e3 = op(op(op(e5,op(e5,e5)),op(e5,op(e5,e5))),e5) final Formula f3 = e[3].eq(expr4); // e4 = op(e5,op(e5,e5)) final Formula f4 = e[4].eq(expr2); // e6 = // op(op(op(op(e5,op(e5,e5)),op(e5,op(e5,e5))),e5),op(e5,op(e5,e5))) final Formula f6 = e[6].eq(expr2.join(expr4.join(op))); return and(f0, f2, f3, f4, f6); }
Example #11
Source File: RegressionTests.java From kodkod with MIT License | 6 votes |
@Test public final void testGreg_02192006() { Relation r1 = Relation.unary("r1"); Relation r2 = Relation.unary("r2"); Relation r3 = Relation.unary("r3"); Expression e = r1.in(r2).thenElse(r2, r1); Formula f = e.eq(r2).and(e.in(r3)); Object o1 = "o1"; Object o2 = "o2"; Universe univ = new Universe(Arrays.asList(o1, o2)); TupleFactory factory = univ.factory(); TupleSet set1 = factory.setOf(o1); TupleSet set2 = factory.setOf(o2); Bounds bounds = new Bounds(univ); bounds.bound(r1, set1); bounds.boundExactly(r2, set2); bounds.bound(r3, set1); assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, solver.solve(f, bounds).outcome()); }
Example #12
Source File: BasicUniverse.java From quetzal with Eclipse Public License 2.0 | 5 votes |
@Override public Bounds boundUniverse(Set<Relation> liveRelations) throws URISyntaxException { Universe u = new Universe(universe()); TupleFactory tf = u.factory(); Bounds b = new Bounds(u); Set<Object> liveAtoms; // if (! (this instanceof BoundedUniverse)) { // liveAtoms = basicBounds(liveRelations, u, tf, b); // u = new Universe(liveAtoms); // tf = u.factory(); // b = new Bounds(u); // basicBounds(liveRelations, u, tf, b); // } else { liveAtoms = universe(); basicBounds(liveRelations, u, tf, b); // } b.boundExactly(QuadTableRelations.NULL, tf.setOf(tf.tuple(QuadTableRelations.NULL_atom))); for(Relation r : nodeRelations) { int arity = r.arity(); TupleSet rb = nodesTableBound(tf, liveAtoms, true, true, true).tuples(); rb.add(tf.tuple(QuadTableRelations.NULL_atom)); for(int i = 1; i < arity; i++) { TupleSet rbi = nodesTableBound(tf, liveAtoms, true, true, true).tuples(); rbi.add(tf.tuple(QuadTableRelations.NULL_atom)); rb = rb.product(rbi); } b.bound(r, rb); } return b; }
Example #13
Source File: DiffEg.java From kodkod with MIT License | 5 votes |
public DiffEg() { Subject = Relation.unary("Subject"); Resource = Relation.unary("Resource"); Action = Relation.unary("Action"); Request = Relation.unary("Request"); Conflicted = Relation.unary("Conflicted"); sRequest = Relation.binary("s"); rRequest = Relation.binary("r"); action = Relation.binary("a"); sConflicted = Relation.binary("s"); rConflicted = Relation.binary("r"); }
Example #14
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_10182006() { // (some x: one { y: one SIG | true } | true) Relation sig = Relation.unary("SIG"); final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Expression e0 = Formula.TRUE.comprehension(y.oneOf(sig)); final Formula f0 = Formula.TRUE.forSome(x.oneOf(e0)); final Universe u = new Universe(Arrays.asList("a0")); final Bounds bounds = new Bounds(u); bounds.bound(sig, u.factory().allOf(1)); final Solution s = solver.solve(f0, bounds); assertEquals(Solution.Outcome.SATISFIABLE, s.outcome()); }
Example #15
Source File: IntTest.java From kodkod with MIT License | 5 votes |
public IntTest() { this.solver = new Solver(); List<String> atoms = new ArrayList<String>(SIZE); for (int i = 0; i < SIZE; i++) { atoms.add(String.valueOf(i)); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); r1 = Relation.unary("r1"); }
Example #16
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@Test public final void testFelix_05072008() { Relation A=Relation.unary("A"), first=Relation.unary("OrdFirst"), last=Relation.unary("OrdLast"), next=Relation.nary("OrdNext", 2); List<String> atomlist = Arrays.asList("A1", "A2", "A3"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet all = factory.setOf("A1","A2","A3"); bounds.boundExactly(A, all); bounds.bound(first, all); bounds.bound(last, all); bounds.bound(next, all.product(all)); Formula form = next.totalOrder(A,first,last); Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(0); solver.options().setSkolemDepth(0); Iterator<Solution> sol = solver.solveAll(form, bounds); assertTrue(sol.hasNext()); assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE); assertTrue(sol.hasNext()); assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE); assertFalse(sol.hasNext()); // int i=1; // // while (sol.hasNext()) { // System.out.println("================================== "+i+" ==================================="); // System.out.println(sol.next()); // System.out.flush(); // i++; // } }
Example #17
Source File: Hotel.java From kodkod with MIT License | 5 votes |
/** * Constructs a new instance of the hotel problem. */ public Hotel() { this.Time = Relation.unary("Time"); this.Event = Relation.unary("Event"); this.first = Relation.unary("first"); this.last = Relation.unary("last"); this.pre = Relation.binary("pre"); this.post = Relation.binary("post"); this.next = Relation.binary("next"); this.Key = Relation.unary("Key"); this.Card = Relation.unary("Card"); this.Guest = Relation.unary("Guest"); this.Room = Relation.unary("Room"); this.HotelEvent = Relation.unary("HotelEvent"); this.RoomCardEvent = Relation.unary("RoomCardEvent"); this.Checkin = Relation.unary("Checkin"); this.Enter = Relation.unary("Enter"); this.NormalEnter = Relation.unary("NormalEnter"); this.RecodeEnter = Relation.unary("RecodeEnter"); this.Checkout = Relation.unary("Checkout"); this.key = Relation.ternary("key"); this.prev = Relation.ternary("prev"); this.occ = Relation.ternary("occ"); this.holds = Relation.ternary("holds"); this.guest = Relation.binary("guest"); this.room = Relation.binary("room"); this.card = Relation.binary("card"); this.k1 = Relation.binary("k1"); this.k2 = Relation.binary("k2"); }
Example #18
Source File: JenaTranslator.java From quetzal with Eclipse Public License 2.0 | 5 votes |
private Expression restrictExistsWithFilter(Set<Variable> lhsVars, Pair<Relation, List<Pair<Variable, Domain>>> rightRelation, Formula filters, Expression tuples) { Expression t = null; Decls d = null; Set<Variable> filterVars = filters==null? Collections.<Variable>emptySet(): ASTUtils.gatherVariables(filters); for(Pair<Variable,Domain> v : rightRelation.snd) { if (lhsVars.contains(v.fst) || filterVars.contains(v.fst)) { t = t==null? v.fst: t.product(v.fst); if (!lhsVars.contains(v.fst)) { Decl x = v.fst.oneOf(QuadTableRelations.nodes.union(NULL)); d = d==null? x: d.and(x); } } } return t.in(tuples).and(filters).comprehension(d); }
Example #19
Source File: LeafInterpreter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns this.vars. * * @return this.vars. */ public final Map<Relation,IntSet> vars() { final Map<Relation,IntSet> ret = new LinkedHashMap<Relation,IntSet>((vars.size() * 4) / 3); for (Map.Entry<Relation,IntRange> e : vars.entrySet()) { ret.put(e.getKey(), Ints.rangeSet(e.getValue())); } return ret; }
Example #20
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Constructs a new instance of Quasigroups7. */ ALG195_1() { op1 = Relation.ternary("op1"); op2 = Relation.ternary("op2"); s1 = Relation.unary("s1"); s2 = Relation.unary("s2"); e1 = new Relation[7]; e2 = new Relation[7]; h = new Relation[7]; for(int i = 0; i < 7; i++) { e1[i] = Relation.unary("e1"+i); e2[i] = Relation.unary("e2"+i); h[i] = Relation.binary("h"+(i+1)); } }
Example #21
Source File: Netconfig.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Constructs an instance of the Netconfig problem. */ public Netconfig() { Time = Relation.unary("Time"); start = Relation.unary("start"); end = Relation.unary("end"); tick = Relation.binary("tick"); Router = Relation.unary("Router"); Site = Relation.unary("Site"); HQ = Relation.unary("HQ"); Sub = Relation.unary("Sub"); site = Relation.binary("site"); satellite = Relation.ternary("satellite"); lineOfSight = Relation.ternary("lineOfSight"); }
Example #22
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Parametrization of axioms 3 and 6. * @requires s is unary, op is ternary */ private static Formula ax3and6(Relation[] e, Relation op) { Formula f = Formula.TRUE; for( Relation x : e) { for (Relation y: e) { Expression expr0 = x.join(y.join(op)); // op(y,x) Expression expr1 = y.join(expr0.join(op)); // op(op(y,x),y) Expression expr2 = y.join(expr1.join(op)); // op(op(op(y,x),y),y) f = f.and(expr2.eq(x)); } } return f; }
Example #23
Source File: SET943.java From kodkod with MIT License | 5 votes |
/** * Constructs a new instance of SET943. */ public SET943() { empty = Relation.unary("empty"); subset = Relation.binary("subset"); in = Relation.binary("in"); union = Relation.binary("union"); union2 = Relation.ternary("set_union2"); }
Example #24
Source File: GRA013_026.java From kodkod with MIT License | 5 votes |
/** * Constructs a new instance of GRA013_026 with the given graph and clique size. * @requires 0 < cliqueSize <= graphSize */ public GRA013_026(int graphSize, int cliqueSize) { if (cliqueSize <= 0) throw new IllegalArgumentException("cliqueSize must be positive: " + cliqueSize); if (cliqueSize > graphSize) throw new IllegalArgumentException("cliqueSize must be less than or equal to graph size: " + cliqueSize + ">" + graphSize); node = Relation.unary("N"); red = Relation.binary("red"); green = Relation.binary("green"); lessThan = Relation.binary("lessThan"); goal = Relation.unary("goal"); this.graphSize = graphSize; this.cliqueSize = cliqueSize; }
Example #25
Source File: A4Solution.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Associates the Kodkod relation to a particular Alloy Type (if it is not * already associated with something) */ void kr2type(Relation relation, Type newType) throws Err { if (solved) throw new ErrorFatal("Cannot alter the k->type mapping since solve() has completed."); if (!rel2type.containsKey(relation)) rel2type.put(relation, newType); }
Example #26
Source File: A4Solution.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Shrink the bounds for the given relation; throws an exception if the new * bounds is not sameAs/subsetOf the old bounds. */ void shrink(Relation relation, TupleSet lowerBound, TupleSet upperBound) throws Err { if (solved) throw new ErrorFatal("Cannot shrink a Kodkod relation since solve() has completed."); TupleSet oldL = bounds.lowerBound(relation); TupleSet oldU = bounds.upperBound(relation); if (oldU.containsAll(upperBound) && upperBound.containsAll(lowerBound) && lowerBound.containsAll(oldL)) { bounds.bound(relation, lowerBound, upperBound); } else { throw new ErrorAPI("Inconsistent bounds shrinking on relation: " + relation); } }
Example #27
Source File: SkolemizationTest.java From kodkod with MIT License | 5 votes |
public SkolemizationTest() { this.solver = new Solver(); List<String> atoms = new ArrayList<String>(USIZE); for (int i = 0; i < USIZE; i++) { atoms.add(""+i); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); this.r1a = Relation.unary("r1a"); this.r1b = Relation.unary("r1b"); this.r2a = Relation.binary("r2a"); this.r2b = Relation.binary("r2b"); this.bounds = new Bounds(universe); }
Example #28
Source File: ListEncoding.java From kodkod with MIT License | 5 votes |
ListEncoding() { list = Relation.unary("List"); node = Relation.unary("Node"); string = Relation.unary("String"); thisList = Relation.unary("this"); nil = Relation.unary("null"); head = Relation.binary("head"); next = Relation.binary("next"); data = Relation.binary("data"); }
Example #29
Source File: BlockedNQueens.java From kodkod with MIT License | 5 votes |
/** * Constructs an instance of BlockedNQueens from the file * with the given name. */ public BlockedNQueens(final String file) { this.file = file; this.queen = Relation.unary("Queen"); this.x = Relation.binary("x"); this.y = Relation.binary("y"); this.blocked = Relation.binary("blocked"); this.num = Relation.unary("num"); this.ord = Relation.binary("ord"); }
Example #30
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Returns the relation constraints. * @returns the relation constraints. */ public final Formula decls() { Formula f = function(s1, op1).and(function(s2, op2)); for(Relation x: h) { f = f.and(x.function(s1, s2)); } for(int i = 0; i < 7; i++) { f = f.and(h[i].function(s1, s2)); f = f.and(e1[i].one()).and(e2[i].one()); } return f; }