Skip to main content

A lightweight and educational Python package for solving linear programming problems using the Simplex method.

Project description

simple_simplex

A lightweight Python package for solving linear programming problems using the simplex method.

🚀 Overview

simple_simplex is a minimal, NumPy-based Simplex solver that provides an easy interface for defining linear programs and solving them. It supports both maximization and minimization problems and includes features for logging pivot steps and returning results in JSON-friendly format — making it ideal for integration with web backends, educational tools, or visualization apps.


📦 Features

  • 🧮 Solve both maximization and minimization problems
  • ✅ Support for and constraints
  • 📊 Pivot step tracking for visualization/debugging
  • 🔗 Returns results as JSON-compatible dicts
  • 📝 Display results as a neatly-formatted ASCII table
  • 🧩 Easy to embed in Flask or FastAPI backends

📥 Installation

pip install simple_simplex

🛠 Usage

1. Create a tableau

Pass in the number of variables, and number of constraints in the problem.

from simple_simplex import *

tableau = create_tableau(number_of_variables=2, number_of_constraints=2)

2. Add constraints

Each constraint is passed as a string in the format:

"coeff1,coeff2,...,<inequality>,rhs"

Example:

add_constraint(tableau, "2,1,L,18")  # 2x + y ≤ 18
add_constraint(tableau, "2,3,L,42")  # 2x + 3y ≤ 42

Use "L" for ≤, "G" for ≥

3. Add objective function

Objective format: "coeff1,coeff2,...,objective"
(Set objective value to 0)

add_objective(tableau, "3,2,0")  # Maximize 3x + 2y = z

4. Solve

Option 1 (print results, no return value)

optimize_max(tableau) #prints results to stdout
optimize_min(tableau) #prints results to stdout

Option 2 (generate and return JSON-compatible results)

See Output Format for more details

result = optimize_json_format(tableau, maximize=True)
print(result["optimalValue"])       # => Optimal Z value
print(result["solutionValues"])     # => Variable values
print(result["pivotSteps"])         # => Step-by-step history
# See Output Format for more details

📄 Output Format

The optimize_json_format() function returns a Python dictionary in the form of:

{
  "status": "optimal",
  "objectiveType": "max",
  "optimalValue": 36.0,
  "solutionValues": {
    "x1": 6.0,
    "x2": 6.0
  },
  "pivotSteps": [...],
  "finalTableau": [...],
  "numSteps": 2
}

The optimize_max() and optimize_min() functions display results as well as the final tableau.


📚 Example Problem

Maximize:
Z = 3x + 2y

Subject to:

2x + y   ≤ 18  
2x + 3y  ≤ 42  
x, y ≥ 0
from simple_simplex import *

tableau = create_tableau(2, 2)
add_constraint(tableau, "2,1,L,18")
add_constraint(tableau, "2,3,L,42")
add_objective(tableau, "3,2,0")

solution_dict = optimize_json_format(tableau, maximize=True)
# OR to print solution to stdout
optimize_max(tableau)

📏 To-Do

  • Better input handling
  • Better error handling

📝 License

This project is licensed under the MIT License.


👤 Author

Joshua Emralino
jemralino@student.sdccd.edu


🌐 Keywords

simplex, linear programming, optimization, math, solver, numpy, backend, json, flask

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

simple_simplex-0.0.3.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

simple_simplex-0.0.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_simplex-0.0.3.tar.gz.

File metadata

  • Download URL: simple_simplex-0.0.3.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for simple_simplex-0.0.3.tar.gz
Algorithm Hash digest
SHA256 19cda98fb578ef001892900fa711e1b1b9a2b844058580df5f1194526d3ed456
MD5 64a6d0c88eb5a5014caf5205d085681d
BLAKE2b-256 7e556edc737a0ae767a973df99d4177fe0088f97168734d808bcabd0f96a916e

See more details on using hashes here.

File details

Details for the file simple_simplex-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: simple_simplex-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for simple_simplex-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 837b8d5e9ac1adc36244205ac79c1a9137e047a4f9bd1ab4aad94f124f2f7291
MD5 9971a3dd8a32199c19b7919fc6141c36
BLAKE2b-256 b1b455f7f7cb8734efed368788d4a885d4c9717613aa990d2daab8ae4f894d18

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