Java Code Examples for kodkod.instance.TupleFactory#range()
The following examples show how to use
kodkod.instance.TupleFactory#range() .
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: 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 3
Source File: Pigeonhole.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns the bounds for the given number of pigeons and holes. * * @return bounds */ public Bounds bounds(int pigeons, int holes) { final List<String> atoms = new ArrayList<String>(pigeons + holes); for (int i = 0; i < pigeons; i++) { atoms.add("Pigeon" + i); } for (int i = 0; i < holes; i++) { atoms.add("Hole" + i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons - 1))); final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes - 1))); b.boundExactly(Pigeon, pbound); b.boundExactly(Hole, hbound); b.bound(hole, pbound.product(hbound)); return b; }
Example 4
Source File: GRA013_026.java From kodkod with MIT License | 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 5
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 6
Source File: Pigeonhole.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the given number of pigeons and holes. * @return bounds */ public Bounds bounds(int pigeons, int holes) { final List<String> atoms = new ArrayList<String>(pigeons + holes); for(int i = 0; i < pigeons; i++) { atoms.add("Pigeon"+i); } for(int i = 0; i < holes; i++) { atoms.add("Hole"+i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons-1))); final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes-1))); b.boundExactly(Pigeon, pbound); b.boundExactly(Hole, hbound); b.bound(hole, pbound.product(hbound)); return b; }
Example 7
Source File: NQueens.java From kodkod with MIT License | 5 votes |
/** * Returns a bounds for the log integer encoding. * @return bounds for the log integer encoding. */ public Bounds bounds() { final int bits = 32 - Integer.numberOfLeadingZeros(n - 1); final List<Object> atoms = new ArrayList<Object>(n + bits); for(int i =0; i < n; i++) { atoms.add("Q"+i); } for(int i = 0; i < bits; i++) { atoms.add(Integer.valueOf(1<<i)); } final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet queens = f.range(f.tuple("Q0"), f.tuple("Q"+(n-1))); final TupleSet ints = f.range(f.tuple(Integer.valueOf(1)), f.tuple(Integer.valueOf(1<<(bits-1)))); b.boundExactly(queen, queens); b.bound(x, queens.product(ints)); b.bound(y, queens.product(ints)); for(int i = 0; i < bits; i++) { b.boundExactly(1<<i, f.setOf(Integer.valueOf(1<<i))); } return b; }
Example 8
Source File: Bigconfig.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns a bounds with the given number of hqs and subs, constructed using the * given universe. * * @requires hqNum > 0 && subNum > 0 * @requires u contains at least (hqNum+sub) Router atoms and as many Site atoms * @return bounds */ private Bounds bounds(int hqNum, int subNum, Universe u) { final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final int siteMax = hqNum + subNum - 1; final String site0 = "Site0"; final String siteN = "Site" + siteMax; final String siteHQ = "Site" + (hqNum - 1); final String siteSub = "Site" + hqNum; final String router0 = "Router0"; final String routerN = "Router" + siteMax; final TupleSet sites = f.range(f.tuple(site0), f.tuple(siteN)); b.boundExactly(Site, sites); b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple(siteHQ))); b.boundExactly(Sub, f.range(f.tuple(siteSub), f.tuple(siteN))); final TupleSet routers = f.range(f.tuple(router0), f.tuple(routerN)); b.boundExactly(Router, routers); b.bound(link, routers.product(routers)); // b.bound(site, routers.product(sites)); final TupleSet routerLocations = f.noneOf(2); for (int i = 0; i <= siteMax; i++) { routerLocations.add(f.tuple("Router" + i, "Site" + i)); } b.boundExactly(site, routerLocations); return b; }
Example 9
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 10
Source File: ListEncoding.java From kodkod with MIT License | 5 votes |
Bounds bounds(int size) { final Universe u = universe(size); final Bounds b = new Bounds(u); final TupleFactory t = u.factory(); final int max = size-1; b.bound(list, t.setOf("l0")); b.bound(node, t.range(t.tuple("n0"), t.tuple("n" + max))); b.bound(string, t.range(t.tuple("s0"), t.tuple("s" + max))); b.bound(thisList, b.upperBound(list)); b.boundExactly(nil, t.setOf("nil")); TupleSet ran = t.range(t.tuple("n0"), t.tuple("n" + max)); ran.add(t.tuple("nil")); b.bound(head, b.upperBound(list).product(ran)); ran = t.range(t.tuple("n0"), t.tuple("n" + max)); ran.add(t.tuple("nil")); b.bound(next, b.upperBound(node).product(ran)); ran = t.range(t.tuple("s0"), t.tuple("s" + max)); ran.add(t.tuple("nil")); b.bound(data, b.upperBound(node).product(ran)); return b; }
Example 11
Source File: Bigconfig.java From kodkod with MIT License | 5 votes |
/** * Returns a bounds with the * given number of hqs and subs, constructed using the * given universe. * @requires hqNum > 0 && subNum > 0 * @requires u contains at least (hqNum+sub) Router atoms and * as many Site atoms * @return bounds */ private Bounds bounds(int hqNum, int subNum, Universe u) { final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final int siteMax = hqNum + subNum - 1; final String site0 = "Site0"; final String siteN = "Site" + siteMax; final String siteHQ = "Site" + (hqNum-1); final String siteSub = "Site" + hqNum; final String router0 = "Router0"; final String routerN = "Router" + siteMax; final TupleSet sites = f.range(f.tuple(site0), f.tuple(siteN)); b.boundExactly(Site, sites); b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple(siteHQ))); b.boundExactly(Sub, f.range(f.tuple(siteSub), f.tuple(siteN))); final TupleSet routers = f.range(f.tuple(router0), f.tuple(routerN)); b.boundExactly(Router, routers); b.bound(link, routers.product(routers)); // b.bound(site, routers.product(sites)); final TupleSet routerLocations = f.noneOf(2); for(int i = 0; i <= siteMax; i++) { routerLocations.add(f.tuple("Router"+i, "Site"+i)); } b.boundExactly(site, routerLocations); return b; }
Example 12
Source File: Dijkstra.java From kodkod with MIT License | 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 13
Source File: RingElection.java From kodkod with MIT License | 5 votes |
/** * Returns a bounds object that scopes Process, Time, and their * fields according to given values. * @return bounds */ public Bounds bounds(int processes, int times) { final List<String> atoms = new ArrayList<String>(processes + times); for(int i = 0; i < processes; i++) { atoms.add("Process"+i); } for(int i = 0; i < times; i++) { atoms.add("Time"+i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process"+ (processes-1))); final TupleSet tb = f.range(f.tuple("Time0"), f.tuple("Time"+(times-1))); b.bound(Process, pb); b.bound(succ, pb.product(pb)); b.bound(toSend, pb.product(pb).product(tb)); b.bound(elected, pb.product(tb)); b.bound(pord, pb.product(pb)); b.bound(pfirst, pb); b.bound(plast, pb); b.bound(Time, tb); b.bound(tord, tb.product(tb)); b.bound(tfirst, tb); b.bound(tlast, tb); return b; }
Example 14
Source File: ALG195_1.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(); final TupleSet s1bound = f.range(f.tuple("e10"), f.tuple("e16")); final TupleSet s2bound = f.range(f.tuple("e20"), f.tuple("e26")); b.boundExactly(s1, s1bound); b.boundExactly(s2, s2bound); // 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 b.bound(op1, f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"))); // axiom 4 b.bound(op2, f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"))); final TupleSet hbound = s1bound.product(s2bound); for(Relation r : h) { b.bound(r, hbound); } return b; }
Example 15
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 16
Source File: RingElection.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns a bounds object that scopes Process, Time, and their fields according * to given values. * * @return bounds */ public Bounds bounds(int processes, int times) { final List<String> atoms = new ArrayList<String>(processes + times); for (int i = 0; i < processes; i++) { atoms.add("Process" + i); } for (int i = 0; i < times; i++) { atoms.add("Time" + i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process" + (processes - 1))); final TupleSet tb = f.range(f.tuple("Time0"), f.tuple("Time" + (times - 1))); b.bound(Process, pb); b.bound(succ, pb.product(pb)); b.bound(toSend, pb.product(pb).product(tb)); b.bound(elected, pb.product(tb)); b.bound(pord, pb.product(pb)); b.bound(pfirst, pb); b.bound(plast, pb); b.bound(Time, tb); b.bound(tord, tb.product(tb)); b.bound(tfirst, tb); b.bound(tlast, tb); return b; }
Example 17
Source File: ALG195_1.java From org.alloytools.alloy with Apache License 2.0 | 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(); final TupleSet s1bound = f.range(f.tuple("e10"), f.tuple("e16")); final TupleSet s2bound = f.range(f.tuple("e20"), f.tuple("e26")); b.boundExactly(s1, s1bound); b.boundExactly(s2, s2bound); // 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 b.bound(op1, f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"))); // axiom 4 b.bound(op2, f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"))); final TupleSet hbound = s1bound.product(s2bound); for (Relation r : h) { b.bound(r, hbound); } return b; }