// domain synchronization between obj&vars (Ilog) and wcsp (ToulBar2) void synchronize() { if (ToulBar2::verbose >= 2) cout << "Domain synchronization between IlogSolver and Toulbar2!" << endl; for (int i = 0; i < size; i++) { if (ToulBar2::verbose >= 2) cout << vars[i] << " (" << wcsp->getInf(i) << "," << wcsp->getSup(i) << ")" << endl; vars[i].setMin(wcsp->getInf(i)); vars[i].setMax(wcsp->getSup(i)); for (int d = wcsp->getInf(i); d <= wcsp->getSup(i); d++) { if (wcsp->cannotbe(i, d)) { vars[i].removeValue(d); } } wcsp->increase(i, vars[i].getMin()); wcsp->decrease(i, vars[i].getMax()); for (int d = vars[i].getMin(); d <= vars[i].getMax(); d++) { if (!vars[i].isInDomain(d)) { wcsp->remove(i, d); } } } obj.setMin(wcsp->getLb()); obj.setMax(wcsp->getUb() - 1); wcsp->decreaseUb(obj.getMax() + 1); UpperBound = wcsp->getUb(); }
// check only modifications on the objective variable void whenRange() { checkFailure(); wcsp->enforceUb(); // fail if lower bound >= upper bound and enforce NC* if (obj.getMax() + 1 < wcsp->getUb()) { wcsp->decreaseUb(obj.getMax() + 1); } push(); // global propagation done after local propagation }
// global propagation using WCSP propagation queues void propagate() { checkFailure(); if (synchronized) { synchronized.setValue(getSolver(), IlcFalse); synchronize(); } if (ToulBar2::verbose >= 2) cout << "ILOG: propagate wcsp index " << wcsp->getIndex() << endl; wcsp->decreaseUb(obj.getMax() + 1); wcsp->propagate(); }
void IlcWeightedCSPI::post() { ToulBar2::setvalue = ::tb2setvalue; ToulBar2::removevalue = ::tb2removevalue; ToulBar2::setmin = ::tb2setmin; ToulBar2::setmax = ::tb2setmax; ToulBar2::setminobj = ::tb2setminobj; for (int i = 0; i < size; i++) { vars[i].whenValue(IlcWeightedCSPWhenValueDemon(getSolver(), this, i)); vars[i].whenDomain(IlcWeightedCSPWhenDomainDemon(getSolver(), this, i)); } obj.whenRange(IlcWeightedCSPWhenRangeDemon(getSolver(), this)); }
// variable varIndex has been assigned void whenValue(const IlcInt varIndex) { checkFailure(); if (ToulBar2::verbose >= 2) cout << "ILOG: " << vars[varIndex].getName() << " = " << vars[varIndex].getValue() << endl; wcsp->assign(varIndex, vars[varIndex].getValue()); if (unassignedVars->canbe(varIndex)) { unassignedVars->erase(varIndex); if (unassignedVars->empty()) { assert(wcsp->verify()); obj.setValue(wcsp->getLb()); } } push(); // global propagation done after local propagation }
IlcConstraint IlcWeightedCSP(IlcIntVar objective, IlcIntVarArray variables, const char* filename) { IloSolver solver = objective.getSolver(); return IlcConstraint(new (solver.getHeap()) IlcWeightedCSPI(solver, objective, variables, filename)); }
IlcInt IlcIntSelectMaxI::select(IlcIntVar var){ return var.getMax(); }
void rulers::print(IlcIntVar var) { if (var.isBound()) var.getManager().out() << " " << var.getValue(); else var.getManager().out() << " ||"; }