Inferensys

Glossary

Optimality Gap

The optimality gap is a metric used in mathematical optimization to quantify the difference between the best-known feasible solution and a proven bound on the optimal solution, indicating solution quality.
QA engineer performing AI quality assurance on laptop, test results visible, casual technical debugging session.
OPTIMIZATION METRIC

What is Optimality Gap?

The Optimality Gap is a core metric in mathematical optimization and operations research, quantifying how close a feasible solution is to the theoretical optimum.

The optimality gap is the absolute or percentage difference between the objective value of the best-known feasible solution (the incumbent) and a proven bound on the optimal value. For a minimization problem, this bound is a lower bound; for maximization, it is an upper bound. A gap of zero confirms optimality, while a positive gap indicates the potential for improvement. This metric is fundamental for evaluating heuristic and exact algorithms in problems like the Vehicle Routing Problem (VRP) and Job Shop Scheduling.

In practice, calculating the exact optimality gap is often impossible for NP-hard problems, as the true optimum is unknown. Solvers instead use the best available bound, such as the linear programming relaxation in Mixed-Integer Programming (MIP). The gap is crucial for decision-making, allowing CTOs and operations researchers to trade off solution quality against computation time. A small, proven gap provides high confidence in a schedule or plan's efficiency within complex spatial-temporal scheduling systems.

METRIC DECOMPOSITION

Key Components of the Optimality Gap

The optimality gap is not a single value but a composite metric derived from the interplay between solution quality and computational bounds. Understanding its components is essential for interpreting its value and guiding optimization efforts.

01

The Incumbent Solution

The incumbent solution is the best feasible solution found by the solver at a given point in the search. It represents the upper bound (for minimization problems) on the optimal solution's cost. Its quality directly determines the gap's numerator.

  • Role: Provides the known, implementable plan (e.g., a specific vehicle route schedule).
  • Source: Typically found by heuristic algorithms (like a greedy construction) early in the search and improved via local search or metaheuristics.
  • Key Property: As the solver runs, the incumbent should monotonically improve, tightening the gap from above.
02

The Lower Bound

The lower bound is a provable, mathematical estimate of the best possible objective value, derived without necessarily finding a feasible solution. For minimization, the true optimum lies between this bound and the incumbent.

  • Calculation Methods: Often comes from solving a Linear Programming (LP) relaxation of the original Mixed-Integer Programming (MIP) model, or from combinatorial arguments like the Held-Karp bound for the Traveling Salesman Problem (TSP).
  • Role: Provides an absolute benchmark for solution quality. A gap of 0% means the incumbent's cost equals the lower bound, proving optimality.
  • Progression: In exact algorithms like Branch and Bound, the global lower bound strengthens as the search tree is explored.
03

The Absolute Gap

The absolute gap is the raw numerical difference between the incumbent solution's objective value and the best-known lower bound. It is the fundamental, unscaled measure of sub-optimality.

  • Formula: Absolute Gap = Incumbent Value - Lower Bound Value (for minimization).
  • Interpretation: A gap of 50 means the current best solution is 50 units (e.g., meters, seconds, dollars) worse than the theoretical optimum.
  • Termination Criterion: Solvers often stop when the absolute gap falls below a user-defined tolerance (e.g., MIPGap = 0.001 in Gurobi), accepting a near-optimal solution.
04

The Relative Gap (%)

The relative gap (or optimality gap percentage) is the absolute gap expressed as a percentage of the lower bound (or sometimes the incumbent). It is the standard, scale-invariant metric for reporting solution quality.

  • Standard Formula: Relative Gap = ((Incumbent - Lower Bound) / |Lower Bound|) * 100%.
  • Business Interpretation: A 5% gap indicates the current operational plan is at most 5% more expensive than the perfect, undiscovered plan. This quantifies the value of further computation.
  • Decision Tool: Helps CTOs perform a cost-benefit analysis: Is closing the final 0.5% gap worth hours of additional compute time?
05

The Dual Bound

In the context of Mixed-Integer Programming (MIP), the dual bound is synonymous with the best global lower bound during the optimization process. It is the solution to the continuous relaxation of the active branch-and-bound nodes.

  • Mechanism: As the solver branches on integer variables, it creates nodes with LP relaxations. The dual bound is the minimum objective value among all active node relaxations.
  • Convergence: The dual bound increases (for minimization) during the search, while the incumbent decreases. The optimality gap closes as these two values converge.
  • Practical Insight: A rapidly improving dual bound indicates the solver is effectively pruning the search space.
