Skip to main content

LinProg

Linear Programming Solver and Sensitivity Analysis Toolkit.

Installation

pip install linprog

Example

# ============================================================
# Example
# max 3x1 + 5x2
#
# s.t.
# x1          <= 4
#      2x2    >= 8
# 3x1 + 2x2   <= 18
# x1 + x2     == 7
# x1, x2 >= 0
# ============================================================
from linprog import LinearProgram

# name of decision variables
var_names = ["x1", "x2"]

# objective sense
objective_sense = "max" # "max" or "min"

# coefficients of the objective function
c = [3, 5]

# name of constraints
con_names = ["cte1", "cte3", "cte3", "cte4"]

# Matrix: each line represents the coefficients of a linear expression
# in the left part of a constraint
A = [
    [1, 0],
    [0, 2],
    [3, 2],
    [1, 1]
]

# sense of each constraint: "<=", ">=", or "=="
senses = ["<=", ">=", "<=", "=="]

# right hand side of each constraint
b = [4, 8, 18, 7]

# bounds on each variable: a bound declares the domain of a variable and only
# these three forms are accepted, whatever the type
#   (0, None)    non-negative
#   (None, 0)    non-positive
#   (None, None) free
bounds = [(0, None), (0, None)]

# type of each variable: 0 for continuous, 1 for integer, 2 for binary.
var_types = [0]*2

lp = LinearProgram(
    c=c,
    A=A,
    senses=senses,
    b=b,
    objective=objective_sense,
    bounds=bounds,
    var_names=var_names,
    con_names=con_names,
    var_types=var_types
)

# solve the linear program
lp.solve()
# display the linear program model
print(lp.reportModel())
# display the solution
print(lp.solution())
# display the linear program in standard form
print(lp.reportStandardModelFormat())
# display the linear program in matrix form
print(lp.reportMatrixFormat())
# display the solution
print(lp.reportSolution())
# display the sensitivity analysis
print(lp.report_sensitive_analysis())

Metadata

Release files for linprog 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linprog 1.4.0
File Size Uploaded
linprog-1.4.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linprog 1.4.0
File Interpreter ABI Platform
linprog-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / linprog-1.4.0.tar.gz

Download URL linprog-1.4.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
45a033ab23c48799066f6cc8b02d39291263650c345145ac84c9c82e77d7cf91
BLAKE2b-256 checksum
How to use checksums
9d21f188586e935a4970ced7a50a6f4991bf2e1a35b8d0ba5a31e3e61878d4f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / linprog-1.4.0-py3-none-any.whl

Download URL linprog-1.4.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2f074994298a0ce247106089cf78e81d97b1e6372f810ca9cbd77cd5712617f
BLAKE2b-256 checksum
How to use checksums
a16b10c61459535330137918adbaf21b9eebed16999200bfe659fad68ef34887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page