Skip to content

Commit 95a9baf

Browse files
committed
update docs
1 parent 0506920 commit 95a9baf

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ from factryengine import Task, Resource, Scheduler
3030
resource = Resource(id=1, available_windows=[(0,10)])
3131

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

3636
# Creating a Scheduler object and scheduling the tasks
37-
scheduler = Scheduler(tasks=[task1, task2])
37+
scheduler = Scheduler(tasks=[task1, task2], resources=[resource])
3838
scheduler_result = scheduler.schedule()
3939
```
4040

docs/usage.md

+48-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Usage
22

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

5-
## Resource
5+
## Resource and ResourceGroup
66

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

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

24+
---
25+
26+
We can put multiple resources into a group which can be used for dynamic assignments.
27+
28+
```python
29+
from factryengine import ResourceGroup
30+
31+
# create resource objects
32+
operator1 = Resource(
33+
id=2,
34+
available_windows=[(0, 5), (10, 15)],
35+
)
36+
operator2 = Resource(
37+
id=3,
38+
available_windows=[(0, 5), (10, 15)],
39+
)
40+
41+
# add them to resource group
42+
43+
operators = ResourceGroup([operator1, operator2])
44+
```
45+
46+
## Assignment
47+
48+
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.
49+
50+
```python
51+
from factryengine import Assignment
52+
53+
assignment = Assignment(resource_groups=(operators), resource_count=1)
54+
```
55+
- `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.
56+
- `resource_count` (`int`): The maximum number of resources which may be selected.
57+
- `use_all_resources` (`bool`): if you want to allow to use all resources in a group then simple set use_all_resources to True.
58+
2459
## Task
2560

2661
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.
@@ -33,9 +68,9 @@ task = Task(
3368
id=1,
3469
duration=5,
3570
priority=1,
36-
resources=[[resource]],
37-
resource_count=1,
38-
predecessors=[],
71+
constraints=[resource],
72+
assigments=[assignment]
73+
predecessor_ids=[1],
3974
predecessor_delay=0,
4075
)
4176
```
@@ -45,26 +80,21 @@ task = Task(
4580
- `id` (`int | str`): Unique identifier for the task.
4681
- `duration` (`int`): Duration of the task with a constraint of being greater than 0.
4782
- `priority` (`int`): Priority of the task with a constraint of being greater than 0.
48-
- `resources` (`list[set[Resource]]`): List of sets of resources required by the task.
49-
- `resource_count` (`int | str`): Number of resources required by the task.
50-
- `predecessors` (`list["Task"]`): List of predecessor tasks.
83+
- `constraints` (`set[Resource]`): Are resource which are required througout the task.
84+
- `assignments` (list[Assignment]): Are used to dynamically assign resources to tasks. If 2 resources are allocated, the task will finish twice as fast.
85+
86+
- `predecessor_ids` (`list[int]`): List of predecessor task ids.
5187
- `predecessor_delay` (`int`): Buffer time after the completion of predecessor tasks before the current task can commence, must be greater than 0.
52-
53-
!!! tip
54-
Resource count allows you to specifiy to use all resources specified:
55-
```python
56-
resource_count = "all"
57-
```
5888

5989
## Scheduler
6090

61-
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.
91+
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.
6292

6393
```python
6494
from factryengine import Scheduler
6595

6696
# Creating a Scheduler object
67-
scheduler = Scheduler(tasks=[task])
97+
scheduler = Scheduler(tasks=[task], resources = [resource])
6898

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

98128
# Task with lower priority
99-
task1 = Task(id=1, duration=3, priority=2, resources=[[resource]])
129+
task1 = Task(id=1, duration=3, priority=2, constraints=[[resource]])
100130

101131
# Task with higher priority, but depends on task1
102-
task2 = Task(id=2, duration=5, priority=1, resources=[[resource]], predecessors=[task1])
132+
task2 = Task(id=2, duration=5, priority=1, constraints=[[resource]], predecessors_ids=[1])
103133
```
104134

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

0 commit comments

Comments
 (0)