Constraint handling in Model Predictive Control (MPC) is the explicit mathematical enforcement of limits on system variables during online optimization. Hard constraints represent absolute physical or safety limits, such as actuator saturation or collision boundaries, that must never be violated. Soft constraints, such as comfort zones or preferred operating ranges, are allowed to be breached at a quantified penalty, often implemented via slack variables to maintain optimization feasibility when conflicts arise.
Glossary
Constraint Handling (Hard and Soft Constraints)

What is Constraint Handling (Hard and Soft Constraints)?
Constraint handling is the systematic method for enforcing physical and operational limits within an optimization-based control framework, distinguishing between inviolable hard constraints and flexible soft constraints.
The distinction is critical for robust control. Hard constraints guarantee safety and hardware protection but can render the Optimal Control Problem (OCP) infeasible. Soft constraints, penalized in the cost function, ensure the solver always finds a solution, trading off minor violations for overall stability. This architecture allows embodied intelligence systems, like autonomous robots, to operate reliably in unpredictable environments by prioritizing critical limits while gracefully handling secondary ones.
Core Characteristics of Constraint Handling
Constraint handling is the mechanism by which Model Predictive Control (MPC) enforces physical, safety, and operational limits. It distinguishes between hard constraints that are inviolable and soft constraints that can be breached at a defined penalty.
Hard Constraints
Hard constraints are absolute physical or safety limits that must never be violated under any circumstance. They define the fundamental operating envelope of the system.
- Examples: Actuator saturation limits (e.g., maximum steering angle), collision avoidance boundaries, or minimum/mimumum tank levels.
- Implementation: Enforced as strict inequalities (e.g.,
x ≤ x_max) within the optimization problem. If no feasible solution exists that satisfies all hard constraints, the optimization fails, potentially causing system shutdown.
Soft Constraints
Soft constraints represent desirable operational limits that are allowed to be violated at a quantifiable cost. This ensures the optimization problem remains feasible.
- Examples: Preferred velocity range, ideal temperature band, or target zone for a robotic arm.
- Implementation: Typically enforced using slack variables (ε) added to the constraint (e.g.,
x ≤ x_max + ε). A penalty term (e.g.,ρ * ε²) is added to the cost function, whereρis a tuning weight. The optimizer will violate the constraint only if the benefit outweighs the penalty.
Slack Variables
Slack variables are auxiliary, non-negative decision variables introduced to convert hard constraints into soft constraints, thereby guaranteeing feasibility.
- Mechanism: A constraint
g(x) ≤ 0is relaxed tog(x) ≤ ε, whereε ≥ 0. The termρεorρε²is added to the objective function. - Purpose: They act as a "safety valve," allowing the controller to temporarily breach a zone (like a soft speed limit) to handle disturbances or conflicting objectives, rather than failing entirely.
Constraint Tightening (Robust MPC)
Constraint tightening is a robust MPC technique where hard constraints are deliberately made more conservative offline to account for bounded model uncertainty or disturbances, ensuring the real system never violates its true limits.
- Process: The feasible region is shrunk by a "tube" margin. If the nominal predicted state satisfies the tightened constraint, the actual state is guaranteed to satisfy the original constraint.
- Use Case: Critical for safety in applications like autonomous vehicle platooning or chemical process control, where uncertainty must not lead to constraint violation.
Feasibility vs. Optimality
A central trade-off in constraint handling is between feasibility (finding any solution that satisfies constraints) and optimality (finding the best solution).
- Infeasibility: Occurs when hard constraints conflict, leaving no solution. This is a critical failure mode.
- The Role of Softening: By softening lower-priority constraints, feasibility is restored. The optimizer then finds the best solution among feasible ones, which may involve minimally violating soft constraints to satisfy higher-priority goals.
Constraint Types: State, Input, and Output
Constraints are categorized by the system variable they limit, each with distinct implications.
- State Constraints: Limits on internal states (e.g., robot joint position, chemical concentration). Often critical for safety.
- Input (Control) Constraints: Limits on actuator commands (e.g., motor torque, valve position). These are typically hard due to physical saturation.
- Output Constraints: Limits on measured outputs. These can be challenging as they must be enforced indirectly via the model prediction.
How Constraint Handling Works in MPC
Constraint handling is the core mechanism in Model Predictive Control (MPC) that enforces physical and operational limits on a system's states and control inputs during online optimization.
Constraint handling in Model Predictive Control (MPC) is the explicit enforcement of physical and operational limits within the online Optimal Control Problem (OCP). Hard constraints, such as actuator saturation or collision avoidance, define an inviolable feasible region; the optimizer must find a solution that never breaches them, ensuring absolute safety. Soft constraints, like desired velocity limits, are allowed to be violated but incur a penalty in the cost function, typically implemented via slack variables. This penalty-based approach guarantees the optimization problem remains feasible even when conflicting demands arise.
The distinction is critical for real-world deployment. Hard constraints protect against catastrophic failures but can render the OCP infeasible. Soft constraints, by introducing a tunable trade-off between performance and constraint violation, ensure the controller always returns a sub-optimal but executable action. Advanced formulations, such as those using Control Barrier Functions (CBFs), can blend these approaches to provide rigorous safety guarantees. Ultimately, effective constraint encoding is what transforms a theoretical optimization into a practical, robust feedback control law for physical systems.
Practical Examples of Hard and Soft Constraints
In Model Predictive Control, constraints are mathematical limits on system variables. Hard constraints are inviolable physical or safety limits, while soft constraints represent desirable operating ranges that can be breached at a calculated penalty.
Autonomous Vehicle Steering
A hard constraint enforces the vehicle's steering angle to remain within the mechanical limits of the steering rack (e.g., ±30 degrees). Violation is physically impossible. A soft constraint encourages the vehicle to stay centered in its lane. The optimizer may allow a temporary, small breach of this lane-centering constraint to avoid a sudden jerk in steering, penalizing the deviation in the cost function instead.
Robotic Arm Payload Lifting
Hard constraints are applied to the joint torques, ensuring they never exceed the maximum ratings of the motors, which would cause overheating or damage. Soft constraints are used for the desired end-effector path. The optimizer may allow the arm to slightly deviate from the ideal Cartesian path to find a sequence of joint angles that satisfies all torque limits, penalizing the path error to keep it minimal.
Chemical Process Temperature Control
A hard constraint is placed on the maximum reactor temperature to prevent a runaway exothermic reaction or catalyst degradation. This limit must never be violated. Soft constraints define an optimal operating temperature range for yield. The controller may allow the temperature to drift slightly above this range if necessary to respect the hard maximum, incurring a cost for reduced efficiency but ensuring absolute safety.
Drone Battery Management
A hard constraint mandates that the battery's state-of-charge (SoC) must remain above 15% at all times to prevent deep discharge and permanent cell damage. A soft constraint encourages the SoC to stay above 30% to preserve battery health for long-term use. The flight controller might dip below 30% to complete a critical mission segment, penalizing the low SoC in its plan, but will always initiate a mandatory landing before hitting the 15% hard limit.
Implementation via Slack Variables
Soft constraints are typically implemented using slack variables. These are additional, non-negative optimization variables that quantify the magnitude of a constraint violation.
- The slack variable is added to the constraint, effectively relaxing it.
- A penalty term, weighted by a tuning parameter, is added to the cost function.
- This ensures the optimization problem remains feasible; if a hard constraint makes the ideal solution impossible, the optimizer can 'pay a price' via slack to find the next-best, physically possible solution.
Feasibility vs. Optimality Trade-off
The core trade-off in constraint handling is between feasibility (finding any solution that satisfies all hard constraints) and optimality (finding the best-performing solution).
- Hard constraints-only: Guarantees safety but can lead to infeasibility where no control sequence exists that satisfies all limits, causing the optimizer to fail.
- Soft constraints: Ensure feasibility by allowing controlled violations of less-critical limits, guaranteeing the controller always has a 'fallback' solution, even if sub-optimal. The penalty weight determines how strictly the soft constraint is enforced.
Hard Constraints vs. Soft Constraints
A comparison of the two primary methods for enforcing limits on system variables (states, inputs, outputs) within a Model Predictive Control (MPC) optimization problem.
| Feature | Hard Constraints | Soft Constraints |
|---|---|---|
Definition | Mathematical inequalities that must be strictly satisfied at all times. A solution violating a hard constraint is deemed infeasible. | Mathematical inequalities that are allowed to be violated, but each violation incurs a penalty in the cost function. |
Mathematical Form | g(x, u) ≤ 0 (strict) | g(x, u) - s ≤ 0, s ≥ 0 |
Implementation | Directly enforced as constraints in the optimization problem (e.g., in the QP or NLP solver). | Implemented via slack variables (s) added to the optimization problem. The slack variable magnitude represents the violation. |
Feasibility Guarantee | No inherent guarantee. An infeasible problem can occur if constraints are too tight or conflicting, causing solver failure. | High guarantee. The addition of slack variables ensures a feasible solution always exists, though possibly at high cost. |
Primary Use Case | Physical limits that cannot be breached under any circumstance (e.g., actuator saturation, joint limits, safety-critical boundaries). | Performance limits or desired operating regions where temporary violations are acceptable but undesirable (e.g., velocity limits, comfort zones, soft obstacle boundaries). |
Solver Behavior | Solver searches within a strictly bounded feasible set. Can lead to infeasibility errors. | Solver trades off constraint violation against other objectives. Always returns a solution. |
Design Parameter | Constraint bounds (e.g., u_min, u_max). | Penalty weights (ρ) on slack variables in the cost function (e.g., ρ * s²). |
Impact on Performance | Can lead to conservative or infeasible control actions if not carefully tuned for all operating conditions. | Allows for graceful degradation. Performance smoothly worsens as violations increase, dictated by penalty weights. |
Typical Penalty Function | N/A (enforced via set membership). | Quadratic: ρ⋅s², or L1-norm: ρ⋅|s|, often with a linear term for exact penalization. |
Frequently Asked Questions
In Model Predictive Control (MPC), constraints define the safe and feasible operating limits of a system. This FAQ explains the critical distinction between hard and soft constraints, their mathematical implementation, and their impact on controller design and performance.
Hard constraints are absolute physical or safety limits that must never be violated, such as actuator saturation or collision boundaries. Soft constraints are desirable operational limits that can be temporarily breached at a calculated penalty, such as a temperature setpoint or a velocity limit, to maintain the feasibility of the online optimization problem.
Mathematically, hard constraints are expressed as strict inequalities (e.g., u_min ≤ u(t) ≤ u_max). Soft constraints are implemented by introducing slack variables (ε) into the optimization, which absorb constraint violations. A penalty term weighted by ρ (e.g., ρ * ε²) is added to the cost function. The optimizer then decides whether violating the soft constraint is 'cheaper' than the alternative, such as a drastic control move.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Constraint handling is a foundational pillar of robust Model Predictive Control. These related concepts define the mathematical and practical tools used to enforce system limits, manage uncertainty, and guarantee safety.
Optimal Control Problem (OCP)
The Optimal Control Problem (OCP) is the core mathematical formulation solved at each step of MPC. It is defined by three key components:
- A dynamic model (e.g., state-space equations) predicting future system behavior.
- A cost function to be minimized (e.g., tracking error, control effort).
- A set of constraints on states, inputs, and outputs over the prediction horizon. Hard and soft constraints are explicitly defined within this OCP framework. The solver's ability to find a feasible solution depends entirely on how these constraints are formulated and handled.
Slack Variables
Slack variables are auxiliary, non-negative decision variables added to an optimization problem to transform hard constraints into soft constraints. In MPC:
- They are added to constraint equations (e.g.,
state <= limit + slack). - A penalty term weighted by a tuning parameter is added to the cost function to penalize any non-zero slack.
- This mechanism ensures the optimization problem remains feasible even when constraints cannot be strictly satisfied, allowing the controller to prioritize which limits are most critical to honor. The magnitude of the slack indicates the severity of the constraint violation.
Feasibility
Feasibility refers to the existence of at least one sequence of control inputs that satisfies all the system's dynamic equations and hard constraints over the prediction horizon. It is a fundamental requirement for the MPC optimization problem. Infeasibility causes the solver to fail. Strategies to ensure feasibility include:
- Careful constraint design and horizon selection.
- Using soft constraints with slack variables.
- Implementing constraint softening or relaxation techniques.
- Employing robust MPC methods that account for uncertainty in advance.
Control Barrier Function (CBF)
A Control Barrier Function (CBF) is a mathematical tool used to enforce safety constraints by defining a forward-invariant safe set. While not part of core MPC, it is a powerful complementary and sometimes integrated approach:
- A CBF defines a safety boundary; control actions must keep the system state within this boundary.
- It can be used as a safety filter applied to the inputs generated by an MPC or other controller, overriding them only if necessary to avoid constraint violation.
- Recent research explores embedding CBF conditions as constraints within the MPC OCP itself, creating a unified predictive safety framework that is less conservative than pure worst-case robust MPC.
Chance Constraints
Chance constraints are probabilistic constraints used primarily in Stochastic MPC. Instead of requiring constraints to hold always (hard) or with a penalty (soft), they require satisfaction with a specified probability (e.g., P(state <= limit) >= 0.95).
- They explicitly account for uncertainty in disturbances or model parameters.
- They are less conservative than robust MPC approaches, which plan for the worst-case scenario, leading to better average performance.
- Implementing chance constraints typically involves reformulating them into deterministic, tractable constraints that can be handled by standard convex solvers, often relying on distributional assumptions.
Robust MPC
Robust MPC is a class of strategies designed to guarantee constraint satisfaction and stability despite bounded model uncertainty, disturbances, or noise. It handles uncertainty differently from soft constraints or chance constraints:
- It uses a tube-based approach, where a nominal trajectory is computed, and constraints are tightened to ensure the actual, uncertain state remains within a bounded 'tube' around it.
- It employs min-max optimization, where the controller plans for the worst-case realization of uncertainty within a defined set.
- This method provides deterministic, worst-case guarantees but can be computationally intensive and may lead to conservative control actions compared to stochastic or soft-constraint methods.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us