kodkod.engine.config.Options Java Examples

The following examples show how to use kodkod.engine.config.Options. 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: BlockedNQueens.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Prints the given solution using the given options to the console
	 */
	void print(Instance instance, Options options) {
		final Evaluator eval = new Evaluator(instance, options);
		final int n = instance.tuples(queen).size();
		for(int i = 0; i < n; i++) { 
			Expression ci = IntConstant.constant(i).toExpression();
			for(int j = 0; j < n; j++) { 
				Expression cj = IntConstant.constant(j).toExpression();
				if (eval.evaluate(x.join(ci).intersection(y.join(cj)).some())) { 
					System.out.print(" Q");
				} else {
					System.out.print(" .");
				}
			}
			System.out.println();
		}
//		System.out.println(instance); 
	}
 
Example #2
Source File: BlockedNQueens2.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Prints the given solution using the given options to the console
	 */
	void print(Instance instance, Options options) {
		final Evaluator eval = new Evaluator(instance, options);
		final int n = instance.universe().size();
		for(int i = 0; i < n; i++) { 
			Expression x = IntConstant.constant(i).toExpression();
			for(int j = 0; j < n; j++) { 
				Expression y = IntConstant.constant(j).toExpression();
				if (eval.evaluate(x.product(y).in(queen))) { 
					System.out.print(" Q");
				} else {
					System.out.print(" .");
				}
			}
			System.out.println();
		}
//		System.out.println(instance); 
	}
 
Example #3
Source File: NQueens.java    From kodkod with MIT License 6 votes vote down vote up
/**
		 * Prints the given solution
		 */
		void print(Instance instance, Options options) {
			final Evaluator eval = new Evaluator(instance, options);
			for(int i = 0; i < n; i++) { 
				Expression ci = IntConstant.constant(i).toExpression();
				for(int j = 0; j < n; j++) { 
					Expression cj = IntConstant.constant(j).toExpression();
					if (eval.evaluate(x.join(ci).intersection(y.join(cj)).some())) { 
						System.out.print(" Q");
					} else {
						System.out.print(" .");
					}
				}
				System.out.println();
			}
//			System.out.println(instance); 
		}
 
Example #4
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
public final void testFelix_11192007() {
    List<String> atomlist = Arrays.asList("A", "B", "C");

    Universe universe = new Universe(atomlist);

    Bounds bounds = new Bounds(universe);

    Solver solver = new Solver();

    solver.options().setLogTranslation(2);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);
    solver.options().setSkolemDepth(0);

    Solution sol = solver.solve(Formula.TRUE, bounds);
    assertNotNull(sol.instance());
}
 
Example #5
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests all comparison ops for this.solver.options and range of vals.
 *
 * @requires this.solver.options.intEncoding = binary
 * @requires vals contains int expressions that represent all integers allowed
 *           by this.solver.options, in proper sequence
 */
private final void testComparisonOps(IntExpression[] vals) {
    final Options options = solver.options();

    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();

    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];

        for (int j = min; j <= max; j++) {

            IntExpression vj = vals[j - min];

            testCompOp(EQ, vi, vj, i, j, i == j);
            testCompOp(LT, vi, vj, i, j, i < j);
            testCompOp(LTE, vi, vj, i, j, i <= j);
            testCompOp(GT, vi, vj, i, j, i > j);
            testCompOp(GTE, vi, vj, i, j, i >= j);

        }
    }

}
 
Example #6
Source File: NQueens.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Prints the given solution
 */
void print(Instance instance, Options options) { 
	final Evaluator eval = new Evaluator(instance, options);
	for(int i = 0; i < n; i++) { 
		Expression ci = IntConstant.constant(i).toExpression();
		for(int j = 0; j < n; j++) { 
			Expression cj = IntConstant.constant(j).toExpression();
			if (eval.evaluate(x.join(ci).intersection(y.join(cj)).some())) { 
				System.out.print(" Q");
			} else {
				System.out.print(" .");
			}
		}
		System.out.println();
	}
}
 
Example #7
Source File: IntTest.java    From kodkod with MIT License 6 votes vote down vote up
private void testIntSum(Options.IntEncoding encoding) {
	solver.options().setIntEncoding(encoding);
	final Variable x = Variable.unary("x");
	bounds.bound(r1, factory.setOf("13","14","15"), factory.setOf("13","14","15"));
	Formula f = IntConstant.constant(3).eq(IntConstant.constant(1).sum(x.oneOf(r1)));
	Solution s = solve(f);
	
	assertNotNull(s.instance());
	bounds.bound(r1, factory.noneOf(1), factory.setOf("1","3","5"));
	bounds.boundExactly(1, factory.setOf("1"));
	bounds.boundExactly(3, factory.setOf("3"));
	bounds.boundExactly(5, factory.setOf("5"));
	
	f = IntConstant.constant(9).eq(x.sum().sum(x.oneOf(r1)));
	s = solve(f);
	assertNotNull(s.instance());
	assertEquals(s.instance().tuples(r1), factory.setOf("1","3","5"));
}
 
Example #8
Source File: ConfigAssure.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Displays an instance obtained with the given options.
 *
 * @requires inst != null and opt != null
 */
private final void display(Instance inst, Options opt) {
    final Universe univ = inst.universe();
    final Evaluator eval = new Evaluator(inst, opt);
    final TupleFactory factory = univ.factory();
    final List<TupleSet> subnets = new ArrayList<TupleSet>();

    System.out.println("address\t\tnetwork id\tmask\tdevice-interface");
    for (int i = 0, ports = univ.size() - 32; i < ports; i++) {
        final Object atom = univ.atom(i);
        final Relation p = Relation.unary(atom.toString());
        inst.add(p, factory.setOf(atom));

        System.out.print(toQuad(eval.evaluate(addr(p))) + "\t");
        System.out.print(toQuad(eval.evaluate(netid(p))) + "\t");
        System.out.print(eval.evaluate(implicitMask(p)) + "\t");
        System.out.println(p);

        final TupleSet members = eval.evaluate(subnet(p));
        if (!members.isEmpty())
            subnets.add(members);
    }

    System.out.println("\nsubnets:");
    for (TupleSet sub : subnets) {
        System.out.println(sub);
    }

}
 
Example #9
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@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 #10
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
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 #12
Source File: HOLSome4AllTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
protected void setupOptions() {
    options = new Options();
    options.setNoOverflow(true);
    options.setBitwidth(bw());
    options.setSolver(SATFactory.MiniSat);
    options.setAllowHOL(true);
}
 
Example #13
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_05152007_3() {
	Relation x5 = Relation.nary("A", 1);

	List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");

	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("A[0]"));
	x5_upper.add(factory.tuple("A[1]"));
	x5_upper.add(factory.tuple("A[2]"));

	bounds.bound(x5, x5_upper);

	Formula a=x5.some();
	Formula a1 = x5.no();
	Formula b=a1.and(Formula.TRUE.and(Formula.TRUE));
	Formula c=a.and(b);

	Solver solver = new Solver();

	solver.options().setLogTranslation(1);
	solver.options().setSolver(SATFactory.DefaultSAT4J);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	Solution sol = solver.solve(c,bounds);
	Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());

	assertEquals(2, core.size());
	assertTrue(core.contains(a));
	assertTrue(core.contains(a1));


}
 
Example #14
Source File: BooleanCircuitTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void init() {
    f = BooleanFactory.factory(size, new Options());
    v = new BooleanVariable[size];
    for (int i = 0; i < size; i++) {
        v[i] = f.variable(i + 1);
        assertNotNull(v[i]);
    }
}
 
Example #15
Source File: IntConstraints.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Prints the solution to the screen.
 */
private final void print(Solution sol, Options options) {
    System.out.println(sol.stats());
    final Evaluator eval = new Evaluator(sol.instance(), options);
    final long mask = -1L >>> 32;
    for (int i = 0; i < 1000; i++) {
        long min = (low + 10 * i) & mask, max = (min + 10) & mask;
        long result = eval.evaluate(var[i].sum()) & mask;
        System.out.println(min + " <= [var_" + (i + 1) + "=" + result + "] <= " + max);
    }
}
 
Example #16
Source File: Skolemizer.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Constructs a skolem replacer from the given arguments. 
 */
