Exemple #1
0
static void satisfiableTest()
{
	Minisat::Formula F;
	Minisat::Model model;

	F.addClause(std::vector<int>{-1, -2, -3, 4});

	F.newVars(11);

	for (int i = 1; i < 10; i++) {
		Minisat::clause c = F.newClause();
		if (i % 2 == 0) {
			c->add(i);
		}
		else {
			c->add(-i);
		}
		c->add(i+1);
		F.finalizeClause(c);
	}

	bool satisfiable = F.solve(model);

	AssertThat(satisfiable, IsTrue());
#if 0
	std::cout << "#vars = " << F.getVariableCount() << std::endl;
	std::cout << "#clauses = " << F.getClauseCount() << std::endl;
	if (val) {
		model.printModel();
	}
	F.reset();
#endif
}
Exemple #2
0
static void readDIMACSTest()
{
	Minisat::Formula formula;
	AssertThat(formula.readDimacs(RESOURCE_DIR + "/" + "minisat/satisfiable.txt"), IsTrue());
	Minisat::Model model;
	bool satisfiable = formula.solve(model);
	AssertThat(satisfiable, IsTrue());

	formula.addClause(std::vector<int>{3});
	satisfiable = formula.solve(model);
	AssertThat(satisfiable, IsFalse());
}
Exemple #3
0
static void readDIMACSTest()
{
	Minisat::Formula formula;
	std::stringstream ss{ResourceFile::get("minisat/satisfiable.txt")->data()};
	AssertThat(formula.readDimacs(ss), IsTrue());
	Minisat::Model model;
	bool satisfiable = formula.solve(model);
	AssertThat(satisfiable, IsTrue());

	formula.addClause(std::vector<int>{3});
	satisfiable = formula.solve(model);
	AssertThat(satisfiable, IsFalse());
}
Exemple #4
0
static void nonsatisfiableTest()
{
	Minisat::Formula F;
	Minisat::Model model;
	F.addClause(std::vector<int>{1, 2});
	F.addClause(std::vector<int>{1, -2, 3});
	F.addClause(std::vector<int>{-1, 2});
	F.addClause(std::vector<int>{-1, -2});
	F.addClause(std::vector<int>{-3});

	bool satisfiable = F.solve(model);

	AssertThat(satisfiable, IsFalse());
}