Optimization · Linear Programming

LINEAR PROGRAMMING

Construct and solve continuous linear programs directly in RainbowStats. Define a model, add linear constraints, set an objective, choose maximization or minimization, and inspect the resulting allocation, slack, and binding constraints.

Model builder Maximize or minimize Linear constraints Nonnegative variables Primal table

Command family

LINEAR_LP(model_name)
ADD_LP_EQUATION(model, linear_constraint)
SET_LP_OBJECTIVE(model, linear_expression)
MAX_LP(model)
MIN_LP(model)
MODEL_LP(model)
RainbowStats decision variables are nonnegative by default. The symbols < and > are interpreted and displayed as the non-strict LP relations ≤ and ≥. Use = for an equality constraint.

Construction workflow

  1. Create an empty model with LINEAR_LP.
  2. Add one linear constraint at a time with ADD_LP_EQUATION.
  3. Set the linear objective with SET_LP_OBJECTIVE.
  4. Solve with MAX_LP or MIN_LP.
  5. Use MODEL_LP and display the LP object to inspect the model.

Mathematical form

A maximization model is written in the standard form:

maximize  c′x
subject to  Ax ≤ b,  Aeqx = beq,  x ≥ 0

Every term must remain linear. Products between decision variables, powers of variables, and nonlinear functions are not valid LP expressions.

Commands

CommandPurposeExample
LINEAR_LP Creates a named, initially empty linear-programming model. LP=LINEAR_LP(TEST)
ADD_LP_EQUATION Adds a linear inequality or equality to the model. ADD_LP_EQUATION(LP,X+Y<75)
SET_LP_OBJECTIVE Defines the linear objective coefficients. SET_LP_OBJECTIVE(LP,113*X+168*Y)
MAX_LP Solves the model as a maximization problem. ANS=MAX_LP(LP)
MIN_LP Solves the model as a minimization problem. ANS=MIN_LP(LP)
MODEL_LP Builds the model presentation after the LP has been solved. LPT=MODEL_LP(LP)

Example: product-mix maximization

LP=LINEAR_LP(TEST)
ANS=ADD_LP_EQUATION(LP,42*X+51*Y<15000)
ANS=ADD_LP_EQUATION(LP,110*X+30*Y<4000)
ANS=ADD_LP_EQUATION(LP,X+Y<75)
ANS=SET_LP_OBJECTIVE(LP,113*X+168*Y)
ANS=MAX_LP(LP)
LPT=MODEL_LP(LP)
Final_LP=LP

The optimal solution is X = 0, Y = 75, with an objective value of 12,600.

Example: minimization

LP=LINEAR_LP(MINTEST)
ANS=ADD_LP_EQUATION(LP,X+Y>10)
ANS=SET_LP_OBJECTIVE(LP,2*X+Y)
ANS=MIN_LP(LP)
LPT=MODEL_LP(LP)
Final_LP=LP

The minimum occurs at X = 0, Y = 10, with an objective value of 10.

Example: multiperiod capital allocation

This model allocates constrained financing among housing, AI-sensitive investment, and other private investment over three periods. AI and housing also face interperiod ramp constraints.

# H = housing, A = AI-sensitive investment, O = other investment
LP=LINEAR_LP(CAPITAL)

ANS=ADD_LP_EQUATION(LP,H1+A1+O1<100)
ANS=ADD_LP_EQUATION(LP,H2+A2+O2<90)
ANS=ADD_LP_EQUATION(LP,H3+A3+O3<80)

ANS=ADD_LP_EQUATION(LP,A1<30)
ANS=ADD_LP_EQUATION(LP,A2<40)
ANS=ADD_LP_EQUATION(LP,A3<50)
ANS=ADD_LP_EQUATION(LP,O1<40)
ANS=ADD_LP_EQUATION(LP,O2<40)
ANS=ADD_LP_EQUATION(LP,O3<40)
ANS=ADD_LP_EQUATION(LP,H1<60)
ANS=ADD_LP_EQUATION(LP,H2<60)
ANS=ADD_LP_EQUATION(LP,H3<60)

ANS=ADD_LP_EQUATION(LP,A2-A1<10)
ANS=ADD_LP_EQUATION(LP,A1-A2<10)
ANS=ADD_LP_EQUATION(LP,A3-A2<10)
ANS=ADD_LP_EQUATION(LP,A2-A3<10)
ANS=ADD_LP_EQUATION(LP,H2-H1<20)
ANS=ADD_LP_EQUATION(LP,H1-H2<20)
ANS=ADD_LP_EQUATION(LP,H3-H2<20)
ANS=ADD_LP_EQUATION(LP,H2-H3<20)

ANS=SET_LP_OBJECTIVE(LP,700*H1+1500*A1+900*O1+679*H2+1455*A2+873*O2+658*H3+1410*A3+846*O3)
ANS=MAX_LP(LP)
LPT=MODEL_LP(LP)
Final_LP=LP
PeriodHousingAIOtherFinancing used
1303040100
210404090
30503080
A multiperiod LP is solved once across all periods. Cross-period ramp, inventory, capital, or project-completion equations make the periods interdependent rather than separate optimizations.

Reading the result

FieldMeaning
SolutionOptimal value assigned to each decision variable.
ObjectiveOptimal value of the objective function.
ActivityLeft-hand side evaluated at the solution.
SlackUnused capacity in a nonbinding constraint.
BindingIndicates that activity equals the constraint boundary.
ShadowMarginal value of relaxing a constraint, when populated.

Shadow-price check

The marginal value of a capacity constraint can always be verified by increasing its right-hand side by one unit and solving the model again:

λj = V(bj + 1) − V(bj)

This finite-difference value is valid locally while the optimal basis remains unchanged. It is especially useful when the displayed Shadow field is not populated.

Interpretation and limitations

Linear programming finds the best feasible allocation under the stated coefficients and constraints. It does not estimate the objective returns, establish causality, or prove that the chosen constraints describe the economy.

Decision variables are continuous. Do not interpret a solution as an integer or binary decision unless the modeled quantity is naturally divisible. Nonlinear returns should be represented with capacity-limited linear tranches or another suitable approximation.