{"id":47228862,"url":"https://github.com/xeland314/simplex","last_synced_at":"2026-03-13T20:00:50.819Z","repository":{"id":314541010,"uuid":"823471986","full_name":"xeland314/simplex","owner":"xeland314","description":"Simplex para problemas de optimización","archived":false,"fork":false,"pushed_at":"2025-12-27T05:35:09.000Z","size":260,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-28T21:46:37.565Z","etag":null,"topics":["jupyter-notebook","optimization","python3","simplex","simplex-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xeland314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-03T05:28:23.000Z","updated_at":"2025-12-27T05:35:12.000Z","dependencies_parsed_at":"2025-09-13T05:45:30.843Z","dependency_job_id":null,"html_url":"https://github.com/xeland314/simplex","commit_stats":null,"previous_names":["xeland314/simplex"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xeland314/simplex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeland314%2Fsimplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeland314%2Fsimplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeland314%2Fsimplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeland314%2Fsimplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeland314","download_url":"https://codeload.github.com/xeland314/simplex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeland314%2Fsimplex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30473959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T17:15:31.527Z","status":"ssl_error","status_checked_at":"2026-03-13T17:15:22.394Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jupyter-notebook","optimization","python3","simplex","simplex-algorithm"],"created_at":"2026-03-13T20:00:14.430Z","updated_at":"2026-03-13T20:00:50.809Z","avatar_url":"https://github.com/xeland314.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simplex Solver\n\nA comprehensive tool for solving linear programming problems, offering multiple interfaces including a command-line solver, a Domain Specific Language (DSL), and a graphical user interface (GUI).\n\n![Example1](https://images.pling.com/img/00/00/83/74/65/2320088/screen-2025-09-13-16-43-53.jpg)\n![Example2](https://images.pling.com/img/00/00/83/74/65/2320088/screen-2025-09-13-16-44-25.jpg)\n\n## Features\n\n### Core Simplex Solver\nThe core solver is implemented using `scipy.optimize.linprog` and provides the fundamental capabilities for solving linear programming problems. It handles maximization and minimization, various inequality types (`\u003c=`, `\u003e=`, `\u003c`, `\u003e`), and equality constraints (`=`).\n\n### Dual Simplex Solver\nIn addition to the scipy-based solver, the project includes a manual implementation of the Dual Simplex algorithm in `dual_simplex.py`. This method is particularly useful for problems where the initial basic solution is primal infeasible (i.e., some right-hand side values are negative). The dual simplex iteratively adjusts the solution to achieve feasibility and optimality.\n\nThe `DualSimplex` class supports both maximization and minimization problems with inequality constraints of the form `Ax \u003c= b`.\n\n**Example Usage (Dual Simplex):**\n```python\nfrom dsl import DSL\n\nproblem = DSL(\"dual.lp\")  # or any .lp file\ndual_solver = problem.to_dual_simplex()\nsolution, optimal_value = dual_solver.solve()\nprint(f\"Solution: {solution}\")\nprint(f\"Optimal value: {optimal_value}\")\n```\n\nThe dual simplex implementation handles cases where the initial tableau has negative b values by performing dual pivots, and switches to primal pivots when necessary to reach optimality.\n\n### Domain Specific Languages (DSLs)\n\n#### 1. String-based DSL\nDefine your linear programming problems using a human-readable string format. This DSL supports both direct string input and loading from standard `.lp` files. It automatically handles variable types, including \"free\" variables by converting them into a pair of non-negative variables.\n\n**Example Usage (String Input):**\n```python\nfrom dsl import DSL\n\nproblem = DSL(\"\"\"\nMINIMIZE z = 3*x1 + 5*x2\nSUBJECT TO\n    2*x1 + x2 \u003e= 8\n    x1 + 3*x2 \u003e= 9\n    x1 \u003c= 5\n    x2 \u003e= 1\nBOUNDS\n    x1 \u003e= 0\n    x2 free\n\"\"\")\n\nsimplex = problem.to_simplex()\nsimplex.solve_problem()\nsimplex.show_results()\n\n# Or use dual simplex\ndual_solver = problem.to_dual_simplex()\nsolution, optimal_value = dual_solver.solve()\nprint(f\"Solution: {solution}, Value: {optimal_value}\")\n```\n\n**Example Usage (LP File Input):**\n```python\nfrom dsl import DSL\n\n# Assuming 'my_problem.lp' contains the problem definition\nproblem = DSL(\"my_problem.lp\")\nsimplex = problem.to_simplex()\nsimplex.solve_problem()\nsimplex.show_results()\n\n# Or use dual simplex\ndual_solver = problem.to_dual_simplex()\nsolution, optimal_value = dual_solver.solve()\nprint(f\"Solution: {solution}, Value: {optimal_value}\")\n```\n\n#### 2. Pythonic DSL\nFor a more integrated and programmatic approach, use the Pythonic DSL inspired by `sympy`. Define variables and construct your objective function and constraints directly using Python objects and operators.\n\n**Example Usage:**\n```python\nfrom pythonic_dsl import Model, Var, maximize\n\nm = Model(\"example_lp\")\n\nx1 = Var(\"x1\", low=0)\nx2 = Var(\"x2\", low=0)\n\nm += maximize(5 * x1 + 4 * x2)\nm += (6 * x1 + 4 * x2 \u003c= 24)\nm += (x1 + 2 * x2 \u003c= 6)\nm += (-x1 + x2 \u003c= 1)\nm += (x2 \u003c= 2)\n\nresult = m.solve()\nresult.show_results()\n```\n\n### Graphical User Interface (GUI)\nA user-friendly desktop application built with PySide6 (Qt for Python) provides an interactive environment for defining, solving, and visualizing linear programming problems.\n\n-   **Input Widget:** A text editor where you can type or load your problem definition.\n-   **Results Table:** Displays the optimal values for variables and the objective function.\n-   **Plotting:** For problems with two variables, a dedicated tab visualizes the constraints and the optimal solution point.\n-   **Console Log:** Redirects and displays all terminal output (e.g., `print` statements, error messages) within a dedicated tab in the GUI, ensuring readability by stripping ANSI escape codes. Includes a \"Clear Console\" button.\n-   **Menu Bar:**\n    -   **File:**\n        -   `Open`: Load problem definitions from `.lp` or `.txt` files.\n        -   `Save`: Save the current problem definition from the editor to an `.lp` file.\n        -   `Quit`: Exit the application.\n    -   **Help:**\n        -   `About`: Displays a custom dialog with application information, author, license, and links to GitHub and donation pages.\n-   **User Experience:**\n    -   Responsive UI: The solver runs in a separate thread to prevent the application from freezing during calculations.\n    -   Custom application icon (`pixel-cat.png`).\n    -   Uses the FiraCode font for enhanced readability and a modern aesthetic.\n\n## Installation\n\n1.  **Clone the repository:**\n    ```bash\n    git clone https://github.com/xeland314/simplex.git\n    cd simplex\n    ```\n2.  **Create a virtual environment (recommended):**\n    ```bash\n    python -m venv .venv\n    source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n    ```\n3.  **Install dependencies:**\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n## Usage\n\n### Command Line (Interactive)\nRun the basic interactive solver:\n```bash\npython simplex.py\n```\n\n### DSL (Programmatic)\nIntegrate the DSLs into your Python scripts as shown in the \"Domain Specific Languages (DSLs)\" section above.\n\n### GUI Application\nLaunch the graphical interface:\n```bash\npython app.py\n```\n\n## Examples\nCheck the `examples/` directory for sample `.lp` and `.txt` files that can be loaded into the GUI or used with the DSLs.\n\n## Development\n-   **Testing:** Run all unit tests with:\n    ```bash\n    uv run python -m unittest discover\n    ```\n    This includes tests for the core simplex solver, DSLs, and the dual simplex implementation (`test_dual_simplex.py`).\n\n## License\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeland314%2Fsimplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeland314%2Fsimplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeland314%2Fsimplex/lists"}