Generated reference › Constrained Nonlinear Minimization — Control Systems/Optimization
kind: generated#block#control-systems-optimization

Constrained Nonlinear Minimization — Control Systems/Optimization

min f

Control_Systems/Optimization/Constrained_Nonlinear_Minimization · 1 input / 3 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

Constrained Nonlinear Minimization

Control Systems / Optimization

Finds the x that minimizes a polynomial subject to polynomial equality and inequality constraints and to bounds, every coefficient arriving on a port – MATLAB's fmincon with its active-set algorithm, solved again on every sample:

minimize over x   f(x)   subject to   ceqk(x) = 0,   ck(x) ≤ 0,   lb ≤ x ≤ ub

where f, every ceqk and every ck is Σt at · x1e(t,1) · … · xne(t,n), each with its own coefficients a over ONE shared set of terms.

The exponents e are configuration – the problem's shape, which fixes the loop bounds every export unrolls. The coefficients are the signal: one column per function, stacked into a single port. So the objective and the constraints can change on every sample while their form does not.

The search is fmincon's active-set method: a sequential quadratic programming iteration with a BFGS Hessian approximation, an active-set QP with its own feasibility phase, a merit line search and a first-order optimality test. Gradients are exact, because a polynomial's gradient is another polynomial.

The factory setting is fmincon's documented example: Rosenbrock's function 100(x₂ − x₁²)² + (1 − x₁)² inside the unit disk x₁² + x₂² ≤ 1, from [0; 0], over the terms [0 2; 2 1; 4 0; 0 0; 1 0; 2 0] (x₂², x₁²x₂, x₁⁴, 1, x₁, x₁²). Feed c the column [100; −200; 100; 1; −2; 1; 1; 0; 0; −1; 0; 1] and the answer is x = (0.7864, 0.6177).

Ports

  • c – the coefficients, a column [(1 + p + q)·T,1] for p equalities and q inequalities: rows 1..T are the objective's, one per ROW of Term Exponents in the same order, then T rows for each equality in turn, then T rows for each inequality. A row vector is refused.
  • x – the minimizer, [n,1] (n = the columns of Term Exponents).
  • fval – f(x), a scalar [1,1].
  • exitflag – a scalar [1,1], fmincon's own: 1 the first-order optimality measure is below Optimality Tolerance and the constraints hold within Constraint Tolerance; 4 the search direction became smaller than twice Step Tolerance; 5 the predicted change in f became smaller than Function Tolerance (both with the constraints met); 0 a limit below stopped the search; −2 no feasible point was found.

Parameters

  • Options – empty (default), or the path of a Solver Options block (Home/Solver Options), MATLAB’s options argument: for the run, every option it sets replaces this block’s parameter of the same name; one it leaves at default, or one this block does not have, changes nothing.
  • Term Exponents – a [T,n] matrix of whole numbers from 0 to 4: row t, column i is the power of xi in term t. T is 1 to 8, n is 1 to 4, and no term may total more than degree 4. The caps are the export's, not the search's – see Code export.
  • Number of Equalities – p, the equality constraints ceq(x) = 0: from 0 to 3, and fewer than n.
  • Number of Inequalities – q, the inequality constraints c(x) ≤ 0: from 0 to 6.
  • Start Point – x0, n entries. A start outside a bound is moved onto it first, as fmincon does. The search is LOCAL, so on a problem with several local minima this chooses which one is found.
  • Lower Bounds lb, Upper Bounds ub – [n,1] each, or [] for none; -Inf/Inf entries leave a variable unbounded on that side. No lower bound may exceed its upper bound.
  • Step Tolerance – StepTolerance, positive; default 1e-6. The search stops with flag 4 once the largest entry of the QP step is below twice this.
  • Function Tolerance – FunctionTolerance, positive; default 1e-6. The search stops with flag 5 once the step's predicted change in f is below this.
  • Optimality Tolerance – OptimalityTolerance, positive; default 1e-6: the first-order measure – the largest entry of the Lagrangian's gradient, or of a multiplier times its constraint – that stops the search with flag 1.
  • Constraint Tolerance – ConstraintTolerance, positive; default 1e-6: how far a constraint may be violated and still count as met.
  • Maximum Iterations – MaxIterations, 1 to 2000, default 400, MATLAB's own.
  • Maximum Function Evaluations – MaxFunctionEvaluations, 0 to 2000. 0 (the default) means MATLAB's own for this algorithm, 100·n.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. Each prints the same description of the iteration that the simulation itself runs, so every target does the same arithmetic in the same order as the simulation.

The exponent pattern is unrolled once: each term's monomial and its n partial derivatives, shared by every function. The bounds are written into the arithmetic, so they are not tunable on the generated code. The iteration is emitted with fixed trip counts and flags that stop the arithmetic once the answer is found, because none of the ten has an unbounded loop a hardware target could also carry. The caps above keep the Java method under the language's 64 KB limit.

⚠ The three HDL targets run the search in simulation-only real arithmetic, quantizing only at the port boundaries: a QP divides and compares across many orders of magnitude, which a Q16.16 datapath does not carry.

Simulink bridge

None (Support::None). The Optimization Toolbox ships no Simulink library at all and fmincon is a MATLAB function, so there is no block to map onto; the bridge reports this block rather than dropping it silently, and it has no parity testbench. Code export verification still covers it across all ten languages.

