Minimize near-collisions between periodic events using simulated annealing.
This repo provides:
- A clean, reusable core library (
src/interval_optimizer/core.py) - A live Streamlit app for interactive visualization (
apps/streamlit_app.py) - Tests and examples to help you get started
Given a set of intervals (in seconds), the optimizer nudges them slightly so that events scheduled every T seconds collide (occur near the same time) as little as possible, according to a user-defined threshold.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activatepip install -r requirements.txtstreamlit run apps/streamlit_app.pyThen open the URL shown in your terminal.
python examples/minimal.pyfrom interval_optimizer.core import optimize_intervals, total_near_collisions
intervals = [100, 628, 2500, 504000, 204000]
total, per_pair = total_near_collisions(intervals, threshold=3.0)
result = optimize_intervals(
initial_intervals=intervals,
threshold=3.0,
iterations=5000,
seed=7
)
print(result["best_intervals"], result["best_total_collisions"])