AlexK73
AlexK73

Reputation: 1

extract score immediately after solving start

If we give an initialized solution to timefold, it displays a current score, e.g., -3hard, -40soft.

How can we extract the detailed score information of this initial solution, either before solving starts, or right after solving has started?

We know how to extract the score of a solution.


How can example code be produced for an API thought to have gone missing? After finding the solution ourselves, we know what original OPTAPY code we should have posted:

    def solve_live(self) -> None:
        """
        https://docs.optaplanner.org/latestFinal/optaplanner-javadoc/org/optaplanner/core/api/solver/SolverManager.html#solveAndListen(ProblemId_,java.util.function.Function,java.util.function.Consumer)
        SolverJob<Solution_,ProblemId_> solveAndListen(ProblemId_ problemId,
           Function<? super ProblemId_,? extends Solution_> problemFinder,
           Consumer<? super Solution_> bestSolutionConsumer,
           Consumer<? super Solution_> finalBestSolutionConsumer,
           BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
        """
        self.job = self.context.solver_manager.solveAndListen(self.id,
                # Called once, when solving starts
                lambda the_id: self.find_by_id(the_id),
                # Called multiple times, for every best solution change
                lambda solution: self.save(solution),
                lambda solution: self.save(solution),
                lambda the_id, exc: self.exception(the_id, exc)
                )

timefold:

    def solve_live(self) -> None:
        self.job = self.context.solver_manager.solve_and_listen(self.id,
                generate_problem(self.context._inputfile),
                # Called multiple times, for every best solution change
                lambda solution: self.save(solution)
                )

Upvotes: -8

Views: 69

Answers (1)

AlexK73
AlexK73

Reputation: 1

Optapy code can get the initial score from a call-back which vanished in timefold.

We did overlook, that the initial generated problem in timefold is a solution which includes a score even without being handled by any solve_and_listen, first. This seems to be different semantically from optapy.

Solution is to store the initial problem, of course:

self.solution_initial = generate_problem(self.context._inputfile)

Upvotes: 0

Related Questions