Skip to main content

Linear Programming Solver and Sensitivity Analysis Toolkit

Project description

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 representing the coefficients of 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: (min, max) or (min, None) or (None, max)
bounds = [(0, 7), (0, None)]

# type of each variable: 0 for continuous, 1 for integer
# A binary variable is handled as an integer variable bounded by 0 and 1.
var_types = [1]*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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linprog-1.3.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linprog-1.3.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file linprog-1.3.0.tar.gz.

File metadata

  • Download URL: linprog-1.3.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for linprog-1.3.0.tar.gz
Algorithm Hash digest
SHA256 94446c011ae9192ed4db468fe046e321b4eb68efd121cc2b6bc1ceea1aa5886e
MD5 67a4ff56b99d7b6c1d8ce4dca907f91f
BLAKE2b-256 9e77ad98dd92925a496a96cb00ea11c7baf8c81d35cc4a7c52be934b432e9851

See more details on using hashes here.

File details

Details for the file linprog-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: linprog-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for linprog-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a519f3e8ff20097a691f905b1de050357f7c5e5f1744ecd8b7f89d5f65226c2d
MD5 37858c95c9e59564e34560befea5a583
BLAKE2b-256 7ec79c821654c864d56f436d43de558207bfdd53a0d9be4e3151705e202ea42a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page