Task Assignment
Intermediate
Multiple Variables
Equality Constraints
PER Clause
THE PROBLEM
A project manager needs to assign workers to tasks. Each worker-task pair has a skill match score and an hours requirement. Each worker can be assigned to at most one task, and each task must be assigned to exactly one worker. The goal is to maximize total skill match. This example demonstrates multiple decision variables (x for assignment, y for hours) and uses the PER clause for grouped constraints — a planned PackDB feature for per-group aggregation.
SAMPLE DATA
CREATE TABLE Assignments (
worker_id INTEGER, task_id INTEGER,
skill_match INTEGER, hours INTEGER
);
INSERT INTO Assignments VALUES
(1, 101, 95, 8), (1, 102, 70, 6), (1, 103, 60, 10),
(2, 101, 80, 8), (2, 102, 88, 6), (2, 103, 75, 10),
(3, 101, 65, 8), (3, 102, 78, 6), (3, 103, 92, 10);
THE QUERY
SELECT worker_id, task_id, skill_match, hours, x as assigned, y as hours_allocated
FROM Assignments
DECIDE x, y
SUCH THAT
x IS BINARY AND y IS INTEGER AND
y = x * hours AND
SUM(x) PER worker_id <= 1 AND
SUM(x) PER task_id = 1
MAXIMIZE SUM(x * skill_match);
Note: PER (grouped constraints) is a planned feature — coming soon.
QUERY BREAKDOWN
1
DECIDE x, y — Two decision variables per row: x (binary assignment) and y (integer hours).
2
y = x * hours — If assigned (x=1), allocate the required hours; otherwise y=0.
3
SUM(x) PER worker_id <= 1 — Each worker is assigned to at most one task.
4
SUM(x) PER task_id = 1 — Each task is assigned to exactly one worker.
5
MAXIMIZE SUM(x * skill_match) — Maximize total skill match across all assignments.RESULT
| worker_id | task_id | skill_match | hours | assigned | hours_allocated |
|---|---|---|---|---|---|
| 1 | 101 | 95 | 8 | 1 | 8 |
| 1 | 102 | 70 | 6 | 0 | 0 |
| 1 | 103 | 60 | 10 | 0 | 0 |
| 2 | 101 | 80 | 8 | 0 | 0 |
| 2 | 102 | 88 | 6 | 1 | 6 |
| 2 | 103 | 75 | 10 | 0 | 0 |
| 3 | 101 | 65 | 8 | 0 | 0 |
| 3 | 102 | 78 | 6 | 0 | 0 |
| 3 | 103 | 92 | 10 | 1 | 10 |
INTERPRETATION
The solver assigns Worker 1 to Task 101 (skill match 95), Worker 2 to Task 102 (88), and Worker 3 to Task 103 (92), for a total skill match of 275. This is a classic assignment problem — each worker goes to their strongest available task. Worker 1 scores highest on Task 101, Worker 3 is best at Task 103, and Worker 2 fits best with Task 102.