<commit_before># Pyschedule

Pyschedule is python package to compute resource-constrained schedules. If you need to get some tasks done, and you have some resources to accomplish this, then pyschedule might be helpful to compute schedules. Some features are: 

- precedence relations between tasks: e.g. task A should be done before task B
- resource requirements: e.g. some task A can be done by resource X or Y
- capacities: e.g. resource X can only process a few tasks

The number of possible applications are endless, some cases to which pyschedule has been applied to compute schedules that assign tasks to resources:

- school timetables: teachers to classes
- beer brewing: equipment to brewing stages
- sport schedules: stadiums to games

A simple pyschedule scenario where houshold tasks need to get assigned to two persons, called Alice and Bob, could look as follows:

```python
from pyschedule import Scenario, solvers, plotters

# the planning horizon has 10 periods
S = Scenario('houshold',horizon=10)

# two resources: Alice and Bob
Alice, Bob = S.Resource('Alice'), S.Resource('Bob')

# three tasks: cook, wash, and clean
cook = S.Task('cook',length=1,delay_cost=1)
wash = S.Task('wash',length=2,delay_cost=1)
clean = S.Task('clean',length=3,delay_cost=2)

# every task can be done either by Alice or Bob
cook += Alice | Bob
wash += Alice | Bob
clean += Alice | Bob

# compute and print a schedule
solvers.mip.solve(S,msg=1)
print(S.solution())
```
```
INFO: execution time for solving mip (sec) = 0.025493860244750977
INFO: objective = 1.0
[(clean, Alice, 0, 3), (cook, Bob, 0, 1), (wash, Bob, 1, 3)]
```
We can also plot the schedule as a GANTT-chart and write it to a file:

```python
plotters.matplotlib.plot(S,img_filename='pics/hello-world.png')
```

![](houshold.png)

There are example notebooks <a href="https://github.com/timnon/pyschedule/tree/master/example-notebooks">here</a> and simpler examples in the <a href="https://github.com/timnon/pyschedule/tree/master/examples">examples folder</a>.


## Limits

Note that pyschedule aims to be *a general solver for small to medium-sized scheduling problems*. A typical scenario that pyschedule consists of 10 resources and 100 tasks with a planning horizon of 100 periods. If your requirements are much larger than this, then an out-of-the box solution is hard to obtain. There are some ways to speed-up pyschedule (e.g. see task groups and solver parameters). It is also possible to build heuristics on top of pyschedule to solve large-scaled scheduling problems.


## How to start

When creating a scenario using pyschedule, the following imports are recommended:

```python
from pyschedule import Scenario, solvers, plotters, alt
```

This allows the creation of a scenario:

```python
S = Scenario('hello_world',horizon=10)
```

This scenario is named `hello_world` and has a time horizon of 10 periods. The granularity of the periods depends on your problem, e.g. a period could be an hour, a week, or a day. However, having far more than 100 periods makes the computation of a schedule quite hard. Some tricks to reduce the number of periods are:

- Remove periods which are not used, like hours during the night.<commit_msg>picture link<commit_after># Pyschedule

Pyschedule is python package to compute resource-constrained schedules. If you need to get some tasks done, and you have some resources to accomplish this, then pyschedule might be helpful to compute schedules. Some features are: 

- **precedence relations:** e.g. task A should be done before task B
- **resource requirements:** e.g. some task A can be done by resource X or Y
- **resource capacities:** e.g. resource X can only process a few tasks

Some previous use-cases where pyschedule has been applied to assign tasks to resources:

- school timetables: assign teachers to classes
- beer brewing: assign equipment to brewing stages
- sport schedules: assign stadiums to games

A simple pyschedule scenario where houshold tasks need to get assigned to two persons, called Alice and Bob, could look as follows:

```python
from pyschedule import Scenario, solvers, plotters

# the planning horizon has 10 periods
S = Scenario('houshold',horizon=10)

# two resources: Alice and Bob
Alice, Bob = S.Resource('Alice'), S.Resource('Bob')

# three tasks: cook, wash, and clean
cook = S.Task('cook',length=1,delay_cost=1)
wash = S.Task('wash',length=2,delay_cost=1)
clean = S.Task('clean',length=3,delay_cost=2)

# every task can be done either by Alice or Bob
cook += Alice | Bob
wash += Alice | Bob
clean += Alice | Bob

# compute and print a schedule
solvers.mip.solve(S,msg=1)
print(S.solution())
```
```
INFO: execution time for solving mip (sec) = 0.025493860244750977
INFO: objective = 1.0
[(clean, Alice, 0, 3), (cook, Bob, 0, 1), (wash, Bob, 1, 3)]
```
We can also plot the schedule as a GANTT-chart and write it to a file:

```python
plotters.matplotlib.plot(S,img_filename='pics/hello-world.png')
```

![png](pics/household.png)

There are example notebooks <a href="https://github.com/timnon/pyschedule/tree/master/example-notebooks">here</a> and simpler examples in the <a href="https://github.com/timnon/pyschedule/tree/master/examples">examples folder</a>.


## Limits

Note that pyschedule aims to be *a general solver for small to medium-sized scheduling problems*. A typical scenario that pyschedule consists of 10 resources and 100 tasks with a planning horizon of 100 periods. If your requirements are much larger than this, then an out-of-the box solution is hard to obtain. There are some ways to speed-up pyschedule (e.g. see task groups and solver parameters). It is also possible to build heuristics on top of pyschedule to solve large-scaled scheduling problems.


## How to start

When creating a scenario using pyschedule, the following imports are recommended:

```python
from pyschedule import Scenario, solvers, plotters, alt
```

This allows the creation of a scenario:

```python
S = Scenario('hello_world',horizon=10)
```

This scenario is named `hello_world` and has a time horizon of 10 periods. The granularity of the periods depends on your problem, e.g. a period could be an hour, a week, or a day. However, having far more than 100 periods makes the computation of a schedule quite hard. Some tricks to reduce the number of periods are:

- Remove periods which are not used, like hours during the night.
{'fraction_non_alphanumeric': 0.08816160350767303, 'fraction_numerical': 0.01659880989664892, 'mean_word_length': 4.672291296625222, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2026610', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1809, 'n_words': 862}