Example #1
0
void ModelEnumerator::initProjection(SharedContext& ctx) {
	if (!project_) { return; }
	project_->clear();
	const SymbolTable& index = ctx.symbolTable();
	if (index.type() == SymbolTable::map_indirect) {
		for (SymbolTable::const_iterator it = index.begin(); it != index.end(); ++it) {
			if (!it->second.name.empty() && it->second.name[0] != '_') {
				addProjectVar(ctx, it->second.lit.var(), true);
			}
		}
		for (VarVec::const_iterator it = project_->begin(), end = project_->end(); it != end; ++it) {
			ctx.unmark(*it);
		}
	}
	else {
		for (Var v = 1; v < index.size(); ++v) { addProjectVar(ctx, v, false); }
	}
	// tag projection nogoods with step literal (if any).
	addProjectVar(ctx, ctx.stepLiteral().var(), false);
	if (project_->empty()) { 
		// We project to the empty set. Add true-var so that 
		// we can distinguish this case from unprojected search
		project_->push_back(0);
	}
}
Example #2
0
void ModelEnumerator::initProjection(SharedContext& ctx) {
	if (!projectionEnabled()) { return; }
	const OutputTable& out = ctx.output;
	char const filter = static_cast<char>(options_ >> 24);
	// Make sure that nogoods are tagged with step literal.
	addProject(ctx, ctx.stepLiteral().var());
	if (out.projectMode() == OutputTable::project_output) {
		// Mark all relevant output variables.
		for (OutputTable::pred_iterator it = out.pred_begin(), end = out.pred_end(); it != end; ++it) {
			if (*it->name != filter) { addProject(ctx, it->cond.var()); }
		}
		for (OutputTable::range_iterator it = out.vars_begin(), end = out.vars_end(); it != end; ++it) {
			for (Var v = it->lo; v != it->hi; ++v) { addProject(ctx, v); }
		}
	}
	else {
		// Mark explicitly requested variables only.
		for (OutputTable::lit_iterator it = out.proj_begin(), end = out.proj_end(); it != end; ++it) {
			addProject(ctx, it->var());
		}
	}
	domRec_.clear();
}