Scheduling extension for PyCSP3 with interval variables, sequence variables, and scheduling constraints
Project description
pycsp3-scheduling
Scheduling extension for pycsp3 with interval variables, sequence variables, and scheduling constraints.
Features
- Interval Variables: Represent tasks/activities with start, end, size, length, and optional presence
- Intensity Functions: Stepwise intensity metadata with granularity scaling for size/length
- Sequence Variables: Ordered sequences of intervals on disjunctive resources
- Precedence Constraints:
end_before_start,start_at_start, etc. - Grouping Constraints:
span,alternative,synchronize - Cumulative Functions:
pulse,step_at_start,step_at_endfor resource modeling - State Functions: Model resource states with transitions
- XCSP3 Extension: Output scheduling models in extended XCSP3 format
- Visualization: Gantt charts and resource profiles
Installation
pip install pycsp3-scheduling
For development:
git clone https://github.com/sohaibafifi/pycsp3-scheduling.git
cd pycsp3-scheduling
pip install -e ".[dev]"
Quick Start
from pycsp3 import *
from pycsp3_scheduling import *
# Create interval variables for tasks
task1 = IntervalVar(size=10, name="task1")
task2 = IntervalVar(size=15, name="task2")
task3 = IntervalVar(size=8, name="task3")
# Precedence: task1 must finish before task2 starts
satisfy(end_before_start(task1, task2))
# No overlap: task2 and task3 cannot overlap
satisfy(SeqNoOverlap([task2, task3]))
# Minimize makespan
minimize(max(end_time(task1), end_time(task2), end_time(task3)))
Example: Job Shop Scheduling
from pycsp3 import *
from pycsp3_scheduling import *
# Data
n_jobs, n_machines = 3, 3
durations = [[3, 2, 2], [2, 1, 4], [4, 3, 3]]
machines = [[0, 1, 2], [0, 2, 1], [1, 0, 2]]
# Create interval variables for each operation
ops = [[IntervalVar(size=durations[j][o], name=f"op_{j}_{o}")
for o in range(n_machines)] for j in range(n_jobs)]
# Sequences for each machine
sequences = [SequenceVar(
intervals=[ops[j][o] for j in range(n_jobs)
for o in range(n_machines) if machines[j][o] == m],
name=f"machine_{m}"
) for m in range(n_machines)]
# Precedence within jobs
satisfy(
end_before_start(ops[j][o], ops[j][o+1])
for j in range(n_jobs) for o in range(n_machines-1)
)
# No overlap on machines
satisfy(SeqNoOverlap(seq) for seq in sequences)
# Minimize makespan
minimize(Maximum(end_time(ops[j][-1]) for j in range(n_jobs)))
Example: RCPSP (Resource-Constrained Project Scheduling)
from pycsp3 import *
from pycsp3_scheduling import *
# Data
durations = [3, 2, 5, 4, 2]
demands = [[2, 1], [1, 2], [3, 0], [2, 1], [1, 3]]
capacities = [4, 3]
precedences = [(0, 2), (1, 3), (2, 4)]
# Interval variables
tasks = [IntervalVar(size=durations[i], name=f"task_{i}")
for i in range(len(durations))]
# Precedence constraints
satisfy(end_before_start(tasks[p], tasks[s]) for p, s in precedences)
# Cumulative resource constraints
for r in range(len(capacities)):
resource = sum(pulse(tasks[i], demands[i][r])
for i in range(len(tasks)) if demands[i][r] > 0)
satisfy(resource <= capacities[r])
# Minimize makespan
minimize(Maximum(end_time(t) for t in tasks))
API Reference
Variables
| Function | Description |
|---|---|
IntervalVar(size, start, end, length, intensity, granularity, optional, name) |
Create an interval variable |
IntervalVarArray(size, ...) |
Create array of interval variables |
SequenceVar(intervals, types, name) |
Create a sequence variable |
Expressions
| Function | Description |
|---|---|
start_of(interval, absent_value=0) |
Start time of interval |
end_of(interval, absent_value=0) |
End time of interval |
size_of(interval, absent_value=0) |
Size/duration of interval |
length_of(interval, absent_value=0) |
Length of interval |
presence_of(interval) |
Boolean presence status |
Interop Helpers
| Function | Description |
|---|---|
start_time(interval) |
pycsp3 variable for start time |
end_time(interval) |
pycsp3 expression for end time |
Precedence Constraints
| Constraint | Semantics (when both present) |
|---|---|
start_before_start(a, b, delay) |
start(b) >= start(a) + delay |
start_before_end(a, b, delay) |
end(b) >= start(a) + delay |
end_before_start(a, b, delay) |
start(b) >= end(a) + delay |
end_before_end(a, b, delay) |
end(b) >= end(a) + delay |
start_at_start(a, b, delay) |
start(b) == start(a) + delay |
start_at_end(a, b, delay) |
start(b) == end(a) + delay |
end_at_start(a, b, delay) |
end(a) == start(b) + delay |
end_at_end(a, b, delay) |
end(b) == end(a) + delay |
Grouping Constraints
| Constraint | Description |
|---|---|
span(main, subtasks) |
Main interval spans all present subtasks |
alternative(main, alts, card=1) |
Select card alternatives matching main |
synchronize(main, intervals) |
All present intervals sync with main |
Cumulative Functions
| Function | Description |
|---|---|
pulse(interval, height) |
Constant consumption during interval |
step_at(time, height) |
Step at fixed time point |
step_at_start(interval, height) |
Step at interval start |
step_at_end(interval, height) |
Step at interval end |
cumul_range(cumul, min, max) |
Constrain cumul to [min, max] |
State Functions
| Function | Description |
|---|---|
StateFunction(transition_matrix) |
Create state function |
always_in(func, interval, min, max) |
State in range during interval |
always_equal(func, interval, value) |
State equals value during interval |
always_constant(func, interval) |
State constant during interval |
Requirements
- Python >= 3.9
- pycsp3 >= 2.5
- lxml >= 4.9
- matplotlib >= 3.7
License
MIT License - see LICENSE file.
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycsp3_scheduling-0.1.4.tar.gz.
File metadata
- Download URL: pycsp3_scheduling-0.1.4.tar.gz
- Upload date:
- Size: 466.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56e0eee0242aca371a8ee1701e7363be69ecc42b63e0d65d7a37bb5b233896e3
|
|
| MD5 |
0fcf888a3a2cc702b1cdca018a3158f3
|
|
| BLAKE2b-256 |
5632f7a2c2ab26f6e035f0703cc53ea1a630fa26b8d17cca673471e929f72647
|
Provenance
The following attestation bundles were made for pycsp3_scheduling-0.1.4.tar.gz:
Publisher:
publish.yml on sohaibafifi/pycsp3-scheduling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycsp3_scheduling-0.1.4.tar.gz -
Subject digest:
56e0eee0242aca371a8ee1701e7363be69ecc42b63e0d65d7a37bb5b233896e3 - Sigstore transparency entry: 789719423
- Sigstore integration time:
-
Permalink:
sohaibafifi/pycsp3-scheduling@e1d06cd7feea21cbe7d00d3340e1098a4fa6536b -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e1d06cd7feea21cbe7d00d3340e1098a4fa6536b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycsp3_scheduling-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pycsp3_scheduling-0.1.4-py3-none-any.whl
- Upload date:
- Size: 58.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
132e8c088415302e705d176c9171ec6211b9d90d31ce960b81411ba259dc6bed
|
|
| MD5 |
57ac33411b7c1379dbab3bbfdf1b2d28
|
|
| BLAKE2b-256 |
35cb605c419df44d585306d9aa45e0d25c390dfaed2a1e0951e08d7155ff8dd4
|
Provenance
The following attestation bundles were made for pycsp3_scheduling-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on sohaibafifi/pycsp3-scheduling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycsp3_scheduling-0.1.4-py3-none-any.whl -
Subject digest:
132e8c088415302e705d176c9171ec6211b9d90d31ce960b81411ba259dc6bed - Sigstore transparency entry: 789719424
- Sigstore integration time:
-
Permalink:
sohaibafifi/pycsp3-scheduling@e1d06cd7feea21cbe7d00d3340e1098a4fa6536b -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sohaibafifi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e1d06cd7feea21cbe7d00d3340e1098a4fa6536b -
Trigger Event:
push
-
Statement type: