# hub.solver.do_solver.sgs_policies
Domain specification
# BasePolicyMethod
Base options to define Scheduling policies
# FOLLOW_GANTT BasePolicyMethod
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_INDEX_FREEDOM BasePolicyMethod
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.
# SGS_PRECEDENCE BasePolicyMethod
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 BasePolicyMethod
Same as SGS_PRECEDENCE, one of those 2 will be in deprecation soon.
# SGS_STRICT BasePolicyMethod
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 BasePolicyMethod
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.
# PolicyMethodParams
Wrapped params for scheduling policy parameters, see BasePolicyMethod for more details
# Constructor PolicyMethodParams
PolicyMethodParams(
base_policy_method: BasePolicyMethod,
delta_time_freedom = 10,
delta_index_freedom = 10
)
Initialize self. See help(type(self)) for accurate signature.
# complete_with_default_hyperparameters Hyperparametrizable
complete_with_default_hyperparameters(
kwargs: dict[str, Any],
names: Optional[list[str]] = None
)
Add missing hyperparameters to kwargs by using default values
Args:
kwargs: keyword arguments to complete (e.g. for __init__
, init_model
, or solve
)
names: names of the hyperparameters to add if missing.
By default, all available hyperparameters.
Returns: a new dictionary, completion of kwargs
# copy_and_update_hyperparameters Hyperparametrizable
copy_and_update_hyperparameters(
names: Optional[list[str]] = None,
**kwargs_by_name: dict[str, Any]
) -> list[Hyperparameter]
Copy hyperparameters definition of this class and update them with specified kwargs.
This is useful to define hyperparameters for a child class for which only choices of the hyperparameter change for instance.
Args: names: names of hyperparameters to copy. Default to all. **kwargs_by_name: for each hyperparameter specified by its name, the attributes to update. If a given hyperparameter name is not specified, the hyperparameter is copied without further update.
Returns:
# get_default_hyperparameters Hyperparametrizable
get_default_hyperparameters(
names: Optional[list[str]] = None
) -> dict[str, Any]
Get hyperparameters default values.
Args: names: names of the hyperparameters to choose. By default, all available hyperparameters will be suggested.
Returns: a mapping between hyperparameter's name_in_kwargs and its default value (None if not specified)
# get_hyperparameter Hyperparametrizable
get_hyperparameter(
name: str
) -> Hyperparameter
Get hyperparameter from given name.
# get_hyperparameters_by_name Hyperparametrizable
get_hyperparameters_by_name(
) -> dict[str, Hyperparameter]
Mapping from name to corresponding hyperparameter.
# get_hyperparameters_names Hyperparametrizable
get_hyperparameters_names(
) -> list[str]
List of hyperparameters names.
# suggest_hyperparameter_with_optuna Hyperparametrizable
suggest_hyperparameter_with_optuna(
trial: optuna.trial.Trial,
name: str,
prefix: str,
**kwargs
) -> Any
Suggest hyperparameter value during an Optuna trial.
This can be used during Optuna hyperparameters tuning.
Args: trial: optuna trial during hyperparameters tuning name: name of the hyperparameter to choose prefix: prefix to add to optuna corresponding parameter name (useful for disambiguating hyperparameters from subsolvers in case of meta-solvers) **kwargs: options for optuna hyperparameter suggestions
Returns:
kwargs can be used to pass relevant arguments to
- trial.suggest_float()
- trial.suggest_int()
- trial.suggest_categorical()
For instance it can
- add a low/high value if not existing for the hyperparameter or override it to narrow the search. (for float or int hyperparameters)
- add a step or log argument (for float or int hyperparameters, see optuna.trial.Trial.suggest_float())
- override choices for categorical or enum parameters to narrow the search
# suggest_hyperparameters_with_optuna Hyperparametrizable
suggest_hyperparameters_with_optuna(
trial: optuna.trial.Trial,
names: Optional[list[str]] = None,
kwargs_by_name: Optional[dict[str, dict[str, Any]]] = None,
fixed_hyperparameters: Optional[dict[str, Any]] = None,
prefix: str
) -> dict[str, Any]
Suggest hyperparameters values during an Optuna trial.
Args:
trial: optuna trial during hyperparameters tuning
names: names of the hyperparameters to choose.
By default, all available hyperparameters will be suggested.
If fixed_hyperparameters
is provided, the corresponding names are removed from names
.
kwargs_by_name: options for optuna hyperparameter suggestions, by hyperparameter name
fixed_hyperparameters: values of fixed hyperparameters, useful for suggesting subbrick hyperparameters,
if the subbrick class is not suggested by this method, but already fixed.
Will be added to the suggested hyperparameters.
prefix: prefix to add to optuna corresponding parameters
(useful for disambiguating hyperparameters from subsolvers in case of meta-solvers)
Returns:
mapping between the hyperparameter name and its suggested value.
If the hyperparameter has an attribute name_in_kwargs
, this is used as the key in the mapping
instead of the actual hyperparameter name.
the mapping is updated with fixed_hyperparameters
.
kwargs_by_name[some_name] will be passed as **kwargs to suggest_hyperparameter_with_optuna(name=some_name)
# PolicyRCPSP
Policy object containing results of scheduling solver policy.
# Attributes
- domain: scheduling domain where the policy will be applied
- policy_method_params: params of the policy
- permutation_task: list of tasks ids, representing a priority list for scheduling
- modes_dictionnary: when relevant (multimode rcpsp for e.g) specifies in which mode a task is executed
- schedule: when given, details the schedule to follow : this will be relevant for deterministic scheduling problems
- resource_allocation: when relevant (multiskill problems for e.g), list the allocated (unitary) resources to the tasks
- resource_allocation_priority: for each task, store a preference order for resources to be allocated to the task. Resource will be greedily allocated based on this priority
# Constructor PolicyRCPSP
PolicyRCPSP(
domain: SchedulingDomain,
policy_method_params: PolicyMethodParams,
permutation_task: list[int],
modes_dictionnary: dict[int, int],
schedule: Optional[dict[int, dict[str, int]]] = None,
resource_allocation: Optional[dict[int, list[str]]] = None,
resource_allocation_priority: Optional[dict[int, list[str]]] = None
)
Initialize self. See help(type(self)) for accurate signature.
# get_next_action DeterministicPolicies
get_next_action(
self,
observation: StrDict[D.T_observation]
) -> StrDict[list[D.T_event]]
Get the next deterministic action (from the solver's current policy).
# Parameters
- observation: The observation for which next action is requested.
# Returns
The next deterministic action.
# get_next_action_distribution UncertainPolicies
get_next_action_distribution(
self,
observation: StrDict[D.T_observation]
) -> Distribution[StrDict[list[D.T_event]]]
Get the probabilistic distribution of next action for the given observation (from the solver's current policy).
# Parameters
- observation: The observation to consider.
# Returns
The probabilistic distribution of next action.
# is_policy_defined_for Policies
is_policy_defined_for(
self,
observation: StrDict[D.T_observation]
) -> bool
Check whether the solver's current policy is defined for the given observation.
# Parameters
- observation: The observation to consider.
# Returns
True if the policy is defined for the given observation memory (False otherwise).
# sample_action Policies
sample_action(
self,
observation: StrDict[D.T_observation]
) -> StrDict[list[D.T_event]]
Sample an action for the given observation (from the solver's current policy).
# Parameters
- observation: The observation for which an action must be sampled.
# Returns
The sampled action.
# _get_next_action DeterministicPolicies
_get_next_action(
self,
observation: StrDict[D.T_observation]
) -> StrDict[list[D.T_event]]
Get the next deterministic action (from the solver's current policy).
# Parameters
- observation: The observation for which next action is requested.
# Returns
The next deterministic action.
# _get_next_action_distribution UncertainPolicies
_get_next_action_distribution(
self,
observation: StrDict[D.T_observation]
) -> Distribution[StrDict[list[D.T_event]]]
Get the probabilistic distribution of next action for the given observation (from the solver's current policy).
# Parameters
- observation: The observation to consider.
# Returns
The probabilistic distribution of next action.
# _is_policy_defined_for Policies
_is_policy_defined_for(
self,
observation: StrDict[D.T_observation]
) -> bool
Check whether the solver's current policy is defined for the given observation.
# Parameters
- observation: The observation to consider.
# Returns
True if the policy is defined for the given observation memory (False otherwise).
# _sample_action Policies
_sample_action(
self,
observation: StrDict[D.T_observation]
) -> StrDict[list[D.T_event]]
Sample an action for the given observation (from the solver's current policy).
# Parameters
- observation: The observation for which an action must be sampled.
# Returns
The sampled action.
# next_action_follow_static_gantt
next_action_follow_static_gantt(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
**kwargs
)
Implements the policy with the parameters FOLLOW_GANTT (see its doc)
# next_action_sgs_first_task_precedence_ready
next_action_sgs_first_task_precedence_ready(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
**kwargs
)
Implements the policy with the parameters SGS_PRECEDENCE (see its doc)
# next_action_sgs_first_task_ready
next_action_sgs_first_task_ready(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
domain_sk_decide: Union[MultiModeRCPSP, SingleModeRCPSP] = None,
**kwargs
)
Implements the policy with the parameters SGS_READY (see its doc)
# next_action_sgs_strict
next_action_sgs_strict(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
domain_sk_decide: Union[MultiModeRCPSP, SingleModeRCPSP] = None,
**kwargs
)
Implements the policy with the parameters SGS_STRICT (see its doc)
# next_action_sgs_time_freedom
next_action_sgs_time_freedom(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
domain_sk_decide: Union[MultiModeRCPSP, SingleModeRCPSP] = None,
delta_time_freedom: int = 10,
**kwargs
)
Implements the policy with the parameters SGS_TIME_FREEDOM (see its doc)
# next_action_sgs_index_freedom
next_action_sgs_index_freedom(
policy_rcpsp: PolicyRCPSP,
state: State,
check_if_applicable: bool = False,
domain_sk_decide: Union[MultiModeRCPSP, SingleModeRCPSP] = None,
delta_index_freedom: int = 10,
**kwargs
)
Implements the policy with the parameters SGS_INDEX_FREEDOM (see its doc)