Skip to Content

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:

Minimize: cTx\text{Minimize: } c^T x

Subject to:

AubxbubAeqx=beqboundsiminxiboundsimaxA_{ub} x \leq b_{ub} \\ A_{eq} x = b_{eq} \\ bounds_i^{min} \leq x_i \leq bounds_i^{max}

Where:

  • xx is the vector of decision variables
  • cc is the vector of objective coefficients
  • AubA_{ub} and bubb_{ub} define the inequality constraints
  • AeqA_{eq} and beqb_{eq} define the equality constraints
  • boundsbounds 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 cTxc^T x). Example: [[3, 5]]
  • A_ub (2D list, optional): Inequality constraint coefficients (AubxbubA_{ub} x \leq b_{ub}). Example: [[-1, -2], [-2, -1]]
  • b_ub (2D list, optional): Inequality constraint bounds. Example: [[-8], [-8]]
  • A_eq (2D list, optional): Equality constraint coefficients (Aeqx=beqA_{eq} x = b_{eq}). 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