Skip to content

About

Assembly line balancing with Hoffmann's (1963) precedence-matrix method — Python core, CLI, Streamlit UI (EN/TR/DE/ES/FR). Live demo: hoffmann-line-balancing.streamlit.app

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

hoffmann-line-balancing

CI Python 3.11+ License: Apache-2.0 Live demo

English · Türkçe

Assembly line balancing (SALBP-1) with Hoffmann's (1963) precedence-matrix method. Pure-Python core with no mandatory dependencies; command-line tool and a Streamlit interface available in English, Türkçe, Deutsch, Español, Français.

Live demo: https://hoffmann-line-balancing.streamlit.app/ — no installation needed.

Streamlit interface

$ python -m hoffmann_lb examples/course_example.csv --cycle 18

Method: hoffmann   Cycle time: 18

Station  1: 1, 2            load      18   idle       0
Station  2: 3, 4, 5, 7, 9   load      18   idle       0
Station  3: 6, 8            load      17   idle       1
Station  4: 10, 11, 12      load      17   idle       1

Stations          : 4 (equals lower bound)
Lower bound       : 4
Total time        : 70
Total idle        : 2
Efficiency (E)    : 97.22 %
Balance delay (D) : 2.78 %
Smoothness (SI)   : 1.4142  [ref: max_load]

Installation

git clone https://github.com/DailyDana/hoffmann-line-balancing.git
cd hoffmann-line-balancing
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e .            # core + CLI
pip install -e ".[app]"     # + Streamlit interface
pip install -e ".[dev]"     # + ruff, mypy, pytest, hypothesis

Usage

Streamlit interface

pip install -e ".[app]"
streamlit run app/streamlit_app.py
  • Language selector in the sidebar (EN / TR / DE / ES / FR).
  • Task table (st.data_editor): duration and successor list; row count follows "Number of tasks".
  • Solve → metric cards, station table, CSV/JSON download.
  • "Compare with legacy method (greedy)": both solutions side by side.
  • Cycle-time sweep: station count / efficiency table and chart over a range of C.
  • CSV upload (, or ; delimiter, decimal comma).

Command line

python -m hoffmann_lb input.csv --cycle 15
python -m hoffmann_lb input.csv --cycle 15 --lang tr                # tr, de, es, fr
python -m hoffmann_lb input.csv --cycle 15 --format json            # full result + metrics
python -m hoffmann_lb input.csv --cycle 15 --format csv             # station table only
python -m hoffmann_lb input.csv --cycle 15 --method greedy          # legacy comparison
python -m hoffmann_lb input.csv --cycle 15 --tie-break most_tasks
python -m hoffmann_lb tr.csv   --cycle 15 --delimiter ";" --decimal-comma   # Turkish Excel

Input CSV (examples/course_example.csv):

id,duration,successors
1,12,2;3;4;5;6;7;8;9;10;11;12
2,6,3;4;5;6;7;8;9;10;11;12
3,6,7;8;11;12
...
12,7,

Column headers may also be Turkish (İş No, Süre, Ardıllar). Successors within a cell are separated by ; or whitespace.

Python

from hoffmann_lb import PrecedenceGraph, Task, TieBreak, compute_metrics, hoffmann

g = PrecedenceGraph(
    [Task(1, 4), Task(2, 3), Task(3, 3)],
    edges=[(1, 2), (1, 3)],  # (predecessor, successor)
)
result = hoffmann(g, cycle_time=7, tie_break=TieBreak.ORIGINAL)
metrics = compute_metrics(result, total_time=g.total_time)

for s in result.stations:
    print(s.index, s.task_ids, s.load, s.idle)
print(metrics.n_stations, metrics.lower_bound, metrics.efficiency_pct)

All errors derive from hoffmann_lb.BalancingError (CycleError, InvalidDurationError, ParseError, GraphError); messages are English and name the offending task ids.

Method

For each station, every task subset that satisfies precedence is enumerated and the one with minimum idle time is chosen (Hoffmann 1963). The tie-break rule is selectable (ORIGINAL, MOST_TASKS, MOST_FOLLOWERS). Details, design decisions and limitations: docs/ALGORITHM.md.

Metrics: efficiency, balance delay, theoretical lower bound ⌈Σt/C⌉, smoothness index (Moodie & Young).

Why the rewrite

The first version of this project was a coursework assignment (MATLAB → Python port → Tkinter GUI; see archive/legacy/). A code review (archive/LEGACY_REVIEW.md, in Turkish) showed that the implemented loop was not Hoffmann's method but a first-fit heuristic ("take the first available task whose code is zero"). Without subset enumeration it deviated from the optimum ([4,4,3,3,3,3], C=10 → 3 stations; Hoffmann finds 2). It also looped forever on precedence cycles, rejected fractional durations and silently dropped invalid input.