private Skolemizer(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
	super(annotated.sharedNodes());

	// only cache intermediate computations for expressions with no free variables
	// and formulas with no free variables and no quantified descendants
	
	for(Node n: annotated.sharedNodes()) {
		final AbstractDetector fvdetect = annotated.freeVariableDetector();
		final AbstractDetector qdetect = annotated.quantifiedFormulaDetector();
		if (!(Boolean)n.accept(fvdetect)) {
			if (!(n instanceof Formula) || !((Boolean)n.accept(qdetect)))
				this.cache.put(n, null);
		}
	}
	this.reporter = options.reporter();
	this.bounds = bounds;
	this.interpreter = LeafInterpreter.overapproximating(bounds, options);
	this.repEnv = Environment.empty();
	this.nonSkolems = new ArrayList<DeclInfo>();
	this.nonSkolemsView = new AbstractList<Decl>() {
		public Decl get(int index) { return nonSkolems.get(index).decl;	}
		public int size() { return nonSkolems.size(); }
	};
	this.topSkolemConstraints = new ArrayList<Formula>();
	this.negated = false;
	this.skolemDepth = options.skolemDepth();
}
 
Example #17
Source File: OverflowTheoremTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
protected Solution[] solve(Formula formula) {
    Solution s1 = new Solver(options).solve(formula, bounds);
    Options opt2 = options.clone();
    opt2.setSkolemDepth(2);
    // Solution s2 = new Solver(opt2).solve(formula, bounds);
    return new Solution[] {
                           s1
    };
}
 
Example #18
Source File: SolutionIterator.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a solution iterator for the given formula, bounds, and options.
 */
SolutionIterator(Formula formula, Bounds bounds, Options options) {
    this.translTime = System.currentTimeMillis();
    this.translation = Translator.translate(formula, bounds, options);
    this.translTime = System.currentTimeMillis() - translTime;
    this.trivial = 0;
}
 
Example #19
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void testIfIntExpr(Options.IntEncoding encoding) {
    solver.options().setIntEncoding(encoding);
    bounds.bound(r1, factory.setOf("15"), factory.setOf("15"));
    Formula f = (r1.some().thenElse(r1.count(), IntConstant.constant(5))).eq(IntConstant.constant(1));
    Solution s = solve(f);
    assertNotNull(s.instance());
    assertEquals(Ints.singleton(15), s.instance().tuples(r1).indexView());

    f = (r1.some().thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(1));
    s = solve(f);
    assertNull(s.instance());

    bounds.bound(r1, factory.setOf("3"), factory.allOf(1));
    bounds.boundExactly(3, factory.setOf("3"));
    bounds.boundExactly(1, factory.setOf("1"));
    f = ((r1.count().eq(IntConstant.constant(2))).thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(4));
    s = solve(f);
    assertNotNull(s.instance());
    assertTrue(s.instance().tuples(r1).indexView().contains(1));
    assertTrue(s.instance().tuples(r1).indexView().contains(3));
    assertEquals(2, s.instance().tuples(r1).size());

    f = Formula.TRUE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(4));
    s = solve(f);
    assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, s.outcome());

    f = Formula.FALSE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(3));
    s = solve(f);
    assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, s.outcome());
}
 
Example #20
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Tests all binary ops for this.solver.options and range of vals.
 * @requires this.solver.options.intEncoding = binary 
 * @requires vals contains int expressions that represent all 
 * integers allowed by this.solver.options, in proper sequence
 */
private final void test2sComplementBinOps(IntExpression[] vals) {
	final Options options = solver.options();
	final int bw = options.bitwidth();
	final IntRange range = options.integers();
	final int min = range.min(), max = range.max();
	final int mask = ~(-1 << bw);
	
	for(int i = min; i <= max; i++) {
			IntExpression vi = vals[i-min];
		
		for(int j = min; j <= max; j++) {
			
			IntExpression vj = vals[j-min];
			testBinOp(PLUS, vi, vj, i, j, i+j, mask);
			testBinOp(MINUS, vi, vj, i, j, i-j, mask);
			testBinOp(MULTIPLY, vi, vj, i, j, i*j, mask);
			
			if (j!=0) {
				testBinOp(DIVIDE, vi, vj, i, j, i/j, mask);
				testBinOp(MODULO, vi, vj, i, j, i%j, mask);
			}
			
			testBinOp(AND, vi, vj, i, j, i & j, mask);
			testBinOp(OR, vi, vj, i, j, i | j, mask);
			testBinOp(XOR, vi, vj, i, j, i ^ j, mask);
			
			final int shrmask = ~(-1 << (bw - ((j < 0 || j > bw) ? bw : j)));
			testBinOp(SHL, vi, vj, i, j, i << j, mask);				
			testBinOp(SHR, vi, vj, i, j, shrmask & (i >> j), mask);
			testBinOp(SHA, vi, vj, i, j, i >> j, mask);
		}
	}
	
}
 
