Skip to content

Commit

Permalink
Adapt to do 0.5.0
Browse files Browse the repository at this point in the history
Full renaming of modules and classes in do 0.5.0 (to come).
  • Loading branch information
nhuet authored and g-poveda committed Oct 18, 2024
1 parent a13d22d commit 88cce97
Show file tree
Hide file tree
Showing 10 changed files with 1,941 additions and 1,970 deletions.
13 changes: 8 additions & 5 deletions examples/scheduling/rcpsp_examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from discrete_optimization.rcpsp.rcpsp_solvers import CP_MRCPSP_MZN, CP_RCPSP_MZN
from discrete_optimization.rcpsp.solvers_map import (
CpMultimodeRcpspSolver,
CpRcpspSolver,
)

from examples.scheduling.rcpsp_datasets import get_complete_path
from examples.scheduling.rcpsp_multiskill_datasets import get_data_available_ms
Expand Down Expand Up @@ -33,11 +36,11 @@ def random_walk():
print("end times: ")
for task_id in states[-1].tasks_details.keys():
print("end task", task_id, ": ", states[-1].tasks_details[task_id].end)
from discrete_optimization.rcpsp.rcpsp_utils import (
import matplotlib.pyplot as plt
from discrete_optimization.rcpsp.utils import (
plot_resource_individual_gantt,
plot_ressource_view,
plot_task_gantt,
plt,
)

from skdecide.hub.solver.do_solver.sk_to_do_binding import (
Expand All @@ -63,7 +66,7 @@ def do_singlemode():
delta_index_freedom=0,
delta_time_freedom=0,
),
do_solver_type=CP_RCPSP_MZN,
do_solver_type=CpRcpspSolver,
)
solver.solve()
states, actions, values = rollout(
Expand Down Expand Up @@ -92,7 +95,7 @@ def do_multimode():
delta_index_freedom=0,
delta_time_freedom=0,
),
do_solver_type=CP_MRCPSP_MZN,
do_solver_type=CpMultimodeRcpspSolver,
)
solver.solve()
states, actions, values = rollout(
Expand Down
8 changes: 4 additions & 4 deletions examples/scheduling/toy_rcpsp_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ def run_astar():
)

do_sol = from_last_state_to_solution(states[-1], domain)
from discrete_optimization.rcpsp.rcpsp_utils import (
import matplotlib.pyplot as plt
from discrete_optimization.rcpsp.utils import (
plot_resource_individual_gantt,
plot_ressource_view,
plot_task_gantt,
plt,
)

plot_task_gantt(do_sol.problem, do_sol)
Expand Down Expand Up @@ -528,11 +528,11 @@ def run_do():
)

do_sol = from_last_state_to_solution(states[-1], domain)
from discrete_optimization.rcpsp.rcpsp_utils import (
import matplotlib.pyplot as plt
from discrete_optimization.rcpsp.utils import (
plot_resource_individual_gantt,
plot_ressource_view,
plot_task_gantt,
plt,
)

plot_task_gantt(do_sol.problem, do_sol)
Expand Down
2 changes: 1 addition & 1 deletion notebooks/13_scheduling_tuto.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@
"from skdecide.hub.solver.do_solver.sk_to_do_binding import from_last_state_to_solution\n",
"\n",
"do_sol = from_last_state_to_solution(states[-1], domain)\n",
"from discrete_optimization.rcpsp.rcpsp_utils import plot_ressource_view, plot_task_gantt\n",
"from discrete_optimization.rcpsp.utils import plot_ressource_view, plot_task_gantt\n",
"\n",
"# Each line of the plot is a task\n",
"fig_gantt = plot_task_gantt(do_sol.problem, do_sol)\n",
Expand Down
3,752 changes: 1,860 additions & 1,892 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ matplotlib = { version = ">=3.3.4", optional = true }
joblib = { version = ">=1.0.1", optional = true }
stable-baselines3 = { version = ">=2.0.0", optional = true }
ray = { extras = ["rllib"], version = ">=2.9.0", optional = true }
discrete-optimization = { version = ">=0.4.0" }
discrete-optimization = { version = ">=0.5.0" }
openap = { version = ">=1.5", python = ">=3.9", optional = true }
pygeodesy = { version = ">=23.6.12", optional = true }
unified-planning = { version = ">=1.1.0", python = ">=3.10", optional = true }
Expand Down
10 changes: 4 additions & 6 deletions skdecide/hub/domain/rcpsp/rcpsp_sk_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

def load_domain(file_path):
""""""
from discrete_optimization.rcpsp.rcpsp_model import RCPSPModel
from discrete_optimization.rcpsp.rcpsp_parser import parse_file
from discrete_optimization.rcpsp.parser import parse_file
from discrete_optimization.rcpsp.problem import RcpspProblem

from skdecide.hub.domain.rcpsp.rcpsp_sk import MRCPSP, RCPSP

rcpsp_model: RCPSPModel = parse_file(file_path)
rcpsp_model: RcpspProblem = parse_file(file_path)
if not rcpsp_model.is_rcpsp_multimode():
my_domain = RCPSP(
resource_names=rcpsp_model.resources_list,
Expand Down Expand Up @@ -50,9 +50,7 @@ def load_domain(file_path):


def load_multiskill_domain(file_path):
from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill_parser import (
parse_file,
)
from discrete_optimization.rcpsp_multiskill.parser import parse_file

model_msrcpsp, new_tame_to_original_task_id = parse_file(
file_path, max_horizon=2000
Expand Down
49 changes: 25 additions & 24 deletions skdecide/hub/solver/do_solver/do_solver_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from discrete_optimization.generic_tools.result_storage.result_storage import (
ResultStorage,
)
from discrete_optimization.rcpsp.rcpsp_model import RCPSPModel, RCPSPSolution
from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill import (
MS_RCPSPModel,
MS_RCPSPSolution,
MS_RCPSPSolution_Variant,
from discrete_optimization.rcpsp.problem import RcpspProblem, RcpspSolution
from discrete_optimization.rcpsp_multiskill.problem import (
MultiskillRcpspProblem,
MultiskillRcpspSolution,
VariantMultiskillRcpspSolution,
)

from skdecide import Domain
Expand Down Expand Up @@ -78,22 +78,21 @@ def build_solver(
A class of do-solver, associated with some default parameters to be passed to its constructor and solve function
(and potentially init_model function)
"""
if isinstance(do_domain, RCPSPModel):
from discrete_optimization.rcpsp.rcpsp_solvers import (
look_for_solver,
solvers_map,
)
if isinstance(do_domain, RcpspProblem):
from discrete_optimization.rcpsp.solvers_map import look_for_solver, solvers_map

do_domain_cls = RCPSPModel
elif isinstance(do_domain, MS_RCPSPModel):
from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill_solvers import (
do_domain_cls = RcpspProblem
elif isinstance(do_domain, MultiskillRcpspProblem):
from discrete_optimization.rcpsp_multiskill.solvers_map import (
look_for_solver,
solvers_map,
)

do_domain_cls = MS_RCPSPModel
do_domain_cls = MultiskillRcpspProblem
else:
raise ValueError("do_domain should be either a RCPSPModel or a MS_RCPSPModel.")
raise ValueError(
"do_domain should be either a RcpspProblem or a MultiskillRcpspProblem."
)
available = look_for_solver(do_domain)
if solver_type is not None:
if solver_type in solvers_map:
Expand All @@ -114,7 +113,9 @@ def build_solver(


def from_solution_to_policy(
solution: Union[RCPSPSolution, MS_RCPSPSolution, MS_RCPSPSolution_Variant],
solution: Union[
RcpspSolution, MultiskillRcpspSolution, VariantMultiskillRcpspSolution
],
domain: SchedulingDomain,
policy_method_params: PolicyMethodParams,
) -> PolicyRCPSP:
Expand All @@ -125,7 +126,7 @@ def from_solution_to_policy(
schedule = None
resource_allocation = None
resource_allocation_priority = None
if isinstance(solution, RCPSPSolution):
if isinstance(solution, RcpspSolution):
permutation_task = sorted(
solution.rcpsp_schedule,
key=lambda x: (solution.rcpsp_schedule[x]["start_time"], x),
Expand All @@ -137,7 +138,7 @@ def from_solution_to_policy(
modes_dictionnary[solution.problem.n_jobs_non_dummy + 2] = 1
for i in range(len(solution.rcpsp_modes)):
modes_dictionnary[i + 2] = solution.rcpsp_modes[i]
elif isinstance(solution, MS_RCPSPSolution):
elif isinstance(solution, MultiskillRcpspSolution):
permutation_task = sorted(
solution.schedule, key=lambda x: (solution.schedule[x]["start_time"], x)
)
Expand All @@ -149,7 +150,7 @@ def from_solution_to_policy(
] # warning here...
for task in solution.employee_usage
}
if isinstance(solution, MS_RCPSPSolution_Variant):
if isinstance(solution, VariantMultiskillRcpspSolution):
resource_allocation_priority = solution.priority_worker_per_task
modes_dictionnary = {}
# set modes for start and end (dummy) jobs
Expand Down Expand Up @@ -219,15 +220,15 @@ def __init__(

def get_available_methods(self, domain: SchedulingDomain):
do_domain = build_do_domain(domain)
if isinstance(do_domain, (MS_RCPSPModel)):
from discrete_optimization.rcpsp_multiskill.rcpsp_multiskill_solvers import (
if isinstance(do_domain, (MultiskillRcpspProblem)):
from discrete_optimization.rcpsp_multiskill.solvers_map import (
look_for_solver,
solvers_map,
)

available = look_for_solver(do_domain)
elif isinstance(do_domain, RCPSPModel):
from discrete_optimization.rcpsp.rcpsp_solvers import (
elif isinstance(do_domain, RcpspProblem):
from discrete_optimization.rcpsp.solvers_maps import (
look_for_solver,
solvers_map,
)
Expand Down Expand Up @@ -263,7 +264,7 @@ def _solve(self) -> None:
self.solver.init_model(**copy_dict_params)

result_storage = self.solver.solve(callbacks=callbacks, **copy_dict_params)
best_solution: RCPSPSolution = result_storage.get_best_solution()
best_solution: RcpspSolution = result_storage.get_best_solution()

assert best_solution is not None

Expand Down
14 changes: 7 additions & 7 deletions skdecide/hub/solver/do_solver/gphh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from discrete_optimization.generic_tools.hyperparameters.hyperparametrizable import (
Hyperparametrizable,
)
from discrete_optimization.rcpsp.rcpsp_model import RCPSPSolution
from discrete_optimization.rcpsp.solver.cpm import CPM
from discrete_optimization.rcpsp.problem import RcpspSolution
from discrete_optimization.rcpsp.solvers.cpm import CpmRcpspSolver
from scipy import stats
from scipy.spatial import distance

Expand Down Expand Up @@ -172,7 +172,7 @@ def feature_precedence_done(


def compute_cpm(do_domain):
cpm_solver = CPM(do_domain)
cpm_solver = CpmRcpspSolver(do_domain)
path = cpm_solver.run_classic_cpm()
cpm = cpm_solver.map_node
cpm_esd = cpm[path[-1]]._ESD # to normalize...
Expand Down Expand Up @@ -727,7 +727,7 @@ def evaluate_heuristic(self, individual, domains) -> float:
if normalized_values[i] not in {1, len(normalized_values)}
]

solution = RCPSPSolution(
solution = RcpspSolution(
problem=do_model,
rcpsp_permutation=normalized_values_for_do,
rcpsp_modes=modes,
Expand Down Expand Up @@ -941,7 +941,7 @@ def _get_next_action(
for j in scheduled_tasks_start_times
if j not in tasks_complete_dict
}
solution = RCPSPSolution(
solution = RcpspSolution(
problem=do_model,
rcpsp_permutation=normalized_values_for_do,
rcpsp_modes=modes,
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def _get_next_action(

if run_sgs:

solution = RCPSPSolution(
solution = RcpspSolution(
problem=do_model,
rcpsp_permutation=normalized_values_for_do,
rcpsp_modes=modes,
Expand Down Expand Up @@ -1218,7 +1218,7 @@ def _get_next_action(

if run_sgs:

solution = RCPSPSolution(
solution = RcpspSolution(
problem=do_model,
rcpsp_permutation=normalized_values_for_do,
rcpsp_modes=modes,
Expand Down
Loading

0 comments on commit 88cce97

Please sign in to comment.