This repository was written from scratch; the old behaviour is preserved as greedy_first_fit for comparison.

Verification

  • 127 tests: unit, end-to-end CLI, Streamlit AppTest smoke tests, i18n completeness, and hypothesis property tests on random DAGs.
  • Expected values for the course example were computed with an independent brute-force oracle and an exact bitmask-DP solver; Hoffmann reaches the exact optimum for every tested C.
  • With the ORIGINAL rule, Hoffmann yields exactly the same station sets as the oracle on random graphs up to 8 tasks.
  • ruff, mypy --strict, CI on Python 3.11 / 3.12.
pytest
ruff check . && ruff format --check .
mypy

Roadmap

  • M1 — core: model, validation, Hoffmann, greedy, metrics (v0.1.0)
  • M2 — CSV/JSON, CLI, documentation (v0.2.0)
  • M3 — Streamlit interface: table editor, cycle-time sweep, greedy comparison (v1.0.0)
  • Multilingual UI and CLI (v1.1.0)

Possible next steps: exact solver (branch-and-bound / MILP) for optimality checks, precedence-graph visualisation, SALBP-2 (fixed station count, minimise C).

License

Apache License 2.0 — see LICENSE. Releases up to v1.0.0 were published under MIT (see NOTICE).


Türkçe

English · Türkçe

Hoffmann (1963) öncelik-matrisi yöntemiyle montaj hattı dengeleme (SALBP-1). Saf Python çekirdek, zorunlu bağımlılık yok; komut satırı aracı ve İngilizce, Türkçe, Almanca, İspanyolca, Fransızca arayüzlü Streamlit uygulaması.

Canlı demo: https://hoffmann-line-balancing.streamlit.app/ — kurulum gerekmez.

Kurulum

git clone https://github.com/DailyDana/hoffmann-line-balancing.git
cd hoffmann-line-balancing
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e .            # yalnızca çekirdek + CLI
pip install -e ".[app]"     # + Streamlit arayüzü
pip install -e ".[dev]"     # + ruff, mypy, pytest, hypothesis

Kullanım

Streamlit arayüzü

streamlit run app/streamlit_app.py

Kenar çubuğundan dil seçilir (varsayılan İngilizce). İş tablosu, Hesapla, greedy karşılaştırma, çevrim süresi taraması, CSV/JSON indirme ve CSV yükleme mevcuttur.

Komut satırı

python -m hoffmann_lb girdi.csv --cycle 15 --lang tr
python -m hoffmann_lb girdi.csv --cycle 15 --lang tr --format json
python -m hoffmann_lb girdi.csv --cycle 15 --lang tr --method greedy
python -m hoffmann_lb tr.csv    --cycle 15 --lang tr --delimiter ";" --decimal-comma

--lang yalnızca metin çıktısını etkiler; JSON ve CSV dilden bağımsızdır. Girdi CSV'sinde sütun başlıkları Türkçe olabilir (İş No, Süre, Ardıllar); ardıllar hücre içinde ; ya da boşlukla ayrılır.

Yöntem

Her istasyon için öncelik kısıtını sağlayan tüm iş alt kümeleri sayılır ve boş süreyi en aza indiren seçilir (Hoffmann 1963). Eşitlik kuralı seçilebilir. Ayrıntı, karar gerekçeleri ve sınırlamalar: docs/ALGORITHM.md (Türkçe).

Ölçütler: verimlilik, denge kaybı, teorik alt sınır ⌈Σt/C⌉, düzgünlük indeksi.

Neden yeniden yazıldı

Projenin ilk sürümü bir ders ödeviydi (archive/legacy/). İnceleme (archive/LEGACY_REVIEW.md) uygulanan döngünün Hoffmann yöntemi değil first-fit sezgiseli olduğunu gösterdi; optimumdan sapıyor, öncelik döngüsünde sonsuz döngüye giriyor, ondalık süre kabul etmiyor ve geçersiz girdileri sessizce yutuyordu. Depo sıfırdan yazıldı; eski davranış greedy_first_fit olarak karşılaştırma için korundu.

Doğrulama

127 test (birim, CLI, Streamlit AppTest, i18n bütünlüğü, hypothesis özellik testleri). Ders örneğinin beklenen değerleri bağımsız kaba-kuvvet oracle ve kesin çözücüyle hesaplandı. ruff, mypy --strict, CI (Python 3.11 / 3.12).

Lisans

Apache License 2.0 — bkz. LICENSE. v1.0.0'a kadar olan sürümler MIT ile yayımlanmıştı (NOTICE).

About

Assembly line balancing with Hoffmann's (1963) precedence-matrix method — Python core, CLI, Streamlit UI (EN/TR/DE/ES/FR). Live demo: hoffmann-line-balancing.streamlit.app

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages