Skip to content

Commit

Permalink
Revert "update toulbar solvers: callback well called at start end end…
Browse files Browse the repository at this point in the history
… of solver calls"

This reverts commit 43670ee.
  • Loading branch information
g-poveda committed Nov 29, 2024
1 parent 43670ee commit ced908d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
10 changes: 2 additions & 8 deletions discrete_optimization/facility/solvers/toulbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ def init_model_boolean_variable(self, **kwargs):
"""
nb_facilities = self.problem.facility_count
nb_customers = self.problem.customer_count
if "vns" in kwargs:
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8), vns=kwargs["vns"])
else:
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8))
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8))
x: Dict[Tuple[int, int], Union[int, Any]] = {}
key_to_index = {}
index = 0
Expand Down Expand Up @@ -136,10 +133,7 @@ def init_model_integer_variable(self, **kwargs):
"""
nb_facilities = self.problem.facility_count
nb_customers = self.problem.customer_count
if "vns" in kwargs:
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8), vns=kwargs["vns"])
else:
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8))
model = pytoulbar2.CFN(kwargs.get("upper_bound", 10e8))
index = 0
matrix_fc_indicator, matrix_length = prune_search_space(
self.problem, n_cheapest=nb_facilities, n_shortest=nb_facilities
Expand Down
7 changes: 1 addition & 6 deletions discrete_optimization/generic_tools/toulbar_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import logging

from discrete_optimization.generic_tools.callbacks.callback import CallbackList
from discrete_optimization.generic_tools.do_solver import SolverDO
from discrete_optimization.generic_tools.hyperparameters.hyperparameter import (
CategoricalHyperparameter,
Expand Down Expand Up @@ -54,16 +53,12 @@ def solve(
) -> ResultStorage:
if self.model is None:
self.init_model(**kwargs)
callback = CallbackList(callbacks)
callback.on_solve_start(solver=self)
solution = self.model.Solve(showSolutions=1, timeLimit=int(time_limit))
logger.info(
f"Solution value = {solution[1]}, bound={self.model.GetDDualBound()}"
)
sol = self.retrieve_solution(solution)
res = self.create_result_storage([(sol, self.aggreg_from_sol(sol))])
callback.on_solve_end(res=res, solver=self)
return res
return self.create_result_storage([(sol, self.aggreg_from_sol(sol))])


def to_lns_toulbar(cls: Type[ToulbarSolver]):
Expand Down
6 changes: 2 additions & 4 deletions discrete_optimization/rcpsp/solvers/toulbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ def init_model(self, **kwargs: Any) -> None:
)
raise exc
if "vns" in kwargs:
model = pytoulbar2.CFN(
ubinit=kwargs.get("ub", self.problem.horizon), vns=kwargs["vns"]
)
model = pytoulbar2.CFN(ubinit=self.problem.horizon, vns=kwargs["vns"])
else:
model = pytoulbar2.CFN(ubinit=kwargs.get("ub", self.problem.horizon))
model = pytoulbar2.CFN(ubinit=self.problem.horizon)
n_jobs = self.problem.n_jobs
horizon = self.problem.horizon
index_var = 0
Expand Down

0 comments on commit ced908d

Please sign in to comment.