Expose solver stats and info programatically
Currently, the Solver class exposes several methods that can be used to get insight into different solver metrics: void printStat(PrintWriter out, String prefix) void printStat(PrintStream out, String prefix) int nVars() void printLearntClausesInfos(PrintWriter out, String prefix) void printInfos(PrintWriter out, String prefix) Map<String, Number> getStat() long getTimeoutMs() int realNumberOfVariables() int nConstraints()
While some of these methods may be used while building constraints, most of them return information about the problem being represented and status of the solving process. Furthermore, some of this information can't be accessed programatically, but printed to a Stream or Writer.
The proposal would be to create an interface that provides methods for retrieving all these information and add a method in Solver that returns an implementation of this interface. Ideally, all the printXXX methods could be moved from Solver into another class that would receive this interface.
Here is a possible draft of this interface: public interface SolverStats { int numberOfVars(); int realNumberOfVars(); int nContraints();
void observeStats(StatObserver observer); void observeConstraintTypes(ConstraintTypeObserver observer); void observeLearnedConstraintTypes(ConstraintTypeObserver observer); }
public interface StatObserver { public void observe(String stat, Number value); // or a method per value type }
public interface ConstraintTypeObserver { public void observe(String type, int count); }