Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/FabianeloV/Metodo-simplex/llms.txt

Use this file to discover all available pages before exploring further.

The Karush-Kuhn-Tucker (KKT) conditions are necessary optimality conditions for constrained nonlinear programs. For a minimization problem with inequality constraints gᵢ(x) ≤ 0 and equality constraints hⱼ(x) = 0, any local optimum x* must satisfy:
  1. Stationarity: ∇f(x*) + Σ λᵢ ∇gᵢ(x*) + Σ μⱼ ∇hⱼ(x*) = 0
  2. Dual feasibility: λᵢ ≥ 0 for all inequality constraints
  3. Primal feasibility: gᵢ(x*) ≤ 0 and hⱼ(x*) = 0
  4. Complementary slackness: λᵢ · gᵢ(x*) = 0
The engine solves this by enumerating all combinations of active inequality constraints. For each subset S of inequality constraints treated as active (gᵢ(x) = 0, i ∈ S), it assembles a square KKT system and solves it with multivariate Newton’s method. Candidates that violate dual feasibility (λᵢ < 0) or primal feasibility (an inactive constraint is violated) are discarded. The best valid candidate becomes the reported optimum. For maximization, the engine internally minimizes −f subject to the same constraints; the multipliers returned are directly the correct KKT multipliers for the original maximization problem.

Endpoint

POST /api/v1/kkt/solve

Request

expression
string
required
The objective function as a SymPy-compatible symbolic string. Use ** for exponents and * for multiplication.Examples: "x**2 + y**2", "x**2 + 2*y**2 - x*y"
variables
string[]
required
List of variable names in the expression. Must contain 2 or 3 names.Example: ["x", "y"]
goal
string
required
Optimization direction: "min" or "max".
constraints
KKTConstraint[]
required
List of constraints. Must contain 1 to 5 entries.

Response

status
string
"optimal" if at least one case satisfies all KKT conditions; "infeasible" if no valid case was found across all enumerated active-set combinations.
variables
string[]
Echo of the variable names from the request.
function_str
string
The objective expression as parsed and simplified by SymPy.
goal
string
Echo of the goal field from the request ("min" or "max").
constraints_str
string[]
Human-readable representation of each constraint as processed by the engine, e.g., ["x + y ≤ 4", "x ≥ 0"].
optimal_point
number[] | null
Coordinates of the global KKT optimum found, ordered to match variables. null when status is "infeasible".
optimal_value
number | null
Objective function value at optimal_point.
optimal_case_id
number | null
The case_id of the winning case. Use this to look up the full case detail (active constraints and multipliers) in the cases array.
cases
KKTCase[]
Full record of every active-set combination tried. Includes both valid and discarded cases — useful for understanding why certain constraint combinations were rejected.
cases_explored
number
Total number of active-set combinations tried. For m inequality constraints, this equals 2^m (all subsets). For example, 3 inequality constraints → 8 cases explored.
message
string
Human-readable summary of the result, including the optimal point, objective value, and winning case ID.

Multiplier Conventions

lambdas (λ) are the inequality constraint multipliers. For a valid KKT point, all λᵢ must be non-negative (dual feasibility). Keys reflect the original 1-based position of each constraint in the constraints array — for example, if constraints at indices 0 and 2 are active, the keys are "λ1" and "λ3".mus (μ) are the equality constraint multipliers. They have no sign restriction and are indexed over the equality constraints in the order they appear in the request.

Example

Minimize f(x, y) = x² + 2y² − x·y subject to x + y ≤ 4 and x ≥ 0:
curl -X POST https://api.example.com/api/v1/kkt/solve \
  -H "Content-Type: application/json" \
  -d '{
    "expression": "x**2 + 2*y**2 - x*y",
    "variables": ["x", "y"],
    "goal": "min",
    "constraints": [
      { "expression": "x + y", "inequality": "<=", "rhs": 4 },
      { "expression": "x",     "inequality": ">=", "rhs": 0 }
    ]
  }'
Response:
{
  "status": "optimal",
  "variables": ["x", "y"],
  "function_str": "x**2 - x*y + 2*y**2",
  "goal": "min",
  "constraints_str": ["x + y ≤ 4", "x ≥ 0"],
  "optimal_point": [0.0, 0.0],
  "optimal_value": 0.0,
  "optimal_case_id": 0,
  "cases": [
    {
      "case_id": 0,
      "active_indices": [],
      "status": "valid",
      "point": [0.0, 0.0],
      "lambdas": {},
      "mus": {},
      "objective_value": 0.0,
      "note": "Caso válido (restricciones activas: ninguna)."
    },
    {
      "case_id": 1,
      "active_indices": [0],
      "status": "dual_infeasible",
      "point": [1.333, 2.667],
      "lambdas": { "λ1": -0.4444 },
      "mus": {},
      "objective_value": 5.333,
      "note": "Descartado: λ1 = -0.4444 < 0 (debe ser ≥ 0)."
    }
  ],
  "cases_explored": 4,
  "message": "Punto óptimo KKT en (x = 0, y = 0) con f = 0 (caso #0)."
}

Algorithm Notes

The number of cases explored grows as 2^m, where m is the number of inequality constraints. With the maximum of 5 constraints, up to 32 cases are explored. Equality constraints ("=") do not create additional cases — they are always treated as active.
cases_explored counts every active-set combination attempted, including cases that failed to converge. Inspecting the cases array lets you trace exactly which combinations were tried, why each was accepted or rejected, and what multiplier values were found.
KKT conditions are necessary but not sufficient for a global optimum in non-convex problems. If the feasible region is non-convex or the objective has multiple local optima, the engine returns the best valid KKT point found, which may be a local rather than global optimum.

Build docs developers (and LLMs) love