Generated reference › Linear Program — Control Systems/Optimization
kind: generated#block#control-systems-optimization

Linear Program — Control Systems/Optimization

Control_Systems/Optimization/Linear_Program · 2 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.

Linear Program

Control Systems / Optimization

Solves a linear program on every step – MATLAB's linprog:

minimize f·x   subject to   A·x ≤ b, Aeq·x = beq, lb ≤ x ≤ ub

The cost f and the inequality right-hand side b are signals, so the problem can change every step (a cost that follows a price, constraints that follow the state – the way an MPC uses it); the constraint matrices and bounds are parameters. The block publishes the minimizer, the minimum and linprog's exit flag.

Ports

  • f – the cost vector, [n,1], n the number of columns of Inequality Matrix A.
  • b – the inequality right-hand side, [m,1], m the number of rows of A.
  • x – the minimizer, [n,1]. All zeros when the exit flag is not 1.
  • fval – f·x at the minimizer, [1,1]; 0 when the exit flag is not 1.
  • exitflag – [1,1], linprog's codes: 1 optimal, 0 the iteration cap was reached, −2 no point satisfies the constraints, −3 the minimum is unbounded below.

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.
  • Inequality Matrix A – [m,n], 1 ≤ m ≤ 32, 1 ≤ n ≤ 16. It fixes both port sizes. A problem with no inequality can use one row of zeros and feed b a positive constant.
  • Equality Matrix Aeq – [p,n], p ≤ 16, or [] (the default) for none.
  • Equality Vector beq – [p,1], or [] with an empty Aeq.
  • Lower Bounds lb – a scalar for every variable or an n-vector; -inf leaves a variable unbounded below and [] means -inf throughout, as in linprog. The default 0 is the usual x ≥ 0 – note linprog's own default is no bound at all.
  • Upper Bounds ub – the same, inf (the default) or [] for no bound.
  • Maximum Iterations – the most pivots one step may take, 1 to 1000, default 100. It bounds the work per step; a problem that needs more reports exit flag 0.
  • Optimality Tolerance – a reduced cost must be below minus this to enter the basis; default 1e-7, linprog's.
  • Constraint Tolerance – phase I ending above this is infeasible (exit flag −2); default 1e-7, linprog's.
  • 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, all from one program, so every target pivots the same tableau in the same order as the simulation. The matrices, bounds, iteration cap and tolerances are baked into the exported code; re-export after changing them. A step costs at most Maximum Iterations pivots.

The three HDL targets run the solver in real arithmetic and quantize only at the ports: simulation-only, not offered as synthesizable. A simplex divides by a data-dependent pivot and chooses its rows by comparison, neither of which belongs in a Q16.16 datapath.

Simulink bridge

None (Support::None). linprog is an Optimization Toolbox function and that toolbox ships no Simulink library, so there is no path a diagram could name. The bridge reports this block rather than dropping it silently, and it has no parity testbench; code export verification covers all ten languages.

Notes

  • The algorithm is a two-phase primal simplex on a dense tableau with Bland's rule: the entering column is the lowest-index one with a negative reduced cost, ties in the ratio test go to the lowest-index basic variable, so it cannot cycle. linprog's default is a dual simplex. When the minimizer is unique the two agree to rounding (measured: see the source banner). When it is not – a cost parallel to a face of the feasible set – any point of that face is a minimizer, and the vertex this block returns may differ from linprog's; fval is the same.
  • Infeasible wins: a problem whose constraints conflict reports −2 whatever the cost, as linprog does.
  • Maximum Iterations counts this solver's pivots, not linprog's iterations (its presolve often solves a small problem in none).
  • The answer is discrete in f: as f turns, x jumps from one vertex to the next. On the HDL targets f arrives quantized to Q16.16, so a step whose cost sits within about 1e-5 of a vertex change can land on the neighbouring vertex there. x is continuous in b.
  • Algebraic: every output depends on this step's f and b alone; there is no state and no warm start.

Code facts#

FactValue
registered typeControl_Systems/Optimization/Linear_Program
familyControl_Systems/Optimization
solver environment classICoreBlock_0_Control_Systems_1_Optimization_2_Linear_Program
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Linear_Program/ICoreBlock_0_Control_Systems_1_Optimization_2_Linear_Program.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Linear_Program/ICoreBlock_0_Control_Systems_1_Optimization_2_Linear_Program.h
default size on canvas160 × 90 px
ports at insert2 in, 3 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublef
2inICoreDoubleb
3outICoreDoublex
4outICoreDoublefval
5outICoreDoubleexitflag

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
Inequality Matrix A[1 1; 2 -1]—
Equality Matrix Aeq[]—
Equality Vector beq[]—
Lower Bounds lb0—
Upper Bounds ubinf—
Maximum Iterations100—
Optimality Tolerance1e-7—
Constraint Tolerance1e-7—
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): linprog is an Optimization Toolbox function, not a Simulink library block -- that toolbox ships no Simulink library at all -- so there is no path a diagram could name; 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 every stimulus in the sample errored — cross-checks skipped

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

Linear Program -- Optimization Toolbox's linprog, solved on every step minimize f.' * x subject to A * x <= b, Aeq * x = beq, lb <= x <= ub

f and b arrive on ports; A, Aeq, beq, lb and ub are config. Outputs x, fval = f.' * x and linprog's exit flag: 1 optimal, 0 iteration cap, -2 infeasible, -3 unbounded.

The solver, written ONCE here as C++ for the run and once as an ICoreStatementProgram for the ten exports, in the same operation order:

  1. Standard form y >= 0. Per variable, decided at config load: lb finite -> x = lb + y (and

a row y <= ub - lb when ub is finite too); only ub finite -> x = ub - y; both infinite -> x = y+ - y-. So the tableau's SHAPE is fixed by config and only its numbers move.

  1. One row per inequality (with a slack), per finite bound pair, and per equality. A row whose

right-hand side is negative is negated; it and every equality row take an artificial. An inequality row with rhs >= 0 starts with its slack basic.

  1. Phase I minimizes the sum of the artificials. Above the Constraint Tolerance at its end:

exit -2. Otherwise basic artificials (at zero) are pivoted out on the first non-artificial column with a nonzero entry; a row with none is redundant and stays.

  1. Phase II on the cost. Entering column: the LOWEST index with reduced cost below

-Optimality Tolerance (Bland). Leaving row: minimum ratio over entries above 1e-9, ties (within 1e-12) to the lowest basic-variable index (Bland) -- so it cannot cycle. No entry above 1e-9 in the entering column: exit -3. Pivots in both phases count against Maximum Iterations; the pivot that would exceed it is not taken: exit 0.

Measured against R2026a's linprog (dual-simplex-highs, its default) on the export-verify rigs' own data, 2000 random steps per rig, 8000 in all: the exit flags agree on every step except where this block's iteration cap stops it (linprog has none at that size), and where both are optimal max |x - x_linprog| = 7.5e-15, max |fval - fval_linprog| = 7.8e-14.

Support::None: linprog is an Optimization Toolbox function and that toolbox ships no Simulink library.

Sample results#

No stimulus produced a sampled output in this rig — Invalid input size at Linear Program block: ICore Blocks/Home/Linear Program. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit 83b4036dc8d5efdf28a47c36be1e27203065c75b · produced by docsSample --out <folder> --blocks Symbolic_Expression Symbolic_Derivative Gradient Jacobian Hessian Divergence_And_Curl Laplacian Taylor_Approximation Linear_Program LTI_System Wind_Turbulence_Model --steps 60

Sample data: docs/generated/samples/Control_Systems__Optimization__Linear_Program.json