LINEAR_PROG
Overview
The linear_prog
function solves linear programming (LP) problems using the scipy.optimize.linprog
function. The function accepts the objective coefficients, constraint matrices, and bounds as arguments, and returns the optimal solution and value, or an error message (as a string) if the problem is infeasible or input is invalid.
The standard form of a linear programming problem is:
Subject to:
Where:
- is the vector of decision variables
- is the vector of objective coefficients
- and define the inequality constraints
- and define the equality constraints
- specify lower and upper bounds for each variable
This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=LINEAR_PROG(c, [A_ub], [b_ub], [A_eq], [b_eq], [bounds], [method])
c
(2D list, required): Objective coefficients (to minimize ). Example:[[3, 5]]
A_ub
(2D list, optional): Inequality constraint coefficients (). Example:[[-1, -2], [-2, -1]]
b_ub
(2D list, optional): Inequality constraint bounds. Example:[[-8], [-8]]
A_eq
(2D list, optional): Equality constraint coefficients (). Example:[[0, 0]]
b_eq
(2D list, optional): Equality constraint bounds. Example:[[0]]
bounds
(2D list, optional): Variable bounds[[min1, max1], [min2, max2], ...]
. Example:[[0, None], [0, None]]
method
(string, optional): LP algorithm to use. Possible values:"highs"
,"highs-ds"
,"highs-ipm"
,"revised simplex"
,"simplex"
,"interior-point"
. Example:"highs"
The function returns a 2D list: [[x1, x2, ..., optimal_value]]
if successful, or an error message as a string if the problem is infeasible or input is invalid.
Examples
Live Notebook
Edit this function in a live notebook .
Live Demo
Last updated on