コード例 #1
0
bool Constraint::verifySeparate(Constraint * ctr1, Constraint * ctr2){
	assert(scopeIncluded(ctr1));
	assert(scopeIncluded(ctr2));
	String tuple;
	Cost cost, c1,c2;
	firstlex();
	if(ToulBar2::verbose >= 3) { cout << "[ ";
	for(int i = 0; i< arity(); ++i)
		cout << getVar(i)->getName() << " ";
	cout << " ]\n" ;
	}
	while(nextlex(tuple,cost)){
		c1 = ctr1->evalsubstr(tuple,this);
		c2 = ctr2->evalsubstr(tuple,this);
		if(ToulBar2::verbose >= 3){
			for(int i = 0; i< arity(); ++i)
				cout << tuple[i] - CHAR_FIRST << " ";
			//cout << endl;
			cout << " : " << cost << " =? " << c1 << " + " << c2 << " : " << c1 + c2 << endl;
		}
		if(cost < wcsp->getUb() && c1+c2 != cost) return false;
		if(cost >= wcsp->getUb() && c1+c2 < wcsp->getUb()) return false;
	}
	return true;
}
コード例 #2
0
    set<Constraint *> subConstraint(){
    	set <Constraint *> subcstr;
    	set<int> scope;
    	for(int k=0; k < arity(); k++) {
    		scope.insert(getVar(k)->wcspIndex);
    	}
    	for(set<int>::iterator itx = scope.begin(); itx != scope.end(); ++itx){
    		ConstraintList* xctrs = (wcsp->getVar(*itx))->getConstrs();
    		for (ConstraintList::iterator it=xctrs->begin(); it != xctrs->end(); ++it){
    			Constraint * ctr = (*it).constr;
    			if(ctr->arity() < arity() && scopeIncluded(ctr)) subcstr.insert(ctr);
    		}
    	}

    	return subcstr;
    }