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();
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;
}
- See also
- another code example in ./src/toulbar2test.cpp
- Warning
- variable domains must start at zero, otherwise recompile libtb2.so without flag WCSPFORMATONLY