Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Metaheuristic optimization framework for TV advertisement scheduling using NSGA-II, Genetic Algorithm, Simulated Annealing, and Tabu Search. Includes custom solution representation, constraint handling, initial population heuristics, and multi-objective evaluation (profit vs. cost).

Notifications You must be signed in to change notification settings

Aliz-f/tv-ad-scheduling-metaheuristics

Repository files navigation

TV Advertisement Scheduling - Metaheuristic Optimization

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.


πŸš€ Features

βœ” Metaheuristic Algorithms

  • 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 Scheduling Model

  • Custom commercial allocation structure using NumPy structured arrays
  • Automatic start/end time calculation
  • Repair mechanisms for feasibility
  • Built-in dominance sorting & evaluation

βœ” Constraint Handling (12 Constraints)

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

βœ” Parameter Tuning

Taguchi-based experiment automation for:

  • NSGA-II
  • Tabu Search
  • Simulated Annealing

βœ” Utilities

  • Initial population generator
  • Custom dominance sorting
  • Constraint checker
  • Solution pretty-printing

πŸ“˜ Problem Overview

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:

NSGA-II (multi-objective):

  • Maximize Profit
  • Minimize Cost
  • Constraints are handled using penalization and repair operators.

GA, SA, Tabu Search (single-objective):

  • Maximize: Profit – Cost

πŸ”§ Installation

1. Clone the Repository

git clone https://github.com/aliz-f/tv-ad-scheduling-metaheuristics
cd tv-ad-scheduling-metaheuristics

2. Install Requirements

pip install -r requirements.txt

Dependencies include:

  • pymoo
  • numpy
  • loguru
  • click

▢️ Running the Metaheuristics

NSGA-II

python main.py -d data/sample.json

Genetic Algorithm

python genetic_algorithm/genetic_main.py -d data/sample.json

Simulated Annealing

python main.py -d data/sample.json --taguchi sa

Tabu Search

python main.py -d data/sample.json --taguchi tabu

βš™οΈ Data Format

Each 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": [...]
}

πŸ” Understanding the Solution Object

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 version
  • filtered_list (non-empty slots)
  • break_free_space
  • min_max_played
  • used_budget
  • obtained_reach
  • Automatic time recalculation (reconfig_times())

πŸ”¨ Constraint System

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.


πŸ§ͺ Parameter Tuning (Taguchi Mode)

Run full Taguchi experiments:

NSGA-II

python main.py -d sample.json -t nsga

Tabu Search

python main.py -d sample.json -t tabu

SA

python main.py -d sample.json -t sa

Each test produces results under:

result/NSGA/
result/TABU/
result/SA/

πŸ“ˆ Output

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.


Relation to the Overall Project

This MILP model is one of three main components of the TV scheduling thesis project:

  1. Data Generator

    • Generates synthetic instances (breaks, commercials, budgets, reach, etc.)
    • Exports JSON for NSGA-II/metaheuristics and for CPLEX (scaled).
  2. MILP Model

    • Reads CPLEX-ready JSON.
    • Solves the scheduling problem exactly (within MIP gap limits).
  3. Metaheuristic Algorithms (this repo)

    • NSGA-II, simulated annealing, tabu search.
    • Use the same data to compare against MILP performance.

About

Metaheuristic optimization framework for TV advertisement scheduling using NSGA-II, Genetic Algorithm, Simulated Annealing, and Tabu Search. Includes custom solution representation, constraint handling, initial population heuristics, and multi-objective evaluation (profit vs. cost).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages