ObjectiveFunction objFunc = new ObjectiveFunction(literals,
coefficients);
solver.setObjectiveFunction(objFunc);
/* Solve */
IOptimizationProblem op = (IOptimizationProblem) solver;
int[] model = null;
try {
if (deadline != Long.MAX_VALUE) {
solver.setTimeoutMs(deadline - System.currentTimeMillis());
}
long stepref = System.nanoTime();
while (System.currentTimeMillis() < deadline
&& !Thread.currentThread().isInterrupted()
&& op.admitABetterSolution()) {
model = solver.model();
GraphColoring<V, E> coloring = this.getColoring(colors,
vertices, numberOfVertices, model);
long now = System.nanoTime();
LOGGER.debug(
"solution found with {} colors and objective value {} in {}/{} ns",
new Object[] { coloring.getNumberOfColors(),
op.getObjectiveValue(), now - stepref,
now - baseref });
if (listener != null) {
listener.handle(this, coloring);
}
op.discardCurrentSolution();
stepref = System.nanoTime();
long nextTO = Math.max(0,
deadline - System.currentTimeMillis());
solver.setTimeoutMs(nextTO);
LOGGER.debug("timeout set to {} ms", nextTO);