kodkod.engine.Solver Java Examples

The following examples show how to use kodkod.engine.Solver. 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: 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 #2
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 #3
Source File: GraphColoring.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 GraphColoring model = new GraphColoring(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 #4
Source File: ALG197.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.ALG197
 */
public static void main(String[] args) {

    try {

        final ALG197 model = new ALG197();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula f = model.checkCO1();
        final Bounds b = model.bounds();
        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 #5
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 #6
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 #7
Source File: GEO091.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.GEO191 [univ size]
 */
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 GEO091 model = new GEO091();
        final Formula f = model.checkTheorem_2_13();

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

        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: 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 #9
Source File: MED007.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.tptp.MED007 [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 MED007 model = new MED007();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setSymmetryBreaking(1000);
        // solver.options().setFlatten(false);
        final Formula f = model.checkTranssls2_qilt27();
        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 #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: Netconfig.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.Netconfig [# sites] [# hq] [# routers] [# time steps]
 */
public static void main(String[] args) {
    if (args.length < 4)
        usage();
    final Netconfig model = new Netconfig();
    final Solver solver = new Solver();
    // solver.options().setSolver(SATFactory.ZChaffMincost);
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final Formula show = model.show();
        final Solution sol = solver.solve(show, model.bounds(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
        // System.out.println(show);
        // System.out.println("p cnf " +
        // (solver.numberOfIntermediateVariables()+solver.numberOfPrimaryVariables())
        // + " " + solver.numberOfClauses());
        System.out.println(sol.outcome());
        System.out.println(sol.stats());

    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #12
Source File: SET967.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.SET967 [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 SET967 model = new SET967();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(n*n);
//			solver.options().setFlatten(false);
			final Formula f = model.checkT120_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 #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: GEO115.java    From kodkod with MIT License 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 #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: 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 #17
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 #18
Source File: DNACuts.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Usage: java examples.alloy.DNACuts [cut chain length] [# links]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();

    try {
        final DNACuts model = new DNACuts(Integer.parseInt(args[0]));
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.DefaultSAT4J);
        Formula f = model.show();
        Bounds b = model.bounds(Integer.parseInt(args[1]));
        System.out.println("solving...");
        Solution sol = solver.solve(f, b);
        // System.out.println(f);
        // System.out.println(b);
        System.out.println(sol.outcome());
        System.out.println(sol.stats());
    } catch (NumberFormatException nfe) {
        usage();
    }
}
 
Example #19
Source File: ALG197.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: java examples.tptp.ALG197
 */
public static void main(String[] args) {

	try {

		final ALG197 model = new ALG197();
		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);
		final Formula f = model.checkCO1();
		final Bounds b = model.bounds();
		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 #20
Source File: ALG195_1.java    From kodkod with MIT License 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 #21
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 #22
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 #23
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 #24
Source File: GEO091.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Usage: java examples.tptp.GEO191 [univ size]
 */
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 GEO091 model = new GEO091();
		final Formula f = model.checkTheorem_2_13();
		
		System.out.println(model.theorem_2_13());
		
		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 #25
Source File: GEO092.java    From kodkod with MIT License 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 #26
Source File: MED007.java    From kodkod with MIT License 6 votes vote down vote up
/**
	 * Usage: java examples.tptp.MED007 [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 MED007 model = new MED007();
			final Solver solver = new Solver();
			solver.options().setSolver(SATFactory.MiniSat);
//			solver.options().setSymmetryBreaking(1000);
//			solver.options().setFlatten(false);
			final Formula f = model.checkTranssls2_qilt27();
			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 #27
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 #28
Source File: UCoreStats.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Checks that the given core is unsatisfiable with respect to the given bounds.
 *
 * @return true if the core is correct; false otherwise
 */
static boolean checkCorrect(Set<Formula> core, Bounds bounds) {
    System.out.print("checking correctness ... ");
    final long start = System.currentTimeMillis();
    Solver solver = solver();
    solver.options().setSolver(SATFactory.MiniSat);
    final Solution sol = solver.solve(Formula.and(core), bounds);
    final long end = System.currentTimeMillis();
    if (sol.instance() == null) {
        System.out.println("correct (" + (end - start) + " ms).");
        return true;
    } else {
        System.out.println("incorrect! (" + (end - start) + " ms). The core is satisfiable:");
        System.out.println(sol);
        return false;
    }
}
 
Example #29
Source File: MagicSeries.java    From kodkod with MIT License 6 votes vote down vote up
private void print(Solution sol, Solver s) { 
	if (sol.instance()==null)
		System.out.println(sol);
	else {
		System.out.println(sol.outcome());
		System.out.println(sol.stats());
		final Evaluator eval = new Evaluator(sol.instance(), s.options());
		final Relation r = Relation.unary("r");
		final TupleFactory f = sol.instance().universe().factory();
		for(Object atom : f.universe()) { 
			eval.instance().add(r,  f.setOf(atom));
			System.out.print(atom + "->" + eval.evaluate(r.join(el).sum()) + "; ");
		}
		System.out.println();
	}
}
 
Example #30
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();
		}
	}