Skip to content

Add linear programming implementation using the simplex method #11928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MohdFuzailHaider
Copy link

Describe your change:

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

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • 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".

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 9, 2024
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 10, 2024
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 10, 2024
@MohdFuzailHaider
Copy link
Author

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

@CaedenPH
Copy link
Contributor

@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?

@MohdFuzailHaider
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants