示例#1
0
bool Antecedent::checkPlatformAssumptions() {
	int32* i = new int32(22);
	uint64 p = (uint64)(uintp)i;
	bool convOk = ((int32*)(uintp)p) == i;
	bool alignmentOk = (p & 3) == 0;
	delete i;
	if ( !alignmentOk ) {
		throw PlatformError("Unsupported Pointer-Alignment!");
	}
	if ( !convOk ) {
		throw PlatformError("Can't convert between Pointer and Integer!");
	}
	p = ~uintp(1);
	store_set_bit(p, 0);
	if (!test_bit(p, 0)) {
		throw PlatformError("Can't set LSB in pointer!");
	}
	store_clear_bit(p, 0);
	if (p != (~uintp(1))) {
		throw PlatformError("Can't restore LSB in pointer!");
	}
	Literal max = posLit(varMax-1);
	Antecedent a(max);
	if (a.type() != Antecedent::binary_constraint || a.firstLiteral() != max) {
		throw PlatformError("Cast between 64- and 32-bit integer does not work as expected!");
	}
	Antecedent b(max, ~max);
	if (b.type() != Antecedent::ternary_constraint || b.firstLiteral() != max || b.secondLiteral() != ~max) {
		throw PlatformError("Cast between 64- and 32-bit integer does not work as expected!");
	}
	return true;
}
示例#2
0
/////////////////////////////////////////////////////////////////////////////////////////
// solve
/////////////////////////////////////////////////////////////////////////////////////////
bool solve(Solver& s, const SolveParams& p) {
	s.stats.solve.reset();
	if (s.hasConflict()) return false;
	double maxLearnts   = p.computeReduceBase(s);
	double boundLearnts = p.reduce.max();
	RestartStrategy rs(p.restart);
	ValueRep result;
	uint32 randRuns = p.randRuns();
	double randFreq = randRuns == 0 ? p.randomProbability() : 1.0;
	uint64 maxCfl   = randRuns == 0 ? rs.next() : p.randConflicts();
	uint32 shuffle  = p.shuffleBase();
	do {
		result    = p.enumerator()->search(s, maxCfl, (uint32)maxLearnts, randFreq, p.restart.local);
		if ((result & value_true) != 0) {
			if (!p.enumerator()->backtrackFromModel(s)) {
				break; // No more models requested
			}
			else {
				// continue enumeration
				// but cancel remaining probings
				randRuns = 0;        
				randFreq = p.randomProbability();
				if (p.restart.resetOnModel) {
					rs.reset();
					maxCfl = rs.next();
				}
				if (!p.restart.bounded && s.backtrackLevel() > 0) {
					// After the first solution was found, we allow further restarts only if this
					// is compatible with the enumerator used. 
					maxCfl = static_cast<uint64>(-1);	
				}
			}
		}
		else if (result == value_free){  // restart search
			if (randRuns == 0) {
				maxCfl = rs.next();
				if (p.reduce.reduceOnRestart) { s.reduceLearnts(.33f); }
				if (maxLearnts != (double)std::numeric_limits<uint32>::max() && maxLearnts < boundLearnts && (s.numLearntConstraints()+maxCfl) > maxLearnts) {
					maxLearnts = std::min(maxLearnts*p.reduce.inc(), (double)std::numeric_limits<uint32>::max());
				}
				if (++s.stats.solve.restarts == shuffle) {
					shuffle += p.shuffleNext();
					s.shuffleOnNextSimplify();
				}
			}
			else if (--randRuns == 0) {
				maxCfl    = rs.next();
				randFreq  = p.randomProbability();
			} 
		}
	} while (result < value_false);
	store_clear_bit(result, Enumerator::LIMIT_BIT);
	bool more = result == value_free || s.decisionLevel() > s.rootLevel();
	p.enumerator()->endSearch(s, !more);
	s.undoUntil(0);
	return more;
}