Inferensys

Glossary

Constraint Handling (Hard and Soft Constraints)

Constraint handling in Model Predictive Control (MPC) is the method of enforcing physical and operational limits on system variables, distinguishing between inviolable hard constraints and flexible soft constraints that incur a penalty for violation.
ML engineer managing model versions on laptop, version history visible, technical Git-like workflow.
MODEL PREDICTIVE CONTROL (MPC)

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.

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.

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.

MODEL PREDICTIVE CONTROL (MPC)

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.

01

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.
02

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.
03

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) ≤ 0 is relaxed to g(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.
04

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.
05

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.
06

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.
MECHANISM

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.

MODEL PREDICTIVE CONTROL (MPC)

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.

01

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.

02

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.

03

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.

04

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.

05

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.
06

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.
CONSTRAINT HANDLING IN MPC

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.

FeatureHard ConstraintsSoft 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.

CONSTRAINT HANDLING

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.

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.