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.
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.
The stack reflects a mix of practicality and precision:
google-genai, with .env key management using python-dotenv because of free limits and great performancegit clone https://github.com/nicolas2912/linear-programming-solver.git
cd linear-programming-solver
conda create -n lp-solver python=3.12
conda activate lp-solver
pip install -r requirements.txt
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
Core Modules
simplex.py: Implements Two-Phase Primal Simplex. Handles standard form conversion, pivot logic, artificial vars, and degeneracy.inner_point.py: Early version of a Karmarkar interior-point solver (not yet integrated into the UI).sensitivity.py: Computes objective/RHS ranges, shadow prices, and supports interactive sliders for what-if analysis.Utilities
utils.py: Input validation, session state helpers, and example problem generators (2D/3D).plotting.py: Handles 2D/3D visualization of feasible regions, isoprofit lines, and analysis plots.ui_components.py: LaTeX problem display, fraction-rendered tableaus, consistent UI elements.Streamlit Apps
frontend_simplex.py: Main solver interface. Supports example loading, custom input, problem visualization, and solver step review.sensitivity_ui.py: Separate tab for sensitivity analysis.pages/llm_lp_solver.py: Uses Gemini to translate English â LP â SciPy code â solution â explanation.Tests
test_simplex.py: Unit tests that validate solver correctness, check edge cases, and compare results against SciPy.A few areas required extra care:
Hereâs what I think would bring the most value going forward:
