Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update existing enumerations doc and class attributes doc #377

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions skdecide/builders/domain/scheduling/scheduling_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@


class SchedulingObjectiveEnum(Enum):
"""
Enum defining the different scheduling objectives:
- MAKESPAN: makespan (to be minimize)
- COST: cost of resources (to be minimized)
"""
"""Enum defining the different scheduling objectives"""

MAKESPAN = 0
COST = 1


SchedulingObjectiveEnum.MAKESPAN.__doc__ = "makespan (to be minimized)"
SchedulingObjectiveEnum.COST.__doc__ = "cost of resources (to be minimized)"


class D(
Domain,
SingleAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ def __copy__(self):


class SchedulingActionEnum(Enum):
"""
Enum defining the different types of scheduling actions:
- START: start a task
- PAUSE: pause a task
- RESUME: resume a task
- TIME_PR: do not apply actions on tasks and progress in time
"""
"""Enum defining the different types of scheduling actions"""

START = 0
PAUSE = 1
RESUME = 2
TIME_PR = 3


SchedulingActionEnum.START.__doc__ = "start a task"
SchedulingActionEnum.PAUSE.__doc__ = "pause a task"
SchedulingActionEnum.RESUME.__doc__ = "resume a task"
SchedulingActionEnum.TIME_PR.__doc__ = (
"do not apply actions on tasks and progress in time"
)


class State:
"""Class modelling a scheduling state and used by sk-decide scheduling domains.

Expand Down
150 changes: 75 additions & 75 deletions skdecide/hub/domain/rcpsp/rcpsp_sk.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ class D(MultiModeRCPSP):


class MRCPSP(D):
"""
Multimode RCPSP domain
"""Multimode RCPSP domain

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks/modes :
format is the following : {task_id: {mode_1: {"duration": 2, "res_1": 1}, mode_2: {"duration": 3, "res_2": 2}}}
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its (constant) capacity
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks/modes :
format is the following : {task_id: {mode_1: {"duration": 2, "res_1": 1}, mode_2: {"duration": 3, "res_2": 2}}}
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its (constant) capacity
resource_renewable: for each resource, indicates if it's renewable or not
"""

def __init__(
Expand Down Expand Up @@ -110,18 +110,18 @@ class D(MultiModeRCPSPCalendar):


class MRCPSPCalendar(D):
"""
Multimode RCPSP with calendars domain
"""Multimode RCPSP with calendars domain

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks/modes :
format is the following : {task_id: {mode_1: {"duration": 2, "res_1": 1}, mode_2: {"duration": 3, "res_2": 2}}}
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its capacity through time as a list of integer
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks/modes :
format is the following : {task_id: {mode_1: {"duration": 2, "res_1": 1}, mode_2: {"duration": 3, "res_2": 2}}}
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its capacity through time as a list of integer
resource_renewable: for each resource, indicates if it's renewable or not
"""

def _get_quantity_resource(self, resource: str, time: int, **kwargs) -> int:
Expand Down Expand Up @@ -195,18 +195,18 @@ def _get_objectives(self) -> List[int]:


class RCPSP(MRCPSP, SingleMode):
"""
Monomode RCPSP domain
"""Monomode RCPSP domain

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"duration": 2, "res_1": 1}}, only 1 mode in this template
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its constant capacity
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"duration": 2, "res_1": 1}}, only 1 mode in this template
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its constant capacity
resource_renewable: for each resource, indicates if it's renewable or not
"""

def __init__(
Expand Down Expand Up @@ -238,18 +238,18 @@ def _get_tasks_mode(self) -> Dict[int, ModeConsumption]:


class RCPSPCalendar(MRCPSPCalendar, SingleMode):
"""
Monomode RCPSP with calendars domain
"""Monomode RCPSP with calendars domain

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"duration": 2, "res_1": 1}}, only 1 mode in this template
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its capacity through time
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"duration": 2, "res_1": 1}}, only 1 mode in this template
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its capacity through time
resource_renewable: for each resource, indicates if it's renewable or not
"""

def __init__(
Expand Down Expand Up @@ -281,19 +281,19 @@ def _get_tasks_mode(self) -> Dict[int, ModeConsumption]:


class Stochastic_RCPSP(MultiModeRCPSP_Stochastic_Durations):
"""
Stochastic RCPSP
"""Stochastic RCPSP

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"res_1": 1}, 2: {"res_1": 2}}
- duration_distribution: dictionary giving distribution of task duration function of mode.
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its constant capacity
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"res_1": 1}, 2: {"res_1": 2}}
duration_distribution: dictionary giving distribution of task duration function of mode.
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its constant capacity
resource_renewable: for each resource, indicates if it's renewable or not
"""

def _get_max_horizon(self) -> int:
Expand Down Expand Up @@ -427,19 +427,19 @@ class D(MultiModeRCPSPCalendar_Stochastic_Durations):


class SMRCPSPCalendar(D):
"""
Stochastic RCPSP With calendars domain
"""Stochastic RCPSP With calendars domain

# Attributes
- resource_names: list of resource names
- task_ids: list of tasks ids
- tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"res_1": 1}, 2: {"res_1": 2}}
- duration_distribution: dictionary giving distribution of task duration function of mode.
- successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
- max_horizon: the max horizon for scheduling
- resource_availability: for each resource, gives its variable capacity
- resource_renewable: for each resource, indicates if it's renewable or not
resource_names: list of resource names
task_ids: list of tasks ids
tasks_mode: dictionary giving details of resource consumption and duration for each tasks :
format is the following : {task_id: {1: {"res_1": 1}, 2: {"res_1": 2}}
duration_distribution: dictionary giving distribution of task duration function of mode.
successors: dictionary of precedence constraint:
format is the following {task_id: List[task_id]}, where the values are the list of successor task of a given task_id
max_horizon: the max horizon for scheduling
resource_availability: for each resource, gives its variable capacity
resource_renewable: for each resource, indicates if it's renewable or not
"""

def _get_task_duration_distribution(
Expand Down Expand Up @@ -525,14 +525,14 @@ class D(MultiModeMultiSkillRCPSP):


class MSRCPSP(D):
"""
Multi-skill RCPSP domain
"""Multi-skill RCPSP domain

# Attributes
-skills_names: list of skills id
-resource_unit_names: list of unitary skilled resource
-resource_type_names: list of cumulative resource
-resource_skills: for each resource_unit and skills store the skill level
-others : see classical RCPSP doc
skills_names: list of skills id
resource_unit_names: list of unitary skilled resource
resource_type_names: list of cumulative resource
resource_skills: for each resource_unit and skills store the skill level
others : see classical RCPSP doc
"""

def __init__(
Expand Down
23 changes: 14 additions & 9 deletions skdecide/hub/solver/do_solver/do_solver_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ class D(SchedulingDomain):


class SolvingMethod(Enum):
"""
- PILE : solve scheduling problem with greedy queue method
- GA : solve scheduling problem with genetic algorithm
- LS : solve scheduling problem with local search algorithm (hill climber or simulated annealing)
- LP : solve scheduling problem with constraint programming solver
- CP : solve scheduling problem with constraint programming solver
- LNS_LP : solve scheduling problem with large neighborhood search + LP solver
- LNS_CP : solve scheduling problem with large neighborhood search + CP solver
"""
"""Type of discrete-optimization algorithm to use"""

PILE = "greedy"
GA = "ga"
Expand All @@ -52,6 +44,19 @@ class SolvingMethod(Enum):
LNS_CP = "lns-scheduling"


SolvingMethod.PILE.__doc__ = "solve scheduling problem with greedy queue method"
SolvingMethod.GA.__doc__ = "solve scheduling problem with genetic algorithm"
SolvingMethod.LS.__doc__ = "solve scheduling problem with local search algorithm (hill climber or simulated annealing)"
SolvingMethod.LP.__doc__ = "solve scheduling problem with linear programming solver"
SolvingMethod.CP.__doc__ = "solve scheduling problem with constraint programming solver"
SolvingMethod.LNS_LP.__doc__ = (
"solve scheduling problem with large neighborhood search + LP solver"
)
SolvingMethod.LNS_CP.__doc__ = (
"solve scheduling problem with large neighborhood search + CP solver"
)


def build_solver(
solving_method: SolvingMethod, do_domain: Problem
) -> Tuple[SolverDO, Dict[str, Any]]:
Expand Down
56 changes: 34 additions & 22 deletions skdecide/hub/solver/do_solver/sgs_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,7 @@


class BasePolicyMethod(Enum):
"""Base options to define Scheduling policies

# Attributes
- FOLLOW_GANTT: Strictly return scheduling policy based on the gantt chart.
Based on the time stored in the state, task are started at the right time.
- SGS_PRECEDENCE: At a given state, look for the first available task in an ordered permutation
that is start-able and do it. If no activity is launchable, just advance in time.
- SGS_READY: [Same as SGS_PRECEDENCE, one of those 2 will be in deprecation]
- SGS_STRICT: At a given state, look for the first task in the permutation that is not started or scheduled yet,
If it's not available to start yet, we advance in time until it is. Warning : this will only work
when the permutation of tasks fulfills the precedence constraints.
- SGS_TIME_FREEDOM: At a given state, look for the first task "TASK" in the permutation that is not started or scheduled yet,
If it's not available to start yet, some other task are considered candidates based their time
closeness to the starting time of "TASK", the policy will consider starting task that are close to
the one that was first expected. ```delta_time_freedom``` is the parameter that impacts this setting.
- SGS_INDEX_FREEDOM: At a given state, look for the first task "TASK" in the permutation that is not started or scheduled yet,
If it's not available to start yet, some other task are considered candidates based their "ordering"
closeness to the starting time of "TASK", the policy will consider starting task that are close to
the one that was first expected. ```delta_index_freedom``` is the parameter that impacts this setting.
# Parameters
memory: The memory to set internally.
"""
"""Base options to define Scheduling policies"""

FOLLOW_GANTT = 0
SGS_PRECEDENCE = 1
Expand All @@ -54,6 +33,39 @@ class BasePolicyMethod(Enum):
SGS_INDEX_FREEDOM = 5


BasePolicyMethod.FOLLOW_GANTT.__doc__ = """
Strictly return scheduling policy based on the gantt chart.
Based on the time stored in the state, task are started at the right time.
"""
BasePolicyMethod.SGS_PRECEDENCE.__doc__ = """
At a given state, look for the first available task
in an ordered permutation that is start-able and do it.
If no activity is launchable, just advance in time.
"""
BasePolicyMethod.SGS_READY.__doc__ = """
Same as SGS_PRECEDENCE, one of those 2 will be in deprecation soon.
"""
BasePolicyMethod.SGS_STRICT.__doc__ = """
At a given state, look for the first task in the permutation that is not started or scheduled yet.
If it's not available to start yet, we advance in time until it is.

!!! warning
This will only work when the permutation of tasks fulfills the precedence constraints.
"""
BasePolicyMethod.SGS_TIME_FREEDOM.__doc__ = """
At a given state, look for the first task "TASK" in the permutation that is not started or scheduled yet,
If it's not available to start yet, some other task are considered candidates based their time
closeness to the starting time of "TASK", the policy will consider starting task that are close to
the one that was first expected. ```delta_time_freedom``` is the parameter that impacts this setting.
"""
BasePolicyMethod.SGS_INDEX_FREEDOM.__doc__ = """
At a given state, look for the first task "TASK" in the permutation that is not started or scheduled yet,
If it's not available to start yet, some other task are considered candidates based their "ordering"
closeness to the starting time of "TASK", the policy will consider starting task that are close to
the one that was first expected. ```delta_index_freedom``` is the parameter that impacts this setting.
"""


class PolicyMethodParams:
"""Wrapped params for scheduling policy parameters, see BasePolicyMethod for more details"""

Expand Down
18 changes: 9 additions & 9 deletions skdecide/hub/solver/pile_policy_scheduling/pile_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@


class GreedyChoice(Enum):
"""Enumeration representing different greedy method to use in PilePolicy

Attributes:
MOST_SUCCESSORS (int): Start first the tasks that have the most successors in the precedence graph
SAMPLE_MOST_SUCCESSORS (int): Sample next task to schedule based on a probability weight proportional
to its number of successors in the precedence graph.
FASTEST (int): Schedule first the task that has the lowest duration
TOTALLY_RANDOM (int): Sample random next task to schedule next.
"""
"""Enumeration representing different greedy method to use in PilePolicy"""

MOST_SUCCESSORS = 1
SAMPLE_MOST_SUCCESSORS = 2
FASTEST = 3
TOTALLY_RANDOM = 4


GreedyChoice.MOST_SUCCESSORS.__doc__ = (
"Start first the tasks that have the most successors in the precedence graph"
)
GreedyChoice.SAMPLE_MOST_SUCCESSORS.__doc__ = "Sample next task to schedule based on a probability weight proportional to its number of successors in the precedence graph"
GreedyChoice.FASTEST.__doc__ = "Schedule first the task that has the lowest duration"
GreedyChoice.TOTALLY_RANDOM.__doc__ = "Sample random next task to schedule next"


class PilePolicy(Solver, DeterministicPolicies):
T_domain = D

Expand Down
Loading