Ejemplo n.º 1
0
void CompressInterface::rearrangeCnfFactor(CFactor &cnfClause) {
	State state(cnfClause.vars());
	vector<size_t> (cnfClause.vars().size());
	vector<size_t> pos,neg,sigma;
	for (size_t i=0; i<cnfClause.states(); i++) {
		if (cnfClause[i] == 1) {
			for (vector<Var>::const_iterator varIter=cnfClause.vars().begin(); varIter!=cnfClause.vars().end();varIter++) {
				if (state(*varIter) == 0) {
					pos.push_back(varIter - cnfClause.vars().begin());
				} else {
					neg.push_back(varIter - cnfClause.vars().begin());
				}
			}
			break;
		} else if (cnfClause[i] == 0) {
			//TODO handle factors which contain zero states
			// in such cases the possible zero state could have been clamped;
			// possible solutions:
			// i) restore factor from backup (requires to clamp factors accordingly)
			// ii) cache zero states in advance
			return;
		}
		state++;
	}
	sigma.insert(sigma.begin(),pos.begin(), pos.end());
	sigma.insert(sigma.begin() + pos.size(),neg.begin(), neg.end());
	cnfClause.sigma() = sigma;
}
Ejemplo n.º 2
0
void cfactor_setitem(CFactor& factor, size_t index, double value)
{
	if (index >= 0 && index < factor.states()) {
		factor[index] = value;
	}
	else {
		PyErr_SetString(PyExc_IndexError, "index out of range");
		boost::python::throw_error_already_set();
	}
}
Ejemplo n.º 3
0
double cfactor_getitem(CFactor &factor, size_t index)
{
	if (index >= 0 && index < factor.states()) {
		return factor[index];
	}
	else {
		PyErr_SetString(PyExc_IndexError, "index out of range");
		boost::python::throw_error_already_set();
		return -1;
	}
}