IsKan
IsKan

Reputation: 17

Getting partial results from Optapy solver during running time

I am using the Optapy library in python for school timetabling optimisation. I am trying to solve complex problem, which demand long time of solving. Is there any option to get partial results during running the solver? For example, I define the termination time for 1 week and I want to get the partial results achieved so far by the algorithm everyday during this week.

Help appreciated.

Upvotes: 0

Views: 144

Answers (1)

Christopher Chianelli
Christopher Chianelli

Reputation: 2013

In order to get the best solution found so far, use Solver Event listeners, which are called whenever the Solver finds a new best solution. If you are using the SolverFactory API, it would look like this:

score_list = []
solution_list = []

def on_best_solution_changed(event):
    solution_list.append(event.getNewBestSolution())
    score_list.append(event.getNewBestScore())

solver = optapy.solver_factory_create(solver_config).buildSolver()
solver.addEventListener(on_best_solution_changed)
solution = solver.solve(problem)

If you are using the SolverManager API it would look like this:

solution_list = []

def on_best_solution_changed(solution):
    solution_list.append(solution)

solver_job = solver_manager.solve(1, get_problem, on_best_solution_changed)

Upvotes: 1

Related Questions