Example #21
Source File: HOLTranslationOld.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public FOL(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
    super(bounds, options);
    this.annotated = annotated;
    this.prev = null;
    // TODO: pass annotated instead, so that it doesn't have to
    // re-annotate again
    folTr = Translator.translateIncremental(annotated.node(), bounds, options);
}
 
Example #22
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public static HOLTranslation proc2transl(Proc proc, Options options, int depth) {
    if (proc instanceof Proc.FOL)
        return new HOLTranslationNew.FOL((FOL) proc, options, depth);
    if (proc instanceof Proc.Some4All)
        return new HOLTranslationNew.Some4All((Some4All) proc, options, depth);
    if (proc instanceof Proc.OR)
        return new HOLTranslationNew.OR((OR) proc, options, depth);
    if (proc instanceof Proc.Fixpoint)
        return new HOLTranslationNew.Fixpoint((Fixpoint) proc, options, depth);
    throw new RuntimeException("translation not implemented for " + proc.getClass().getName());
}
 
Example #23
Source File: Translator.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the given options are suitable for incremental translation.
 *
 * @requires options.solver.incremental() && options.logTranslation = 0
 * @throws IllegalArgumentException any of the preconditions are violated
 */
public static void checkIncrementalOptions(Options options) {
    if (!options.solver().incremental())
        throw new IllegalArgumentException("An incremental solver is required for incremental translation: " + options);
    if (options.logTranslation() != 0)
        throw new IllegalArgumentException("Translation logging must be disabled for incremental translation: " + options);
}
 
Example #24
Source File: Translator.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Translator for the given formula, bounds, options and
 * incremental flag. If the flag is true, then the translator produces an
 * initial {@linkplain Translation.Incremental incremental translation}.
 * Otherwise, the translator produces a {@linkplain Translation.Whole basic
 * translation}.
 *
 * @ensures this.originalFormula' = formula and this.options' = options and
 *          this.originalBounds' = bounds and this.bounds' = bounds.clone() and
 *          this.incremental' = incremental
 */
private Translator(Formula formula, Bounds bounds, Options options, boolean incremental, boolean hol) {
    this.originalFormula = formula;
    this.originalBounds = bounds;
    this.bounds = bounds.clone();
    this.options = options;
    this.logging = options.logTranslation() > 0;
    this.incremental = incremental;
    this.hol = hol;
    if (this.hol)
        this.bounds.ensureAtomRelations();
}
 
Example #25
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
private IntExpression[] nonConstants() {
	final Options options = solver.options();
		
	final IntRange range = options.integers();
	final int min = range.min(), max = range.max();
	final int size = range.size();
	
	final Relation[] r = new Relation[size];
			
	final TupleFactory f = bounds.universe().factory();
	for(int i = 0; i < size; i++) {
		int arity = i%3 + 1;
		r[i] = Relation.nary("r"+i, arity);
		
		TupleSet b = f.noneOf(arity);
		for(int j = (i/3)*((int)Math.pow(SIZE, arity-1)), jmax = j+size; j < jmax; j++ ) {
			b.add(f.tuple(arity, j%b.capacity()));
		}
		
		bounds.bound(r[i], b);
	}
	
	final IntExpression[] vals = new IntExpression[max-min+1];
	for(int i = 0; i < size; i++) {
		vals[i] = i+min < 0 ? r[i].count().negate() : r[i].count();
	}
	
	return vals;
}
 
Example #26
Source File: Transpose4x4UnaryL.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the options used for solving.
 * @return options used for solving.
 */
final Options options() {
	final Options opt = new Options();
	opt.setSolver(SATFactory.MiniSat);
	opt.setBitwidth(5);
	return opt;
}
 
Example #27
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
private void testIfIntExpr(Options.IntEncoding encoding) {
	solver.options().setIntEncoding(encoding);
	bounds.bound(r1, factory.setOf("15"), factory.setOf("15"));
	Formula f = (r1.some().thenElse(r1.count(), IntConstant.constant(5))).eq(IntConstant.constant(1));
	Solution s = solve(f);
	assertNotNull(s.instance());
	assertEquals(Ints.singleton(15), s.instance().tuples(r1).indexView());
	
	f = (r1.some().thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(1));
	s = solve(f);
	assertNull(s.instance());
	
	bounds.bound(r1, factory.setOf("3"), factory.allOf(1));
	bounds.boundExactly(3, factory.setOf("3"));
	bounds.boundExactly(1, factory.setOf("1"));
	f = ((r1.count().eq(IntConstant.constant(2))).thenElse(r1.sum(), IntConstant.constant(5))).eq(IntConstant.constant(4));
	s = solve(f);
	assertNotNull(s.instance());
	assertTrue(s.instance().tuples(r1).indexView().contains(1));
	assertTrue(s.instance().tuples(r1).indexView().contains(3));
	assertEquals(2, s.instance().tuples(r1).size());
	
	f = Formula.TRUE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(4));
	s = solve(f);
	assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, s.outcome());
	
	f = Formula.FALSE.thenElse(IntConstant.constant(2), IntConstant.constant(3)).eq(IntConstant.constant(3));
	s = solve(f);
	assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, s.outcome());
}
 
Example #28
Source File: Skolemizer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a skolem replacer from the given arguments.
 */
private Skolemizer(AnnotatedNode<Formula> annotated, Bounds bounds, Options options) {
    super(annotated.sharedNodes());

    // only cache intermediate computations for expressions with no free
    // variables
    // and formulas with no free variables and no quantified descendents
    for (Node n : annotated.sharedNodes()) {
        final AbstractDetector fvdetect = annotated.freeVariableDetector();
        final AbstractDetector qdetect = annotated.quantifiedFormulaDetector();
        if (!(Boolean) n.accept(fvdetect)) {
            if (!(n instanceof Formula) || !((Boolean) n.accept(qdetect)))
                this.cache.put(n, null);
        }
    }
    this.reporter = options.reporter();
    this.bounds = bounds;
    this.interpreter = LeafInterpreter.overapproximating(bounds, options);
    this.repEnv = Environment.empty();
    this.nonSkolems = new ArrayList<DeclInfo>();
    this.nonSkolemsView = new AbstractList<Decl>() {

        @Override
        public Decl get(int index) {
            return nonSkolems.get(index).decl;
        }

        @Override
        public int size() {
            return nonSkolems.size();
        }
    };
    this.topSkolemConstraints = new ArrayList<Formula>();
    this.negated = false;
    this.skolemDepth = options.skolemDepth();
}
 
Example #29
Source File: Translator.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Checks that the given options are suitable for incremental translation.
 * @requires options.solver.incremental() && options.logTranslation = 0  
 * @throws IllegalArgumentException any of the preconditions are violated
 */
public static void checkIncrementalOptions(Options options) {
	if (!options.solver().incremental())
		throw new IllegalArgumentException("An incremental solver is required for incremental translation: " + options);
	if (options.logTranslation() != 0)
		throw new IllegalArgumentException("Translation logging must be disabled for incremental translation: " + options);
}
 
Example #30
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testEmina_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"),
                    next = Relation.nary("OrdNext", 2);
    Relation B = Relation.unary("B"), acyclic = Relation.binary("acyclic");

    List<String> atomlist = Arrays.asList("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    TupleSet allA = factory.setOf("A1", "A2", "A3");
    TupleSet allB = factory.setOf("B1", "B2", "B3");
    TupleSet allC = factory.setOf("C1", "C2");
    bounds.boundExactly(A, allA);
    bounds.bound(first, allA);
    bounds.bound(last, allA);
    bounds.bound(next, allA.product(allA));
    bounds.boundExactly(B, allB);
    bounds.bound(acyclic, allC.product(allC));

    Variable v = Variable.unary("v");
    Formula f0 = Formula.TRUE.forSome(v.setOf(B));
    Formula f1 = next.totalOrder(A, first, last);
    Formula f2 = acyclic.acyclic();
    Formula form = f0.and(f1).and(f2);

    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);
    int i = 1;

    while (sol.hasNext()) {
        assertTrue(i <= 17);
        sol.next();
        i++;
    }
}