Notes

  • Stateless: the search restarts from Start Point on every sample, so the answer depends only on the coefficients present at that step.
  • ⚠ Active-set, not interior-point. fmincon's default algorithm is interior-point; this block reproduces optimoptions('fmincon','Algorithm','active-set'), which on a problem with several local minima may find a different one.
  • ⚠ LOCAL. The method finds a point where no small feasible step lowers f; on a non-convex problem that depends on Start Point.
  • ⚠ If f is unbounded below on the feasible set – an odd-degree term with nothing to hold it – there is no answer, and the point reported is wherever the evaluation limit stopped the search (flag 0).
  • eps has no spelling in nine of the ten targets, so MATLAB's eps and the constants built from it are the exact binary values here.

Code facts#

FactValue
registered typeControl_Systems/Optimization/Constrained_Nonlinear_Minimization
familyControl_Systems/Optimization
solver environment classICoreBlock_0_Control_Systems_1_Optimization_2_Constrained_Nonlinear_Minimization
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Constrained_Nonlinear_Minimization/ICoreBlock_0_Control_Systems_1_Optimization_2_Constrained_Nonlinear_Minimization.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Constrained_Nonlinear_Minimization/ICoreBlock_0_Control_Systems_1_Optimization_2_Constrained_Nonlinear_Minimization.h
default size on canvas190 × 100 px
ports at insert1 in, 3 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublec
2outICoreDoublex
3outICoreDoublefval
4outICoreDoubleexitflag

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Term Exponents[0 2; 2 1; 4 0; 0 0; 1 0; 2 0]—
Number of Equalities0—
Number of Inequalities1—
Start Point[0; 0]—
Lower Bounds lb[]—
Upper Bounds ub[]—
Step Tolerance1e-6—
Function Tolerance1e-6—
Optimality Tolerance1e-6—
Constraint Tolerance1e-6—
Maximum Iterations400—
Maximum Function Evaluations0—
Options——

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::None
Simulink path—
port-count rulePortsParam::None
SampleTime parameteryes

Caveat (shown to the user): the Optimization Toolbox ships no Simulink library at all, so there is no block to map onto and no library path a diagram could name; fmincon is a MATLAB function. The block is reported rather than dropped when a model crosses

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 no sample under docs/generated/samples/ — nothing to cross-check (P8.1)

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

Constrained Nonlinear Minimization -- fmincon over polynomials whose coefficients are a wire minimize f(x) subject to ceq(x) = 0, c(x) <= 0, lb <= x <= ub [x, fval, exitflag] = fmincon(f, x0, [], [], [], [], lb, ub, nonlcon) (Algorithm 'active-set')

THE OBJECTIVE SEAM IS THE FAMILY'S. The exponent pattern is configuration -- the problem's SHAPE, which fixes every loop bound the ten exports unroll -- and the coefficients are the signal. The objective, the equalities and the inequalities share one term dictionary, as Minimax's objectives do, so the port is their coefficient columns stacked into one: the objective's first, then each equality's, then each inequality's. One unrolled evaluation then serves every function and every gradient.

THE SOLVER IS fmincon's 'active-set' ALGORITHM, TRANSCRIBED, and it is the same nlconst.m SQP and qpsub.m QP that Minimax and Goal Attainment already carry, run under fmincon's own merit function: a BFGS Hessian with its two positive-definiteness repairs, the first-order (KKT) stopping test, testConvergence's fresh multipliers from -AN(ACTIND,:)' \ gf, and qpsub with its EQUALITY branches -- the warm-start safeguard that puts every equality back in front of the working set, eqnsolv's consistency test and its removal of redundant equalities, and the phase-1 LP whose equality rows carry no slack. So the whole solver lives in ICoreGoalAttainmentSupport; this block is its constrained program. fmincon's DEFAULT algorithm is 'interior-point', which is sealed (barrier.p) and is NOT what this block runs; 'active-set' is the one whose every line is readable in R2026a, and it is the one this block reproduces.

⚠ MEASURED AGAINST R2026a, fmincon('Algorithm','active-set') with the analytic gradients supplied as this block computes them, over 1900 random problems -- n = 1..4, up to 2 equalities and 3 inequalities over up to 10 terms of degree <= 4 (two past this block's cap of 8), bounds on about half the variables -- and 400 DEGENERATE ones (a duplicated equality, an equality whose gradient vanishes at a feasible start, a zero-gradient constraint at an infeasible start), the PROGRAM THIS BLOCK RUNS, compiled standalone and fed the same problems:

exit flag identical on every run that stopped on a test 2042 / 2042 iteration count identical 2041 / 2042 evaluation count identical 2040 / 2042 x within 1e-12 relative 2034 / 2042, bit-identical on 1238

and at non-default tolerances and limits (500 more), 409 / 409 in flag and iteration count. The 258 runs that ran into the evaluation limit (flag 0) agree on the flag in 249: those are mostly unbounded problems whose last point is an artefact of the path in both.

At the factory setting -- fmincon's documented "Rosenbrock inside the unit disk" example -- this block answers x = [0.786415154246272; 0.6176983125996], flag 5, in 20 iterations and 59

Sample results#

No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.