Mixed-integer linear programming

Also known as: MILP

On this page 7

Mixed-integer linear programming (MILP) is the class of optimization problems in which a linear objective function is minimized or maximized subject to linear constraints, while some decision variables must take integer values and the rest may remain continuous. In optimization for artificial intelligence, MILP is the standard language for discrete decisions with exact guarantees: scheduling, routing, resource allocation, neural network verification and many planning tasks that gradient methods cannot express.

The integer requirement is what makes MILP powerful and hard at the same time. A plain linear program can be solved in polynomial time, but adding integrality makes the general problem NP-hard. Modern solvers still handle instances with millions of variables in practice, because they combine branch and bound, cutting planes, presolve reductions and primal heuristics into a single search that proves how far the best known solution is from optimal.

How a MILP model is formulated

A MILP model is defined by decision variables, a linear objective and a set of linear constraints, together with an integrality condition on a chosen subset of variables. In matrix form, the problem minimizes c^T x subject to A x <= b, with bounds on every variable and with x_j integer for every index in the integer set. Binary variables, which can only be 0 or 1, are the most common integer type because they encode yes-or-no decisions.

The modeling skill lies in expressing logical relations through linear inequalities. Implications, fixed costs, either-or constraints and piecewise linear functions are all written with binary indicators. The big-M technique links a binary switch to a continuous quantity, for example forcing production to zero unless a facility is opened. Choosing a tight value for M matters greatly, because an oversized constant weakens the model.

The table below summarizes the building blocks of a typical formulation and the role each one plays.

ComponentMathematical formTypical meaning
Continuous variablex in a real intervalFlow, quantity, time or power level
Integer variablex in a range of integersNumber of vehicles, machines or batches
Binary variablex in {0, 1}Open a site, assign a task, select an item
Objective functionminimize c^T xCost, makespan, distance or lost revenue
Linear constrainta^T x <= bCapacity, demand, budget or precedence
Indicator constraintz = 1 implies a^T x <= bConditional rule tied to a decision
Components of a MILP formulation

How solvers find and prove optimal solutions

MILP solvers rely on the linear programming relaxation, which drops the integrality requirement and yields a bound on the best achievable objective. If the relaxed solution already satisfies integrality, it is optimal. Otherwise the solver branches on a fractional variable, creating two subproblems with tighter bounds, and explores the resulting tree while pruning nodes whose bound cannot beat the incumbent.

Cutting planes strengthen the relaxation by adding inequalities that remove fractional points without cutting off any integer solution. Gomory cuts, mixed-integer rounding cuts, cover cuts and clique cuts are standard families. The combination of both ideas, called branch and cut, is the core of every competitive solver, and it is supported by presolve, which removes redundant rows and fixes variables before the search starts.

Progress is reported through the optimality gap, the relative difference between the best integer solution found and the best proven bound. A gap of zero certifies optimality, and many practical runs stop at a gap of 0.1 to 1 percent to save time. The table below lists the main solver components and their effect.

ComponentWhat it doesEffect on performance
PresolveRemoves redundant constraints and fixes variablesSmaller and tighter model
LP relaxationSolves the problem without integralityProvides the dual bound
BranchingSplits the domain of a fractional variableDrives the tree search
Cutting planesAdds valid inequalities to the relaxationCloses the gap faster
Primal heuristicsSearches for good feasible solutions earlyImproves the incumbent
Node selectionChooses which open node to process nextBalances bound and solution quality
Main components of a branch-and-cut solver

MILP sits between linear programming and more general nonlinear models. Pure integer programming is the special case in which every variable is integer, while quadratic and nonlinear variants allow curved objectives or constraints at a higher computational price. The comparison below helps decide which class a problem belongs to.

Problem classVariablesComplexityTypical solution method
Linear programmingContinuous onlyPolynomial timeSimplex or interior-point method
Mixed-integer linear programmingContinuous and integerNP-hard in generalBranch and cut
Pure integer programmingInteger onlyNP-hard in generalBranch and cut, enumeration
Mixed-integer quadratic programmingContinuous and integerNP-hard in generalBranch and cut with QP relaxations
Constraint programmingFinite domainsNP-hard in generalPropagation and search
MetaheuristicsAny encodingNo optimality proofSimulated annealing, tabu search
MILP and neighboring problem classes

The decisive difference from metaheuristics is the bound. A metaheuristic may find good solutions quickly, but only a MILP solver reports how far a solution is from the optimum, which is essential when decisions carry contractual or safety consequences.

Where MILP is used in artificial intelligence

In artificial intelligence, MILP serves both as a decision layer on top of predictions and as a tool for analyzing models. A demand forecast produced by a neural network often feeds a MILP that decides orders, shifts or routes, an approach known as predict-then-optimize. MILP also encodes ReLU networks exactly, because each ReLU unit can be modeled with one binary variable and big-M constraints.

  • Neural network verification: proving that no input within a perturbation radius changes the predicted class.
  • Counterfactual explanations: finding the smallest feature change that flips a model decision under feasibility rules.
  • Optimal decision trees: training sparse trees with a proven optimal accuracy for a given depth.
  • Learning to optimize: using graph neural networks to guide branching and heuristics inside solvers.

The last direction reverses the relationship: machine learning accelerates MILP solvers by imitating expensive branching rules or predicting promising partial assignments. These learned components usually keep the exactness of the solver, since the search still proves optimality.

Limitations and common modeling mistakes

Solve time for MILP is highly sensitive to the formulation. Two mathematically equivalent models can differ by several orders of magnitude in runtime, because one has a much tighter relaxation. Symmetry is another frequent problem: identical machines or vehicles create many equivalent solutions that the tree must explore repeatedly.

SymptomLikely causeRemedy
Gap stays large for hoursWeak big-M valuesDerive tight bounds for each constraint
Many equivalent solutionsSymmetric variablesAdd symmetry-breaking constraints
Numerical warningsCoefficients spanning many magnitudesRescale units and data
Model reported infeasibleConflicting hard constraintsCompute an irreducible infeasible subset
Slow LP at each nodeVery large dense modelDecompose or aggregate the data
Frequent MILP problems and their fixes

Linearity itself is a restriction. Nonlinear effects must be approximated with piecewise linear segments, which adds binary variables and can enlarge the search tree. For very large or time-critical tasks, practitioners often combine MILP with decomposition methods or accept a heuristic solution with a known gap.

Stripped to the essentials

MILP is a way to make the best possible choice under strict rules. Some choices are amounts, such as liters or hours. Other choices are whole numbers or simple yes-or-no decisions, such as whether to open a warehouse.

A computer explores the options in a smart order. It first solves an easier version that ignores the whole-number rule. Then it splits the problem into smaller cases and drops the cases that cannot win. In the end it delivers a plan and states how close that plan is to the true best.

Where it is applied

A regional grocery distributor uses a machine learning model to forecast daily demand for 240 stores. The forecasts feed a MILP that decides which of 12 depots serve each store, how many trucks to dispatch and which delivery windows to use. Binary variables represent depot-to-store assignments and truck usage, while continuous variables represent shipped volume.

The model has about 80,000 variables and 120,000 constraints. A commercial solver finds a plan within a 0.5 percent optimality gap in under ten minutes each night. Compared with the previous rule-based dispatch, the planning team reports fewer trucks on the road and fewer missed delivery windows, and it can explain every decision by pointing to the constraints that shaped it.