Commit 45105072 authored by Simon de Givry's avatar Simon de Givry
Browse files

Merge branch 'tmpmaster'

parents d613ddfc bcc2ee75
......@@ -54,7 +54,7 @@ echo "\\end{DoxyCode}}"
echo -n "\\item "
#echo "________________________________________________________________________________"
echo "Download file {\\em 404.wcsp}. Solve it using Depth-First Brand and Bound with Tree Decomposition (BTD)~\\cite{Schiex06a} based on a min-fill variable ordering:"
echo "Download file {\\em 404.wcsp}. Solve it using Depth-First Brand and Bound with Tree Decomposition and HBFS (BTD-HBFS)~\\cite{Schiex06a} based on a min-fill variable ordering:"
echo "\\begin{DoxyCode}"
echo " toulbar2 EXAMPLES/404.wcsp -O=-3 -B=1"
echo "\\end{DoxyCode}"
......@@ -82,7 +82,25 @@ echo "\\end{DoxyCode}}"
echo -n "\\item "
#echo "________________________________________________________________________________"
echo "Download a Markov Random Field (MRF) file {\\em pedigree9.uai} in UAI format from the toulbar2's Documentation Web page. Solve it using bounded (of degree at most 8) variable elimination enhanced by cost function decomposition in preprocessing~\\cite{Favier11a} followed by BTD exploiting only small-size (less than four variables) separators:"
echo "Download file {\\em example.order}. Solve it using BTD-HBFS based on a given (min-fill) reverse variable elimination ordering:"
echo "\\begin{DoxyCode}"
echo " toulbar2 EXAMPLES/example.wcsp EXAMPLES/example.order -B=1"
echo "\\end{DoxyCode}"
echo "{\\scriptsize" ; echo "\\begin{DoxyCode}" ; toulbar2 EXAMPLES/example.wcsp EXAMPLES/example.order -B=1 | awk '/^Read /{ok=1} ok{print $0}'
echo "\\end{DoxyCode}}"
echo -n "\\item "
#echo "________________________________________________________________________________"
echo "Download file {\\em example.cov}. Solve it using BTD-HBFS based on a given explicit (min-fill path-) tree-decomposition:"
echo "\\begin{DoxyCode}"
echo " toulbar2 EXAMPLES/example.wcsp EXAMPLES/example.cov -B=1"
echo "\\end{DoxyCode}"
echo "{\\scriptsize" ; echo "\\begin{DoxyCode}" ; toulbar2 EXAMPLES/example.wcsp EXAMPLES/example.cov -B=1 | awk '/^Read /{ok=1} ok{print $0}'
echo "\\end{DoxyCode}}"
echo -n "\\item "
#echo "________________________________________________________________________________"
echo "Download a Markov Random Field (MRF) file {\\em pedigree9.uai} in UAI format from the toulbar2's Documentation Web page. Solve it using bounded (of degree at most 8) variable elimination enhanced by cost function decomposition in preprocessing~\\cite{Favier11a} followed by BTD-HBFS exploiting only small-size (less than four variables) separators:"
echo "\\begin{DoxyCode}"
echo " toulbar2 EXAMPLES/pedigree9.uai -O=-3 -p=-8 -B=1 -r=4"
echo "\\end{DoxyCode}"
......
......@@ -225,9 +225,9 @@ or if no integer is given, finds all solutions (or counts the number of zero-cos
\item[{-B=[integer]}] (0) DFBB, (1) BTD~\cite{Schiex06a}, (2) RDS-BTD~\cite{Sanchez09a}, (3) RDS-BTD with
path decomposition instead of tree decomposition~\cite{Sanchez09a} (default value is
0)
\item[{-O=[filename]}] reads a variable elimination order from a file
\item[{-O=[filename]}] reads either a reverse variable elimination order (given by a list of variable indexes) from a file
in order to build a tree decomposition (if BTD-like and/or variable
elimination methods are used). It is also used as a DAC ordering.
elimination methods are used) or reads a valid tree decomposition directly (given by a list of clusters in topological order of a rooted forest, each line contains a cluster number, followed by a cluster parent number with -1 for the first/root(s) cluster(s), followed by a list of variable indexes). It is also used as a DAC ordering.
\item[{-O=[negative integer]}] build a tree decomposition (if BTD-like
and/or variable elimination methods are used) and also a compatible
DAC ordering using
......
......@@ -22,8 +22,7 @@ extern ofstream *ofile; // le fichier de sortie
extern Stat_GWW *Statistiques;
#include "tb2solver.hpp"
#include "tb2naryconstr.hpp"
#include "tb2wcsp.hpp"
INCOP::NaryCSProblem::NaryCSProblem(int nbvar, int nbconst) : CSProblem(nbvar, nbconst) {;}
......@@ -249,10 +248,10 @@ int wcspdata_constraint_read(WCSP *wcsp, int nbconst, vector<INCOP::NaryVariabl
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)->isNary()) ? ((int)((NaryConstraint *) wcsp->getCtr(i))->getNonAssigned()) : wcsp->getCtr(i)->arity());
for (int j = 0 ; j < wcsp->getCtr(i)->arity() ; j++) if (wcsp->getCtr(i)->getVar(j)->unassigned()) arity++;
INCOP::NaryConstraint *ct = new INCOP::NaryConstraint(arity);
vct->push_back(ct);
int numvar = 0;
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);
......
......@@ -40,6 +40,7 @@ void AllDiffConstraint::read(istream& file)
// 2) the cost of the violation edge : assume to be a constant function
// mapping to def
file >> def;
def *= ToulBar2::costMultiplier;
//cout << "str = " << str << endl;
/*if (str == "var") {
mode = VAR;
......
......@@ -27,6 +27,7 @@ void AmongConstraint::read(istream& file)
{
string str;
file >> str >> def;
def *= ToulBar2::costMultiplier;
if (str != "var") {
cout << "Error in reading samong()\n";
......
......@@ -24,7 +24,7 @@ WFA::WFA(istream& file)
Cost weight;
file >> init >> weight;
//cout << "reading INIT = " << init << " " << weight << endl;
pair<int, Cost> initSt = make_pair(init, weight);
pair<int, Cost> initSt = make_pair(init, weight * ToulBar2::costMultiplier);
//cout << initSt.first << " " << initSt.second << endl;
initialStates.push_back(initSt);
}
......@@ -35,7 +35,7 @@ WFA::WFA(istream& file)
Cost weight;
file >> accept >> weight;
//cout << "reading ACCEPT = " << accept << " " << weight << endl;
pair<int, Cost> acceptSt = make_pair(accept, weight);
pair<int, Cost> acceptSt = make_pair(accept, weight * ToulBar2::costMultiplier);
//cout << acceptSt.first << " " << acceptSt.second << endl;
acceptingStates.push_back(acceptSt);
}
......@@ -45,7 +45,7 @@ WFA::WFA(istream& file)
Cost weight;
file >> start >> symbol >> end >> weight;
//cout << "TRANS " << start << "x" << symbol << "-->" << end << " w= " << weight << endl;
transitions.push_back(new WTransition(start, end, symbol, weight));
transitions.push_back(new WTransition(start, end, symbol, weight * ToulBar2::costMultiplier));
}
}
......
......@@ -5,6 +5,7 @@
#include "tb2ternaryconstr.hpp"
#include "tb2enumvar.hpp"
#include "tb2wcsp.hpp"
#include "tb2clusters.hpp"
#include <numeric>
// warning! we assume binary variables
......
......@@ -257,7 +257,7 @@ bool Constraint::verifySeparate(Constraint* ctr1, Constraint* ctr2)
bool Constraint::decompose()
{
bool sep = false;
if (extension() && !universal() && arity() >= 3 && arity() <= ToulBar2::preprocessNary && (isTernary() || getDefCost() > MIN_COST || ((NaryConstraint*)this)->size() > 1)) {
if (extension() && !universal() && arity() >= 3 && arity() <= ToulBar2::preprocessNary && (isTernary() || (isNary() && (getDomainSizeProduct() < MAX_NB_TUPLES) && (getDefCost() > MIN_COST || ((NaryConstraint*)this)->size() > 1)))) {
TSCOPE scopeinv;
getScope(scopeinv);
EnumeratedVariable* vx = NULL;
......
......@@ -55,6 +55,7 @@ void GlobalCardinalityConstraint::read(istream& file)
setSemantics(str);
//JP End//
file >> def;
def *= ToulBar2::costMultiplier;
file >> nvalues;
//JP End//
for (int i = 0; i < nvalues; i++) {
......
......@@ -105,6 +105,7 @@ WeightedAmong::WeightedAmong(unsigned int _arity, int* _scope, istream& file)
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
unsigned int nbValue;
file >> nbValue;
for (unsigned int value = 0; value < nbValue; ++value) {
......@@ -472,6 +473,7 @@ WeightedSum::WeightedSum(unsigned int _arity, int* _scope, istream& file)
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
file >> comparator >> rightRes;
}
......@@ -665,6 +667,7 @@ WeightedVarSum::WeightedVarSum(unsigned int _arity, int* _scope, istream& file)
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
file >> comparator;
}
......@@ -813,6 +816,7 @@ WeightedOverlap::WeightedOverlap(unsigned int _arity, int* _scope, istream& file
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
file >> comparator >> rightRes;
//display();
}
......@@ -1063,6 +1067,7 @@ WeightedVarAmong::WeightedVarAmong(unsigned int _arity, int* _scope, istream& fi
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
unsigned int nbValue;
file >> nbValue;
for (unsigned int value = 0; value < nbValue; ++value) {
......@@ -1198,6 +1203,7 @@ WeightedAllDifferent::WeightedAllDifferent(unsigned int _arity, int* _scope, ist
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
//display();
}
......@@ -1252,6 +1258,7 @@ WeightedGcc::WeightedGcc(unsigned int _arity, int* _scope, istream& file)
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
int nbValueToWatch;
file >> nbValueToWatch;
for (int idvalue = 0; idvalue < nbValueToWatch; idvalue++) {
......@@ -1373,6 +1380,7 @@ WeightedSame::WeightedSame(unsigned int _arity, int* _scope, istream& file)
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
if (_arity % 2 == 1) {
cerr << "WeightedSame::Constructor the scope must be even" << endl;
exit(128);
......@@ -1494,6 +1502,7 @@ WeightedSameGcc::WeightedSameGcc(unsigned int _arity, int* _scope, istream& file
: DecomposableGlobalCostFunction(_arity, _scope)
{
file >> semantics >> baseCost;
baseCost *= ToulBar2::costMultiplier;
file >> nbValueToWatch;
for (int idvalue = 0; idvalue < nbValueToWatch; idvalue++) {
Value value;
......
......@@ -31,6 +31,7 @@ void GrammarConstraint::read(istream& file)
string str;
file >> str >> def;
def *= ToulBar2::costMultiplier;
/*if (str == "var") mode = VAR;
else mode = WEIGHTED;*/
......
......@@ -25,6 +25,7 @@ void MaxConstraint::read(istream& file)
// weightMap.resize(n);
file >> def;
def *= ToulBar2::costMultiplier;
/*for(int i = 0; i < n; i++){
EnumeratedVariable * x = scope[i];
for(EnumeratedVariable::iterator it = x->begin(); it != x->end(); ++it)
......
......@@ -417,9 +417,11 @@ void NaryConstraint::separate(EnumeratedVariable* vx, EnumeratedVariable* vz)
int a = arity_;
String t(a, '0'), tX(a - 1, '0'), tZ(a - 1, '0');
int index, k;
EnumeratedVariable* var;
TernaryConstraint *existX = NULL, *existZ = NULL;
Constraint *naryz, *naryx;
EnumeratedVariable* var = NULL;
Constraint *existX = NULL;
Constraint *existZ = NULL;
Constraint *naryx = NULL;
Constraint *naryz = NULL;
EnumeratedVariable* scope_in[a];
EnumeratedVariable* subscopeX[a - 1];
EnumeratedVariable* subscopeZ[a - 1];
......@@ -456,7 +458,12 @@ void NaryConstraint::separate(EnumeratedVariable* vx, EnumeratedVariable* vz)
subscopeZ[a - 2] = vz;
// creation de la nouvelle contrainte
if (a == 4) {
if (a == 3) {
int size = subscopeX[0]->getDomainInitSize() * subscopeX[1]->getDomainInitSize();
vector<Cost> costs(size, 0);
existX = subscopeX[0]->getConstr(subscopeX[1]);
naryx = wcsp->newBinaryConstr(subscopeX[0], subscopeX[1], costs);
} else if (a == 4) {
int size = subscopeX[0]->getDomainInitSize() * subscopeX[1]->getDomainInitSize() * subscopeX[2]->getDomainInitSize();
vector<Cost> costs(size, 0);
existX = subscopeX[0]->getConstr(subscopeX[1], subscopeX[2]);
......@@ -512,8 +519,12 @@ void NaryConstraint::separate(EnumeratedVariable* vx, EnumeratedVariable* vz)
if (ToulBar2::verbose >= 3)
cout << "-----------------------------------" << endl;
if (a == 4) {
if (a == 3) {
int size = subscopeZ[0]->getDomainInitSize() * subscopeZ[1]->getDomainInitSize();
vector<Cost> costs(size, 0);
existZ = subscopeZ[0]->getConstr(subscopeZ[1]);
naryz = wcsp->newBinaryConstr(subscopeZ[0], subscopeZ[1], costs);
} else if (a == 4) {
int size = subscopeZ[0]->getDomainInitSize() * subscopeZ[1]->getDomainInitSize() * subscopeZ[2]->getDomainInitSize();
vector<Cost> costs(size, 0);
existZ = subscopeZ[0]->getConstr(subscopeZ[1], subscopeZ[2]);
......@@ -587,16 +598,26 @@ void NaryConstraint::separate(EnumeratedVariable* vx, EnumeratedVariable* vz)
cout << scopeX[j] << " ";
cout << " ]" << endl;
}
if (a == 4) {
if (a == 3) {
assert(naryx->isBinary());
if (existX && !existX->universal()) {
((TernaryConstraint*)naryx)->addCosts(existX);
assert(existX->isBinary());
((BinaryConstraint*)naryx)->addCosts((BinaryConstraint*)existX);
existX->deconnect();
}
} else if (a == 4) {
assert(naryx->isTernary());
if (existX && !existX->universal()) {
assert(existX->isTernary());
((TernaryConstraint*)naryx)->addCosts((TernaryConstraint*)existX);
existX->deconnect();
}
}
naryx->reconnect();
naryx->propagate();
} else
} else {
naryx->deconnect();
}
if (!naryz->universal()) {
if (ToulBar2::verbose == 1) {
cout << "[ ";
......@@ -604,16 +625,26 @@ void NaryConstraint::separate(EnumeratedVariable* vx, EnumeratedVariable* vz)
cout << scopeZ[j] << " ";
cout << " ]" << endl;
}
if (a == 4) {
if (a == 3) {
assert(naryz->isBinary());
if (existZ && !existZ->universal()) {
assert(existZ->isBinary());
((BinaryConstraint*)naryz)->addCosts((BinaryConstraint*)existZ);
existZ->deconnect();
}
} else if (a == 4) {
assert(naryz->isTernary());
if (existZ && !existZ->universal()) {
((TernaryConstraint*)naryz)->addCosts(existZ);
assert(existZ->isTernary());
((TernaryConstraint*)naryz)->addCosts((TernaryConstraint*)existZ);
existZ->deconnect();
}
}
naryz->reconnect();
naryz->propagate();
} else
} else {
naryz->deconnect();
}
deconnect();
}
......
......@@ -23,7 +23,7 @@ void naryRandom::generateGlobalCtr(vector<int>& indexs, string globalname, Cost
int* scopeIndexs = new int[arity];
Cost Top = wcsp.getUb();
if (costMax < Top)
Top = costMax;
Top = ToulBar2::costMultiplier * costMax;
for (i = 0; i < arity; i++) {
scopeIndexs[i] = indexs[i];
......
......@@ -624,7 +624,7 @@ void WCSP::read_wcsp(const char* fileName)
file >> funcparam1;
file >> funcparam2;
file >> funcparam3;
postDisjunction(i, j, funcparam1, funcparam2, funcparam3);
postDisjunction(i, j, funcparam1, funcparam2, funcparam3 * K);
} else if (funcname == "sdisj") {
Value funcparam3;
Value funcparam4;
......@@ -636,7 +636,7 @@ void WCSP::read_wcsp(const char* fileName)
file >> funcparam4;
file >> funcparam5;
file >> funcparam6;
postSpecialDisjunction(i, j, funcparam1, funcparam2, funcparam3, funcparam4, funcparam5, funcparam6);
postSpecialDisjunction(i, j, funcparam1, funcparam2, funcparam3, funcparam4, funcparam5 * K, funcparam6 * K);
} else {
int scopeIndex[2];
scopeIndex[0] = i;
......
......@@ -22,6 +22,7 @@ void RegularDPConstraint::read(istream& file)
{
string str;
file >> str >> def;
def *= ToulBar2::costMultiplier;
// input the automaton
int nstate;
......
......@@ -30,6 +30,7 @@ void RegularFlowConstraint::read(istream& file)
string str;
file >> str >> def;
def *= ToulBar2::costMultiplier;
/*if (str == "var") {
subdef = def;
insdef = deldef = 0;
......
......@@ -43,6 +43,7 @@ pair<int, int> SameConstraint::mapto(int varindex, Value val)
void SameConstraint::read(istream& file)
{
file >> def;
def *= ToulBar2::costMultiplier;
int size[2];
//cout << "def. value = " << def << endl;
//cout << "consistency level = " << ToulBar2::consistencyLevel << endl;
......
......@@ -303,6 +303,7 @@ typedef enum {
LC_EDAC = 4,
LC_THEMAX
} LcLevelType;
const int MAX_EAC_ITER = 10000;
struct ValueCost {
Value value;
......
......@@ -206,7 +206,7 @@ bool VACExtension::propagate()
breakCycles = 0;
vector<pair<VACVariable*, Value>> acSupport;
static vector<pair<VACVariable*, Value>> acSupport; /// \warning NOT SAFE FOR MULTITHREADING!!!
bool acSupportOK = false;
while ((!util || isvac) && itThreshold != MIN_COST) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment