toulbar2
Public Member Functions | Static Public Member Functions | List of all members
WeightedCSPSolver Class Referenceabstract

Public Member Functions

virtual WeightedCSPgetWCSP ()=0
 access to its associated Weighted CSP
 
virtual Long getNbNodes () const =0
 number of search nodes (see WeightedCSPSolver::increase, WeightedCSPSolver::decrease, WeightedCSPSolver::assign, WeightedCSPSolver::remove)
 
virtual Long getNbBacktracks () const =0
 number of backtracks
 
virtual void increase (int varIndex, Value value, bool reverse=false)=0
 changes domain lower bound and propagates
 
virtual void decrease (int varIndex, Value value, bool reverse=false)=0
 changes domain upper bound and propagates
 
virtual void assign (int varIndex, Value value, bool reverse=false)=0
 assigns a variable and propagates
 
virtual void remove (int varIndex, Value value, bool reverse=false)=0
 removes a domain value and propagates (valid if done for an enumerated variable or on its domain bounds)
 
virtual Cost read_wcsp (const char *fileName)=0
 reads a Cost function netwrok from a file (format as indicated by ToulBar2:: global variables)
 
virtual void read_random (int n, int m, vector< int > &p, int seed, bool forceSubModular=false, string globalname="")=0
 create a random WCSP, see WeightedCSP::read_random
 
virtual bool solve ()=0
 simplifies and solves to optimality the problem More...
 
virtual Cost narycsp (string cmd, vector< Value > &solution)=0
 solves the current problem using INCOP local search solver by Bertrand Neveu More...
 
virtual bool solve_symmax2sat (int n, int m, int *posx, int *posy, double *cost, int *sol)=0
 quadratic unconstrained pseudo-Boolean optimization Maximize $h' \times W \times h$ where $W$ is expressed by all its non-zero half squared matrix costs (can be positive or negative, with $\forall i, posx[i] \leq posy[i]$) More...
 
virtual void dump_wcsp (const char *fileName, bool original=true)=0
 output current problem in a file More...
 
virtual void read_solution (const char *fileName, bool updateValueHeuristic=true)=0
 read a solution from a file
 
virtual void parse_solution (const char *certificate)=0
 read a solution from a string (see ToulBar2 option -x)
 
virtual Cost getSolution (vector< Value > &solution)=0
 after solving the problem, add the optimal solution in the input/output vector and returns its optimum cost (warning! do not use it if doing solution counting or if there is no solution, see WeightedCSPSolver::solve output for that)
 

Static Public Member Functions

static WeightedCSPSolvermakeWeightedCSPSolver (Cost initUpperBound)
 WeightedCSP Solver factory.
 

Detailed Description

Abstract class WeightedCSPSolver representing a WCSP solver

Member Function Documentation

◆ dump_wcsp()

virtual void WeightedCSPSolver::dump_wcsp ( const char *  fileName,
bool  original = true 
)
pure virtual

output current problem in a file

See also
WeightedCSP::dump

◆ narycsp()

virtual Cost WeightedCSPSolver::narycsp ( string  cmd,
vector< Value > &  solution 
)
pure virtual

solves the current problem using INCOP local search solver by Bertrand Neveu

Returns
best solution cost found
Parameters
cmdcommand line argument for narycsp INCOP local search solver (cmd format: lowerbound randomseed nbiterations method nbmoves neighborhoodchoice neighborhoodchoice2 minnbneighbors maxnbneighbors neighborhoodchoice3 autotuning tracemode)
solutionbest solution assignment found (MUST BE INITIALIZED WITH A DEFAULT COMPLETE ASSIGNMENT)
Warning
cannot solve problems with global cost functions
Note
side-effects: updates current problem upper bound and propagates, best solution saved (using WCSP::setBestValue)

◆ solve()

virtual bool WeightedCSPSolver::solve ( )
pure virtual

simplifies and solves to optimality the problem

Returns
false if there is no solution found
Warning
after solving, the current problem has been modified by various preprocessing techniques
DO NOT READ VALUES OF ASSIGNED VARIABLES USING WeightedCSP::getValue (temporally wrong assignments due to variable elimination in preprocessing) BUT USE WeightedCSPSolver::getSolution INSTEAD

◆ solve_symmax2sat()

virtual bool WeightedCSPSolver::solve_symmax2sat ( int  n,
int  m,
int *  posx,
int *  posy,
double *  cost,
int *  sol 
)
pure virtual

quadratic unconstrained pseudo-Boolean optimization Maximize $h' \times W \times h$ where $W$ is expressed by all its non-zero half squared matrix costs (can be positive or negative, with $\forall i, posx[i] \leq posy[i]$)

Note
costs for $posx \neq posy$ are multiplied by 2 by this method
by convention: $h = 1 \equiv x = 0$ and $h = -1 \equiv x = 1$
Warning
does not allow infinite costs (no forbidden assignments, unconstrained optimization)
Returns
true if at least one solution has been found (array sol being filled with the best solution)
See also
::solvesymmax2sat_ for Fortran call