After creating a Weighted CSP, it can be solved using a local search method INCOP (see WeightedCSPSolver::narycsp) and/or an exact search method (see WeightedCSPSolver::solve).
Various options of the solving methods are controlled by ::Toulbar2 static class members (see files ./src/core/tb2types.hpp and ./src/tb2main.cpp).
A brief code example reading a wcsp problem given as a single command-line parameter and solving it:
#include "toulbar2lib.hpp"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
tb2init();
initCosts();
ToulBar2::verbose = -1;
vector<Value> sol;
cout << "Best solution found cost: " << ub << endl;
cout << "Best solution found:";
for (unsigned int i=0; i<sol.size(); i++) cout << ((i>0)?",":"") << " x" << i << " = " << sol[i];
cout << endl;
} else {
cout << "No solution found!" << endl;
}
delete solver;
}
Definition: toulbar2lib.hpp:458
virtual Cost read_wcsp(const char *fileName)=0
reads a Cost function network from a file (format as indicated by ToulBar2:: global variables)
static WeightedCSPSolver * makeWeightedCSPSolver(Cost initUpperBound)
WeightedCSP Solver factory.
Definition: tb2solver.cpp:30
virtual bool solve(bool first=true)=0
simplifies and solves to optimality the problem
virtual const vector< Value > getSolution()=0
after solving the problem, return the optimal solution (warning! do not use it if doing solution coun...
- See also
- another code example in ./src/toulbar2test.cpp
- Warning
- variable domains must start at zero, otherwise recompile libtb2.so without flag WCSPFORMATONLY