Ejemplo n.º 1
0
	void testDimacs() {
		std::stringstream prg;
		prg << "c simple test case\n"
				<< "p cnf 4 3\n"
			  << "1 2 0\n"
				<< "3 4 0\n"
				<< "-1 -2 -3 -4 0\n";
		CPPUNIT_ASSERT(parseDimacs(prg, ctx));
		CPPUNIT_ASSERT(ctx.numVars() == 4);
		CPPUNIT_ASSERT(ctx.numConstraints() == 3);
	}
Ejemplo n.º 2
0
bool StreamInput::read(Solver& s, ProgramBuilder* api, int numModels) {
	if (format_ == Input::SMODELS) {
		assert(api);
		return parseLparse(prg_, *api);
	}
	else if (format_ == Input::DIMACS) {
		return parseDimacs(prg_, s, numModels == 1);
	}
	else {
		return parseOPB(prg_, s, func_);
	}
}
Ejemplo n.º 3
0
	void testDimacsDontAddDupLit() {
		std::stringstream prg;
		prg << "c simple test case\n"
				<< "p cnf 2 4\n"
			  << "1 2 2 1 0\n"
				<< "1 2 1 2 0\n"
				<< "-1 -2 -1 0\n"
				<< "-2 -1 -2 0\n";
		CPPUNIT_ASSERT(parseDimacs(prg, ctx));
		CPPUNIT_ASSERT(ctx.numVars() == 2);
		CPPUNIT_ASSERT(ctx.numConstraints() == 4);
		CPPUNIT_ASSERT(ctx.numBinary() == 4);
	}
Ejemplo n.º 4
0
	void testPartialWcnf() {
		std::stringstream prg;
		prg << "c comments Weigthed Partial Max-SAT\n"
				<< "p wcnf 4 5 16\n"
			  << "16 1 -2 4 0\n"
				<< "16 -1 -2 3 0\n"
				<< "8 -2 -4 0\n"
				<< "4 -3 2 0\n"
				<< "1 1 3 0\n"
				;
		ObjectiveFunction obj;
		CPPUNIT_ASSERT(parseDimacs(prg, ctx, PureLitMode_t::assert_pure_auto, obj, false));
		CPPUNIT_ASSERT(ctx.numVars() == 7);
		CPPUNIT_ASSERT(ctx.symTab().size() == 5);
		CPPUNIT_ASSERT(ctx.numConstraints() == 5);
		CPPUNIT_ASSERT(obj.lits.size() == 3);
		CPPUNIT_ASSERT(obj.lits[0].second == 8);
		CPPUNIT_ASSERT(obj.lits[1].second == 4);
		CPPUNIT_ASSERT(obj.lits[2].second == 1);
	}
Ejemplo n.º 5
0
	void testWcnf() {
		std::stringstream prg;
		prg << "c comments Weighted Max-SAT\n"
				<< "p wcnf 3 4\n"
			  << "10 1 -2 0\n"
				<< "3 -1 2 -3 0\n"
				<< "8 -3 2 0\n"
				<< "5 1 3 0\n"
				;
		ObjectiveFunction obj;
		CPPUNIT_ASSERT(parseDimacs(prg, ctx, PureLitMode_t::assert_pure_auto, obj, false));
		CPPUNIT_ASSERT(ctx.numVars() == 7);
		CPPUNIT_ASSERT(ctx.symTab().size() == 4);
		CPPUNIT_ASSERT(ctx.numConstraints() == 4);
		CPPUNIT_ASSERT(obj.lits.size() == 4);
		CPPUNIT_ASSERT(obj.lits[0].second == 10);
		CPPUNIT_ASSERT(obj.lits[1].second == 3);
		CPPUNIT_ASSERT(obj.lits[2].second == 8);
		CPPUNIT_ASSERT(obj.lits[3].second == 5);
	}
Ejemplo n.º 6
0
	void testDimacsBadVars() {
		std::stringstream prg;
		prg << "p cnf 2 1\n"
			  << "3 4 0\n";
		CPPUNIT_ASSERT_THROW(parseDimacs(prg, ctx), ReadError);
	}