Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacobolo committed Feb 15, 2024
1 parent 0506920 commit 95a9baf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ from factryengine import Task, Resource, Scheduler
resource = Resource(id=1, available_windows=[(0,10)])

# Creating Task objects
task1 = Task(id=1, duration=3, priority=2, resources=[[resource]])
task2 = Task(id=2, duration=5, priority=1, resources=[[resource]], predecessors=[task1])
task1 = Task(id=1, duration=3, priority=2, constraints=[resource])
task2 = Task(id=2, duration=5, priority=1, constraints=[resource], predecessor_ids=[1])

# Creating a Scheduler object and scheduling the tasks
scheduler = Scheduler(tasks=[task1, task2])
scheduler = Scheduler(tasks=[task1, task2], resources=[resource])
scheduler_result = scheduler.schedule()
```

Expand Down
66 changes: 48 additions & 18 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Usage

The `factryengine` package contains three main components: `Resource`, `Task`, and `Scheduler`. Below is the documentation for using each of these components.
The `factryengine` package contains three main components: `Resource`, `ResourceGroup`, `Assignment`, `Task`, and `Scheduler`. Below is the documentation for using each of these components.

## Resource
## Resource and ResourceGroup

The `Resource` class is used to represent a resource in the scheduling problem. Below is an example of how to create a `Resource` object.

Expand All @@ -21,6 +21,41 @@ resource = Resource(
- `id` (`int`): Unique identifier for the resource.
- `available_windows` (`list[tuple[int, int]]`): List of available windows for the resource represented as tuples of start and end times.

---

We can put multiple resources into a group which can be used for dynamic assignments.

```python
from factryengine import ResourceGroup

# create resource objects
operator1 = Resource(
id=2,
available_windows=[(0, 5), (10, 15)],
)
operator2 = Resource(
id=3,
available_windows=[(0, 5), (10, 15)],
)

# add them to resource group

operators = ResourceGroup([operator1, operator2])
```

## Assignment

Assignments are used for allocating resources to tasks dynamically. You dont need to hardcode the resources you can instead select a pool of resource that could do the task. The algorithm will select the subset which finishes the task the fastest.

```python
from factryengine import Assignment

assignment = Assignment(resource_groups=(operators), resource_count=1)
```
- `resource_groups` (`list[ResouceGroup]`): The resource groups which can be picked from. If multiple resource groups are added then the fastest completing resourcegroup will be selected.
- `resource_count` (`int`): The maximum number of resources which may be selected.
- `use_all_resources` (`bool`): if you want to allow to use all resources in a group then simple set use_all_resources to True.

## Task

The `Task` class is used to represent a task in the scheduling problem. Below is an example of how to create a `Task` object, reusing the `resource` object created above.
Expand All @@ -33,9 +68,9 @@ task = Task(
id=1,
duration=5,
priority=1,
resources=[[resource]],
resource_count=1,
predecessors=[],
constraints=[resource],
assigments=[assignment]
predecessor_ids=[1],
predecessor_delay=0,
)
```
Expand All @@ -45,26 +80,21 @@ task = Task(
- `id` (`int | str`): Unique identifier for the task.
- `duration` (`int`): Duration of the task with a constraint of being greater than 0.
- `priority` (`int`): Priority of the task with a constraint of being greater than 0.
- `resources` (`list[set[Resource]]`): List of sets of resources required by the task.
- `resource_count` (`int | str`): Number of resources required by the task.
- `predecessors` (`list["Task"]`): List of predecessor tasks.
- `constraints` (`set[Resource]`): Are resource which are required througout the task.
- `assignments` (list[Assignment]): Are used to dynamically assign resources to tasks. If 2 resources are allocated, the task will finish twice as fast.

- `predecessor_ids` (`list[int]`): List of predecessor task ids.
- `predecessor_delay` (`int`): Buffer time after the completion of predecessor tasks before the current task can commence, must be greater than 0.

!!! tip
Resource count allows you to specifiy to use all resources specified:
```python
resource_count = "all"
```

## Scheduler

The `Scheduler` class is used to schedule tasks based on their priorities, durations, and resources. Below is an example of how to use the `Scheduler` class, reusing the `task` object created above.
The `Scheduler` class is used to schedule tasks based on their priorities, durations, and resources. Below is an example of how to use the `Scheduler` class, reusing the `task` and `resource` objects created above.

```python
from factryengine import Scheduler

# Creating a Scheduler object
scheduler = Scheduler(tasks=[task])
scheduler = Scheduler(tasks=[task], resources = [resource])

# Scheduling the tasks
scheduler_result = scheduler.schedule()
Expand Down Expand Up @@ -96,10 +126,10 @@ Here's a simple example:
from factryengine import Task, Resource

# Task with lower priority
task1 = Task(id=1, duration=3, priority=2, resources=[[resource]])
task1 = Task(id=1, duration=3, priority=2, constraints=[[resource]])

# Task with higher priority, but depends on task1
task2 = Task(id=2, duration=5, priority=1, resources=[[resource]], predecessors=[task1])
task2 = Task(id=2, duration=5, priority=1, constraints=[[resource]], predecessors_ids=[1])
```

In this case, even though `task2` has higher priority, `task1` will be scheduled first because `task2` depends on it.

0 comments on commit 95a9baf

Please sign in to comment.