Search in sources :

Example 46 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_01062007.

public final void testFelix_01062007() {
    Relation x1 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x1_upper = factory.noneOf(1);
    x1_upper.add(factory.tuple("A"));
    bounds.bound(x1, x1_upper);
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds);
    assertNotNull(sols.next().instance());
    assertNotNull(sols.next().instance());
    assertNull(sols.next().instance());
// Solution sol1=sols.next();
// System.out.println("Solution1:"+sol1.instance());
// 
// Solution sol2=sols.next();
// System.out.println("Solution2:"+sol2.instance());
// 
// Solution sol3=sols.next();
// System.out.println("Solution3:"+sol3.instance());
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 47 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class BugTests method testFelix_05072008.

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().setFlatten(false);
    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++;
// }
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 48 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class Netconfig method bounds.

/**
 * Returns a bounds object that constructs the 'scope' for analyzing the
 * commands, using the given values for the number of sites, routers, and the
 * length of time.
 *
 * @requires all arguments are positive and hqNum <= siteNum
 * @return a bounds for the model
 */
public Bounds bounds(int siteNum, int hqNum, int routerNum, int timeLength) {
    assert siteNum > 0 && hqNum > 0 && hqNum <= siteNum && routerNum > 0 && timeLength > 0;
    final List<String> atoms = new ArrayList<String>(siteNum + routerNum + timeLength);
    for (int i = 0; i < siteNum; i++) {
        atoms.add("Site" + i);
    }
    for (int i = 0; i < routerNum; i++) {
        atoms.add("Router" + i);
    }
    for (int i = 0; i < timeLength; i++) {
        atoms.add("Time" + i);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final String site0 = "Site0";
    final String siteN = "Site" + (siteNum - 1);
    final TupleSet sBound = f.range(f.tuple(site0), f.tuple(siteN));
    b.boundExactly(Site, sBound);
    b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple("Site" + (hqNum - 1))));
    if (hqNum < siteNum) {
        b.boundExactly(Sub, f.range(f.tuple("Site" + hqNum), f.tuple(siteN)));
    } else {
        b.bound(Sub, f.noneOf(1));
    }
    final TupleSet tBound = f.range(f.tuple("Time0"), f.tuple("Time" + (timeLength - 1)));
    b.bound(Time, tBound);
    b.bound(start, tBound);
    b.bound(end, tBound);
    b.bound(tick, tBound.product(tBound));
    final TupleSet rBound = f.range(f.tuple("Router0"), f.tuple("Router" + (routerNum - 1)));
    b.boundExactly(Router, rBound);
    // b.bound(site, rBound.product(sBound));
    b.bound(satellite, rBound.product(rBound).product(tBound));
    b.bound(lineOfSight, b.upperBound(satellite));
    assert siteNum == routerNum;
    final TupleSet siteBound = f.noneOf(2);
    for (int i = 0; i < siteNum; i++) siteBound.add(f.tuple("Router" + i, "Site" + i));
    // rBound.product(sBound));
    b.boundExactly(site, siteBound);
    return b;
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 49 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class ALG195_1 method bounds.

/**
 * 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;
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 50 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class ALG195_1 method main.

/**
 * Usage: java examples.tptp.ALG195_1
 */
public static void main(String[] args) {
    try {
        final ALG195_1 model = new ALG195_1();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula f = model.axioms().and(model.co1().not());
        final Bounds b = model.bounds();
        // System.out.println(model.decls());
        // System.out.println(model.ax2ax7());
        // System.out.println(b);
        final Solution sol = solver.solve(f, b);
        if (sol.instance() == null) {
            System.out.println(sol);
        } else {
            System.out.println(sol.stats());
            model.display(sol.instance());
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Aggregations

Bounds (kodkod.instance.Bounds)140 Formula (kodkod.ast.Formula)83 Universe (kodkod.instance.Universe)79 TupleFactory (kodkod.instance.TupleFactory)76 Solution (kodkod.engine.Solution)75 Solver (kodkod.engine.Solver)67 TupleSet (kodkod.instance.TupleSet)55 Relation (kodkod.ast.Relation)49 ArrayList (java.util.ArrayList)45 Expression (kodkod.ast.Expression)21 Variable (kodkod.ast.Variable)21 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)12 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)8 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Tuple (kodkod.instance.Tuple)6 LinkedHashSet (java.util.LinkedHashSet)5