Esempio n. 1
0
void VACExtension::afterPreprocessing()
{
    int discarded = 0;
    for (unsigned int i = 0; i < wcsp->numberOfConstraints(); i++) {
        Constraint *c = wcsp->getCtr(i);
        if (c->connected() && (c->arity() <= 3) && !c->isSep()) {
            if (c->getTightness() <
                    to_double(ToulBar2::relaxThreshold)) {
                c->deconnect();
                discarded++;
            }
        }
    }
    if (discarded)
        cout << "WARNING num of discarded ctrs: " << discarded << endl;
}
/** lecture des contraintes */
int  wcspdata_constraint_read (WCSP *wcsp, int nbconst, vector<INCOP::NaryVariable*>* vv, vector<INCOP::NaryConstraint*>* vct,
				vector <int>* connexions, vector<Value> * tabdomaines)
{ 
  Cost gap = wcsp->getUb()-wcsp->getLb();
  int nbconst_ = 0;
  for (unsigned int i =0; i< wcsp->numberOfConstraints(); i++) {
      if (wcsp->getCtr(i)->connected() && !wcsp->getCtr(i)->isSep() && !wcsp->getCtr(i)->isGlobal() && wcsp->getCtr(i)->arity() <= ToulBar2::preprocessNary) {
          int arity=0; int numvar=0;
          arity = ((wcsp->getCtr(i)->arity()<=3)?wcsp->getCtr(i)->arity():((NaryConstraint *) wcsp->getCtr(i))->nonassigned);
          INCOP::NaryConstraint* ct = new INCOP::NaryConstraint(arity);
          vct->push_back(ct);
          for (int j=0 ; j< wcsp->getCtr(i)->arity() ; j++) if (wcsp->getCtr(i)->getVar(j)->unassigned()) {
              numvar = wcsp->getCtr(i)->getVar(j)->getCurrentVarId();
              ct->constrainedvariables.push_back(numvar);
              (*vv)[numvar]->constraints.push_back(ct);
          }
          assert(ct->constrainedvariables.size() == arity);
          ct->compute_indexmultiplyers(tabdomaines);
          String tuple;
          Cost cost;
          wcsp->getCtr(i)->firstlex();
          while (wcsp->getCtr(i)->nextlex(tuple, cost)) {
              ct->tuplevalues.push_back(min(gap, cost));
          }
          nbconst_++;
      }
  }
  for (int i =0; i< wcsp->getElimBinOrder(); i++) {
      Constraint *ctr = wcsp->getElimBinCtr(i);
      if (ctr->connected() && !ctr->isSep()) {
          int arity=2; int numvar=0;
          INCOP::NaryConstraint* ct = new INCOP::NaryConstraint(arity);
          vct->push_back(ct);
          for (int j=0 ; j< arity ; j++) if (ctr->getVar(j)->unassigned()) {
              numvar = ctr->getVar(j)->getCurrentVarId();
              ct->constrainedvariables.push_back(numvar);
              (*vv)[numvar]->constraints.push_back(ct);
          }
          ct->compute_indexmultiplyers(tabdomaines);
          String tuple;
          Cost cost;
          ctr->firstlex();
          while (ctr->nextlex(tuple, cost)) {
              ct->tuplevalues.push_back(min(gap, cost));
          }
          nbconst_++;
      }
  }
  for (int i =0; i< wcsp->getElimTernOrder(); i++) {
      Constraint *ctr = wcsp->getElimTernCtr(i);
      if (ctr->connected() && !ctr->isSep()) {
          int arity=3; int numvar=0;
          INCOP::NaryConstraint* ct = new INCOP::NaryConstraint(arity);
          vct->push_back(ct);
          for (int j=0 ; j< arity ; j++) if (ctr->getVar(j)->unassigned()) {
              numvar = ctr->getVar(j)->getCurrentVarId();
              ct->constrainedvariables.push_back(numvar);
              (*vv)[numvar]->constraints.push_back(ct);
          }
          ct->compute_indexmultiplyers(tabdomaines);
          String tuple;
          Cost cost;
          ctr->firstlex();
          while (ctr->nextlex(tuple, cost)) {
              ct->tuplevalues.push_back(min(gap, cost));
          }
          nbconst_++;
      }
  }
  for (unsigned int i =0; i< wcsp->numberOfVariables(); i++) {
      if (wcsp->unassigned(i) && wcsp->getMaxUnaryCost(i) > MIN_COST) {
          int arity=1; int numvar=0;
          INCOP::NaryConstraint* ct = new INCOP::NaryConstraint(arity);
          vct->push_back(ct);
          numvar = wcsp->getVar(i)->getCurrentVarId();
          ct->constrainedvariables.push_back(numvar);
          (*vv)[numvar]->constraints.push_back(ct);
          ct->compute_indexmultiplyers(tabdomaines);
          for (EnumeratedVariable::iterator it=((EnumeratedVariable *)wcsp->getVar(i))->begin() ; it != ((EnumeratedVariable *)wcsp->getVar(i))->end() ; ++it) {
              ct->tuplevalues.push_back(min(gap, wcsp->getUnaryCost(i, *it)));
          }
          nbconst_++;
      }
  }
  assert(nbconst_ <= nbconst);
  return nbconst_;
}