1. Home
  2. Experimental Info - Recipes
  3. Recipe Normalization Solver — How It Works

Recipe Normalization Solver — How It Works

Each recipe normalization set up is composed of the following components:

  • Solver Aspects: A list of all variables and constraints (ingredients, totals, calculations, ratios)
  • Recipe Workflow Structure: The multi-step recipe topology (which steps feed into which)
  • Objective Setup: What the solver should optimize for
  • Epsilon: Solver precision tolerance (default 1e-5)
  • Optimize Mode: If set to *‘*Optimize On Fail’, allows the solver to slightly relax constraints when infeasible

Decision Variables

The solver creates a single variable vector of length N, where each element is either:

  • An ingredient quantity within a recipe step
  • A step-to-step relationship quantity treated as a free variable

Objective Function

Three objective types are available:

TypeFormulaMeaning
Defaultminimize Σ(xᵢ – x₀ᵢ)²Closest feasible point to original values (least-squares)
Proportionalminimize Σxᵢ – x₀ᵢ × (x_ref / x₀_ref)
Customminimize/maximize/target a weighted-sum calculationUser-defined optimization of a specific calculation

When Optimize Mode is set to Optimize on Fail, a slack variable ε ≥ 0 is added to the objective with a large penalty: base_objective + 1000 × |ε|. This allows slight constraint violations when the problem is otherwise infeasible.

Constraint Types

ConstraintWhat It DoesMathematical Form
Input VariableBounds on individual ingredient quantities (min, max, fixed)xᵢ = / ≥ / ≤ value
Recipe TotalThe sum of all compounded inputs for final steps equals a targetΣ(compounded_xᵢ) = / ≥ / ≤ total
Weighted SumA linear combination of variables hits a targetΣ(cᵢ × compounded_xᵢ) = / ≥ / ≤ target
Weighted AverageA ratio (numerator/denominator) hits a target, linearized to avoid divisionΣ(nᵢxᵢ) – target × Σ(dᵢxᵢ) = / ≥ / ≤ 0
Composite CalculationMulti-term numerator/denominator with bias constants(Σnum + bias_n) – target × (Σden + bias_d) = 0
Ingredient RatioFixed proportional ratios between ingredient pairscᵢ × x[i+1] – c[i+1] × xᵢ = 0
Relationship VariableBounds on step-to-step relationship quantitiesSame as input variable constraints

When the epsilon slack variable is active, every constraint is softened by ±ε (e.g., x = value becomes value – ε ≤ x ≤ value + ε).

Post-Solve Processing

Solved values go through two cleanup steps:

  1. Aspect-enforced snapping: Compensates for floating-point imprecision. If a variable had an equality constraint of exactly 5.0, the solver might return 4.9999999997 — this snaps it back to 5.0. Similarly for ≥ and ≤ bounds.
  2. Sanitization: Rounds very small residuals to zero (e.g., 1e-20 → 0), while preserving meaningful precision.

Error Cases

StatusMeaning
OptimalSolution found
Optimal InaccurateSolution found but may have numerical issues (accepted only if accept_optimal_inaccurate is true)
infeasibleConstraints are contradictory — no solution exists
Other non-optimalGeneric solver failure
Updated on February 19, 2026

Was this article helpful?

Related Articles