Source code for discrete_optimization.generic_rcpsp_tools.solvers.lns_cp.postpro_ls

#  Copyright (c) 2022 AIRBUS and its affiliates.
#  This source code is licensed under the MIT license found in the
#  LICENSE file in the root directory of this source tree.

from discrete_optimization.generic_rcpsp_tools.solvers.ls import (
    LsGenericRcpspSolver,
    LsSolverType,
)
from discrete_optimization.generic_rcpsp_tools.typing import ANY_RCPSP
from discrete_optimization.generic_tools.do_problem import (
    ParamsObjectiveFunction,
    build_aggreg_function_and_params_objective,
)
from discrete_optimization.generic_tools.lns_cp import PostProcessSolution
from discrete_optimization.generic_tools.result_storage.result_storage import (
    ResultStorage,
)
from discrete_optimization.rcpsp_multiskill.problem import (
    PreemptiveMultiskillRcpspSolution,
    schedule_solution_preemptive_to_variant,
)


[docs] class LocalSearchPostProcessSolution(PostProcessSolution): def __init__( self, problem: ANY_RCPSP, params_objective_function: ParamsObjectiveFunction = None, **kwargs ): self.problem = problem self.params_objective_function = params_objective_function ( self.aggreg_from_sol, self.aggreg_from_dict, self.params_objective_function, ) = build_aggreg_function_and_params_objective( problem=self.problem, params_objective_function=self.params_objective_function, ) self.dict_params = kwargs
[docs] def build_other_solution(self, result_storage: ResultStorage) -> ResultStorage: solver = LsGenericRcpspSolver(problem=self.problem, ls_solver=LsSolverType.SA) s = result_storage.get_best_solution().copy() if isinstance(s, PreemptiveMultiskillRcpspSolution): s = schedule_solution_preemptive_to_variant(s) if self.problem != s.problem: s.change_problem(self.problem) result_store = solver.solve( nb_iteration_max=self.dict_params.get("nb_iteration_max", 200), init_solution=s, ) solution, f = result_store.get_last_best_solution() result_storage += [(solution, self.aggreg_from_sol(solution))] return result_storage