59 #ifndef TOULBAR2LIB_HPP_ 60 #define TOULBAR2LIB_HPP_ 62 #include "core/tb2types.hpp" 82 virtual string getName()
const = 0;
85 virtual Cost
getLb()
const = 0;
86 virtual Cost
getUb()
const = 0;
91 virtual Double
getDLb()
const = 0;
92 virtual Double
getDUb()
const = 0;
95 virtual void updateUb(Cost newUb) = 0;
109 virtual bool enumerated(
int varIndex)
const = 0;
111 virtual string getName(
int varIndex)
const = 0;
112 virtual Value
getInf(
int varIndex)
const = 0;
113 virtual Value
getSup(
int varIndex)
const = 0;
114 virtual Value
getValue(
int varIndex)
const = 0;
119 virtual Value
toValue(
int varIndex,
unsigned int idx) = 0;
120 virtual unsigned int toIndex(
int varIndex, Value value) = 0;
123 virtual bool assigned(
int varIndex)
const = 0;
124 virtual bool unassigned(
int varIndex)
const = 0;
125 virtual bool canbe(
int varIndex, Value v)
const = 0;
126 virtual bool cannotbe(
int varIndex, Value v)
const = 0;
127 virtual Value
nextValue(
int varIndex, Value v)
const = 0;
129 virtual void increase(
int varIndex, Value newInf) = 0;
130 virtual void decrease(
int varIndex, Value newSup) = 0;
131 virtual void assign(
int varIndex, Value newValue) = 0;
132 virtual void remove(
int varIndex, Value remValue) = 0;
137 virtual void assignLS(vector<int>& varIndexes, vector<Value>& newValues) = 0;
138 virtual void assignLS(
int* varIndexes, Value* newValues,
unsigned int size,
bool dopropagate) = 0;
140 virtual Cost
getUnaryCost(
int varIndex, Value v)
const = 0;
143 virtual Value
getSupport(
int varIndex)
const = 0;
149 virtual int getDegree(
int varIndex)
const = 0;
162 virtual bool verify() = 0;
173 virtual void cartProd(BigInteger& cartesianProduct) = 0;
215 virtual void postUnary(
int xIndex, vector<Cost>& costs) = 0;
216 virtual void postUnaryConstraint(
int xIndex, vector<Cost>& costs) = 0;
217 virtual int postBinaryConstraint(
int xIndex,
int yIndex, vector<Cost>& costs) = 0;
218 virtual int postTernaryConstraint(
int xIndex,
int yIndex,
int zIndex, vector<Cost>& costs) = 0;
219 virtual int postNaryConstraintBegin(
int* scope,
int arity, Cost defval, Long nbtuples = 0) = 0;
221 virtual void postNaryConstraintEnd(
int ctrindex) = 0;
222 virtual int postUnary(
int xIndex, Value* d,
int dsize, Cost penalty) = 0;
223 virtual int postUnaryConstraint(
int xIndex, Value* d,
int dsize, Cost penalty) = 0;
224 virtual int postSupxyc(
int xIndex,
int yIndex, Value cst, Value deltamax = MAX_VAL - MIN_VAL) = 0;
225 virtual int postDisjunction(
int xIndex,
int yIndex, Value cstx, Value csty, Cost penalty) = 0;
226 virtual int postSpecialDisjunction(
int xIndex,
int yIndex, Value cstx, Value csty, Value xinfty, Value yinfty, Cost costx, Cost costy) = 0;
228 virtual int postCliqueConstraint(
int* scopeIndex,
int arity, istream& file) = 0;
230 virtual int postGlobalConstraint(
int* scopeIndex,
int arity,
const string& gcname, istream& file,
int* constrcounter = NULL,
bool mult =
true) = 0;
241 virtual int postWAmong(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost,
242 const vector<Value>& values,
int lb,
int ub)
244 virtual void postWAmong(
int* scopeIndex,
int arity,
string semantics, Cost baseCost, Value* values,
int nbValues,
int lb,
int ub) = 0;
245 virtual void postWVarAmong(
int* scopeIndex,
int arity,
string semantics, Cost baseCost, Value* values,
int nbValues,
int varIndex) = 0;
258 virtual int postWRegular(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost,
260 const vector<WeightedObj<int> >& initial_States,
261 const vector<WeightedObj<int> >& accepting_States,
262 const vector<DFATransition>& Wtransitions)
264 virtual void postWRegular(
int* scopeIndex,
int arity,
int nbStates, vector<pair<int, Cost> > initial_States, vector<pair<int, Cost> > accepting_States,
int** Wtransitions, vector<Cost> transitionsCosts) = 0;
272 virtual int postWAllDiff(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost) = 0;
273 virtual void postWAllDiff(
int* scopeIndex,
int arity,
string semantics, Cost baseCost) = 0;
282 virtual int postWGcc(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost,
283 const vector<BoundedObj<Value> >& values)
285 virtual void postWGcc(
int* scopeIndex,
int arity,
string semantics, Cost baseCost, Value* values,
int nbValues,
int* lb,
int* ub) = 0;
295 virtual int postWSame(
int* scopeIndexG1,
int arityG1,
int* scopeIndexG2,
int arityG2,
const string& semantics,
const string& propagator, Cost baseCost) = 0;
296 virtual void postWSame(
int* scopeIndex,
int arity,
string semantics, Cost baseCost) = 0;
297 virtual void postWSameGcc(
int* scopeIndex,
int arity,
string semantics, Cost baseCost, Value* values,
int nbValues,
int* lb,
int* ub) = 0;
313 virtual int postWGrammarCNF(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost,
316 const vector<CFGProductionRule> WRuleToTerminal)
325 virtual int postMST(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost) = 0;
334 virtual int postMaxWeight(
int* scopeIndex,
int arity,
const string& semantics,
const string& propagator, Cost baseCost,
335 const vector<WeightedVarValPair> weightFunction)
346 virtual void postWSum(
int* scopeIndex,
int arity,
string semantics, Cost baseCost,
string comparator,
int rightRes) = 0;
347 virtual void postWVarSum(
int* scopeIndex,
int arity,
string semantics, Cost baseCost,
string comparator,
int varIndex) = 0;
357 virtual void postWOverlap(
int* scopeIndex,
int arity,
string semantics, Cost baseCost,
string comparator,
int rightRes) = 0;
363 virtual Cost
read_wcsp(
const char* fileName) = 0;
365 virtual void read_random(
int n,
int m, vector<int>& p,
int seed,
bool forceSubModular =
false,
string globalname =
"") = 0;
366 virtual void read_wcnf(
const char* fileName) = 0;
367 virtual void read_qpbo(
const char* fileName) = 0;
369 virtual const vector<Value>&
getSolution(Cost* cost_ptr = NULL) = 0;
370 virtual void setSolution(Cost cost, TAssign* sol = NULL) = 0;
374 virtual void print(ostream& os) = 0;
375 virtual void dump(ostream& os,
bool original =
true) = 0;
381 virtual Cost decimalToCost(
const string& decimalToken,
const unsigned int lineNumber)
const = 0;
382 virtual Double Cost2ADCost(
const Cost& c)
const = 0;
383 virtual Double Cost2RDCost(
const Cost& c)
const = 0;
384 virtual Cost Prob2Cost(TProb p)
const = 0;
385 virtual TProb Cost2Prob(Cost c)
const = 0;
386 virtual TLogProb Cost2LogProb(Cost c)
const = 0;
387 virtual Cost LogProb2Cost(TLogProb p)
const = 0;
388 virtual Cost LogSumExp(Cost c1, Cost c2)
const = 0;
389 virtual TLogProb LogSumExp(TLogProb logc1, Cost c2)
const = 0;
390 virtual TLogProb LogSumExp(TLogProb logc1, TLogProb logc2)
const = 0;
395 virtual void setLb(Cost newLb) = 0;
396 virtual void setUb(Cost newUb) = 0;
397 virtual Cost getNegativeLb()
const = 0;
398 virtual void restoreSolution(Cluster* c = NULL) = 0;
400 virtual void buildTreeDecomposition() = 0;
401 virtual TreeDecomposition* getTreeDec() = 0;
403 virtual void iniSingleton() = 0;
404 virtual void updateSingleton() = 0;
405 virtual void removeSingleton() = 0;
406 virtual int getVACHeuristic() = 0;
407 virtual void printVACStat() = 0;
410 ostream& operator<<(ostream& os,
WeightedCSP& wcsp);
431 virtual Long getNbNodes()
const = 0;
432 virtual Long getNbBacktracks()
const = 0;
434 virtual void increase(
int varIndex, Value value,
bool reverse =
false) = 0;
435 virtual void decrease(
int varIndex, Value value,
bool reverse =
false) = 0;
436 virtual void assign(
int varIndex, Value value,
bool reverse =
false) = 0;
437 virtual void remove(
int varIndex, Value value,
bool reverse =
false) = 0;
490 virtual Cost
read_wcsp(
const char* fileName) = 0;
491 virtual void read_random(
int n,
int m, vector<int>& p,
int seed,
bool forceSubModular =
false,
string globalname =
"") = 0;
497 virtual bool solve() = 0;
505 virtual Cost narycsp(
string cmd, vector<Value>& solution) = 0;
515 virtual bool solve_symmax2sat(
int n,
int m,
int* posx,
int* posy,
double* cost,
int* sol) = 0;
517 virtual void dump_wcsp(
const char* fileName,
bool original =
true) = 0;
518 virtual void read_solution(
const char* fileName,
bool updateValueHeuristic =
true) = 0;
519 virtual void parse_solution(
const char* certificate) = 0;
521 virtual Cost
getSolution(vector<Value>& solution) = 0;
526 virtual set<int> getUnassignedVars()
const = 0;
530 extern void tb2init();
533 extern void tb2checkOptions(Cost initialUpperBound);
Definition: toulbar2lib.hpp:75
virtual void increaseLb(Cost addLb)=0
increases problem lower bound thanks to eg soft local consistencies
virtual int makeIntervalVariable(string n, Value iinf, Value isup)=0
create an interval variable with its domain bounds
virtual Cost getLb() const =0
gets internal dual lower bound
virtual int postWAllDiff(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost)=0
post a soft alldifferent cost function
virtual Long getNbDEE() const =0
number of value removals due to dead-end elimination
virtual int postMaxWeight(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost, const vector< WeightedVarValPair > weightFunction)=0
post a weighted max cost function (maximum cost of a set of unary cost functions associated to a set ...
virtual void postNaryConstraintTuple(int ctrindex, Value *tuple, int arity, Cost cost)=0
virtual void read_wcnf(const char *fileName)=0
load problem in (w)cnf format (see http://www.maxsat.udl.cat/08/index.php?disp=requirements) ...
virtual void postWSum(int *scopeIndex, int arity, string semantics, Cost baseCost, string comparator, int rightRes)=0
post a soft linear constraint with unit coefficients
virtual bool getIsPartOfOptimalSolution()=0
special flag used for debugging purposes only
virtual Double getDUb() const =0
gets problem upper bound as a Double representing a decimal cost
virtual unsigned int numberOfUnassignedVariables() const =0
current number of unassigned variables
virtual Value getSup(int varIndex) const =0
maximum current domain value
virtual unsigned int medianDomainSize() const =0
median current domain size of variables
virtual bool enumerated(int varIndex) const =0
true if the variable has an enumerated domain
virtual void resetWeightedDegree(int varIndex)=0
initialize weighted degree heuristic
virtual void setBestValue(int varIndex, Value v)=0
hint for some value ordering heuristics (only used by RDS)
virtual const vector< Value > & getSolution(Cost *cost_ptr=NULL)=0
returns current best solution and its cost
virtual int getTrueDegree(int varIndex) const =0
degree of a variable
virtual void updateUb(Cost newUb)=0
sets initial problem upper bound and each time a new solution is found
virtual bool isGlobal()=0
true if there are soft global constraints defined in the problem
virtual int postMST(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost)=0
post a Spanning Tree hard constraint
virtual Value getInf(int varIndex) const =0
minimum current domain value
virtual vector< vector< int > > * getListSuccessors()=0
generating additional variables vector created when berge decomposition are included in the WCSP ...
virtual bool getEnumDomain(int varIndex, Value *array)=0
gets current domain values in an array
virtual unsigned int toIndex(int varIndex, Value value)=0
gets index from value (warning! assumes EnumeratedVariable)
virtual void increase(int varIndex, Value newInf)=0
changes domain lower bound
virtual Double getDLb() const =0
gets problem lower bound as a Double representing a decimal cost
virtual unsigned int getDomainSizeSum() const =0
total sum of current domain sizes
virtual void sortConstraints()=0
sorts the list of cost functions associated to each variable based on smallest problem variable index...
virtual Value toValue(int varIndex, unsigned int idx)=0
gets value from index (warning! assumes EnumeratedVariable)
virtual Double getDDualBound() const =0
gets problem dual bound as a Double representing a decimal cost (lower resp. upper bound for minimiza...
virtual void assign(int varIndex, Value newValue)=0
assigns a variable and immediately propagates this assignment
virtual Value getBestValue(int varIndex) const =0
hint for some value ordering heuristics (only used by RDS)
virtual int getMaxDomainSize() const =0
maximum initial domain size found in all variables
virtual string getName() const =0
get WCSP problem name (defaults to filename with no extension)
virtual unsigned int numberOfConnectedConstraints() const =0
current number of cost functions
virtual int postWSame(int *scopeIndexG1, int arityG1, int *scopeIndexG2, int arityG2, const string &semantics, const string &propagator, Cost baseCost)=0
post a soft same cost function (a group of variables being a permutation of another group with the sa...
virtual void propagate()=0
propagates until a fix point is reached (or throws a contradiction)
virtual void setSolution(Cost cost, TAssign *sol=NULL)=0
set best solution from current assigned values or from a given assignment (for BTD-like methods) ...
virtual void setInfiniteCost()=0
updates infinite costs in all cost functions accordingly to the problem global lower and upper bounds...
Definition: toulbar2lib.hpp:423
virtual unsigned int getDomainSize(int varIndex) const =0
current domain size
virtual unsigned int getDomainInitSize(int varIndex) const =0
gets initial domain size (warning! assumes EnumeratedVariable)
virtual void enforceUb()=0
enforces problem upper bound when exploring an alternative search node
virtual Cost getUnaryCost(int varIndex, Value v) const =0
unary cost associated to a domain value
virtual Cost getUb() const =0
gets internal primal upper bound
virtual int postGlobalConstraint(int *scopeIndex, int arity, const string &gcname, istream &file, int *constrcounter=NULL, bool mult=true)=0
virtual void * getSolver() const =0
special hook to access solver information
virtual int getIndex() const =0
instantiation occurrence number of current WCSP object
virtual Value getSupport(int varIndex) const =0
NC/EAC unary support value.
virtual void postWVarSum(int *scopeIndex, int arity, string semantics, Cost baseCost, string comparator, int varIndex)=0
post a soft linear constraint with unit coefficients and variable right-hand side ...
virtual unsigned int medianDegree() const =0
median current degree of variables
virtual void whenContradiction()=0
after a contradiction, resets propagation queues
virtual Value getMaxUnaryCostValue(int varIndex) const =0
a value having the maximum unary cost in the domain
virtual void read_uai2008(const char *fileName)=0
load problem in UAI 2008 format (see http://graphmod.ics.uci.edu/uai08/FileFormat and http://www...
virtual unsigned int numberOfVariables() const =0
number of created variables
virtual Value getValue(int varIndex) const =0
current assigned value
virtual void postWSameGcc(int *scopeIndex, int arity, string semantics, Cost baseCost, Value *values, int nbValues, int *lb, int *ub)=0
post a combination of a same and gcc cost function decomposed as a cost function network ...
virtual unsigned int numberOfConnectedBinaryConstraints() const =0
current number of binary cost functions
virtual int postWAmong(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost, const vector< Value > &values, int lb, int ub)=0
post a soft among cost function
virtual int postWGrammarCNF(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost, int nbSymbols, int startSymbol, const vector< CFGProductionRule > WRuleToTerminal)=0
post a soft/weighted grammar cost function with the dynamic programming propagator and grammar in Cho...
virtual void setIsPartOfOptimalSolution(bool v)=0
special flag used for debugging purposes only
virtual void decrease(int varIndex, Value newSup)=0
changes domain upper bound
virtual void read_qpbo(const char *fileName)=0
load quadratic pseudo-Boolean optimization problem in unconstrained quadratic programming text format...
virtual bool verify()=0
checks the propagation fix point is reached
virtual void dump(ostream &os, bool original=true)=0
output the current WCSP into a file in wcsp format
virtual void print(ostream &os)=0
print current domains and active cost functions (see Output messages, verbosity options and debugging...
virtual Long getWeightedDegree(int varIndex) const =0
weighted degree heuristic
static WeightedCSP * makeWeightedCSP(Cost upperBound, void *solver=NULL)
Weighted CSP factory.
Definition: tb2wcsp.cpp:548
virtual Cost finiteUb() const =0
computes the worst-case assignment finite cost (sum of maximum finite cost over all cost functions pl...
virtual Double getDPrimalBound() const =0
gets problem primal bound as a Double representing a decimal cost (upper resp. lower bound for minimi...
virtual int makeEnumeratedVariable(string n, Value iinf, Value isup)=0
create an enumerated variable with its domain bounds
virtual void postWVarAmong(int *scopeIndex, int arity, string semantics, Cost baseCost, Value *values, int nbValues, int varIndex)=0
post a weighted among cost function with the number of values encoded as a variable with index varInd...
virtual void cartProd(BigInteger &cartesianProduct)=0
Cartesian product of current domain sizes.
virtual unsigned int numberOfConstraints() const =0
initial number of cost functions (before variable elimination)
virtual bool getEnumDomainAndCost(int varIndex, ValueCost *array)=0
gets current domain values and unary costs in an array
virtual void preprocessing()=0
applies various preprocessing techniques to simplify the current problem
virtual int getDegree(int varIndex) const =0
approximate degree of a variable (ie number of active cost functions, see Variable elimination) ...
virtual void read_random(int n, int m, vector< int > &p, int seed, bool forceSubModular=false, string globalname="")=0
create a random WCSP with n variables, domain size m, array p where the first element is a percentage...
virtual Cost read_wcsp(const char *fileName)=0
load problem in all format supported by toulbar2. Returns the UB known to the solver before solving (...
virtual Value nextValue(int varIndex, Value v) const =0
first value after v in the current domain or v if there is no value
virtual int getDACOrder(int varIndex) const =0
index of the variable in the DAC variable ordering
virtual int postWRegular(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost, int nbStates, const vector< WeightedObj< int > > &initial_States, const vector< WeightedObj< int > > &accepting_States, const vector< DFATransition > &Wtransitions)=0
post a soft or weighted regular cost function
virtual void assignLS(vector< int > &varIndexes, vector< Value > &newValues)=0
assigns a set of variables at once and propagates (used by Local Search methods such as Large Neighbo...
virtual Cost getMaxUnaryCost(int varIndex) const =0
maximum unary cost in the domain
virtual void printSolution(ostream &os)=0
prints current best solution
virtual int postWGcc(int *scopeIndex, int arity, const string &semantics, const string &propagator, Cost baseCost, const vector< BoundedObj< Value > > &values)=0
post a soft global cardinality cost function
virtual void postWOverlap(int *scopeIndex, int arity, string semantics, Cost baseCost, string comparator, int rightRes)=0
post a soft overlap cost function (a group of variables being point-wise equivalent – and not equal ...
virtual void postUnary(int xIndex, vector< Cost > &costs)=0