06

The Integrality Gap

The integrality gap is a specific, structural component of the optimality gap for integer programs. It is the worst-case ratio between the optimal integer solution and the optimal solution to its LP relaxation.

  • Definition: It's a property of the problem formulation, not a specific instance. A large integrality gap means the LP relaxation is weak, providing a poor lower bound and making the problem harder to solve.
  • Impact on Solving: Problems with a large integrality gap (e.g., certain Vehicle Routing Problem (VRP) formulations) will have a large initial optimality gap, requiring sophisticated cutting-plane methods or stronger formulations to tighten bounds.
  • Distinction: The optimality gap for a specific instance includes the integrality gap of its formulation but can be larger due to incomplete search.

Calculation and Practical Context

The optimality gap is a critical performance metric in optimization, quantifying how close a practical solution is to the theoretical best. Its calculation and interpretation are central to evaluating solution quality in complex, real-world scheduling and routing problems.

The optimality gap is calculated as the percentage difference between the objective value of the best-known feasible solution (the incumbent) and a proven lower bound (for minimization) or upper bound (for maximization) on the optimal solution. Formally, for a minimization problem, Gap = (Incumbent Value - Lower Bound) / Lower Bound * 100%. A gap of 0% certifies optimality, while a larger gap indicates remaining room for improvement. Solvers for NP-hard problems like the Vehicle Routing Problem (VRP) often report this gap as a termination criterion.

In practical spatial-temporal scheduling for a heterogeneous fleet, a small optimality gap (e.g., <5%) provides high confidence in the operational plan's efficiency regarding travel distance, makespan, or cost. It serves as a key observability metric, allowing operations researchers and CTOs to trade off computation time against solution quality. When real-time replanning is required, a known gap informs the decision to deploy the current plan or continue searching for a better one.

SOLVER COMPARISON

Optimality Gap Across Solver Types

A comparison of how different classes of optimization algorithms approach and report the optimality gap, highlighting trade-offs between solution quality, computational cost, and applicability to real-time scheduling.

Solver CharacteristicExact Solvers (MIP, CP)Metaheuristics (GA, SA, TS)Constructive Heuristics (Greedy, NN)Reinforcement Learning (PPO, DQN)

Theoretical Guarantee on Gap

Yes (provable bound)

No (no guarantee)

No (no guarantee)

No (asymptotic convergence only)

Typical Reported Gap for VRP

< 0.1%

1% - 5%

10% - 25%

Varies widely (5% - 15%)

Computational Time to First Feasible Solution

Minutes to hours

Seconds to minutes

< 1 second

Hours to days (training); < 1 sec (inference)

Computational Time to Proven Optimality / Convergence

Hours to days (may not terminate)

Seconds to hours (convergence)

N/A (single pass)

Hours to days (training)

Primary Method for Gap Calculation

Best bound vs. incumbent

Best found vs. estimated bound or best-known

Solution cost vs. estimated lower bound

Episode reward vs. estimated optimal reward

Handles Dynamic Replanning (Online)

Scalability to Large Problems (>1000 nodes)

Solution Quality Under Tight Time Windows

OPTIMALITY GAP

Frequently Asked Questions

The optimality gap is a critical metric in operations research and combinatorial optimization, quantifying how close a practical solution is to the theoretical best. In the context of spatial-temporal scheduling for heterogeneous fleets, understanding and minimizing this gap is essential for maximizing throughput and resource efficiency.

The optimality gap is a numerical metric that quantifies the difference between the value of the best-known feasible solution (the incumbent) and a proven bound (a lower bound for minimization problems, an upper bound for maximization problems) on the optimal solution's value. It is typically expressed as an absolute difference or, more commonly, as a percentage relative to the bound. A gap of 0% indicates proven optimality, while a larger gap signifies the potential room for improvement in the current solution.

In mathematical terms, for a minimization problem: Optimality Gap = (Incumbent Value - Lower Bound) / Lower Bound * 100%. This metric is the primary output of Mixed-Integer Programming (MIP) solvers and metaheuristic algorithms when reporting solution quality.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.