Python icon indicating copy to clipboard operation
Python copied to clipboard

Add linear programming implementation using the simplex method

Open MohdFuzailHaider opened this issue 1 year ago • 3 comments

Describe your change:

  • [x] Add an algorithm?
  • [ ] Fix a bug or typo in an existing algorithm?
  • [ ] Add or change doctests?
  • [ ] Documentation change?

Checklist:

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized.
  • [x] I know that pull requests will not be merged if they fail the automated tests.
  • [x] This PR only changes one algorithm file.
  • [x] All new Python files are placed inside an existing directory.
  • [x] All filenames are in all lowercase characters with no spaces or dashes.
  • [x] All functions and variable names follow Python naming conventions.
  • [x] All function parameters and return values are annotated with Python type hints.
  • [x] All functions have doctests that pass the automated testing.
  • [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

MohdFuzailHaider avatar Oct 09 '24 21:10 MohdFuzailHaider

Hi, it's been a few days since I submitted this pull request. I just wanted to check in to see if there is anything else needed from my end for the review process. Thank you

MohdFuzailHaider avatar Oct 17 '24 20:10 MohdFuzailHaider

@MohdFuzailHaider There is already a simplex algorithm, https://github.com/TheAlgorithms/Python/blob/master/linear_programming/simplex.py

Is this method substantially different to that of the pre-existing implementation?

CaedenPH avatar Oct 17 '24 22:10 CaedenPH

Thank you for the feedback! Upon reviewing the existing implementation in simplex.py, I believe my code offers several improvements that enhance readability, maintainability, and performance:

Modularity and Structure: My implementation uses an object-oriented approach with the Tableau class, separating concerns into distinct methods (pivot, find_pivot_column, find_pivot_row, etc.). This makes the code easier to follow, debug, and maintain.

Efficiency: I’ve used NumPy for efficient matrix operations, which provides a performance advantage for larger problems. The pivoting operation, for instance, is handled in a vectorized manner, improving execution speed compared to basic Python loops.

Extensibility: The modular design of my code allows for easier future extensions. For example, introducing different pivoting rules or handling degeneracy would require minimal changes.

Error Handling: My code explicitly raises an error when the linear program is unbounded, improving robustness and making debugging simpler.

Solution Extraction: The extract_solution method clearly identifies basic variables, ensuring that the solution is correctly extracted from the tableau.

I believe these enhancements could be beneficial, particularly for larger or more complex linear programming problems.

MohdFuzailHaider avatar Oct 18 '24 09:10 MohdFuzailHaider