This repository contains the metaheuristic optimization engine for solving the
TV Advertisement Scheduling Problem, implemented using:
- NSGA-II (multi-objective optimization)
- Genetic Algorithm
- Simulated Annealing (SA)
- Tabu Search (TS)
The goal is to allocate commercials to TV breaks while maximizing profit and minimizing operational penalties, under complex real-world constraints (time windows, budgets, min/max plays, reach requirements, competitor exclusion, break capacity, sequencing rules, etc.).
This work was part of a Master's thesis in Industrial Engineering focusing on intelligent scheduling in broadcast environments.
- NSGA-II with custom sampling, selection, mutation, crossover
- Genetic Algorithm (pymoo-based implementation)
- Simulated Annealing with cooling and neighbor generation
- Tabu Search with tabu list, intensification/diversification
- Custom commercial allocation structure using NumPy structured arrays
- Automatic start/end time calculation
- Repair mechanisms for feasibility
- Built-in dominance sorting & evaluation
Examples:
- No overlapping commercials
- Budget feasibility
- Min/max number of plays
- Reach satisfaction
- No competitor advertisers in the same break
- Release/due time enforcement
- Break capacity respect
- Sequencing consistency
Taguchi-based experiment automation for:
- NSGA-II
- Tabu Search
- Simulated Annealing
- Initial population generator
- Custom dominance sorting
- Constraint checker
- Solution pretty-printing
The TV-ad scheduling problem involves assigning commercials to predefined breaks under constraints such as:
- Commercial budgets
- Required reach
- Release and due times
- Minimum/maximum number of allowed plays
- Break duration limits
- Conflict avoidance (competitors cannot appear in the same break)
- Start/end time sequencing consistency
Each solution represents a full assignment of commercials across all breaks, encoded in a NumPy structured array.
The objective functions:
- Maximize Profit
- Minimize Cost
- Constraints are handled using penalization and repair operators.
- Maximize: Profit β Cost
git clone https://github.com/aliz-f/tv-ad-scheduling-metaheuristics
cd tv-ad-scheduling-metaheuristicspip install -r requirements.txtDependencies include:
pymoonumpyloguruclick
python main.py -d data/sample.jsonpython genetic_algorithm/genetic_main.py -d data/sample.jsonpython main.py -d data/sample.json --taguchi sapython main.py -d data/sample.json --taguchi tabuEach input JSON file must include:
{
"commercials": 5,
"breaks": 10,
"commercial_duration": [30, 30, 15, 45, 20],
"commercial_copy": [{"min":1,"max":5}, ...],
"break_duration": [120, 140, ...],
"break_length": [{"start": "...", "end": "..."}, ...],
"price": [[...], [...]],
"reach": [[...], [...]],
"budget": [...],
"required_reach": [...],
"penalty": [...],
"due_time": [...],
"release_time": [...],
"competitors": [["A","B"], ...],
"name": [...]
}Each break has positions, and each position is stored as:
(start_time, end_time, advertiser_obj, copy_index, reserved, price, reach)
The solution supports:
calculate_profit()calculate_cost()calculate_cost2()debugging versionfiltered_list(non-empty slots)break_free_spacemin_max_playedused_budgetobtained_reach- Automatic time recalculation (
reconfig_times())
The Constraints class contains 12 feasibility checks.
Examples:
| Constraint | Meaning |
|---|---|
| const1 | No duplicate play numbers for the same advertiser |
| const2 | No overlapping commercials |
| const3 | Respect advertiser min/max plays |
| const4 | Budget not exceeded |
| const5 | Required reach met |
| const7 | No empty gaps before filled positions |
| const9 | Start time >= release time |
| const11 | Adjacent segments must align in time |
Repairs are performed via the Reformations class.
Run full Taguchi experiments:
python main.py -d sample.json -t nsgapython main.py -d sample.json -t tabupython main.py -d sample.json -t saEach test produces results under:
result/NSGA/
result/TABU/
result/SA/
Algorithms print:
- Best or final solution (schedule)
- Profit, cost, and final objective
- Constraint violations
- Execution time
- Parameter settings
NSGA-II prints all Pareto-front candidates, sorted by dominance.
This MILP model is one of three main components of the TV scheduling thesis project:
-
- Generates synthetic instances (breaks, commercials, budgets, reach, etc.)
- Exports JSON for NSGA-II/metaheuristics and for CPLEX (scaled).
-
- Reads CPLEX-ready JSON.
- Solves the scheduling problem exactly (within MIP gap limits).
-
Metaheuristic Algorithms (this repo)
- NSGA-II, simulated annealing, tabu search.
- Use the same data to compare against MILP performance.