kodkod.engine.satlab.SATFactory Java Examples

The following examples show how to use kodkod.engine.satlab.SATFactory. 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: Viktor.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java tests.Viktor
 */
public static void main(String[] args) {

    final Viktor model = new Viktor();

    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    solver.options().setReporter(new ConsoleReporter());
    solver.options().setBitwidth(7);
    final Formula f = model.checkEquations();
    final Bounds b = model.bounds();
    System.out.println(f);
    System.out.println(b);
    final Solution sol = solver.solve(f, b);

    System.out.println(sol);
    if (sol.instance() != null)
        model.display(sol.instance(), solver.options());

}
 
Example #2
Source File: CeilingsAndFloors.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: java examples.CeilingsAndFloors [# men] [# platforms]
 */
public static void main(String[] args) {
	if (args.length < 2) usage();
	
	final CeilingsAndFloors model = new CeilingsAndFloors();
	final Solver solver = new Solver();
	solver.options().setSolver(SATFactory.MiniSat);
	try {
		final int m = Integer.parseInt(args[0]);
		final int p = Integer.parseInt(args[1]);
		final Formula show = model.checkBelowTooDoublePrime();
		final Solution sol = solver.solve(show, model.bounds(m,p));
		System.out.println(show);
		System.out.println(sol);
		
	} catch (NumberFormatException nfe) {
		usage();
	}
}
 
Example #3
Source File: ALG212.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.ALG212 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final ALG212 model = new ALG212();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(n*n);
        // solver.options().setFlatten(false);
        final Formula f = model.checkDistLong();
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #4
Source File: MagicSeries.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.classicnp.MagicSeries <maximum number in the series>
	 */
	public static void main(String[] args) { 
		if (args.length<1) usage();
		try {
			final int max = Integer.parseInt(args[0]);
			if (max < 1) usage();
			final MagicSeries model = new MagicSeries();
			final Formula f = model.magic();
			final Bounds b = model.bounds(max);
//			System.out.println(f);
//			System.out.println(b);
			final Solver s = new Solver();
			s.options().setSolver(SATFactory.MiniSat);
			s.options().setBitwidth(33-Integer.numberOfLeadingZeros(max));
			s.options().setReporter(new ConsoleReporter());
			final Solution sol = s.solve(f, b);
			model.print(sol,s);
			
		} catch (NumberFormatException nfe) { 
			usage();
		}
	}
 
Example #5
Source File: Viktor.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: java tests.Viktor
 */
public static void main(String[] args) {

		
		final Viktor model = new Viktor();
		
		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);
		solver.options().setReporter(new ConsoleReporter());
		solver.options().setBitwidth(7);
		final Formula f = model.checkEquations();
		final Bounds b = model.bounds();
		System.out.println(f);
		System.out.println(b);
		final Solution sol = solver.solve(f, b);
		
		System.out.println(sol);
		if (sol.instance()!=null)
			model.display(sol.instance(), solver.options());
	
}
 
Example #6
Source File: SET948.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.SET948 [univ size]
	 */
	public static void main(String[] args) {
		if (args.length < 1)
			usage();
		
		try {
			final int n = Integer.parseInt(args[0]);
			if (n < 1)
				usage();
			final SET948 model = new SET948();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(n*n);
//			solver.options().setFlatten(false);
			final Formula f = model.checkT101_zfmisc_1();
			final Bounds b = model.bounds(n);
			System.out.println(f);
			final Solution sol = solver.solve(f, b);
			System.out.println(sol);
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #7
Source File: GEO092.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: ava examples.tptp.GEO192 [# curves] [# points]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);

        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final GEO092 model = new GEO092();
        final Formula f = model.checkProposition2141();

        System.out.println(model.proposition2141());

        final Bounds b = model.bounds(n);
        final Solution sol = solver.solve(f, b);

        System.out.println(sol);
        // System.out.println((new
        // Evaluator(sol.instance())).evaluate(model.axioms().and(model.theorem213().not())));
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #8
Source File: GEO159.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: ava examples.tptp.GEO159 [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);

        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);

        final GEO159 model = new GEO159();
        final Formula f = model.checkDefs();

        final Bounds b = model.bounds(n);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #9
Source File: ALG195_1.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #10
Source File: MGT066.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.MGT066 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final MGT066 model = new MGT066();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setSymmetryBreaking(n * n);
        final Formula f = model.axioms();
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #11
Source File: MED009.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.MED009 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final MED009 model = new MED009();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(1000);
        // solver.options().setFlatten(false);
        final Formula f = model.checkTranssls2_qige27();
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #12
Source File: GEO115.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: ava examples.tptp.GEO115 [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);

        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);

        final GEO115 model = new GEO115();
        final Formula f = model.theorem385();

        final Bounds b = model.bounds(n);
        final Solution sol = solver.solve(f, b);

        System.out.println(sol);

    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #13
Source File: TOP020.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.TOP020 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final TOP020 model = new TOP020();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula f = model.checkChallenge_AMR_1_4_4();
        final Bounds b = model.bounds(n);
        // System.out.println(f);
        // System.out.println(b);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #14
Source File: GraphColoring2.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: java examples.classicnp.GraphColoring <filename> <DIMACS | ASP | ASP_EDGES> <# of colors>
 */
public static void main(String[] args) {
	if (args.length!=3) usage();
	
	try {
		final GraphColoring2 model = new GraphColoring2(args[0], Enum.valueOf(Graph.Format.class, args[1].toUpperCase()), Integer.parseInt(args[2]));
		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);
		solver.options().setSymmetryBreaking(0);
		solver.options().setReporter(new ConsoleReporter());
		final Formula f = model.coloring();
		final Bounds b = model.bounds();
		final Solution sol = solver.solve(f, b);
		System.out.println(sol.outcome());
		System.out.println(sol.stats());
		//if (sol.instance()!=null)
		//	System.out.println("coloring: "+sol.instance().tuples(model.v2c));

	} catch (NumberFormatException e) { usage(); }
}
 
Example #15
Source File: SET948.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.SET948 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();

    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final SET948 model = new SET948();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(n*n);
        // solver.options().setFlatten(false);
        final Formula f = model.checkT101_zfmisc_1();
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #16
Source File: ReductionAndProofTest.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
public ReductionAndProofTest(String arg0) {
    super(arg0);
    this.solver = new Solver();
    solver.options().setLogTranslation(2);
    solver.options().setSolver(SATFactory.MiniSatProver);
    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.a = Relation.unary("a");
    this.b = Relation.unary("b");
    this.a2b = Relation.binary("a2b");
    this.b2a = Relation.binary("b2a");
    this.first = Relation.unary("first");
    this.last = Relation.unary("last");
    this.ordered = Relation.unary("ordered");
    this.total = Relation.binary("total");
    this.bounds = new Bounds(universe);
}
 
Example #17
Source File: Pigeonhole.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java tests.Pigeonhole [# pigeons] [# holes]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    final Pigeonhole model = new Pigeonhole();
    final Solver solver = new Solver();

    try {
        final int p = Integer.parseInt(args[0]);
        final int h = Integer.parseInt(args[1]);
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setSymmetryBreaking(p);
        final Formula show = model.declarations().and(model.pigeonPerHole());
        final Solution sol = solver.solve(show, model.bounds(p, h));
        // System.out.println(show);
        System.out.println(sol);

    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #18
Source File: CeilingsAndFloors.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.CeilingsAndFloors [# men] [# platforms]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();

    final CeilingsAndFloors model = new CeilingsAndFloors();
    final Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final int m = Integer.parseInt(args[0]);
        final int p = Integer.parseInt(args[1]);
        final Formula show = model.checkBelowTooDoublePrime();
        final Solution sol = solver.solve(show, model.bounds(m, p));
        System.out.println(show);
        System.out.println(sol);

    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #19
Source File: ALG212.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.ALG212 [univ size]
	 */
	public static void main(String[] args) {
		if (args.length < 1)
			usage();
		
		try {
			final int n = Integer.parseInt(args[0]);
			if (n < 1)
				usage();
			final ALG212 model = new ALG212();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(n*n);
//			solver.options().setFlatten(false);
			final Formula f = model.checkDistLong();
			final Bounds b = model.bounds(n);
			System.out.println(f);
			final Solution sol = solver.solve(f, b);
			System.out.println(sol);
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #20
Source File: NUM378.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.NUM378
	 */
	public static void main(String[] args) {
	
		try {
	
			final NUM378 model = new NUM378();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
			final Formula f = model.decls().and(model.inequalities());
			final Bounds b = model.bounds();
//			System.out.println(f);
//			System.out.println(b);
			final Solution sol = solver.solve(f, b);
			System.out.println(sol.outcome());
			System.out.println(sol.stats());
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #21
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 #22
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
public final void testVincent_03182006_reduced() {
    final Relation pCourses = Relation.binary("pCourses"), prereqs = Relation.binary("prereqs");
    final List<String> atoms = new ArrayList<String>(14);
    atoms.add("6.002");
    atoms.add("8.02");
    atoms.add("6.003");
    atoms.add("6.001");
    atoms.add("[8.02]");
    atoms.add("[6.001]");
    atoms.add("[]");
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();

    b.bound(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001")));

    b.bound(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));

    // System.out.println(u);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    Solution solution = solver.solve((pCourses.some()).and(prereqs.some()), b);
    // System.out.println(solution); // SATISFIABLE
    assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE);

}
 
Example #23
Source File: HamiltonianCycle.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: examples.classicnp.HamiltonianCycle <graph file> <DIMACS | ASP>
	 */
	public static void main(String[] args) {
		if (args.length!=2)
			usage();
		final HamiltonianCycle model = new HamiltonianCycle();
		final Formula f = model.cycleDefinition();
		final Bounds b = model.bounds(args[0], Enum.valueOf(Graph.Format.class, args[1].toUpperCase()));
		System.out.println(f);
		System.out.println(b);
		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);
		solver.options().setReporter(new ConsoleReporter());
//		solver.options().setFlatten(false);
		final Solution s = solver.solve(f,b);
		System.out.println(s);
		if (s.instance()!=null) {
			System.out.print("verifying solution ... ");
			System.out.println(model.verify(s.instance()) ? "correct." : "incorrect!");
		}
	}
 
Example #24
Source File: NativeSolverTest.java    From kodkod with MIT License 6 votes vote down vote up
@Test
public void testProofOfLastEmptyClauseCNF() {
	for(SATFactory factory : solvers) {
		if (!factory.prover()) continue;
		final SATProver solver = (SATProver) factory.instance();
		solver.addVariables(1);
		solver.addClause(new int[]{1});
		solver.addVariables(1);
		solver.addClause(new int[]{-2});
		solver.addVariables(2);
		solver.addClause(new int[]{2, 3, 4});
		solver.addClause(new int[0]);
		assertFalse(solver.solve());
		final ResolutionTrace proof = solver.proof();
		assertEquals(4, proof.size());
		assertEquals(Ints.singleton(3), proof.core());
		assertEquals(Ints.EMPTY_SET, proof.resolvents());
		assertEquals(0, proof.get(3).size());
	}
}
 
Example #25
Source File: WriteCNF.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method that returns a factory for WriteCNF instances.
 */
public static final SATFactory factory(final String filename) {
    return new SATFactory() {

        /** {@inheritDoc} */
        @Override
        public SATSolver instance() {
            return new WriteCNF(filename);
        }

        /** {@inheritDoc} */
        @Override
        public boolean incremental() {
            return false;
        }
    };
}
 
Example #26
Source File: TOP020.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.TOP020 [univ size]
	 */
	public static void main(String[] args) {
		if (args.length < 1)
			usage();
		
		try {
			final int n = Integer.parseInt(args[0]);
			if (n < 1)
				usage();
			final TOP020 model = new TOP020();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
			final Formula f = model.checkChallenge_AMR_1_4_4();
			final Bounds b = model.bounds(n);
//			System.out.println(f);
//			System.out.println(b);
			final Solution sol = solver.solve(f, b);
			System.out.println(sol);
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #27
Source File: GEO159.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: ava examples.tptp.GEO159 [scope]
 */
public static void main(String[] args) {
	if (args.length < 1)
		usage();
	
	try {
		final int n = Integer.parseInt(args[0]);

		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);

		final GEO159 model = new GEO159();
		final Formula f = model.checkDefs();
		
		final Bounds b = model.bounds(n);
		final Solution sol = solver.solve(f,b);
		System.out.println(sol);
	} catch (NumberFormatException nfe) {
		usage();
	}
}
 
Example #28
Source File: SET943.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.SET943 [univ size]
	 */
	public static void main(String[] args) {
		if (args.length < 1)
			usage();
		
		try {
			final int n = Integer.parseInt(args[0]);
			if (n < 1)
				usage();
			final SET943 model = new SET943();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(1000);
//			solver.options().setFlatten(false);
			final Formula f = model.checkT96_zfmisc_1();
			final Bounds b = model.bounds(n);
			System.out.println(f);
			final Solution sol = solver.solve(f, b);
			System.out.println(sol);
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #29
Source File: COM008.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.COM008 [univ size]
	 */
	public static void main(String[] args) {
		if (args.length < 1)
			usage();
		
		try {
			final int n = Integer.parseInt(args[0]);
			if (n < 1)
				usage();
			final COM008 model = new COM008();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(22);
//			solver.options().setFlatten(false);
			final Formula f = model.checkGoalToBeProved();
			final Bounds b = model.bounds(n);
//			System.out.println(f);
			
			final Solution sol = solver.solve(f, b);
			System.out.println(sol);
		
		} catch (NumberFormatException nfe) {
			usage();
		}
	}
 
Example #30
Source File: ALG195.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.ALG195
	 */
	public static void main(String[] args) {
	
		try {
	
			final ALG195 model = new ALG195();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
			final Formula f = model.checkCO1();
			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();
		}
	}