Heuristics

Heuristic Agents

This module provides the following scheduling heuristics as function:

  • EDD: earliest due date

  • SPT: shortest processing time first

  • MTR: most tasks remaining

  • LTR: least tasks remaining

  • Random: random action

You can implement additional heuristics in this file by specifying a function that takes a list of tasks and an action mask and returns the index of the job to be scheduled next.

If you want to call your heuristic via the HeuristicSelectionAgent or edit an existing shortcut, adapt/extend the task_selection dict attribute of the HeuristicSelectionAgent class.

Example

Add a heuristic that returns zeros (this is not a practical example!) 1. Define the according function

def return_0_heuristic(tasks: List[Task], action_mask: np.array) -> int:
    return 0
  1. Add the function to the task_selection dict within the HeuristicSelectionAgent class:

self.task_selections = {
    'rand': random_task,
    'EDD': edd,
    'SPT': spt,
    'MTR': mtr,
    'LTR': ltr,
    'ZERO': return_0_heuristic
}
agents.heuristic.heuristic_agent.get_active_task_dict(tasks: List[Task]) dict

Helper function to determining the next unfinished task to be processed for each job

Parameters

tasks – List of task objects, so one instance

Returns

Dictionary containing the next tasks to be processed for each job

Would be an empty dictionary if all tasks were completed

agents.heuristic.heuristic_agent.edd(tasks: List[Task], action_mask: array) int

EDD: earliest due date. Determines the job with the smallest deadline

Parameters
  • tasks – List of task objects, so one instance

  • action_mask – Action mask from the environment that is to receive the action selected by this heuristic

Returns

Index of the job selected according to the heuristic

agents.heuristic.heuristic_agent.spt(tasks: List[Task], action_mask: array) int

SPT: shortest processing time first. Determines the job of which the next unfinished task has the lowest runtime

Parameters
  • tasks – List of task objects, so one instance

  • action_mask – Action mask from the environment that is to receive the action selected by this heuristic

Returns

Index of the job selected according to the heuristic

agents.heuristic.heuristic_agent.mtr(tasks: List[Task], action_mask: array) int

MTR: most tasks remaining. Determines the job with the least completed tasks

Parameters
  • tasks – List of task objects, so one instance

  • action_mask – Action mask from the environment that is to receive the action selected by this heuristic

Returns

Index of the job selected according to the heuristic

agents.heuristic.heuristic_agent.ltr(tasks: List[Task], action_mask: array) int

LTR: least tasks remaining. Determines the job with the most completed tasks

Parameters
  • tasks – List of task objects, so one instance

  • action_mask – Action mask from the environment that is to receive the action selected by this heuristic

Returns

Index of the job selected according to the heuristic

agents.heuristic.heuristic_agent.random_task(tasks: List[Task], action_mask: array) int

Returns a random task

Parameters
  • tasks – Not needed

  • action_mask – Action mask from the environment that is to receive the action selected by this heuristic

Returns

Index of the job selected according to the heuristic

agents.heuristic.heuristic_agent.choose_random_machine(chosen_task, machine_mask) int

Determines a random machine which is available according to the mask and chosen task. Useful for the FJSSP.

Parameters
  • chosen_task – ID of the task that is scheduled on the selected machine

  • machine_mask – Machine mask from the environment that is to receive the machine action chosen by this function

Returns

Index of the chosen machine

agents.heuristic.heuristic_agent.choose_first_machine(chosen_task, machine_mask) int

Determines the first (by index) machine which is available according to the mask and chosen task. Useful for the FJSSP

Parameters
  • chosen_task – ID of the task that is scheduled on the selected machine

  • machine_mask – Machine mask from the environment that is to receive the machine action chosen by this function

Returns

Index of the chosen machine

class agents.heuristic.heuristic_agent.HeuristicSelectionAgent

Bases: object

This class can be used to get the next task according to the heuristic passed as string abbreviation (e.g. EDD). If you want to edit a shortcut, or add one for your custom heuristic, adapt/extend the task_selection dict.

Example

def my_custom_heuristic():
    ...<function body>...

or

self.task_selections = {
    'rand': random_task,
    'XYZ': my_custom_heuristic
    }
__init__() None