Skip to content

Commit

Permalink
Removing dead code and print
Browse files Browse the repository at this point in the history
  • Loading branch information
galleon committed Oct 23, 2021
1 parent 0463728 commit 9dad62f
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 523 deletions.
24 changes: 1 addition & 23 deletions skdecide/builders/domain/scheduling/scheduling_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,28 +646,6 @@ def get_possible_starting_tasks(self, state: State):
if all(m in state.tasks_complete
for m in set(self.ancestors[n]).intersection(self.get_available_tasks(state)))]

# possible_task_precedence = [(n, mode)
# for n in state.tasks_remaining
# for mode in self.get_task_modes(n).keys()
# if all(m in state.tasks_complete
# for m in self.ancestors[n])]

# print("Possible task precedence : ", possible_task_precedence)

# possible_with_time_window_start = [(n, mode)
# for n, mode in possible_task_precedence
# if (state.t >= self.get_time_window()[n].earliest_start)
# and (state.t <= self.get_time_window()[n].latest_start)
# ]

# TODO: Below - Make sure the foreseen end time of task is within the end TW - how to sample the duration for uncertain env?
# should we add a function get_latest_sampled_duration() to state ?
# possible_with_time_window_end = [(n, mode)
# for n, mode in possible_with_time_window_start
# if (state.t+state.tasks_details[n].sampled_duration >= self.get_time_window()[n].earliest_end)
# and (state.t+state.tasks_details[n].sampled_duration <= self.get_time_window()[n].latest_end)
# ]

possible_task_with_ressource = [(n, mode)
for n, mode in possible_task_precedence
if all(state.resource_availability[key] -
Expand Down Expand Up @@ -887,7 +865,7 @@ def _get_next_state_distribution(self, memory: D.T_memory[D.T_state],
return DeterministicTransitions._get_next_state_distribution(self, memory, action)

"""
Scheduling action space that will work for domains that don't require any
Scheduling action space that will work for domains that don't require any
ressource unit allocation in its formulation.
"""
class SchedulingActionSpace(EnumerableSpace[SchedulingAction], SamplableSpace[SchedulingAction]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,6 @@ def __eq__(self, other):
return self.__hash__() == other.__hash__()


# class SamplableAction:
# """
# [Deprecated and soon will disappear probably]
# Can be used to define all sub-actions that can happen at one point in time. Resource allocation can be managed.
# These actions are not enumerable due to their fine grain definition. They can only be sampled.
#
# E.g.
# action_tasks = {2: 'action': SamplableActionEnum.START, 'resources': [], 'mode': 1
# 4: 'action': SamplableActionEnum.START, 'resources': ['ru_1', 'ru_2'], 'mode': None
# 5: 'action': SamplableActionEnum.PAUSE, 'resources': [], 'mode': None
# 6: 'action': SamplableActionEnum.REALLOCATE, 'resources': ['ru_3', 'ru_4'], 'mode': None
# }
# """
# action_tasks: Dict[int, Dict[str, Any]]
#
# def __init__(self, action_tasks: Dict[int, Dict[str, Any]]):
# self.action_tasks = action_tasks


class SchedulingAction:
"""
Can be used to define actions on single task. Resource allocation can only be managed through changes in the mode.
Expand Down
26 changes: 1 addition & 25 deletions skdecide/discrete_optimization/generic_tools/lns_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,13 @@ def solve_lns(self,
best_solution = init_solution.copy()

satisfy = self.problem.satisfy(init_solution)
print("Satisfy ", satisfy)
best_objective = objective
else:
best_objective = float('inf') if sense==ModeOptim.MINIMIZATION else -float("inf")
best_solution = None
constraint_iterable = {"empty": []}
store_lns = None
for iteration in range(nb_iteration_lns):
print('Starting iteration n°', iteration,
" current objective ", best_objective)
with self.cp_solver.instance.branch() as child:
if iteration == 0 and not skip_first_iteration or iteration >= 1:
constraint_iterable = self.constraint_handler \
Expand All @@ -99,16 +96,10 @@ def solve_lns(self,
result = child.solve(timeout=timedelta(seconds=parameters_cp.TimeLimit),
intermediate_solutions=parameters_cp.intermediate_solution)
result_store = self.cp_solver.retrieve_solutions(result, parameters_cp=parameters_cp)
print("iteration n°", iteration, "Solved !!!")
print(result.status)
if len(result_store.list_solution_fits) > 0:
print("Solved !!!")
bsol, fit = result_store.get_best_solution_fit()
print("Fitness = ", fit)
print("Post Process..")
result_store = self.post_process_solution.build_other_solution(result_store)
bsol, fit = result_store.get_best_solution_fit()
print("After postpro = ", fit)
if sense == ModeOptim.MAXIMIZATION and fit >= best_objective:
if fit > best_objective:
current_nb_iteration_no_improvement = 0
Expand All @@ -131,30 +122,15 @@ def solve_lns(self,
store_lns = result_store
for s, f in result_store.list_solution_fits:
store_lns.add_solution(solution=s, fitness=f)
print("Satisfy : ", self.problem.satisfy(best_solution))
else:
current_nb_iteration_no_improvement += 1
except Exception as e:
current_nb_iteration_no_improvement += 1
print("Failed ! reason : ", e)
if time.time() - deb_time > max_time_seconds:
print("Finish LNS with time limit reached")
break
print(current_nb_iteration_no_improvement, "/", nb_iteration_no_improvement)
if current_nb_iteration_no_improvement > nb_iteration_no_improvement:
print("Finish LNS with maximum no improvement iteration ")
break
# Useless to remove the constraints with the "with", the constraints are only active inside the with.
# print('Removing constraint:')
# # self.constraint_handler.remove_constraints_from_previous_iteration(cp_solver=self.cp_solver,
# # child_instance=child,
# # previous_constraints=constraint_iterable)
# print('Adding constraint:')
# constraint_iterable = self.constraint_handler.adding_constraint_from_results_store(cp_solver=
# self.cp_solver,
# child_instance=child,
# result_storage=
# store_lns)

return store_lns


Expand Down
9 changes: 1 addition & 8 deletions skdecide/discrete_optimization/generic_tools/lns_mip.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,10 @@ def solve_lns(self,
for iteration in range(nb_iteration_lns):
result_store = self.milp_solver.solve(parameters_milp=parameters_milp,
**args)
print("Solved !!!")
bsol, fit = result_store.get_best_solution_fit()
print("Fitness = ", fit)
print("Post Process..")

result_store = self.post_process_solution.build_other_solution(result_store)
bsol, fit = result_store.get_best_solution_fit()
print("After postpro = ", fit)
if sense == ModeOptim.MAXIMIZATION and fit >= best_objective:
if fit > best_objective:
current_nb_iteration_no_improvement = 0
Expand All @@ -126,19 +123,15 @@ def solve_lns(self,
store_lns = result_store
for s, f in result_store.list_solution_fits:
store_lns.add_solution(solution=s, fitness=f)
print('Removing constraint:')
self.constraint_handler.remove_constraints_from_previous_iteration(milp_solver=self.milp_solver,
previous_constraints=constraint_iterable)
print('Adding constraint:')
constraint_iterable = self.constraint_handler.adding_constraint_from_results_store(milp_solver=
self.milp_solver,
result_storage=
result_store)
if time.time()-deb_time > max_time_seconds:
print("Finish LNS with time limit reached")
break
if current_nb_iteration_no_improvement > nb_iteration_no_improvement:
print("Finish LNS with maximum no improvement iteration ")
break
return store_lns

Expand Down
Loading

0 comments on commit 9dad62f

Please sign in to comment.