Simplex

A python implementation of the Simplex algorithm to solve linear optimization problems. With a streamlit interface and additional features for visualization (also sensitivity analysis) and a LLM integration.

Overview

This project is a complete Linear Programming (LP) solver suite built in Python. I implemented both the classic Two-Phase Primal Simplex algorithm and Karmarkar’s Interior-Point method (though the latter isn’t fully wired into the UI yet). The goal was to offer flexibility in solving a wide range of LP problems, while also making the process more transparent and interactive — not just a black box.

The suite comes with a Streamlit web interface that visualizes each pivot step in the Simplex method. Users can toggle between floating-point and exact arithmetic (via Python’s fractions module) to reduce rounding issues. There’s also support for visualizing 2D/3D feasible regions, with LaTeX-rendered problem statements for clarity.

Beyond the core solvers, I built out a sensitivity analysis module that lets users see how changes to objective function coefficients or constraint bounds affect the optimal solution. It calculates shadow prices, allowable ranges, and includes interactive sliders that update plots in real time.

Another key feature is the “LLM LP Solver” page — a natural-language interface that uses Google Gemini to convert plain English problem descriptions into structured LPs. It auto-generates the corresponding scipy.optimize.linprog code, runs it, and interprets the results. This was mainly to make LPs more accessible, even for non-technical users.

To back it all up, there’s a full test suite that validates the custom solver outputs against SciPy’s linprog. Tests cover all the usual cases — feasible, infeasible, unbounded, equality constraints, etc.

Tech Stack

The stack reflects a mix of practicality and precision:

Getting Started

  1. Clone the repository:
    git clone https://github.com/nicolas2912/linear-programming-solver.git
    cd linear-programming-solver
    
  2. Create and activate a conda environment:
    conda create -n lp-solver python=3.12
    conda activate lp-solver
    
  3. Install dependencies:
    pip install -r requirements.txt
    

Usage

Start the Streamlit application (powershell):

python -m streamlit run app.py

or for other shells:

python run app.py

If you want to use the LLM solver, create a .env file in the root directory and add your Gemini API key:

GEMINI_API_KEY=your_api_key_here

Architecture & Components

Core Modules

Utilities

Streamlit Apps

Tests

Challenges

A few areas required extra care:

What I Learned

Improvements I’d Like to Make

Here’s what I think would bring the most value going forward:

Screenshots

simplex_2d_rhs_sensitivity_analysis simplex_2d_sensitivity_analysis simplex_2d_visualiation simplex_3d_visualization simplex_shadow_prices simplex_solution_and_tableau simplex_streamlit_home-ui simplex_whatif_analysis simplex_llm_solver

View on GitHub