The Simplex Method is a straightforward algorithm for finding optimal solutions to optimization problems with linear constraints and cost functions. Because of its simplicity and applicability, this algorithm has been named one of the most important algorithms invented within the last 100 years. In this project I implement a standard Simplex solver for the primal problem.
The Simplex algorithm, being a cornerstone for solving linear optimization problems, iteratively pivots through the vertices of the feasible region determined by constraints until it arrives at the optimal solution. The algorithm thrives on its ability to consistently refine the solution through a series of functions, each of which contributes to different stages of the problem-solving process.
This aspect ensures that the origin is a feasible solution by checking that all elements of b are non-negative.
SimplexSolver.__init__(self, c, A, b): This function initializes the Simplex solver, ensures feasibility, and kickstarts the dictionary.SimplexSolver._generatedictionary(self, c, A, b): Crafts the initial dictionary pivotal to the Simplex algorithm, leveraging the coefficient matrixA, the objective coefficientsc, and the constraint vectorb.
An essential step to improve the current solution:
SimplexSolver._pivot_col(self): Determines the column (or variable) that, when increased in value, will enhance the objective function.SimplexSolver._pivot_row(self, index): Utilizes Bland's Rule to ascertain the tightest constraint, consequently deciding which variable will reduce to zero.SimplexSolver.pivot(self): This function actualizes the pivot, resulting in updates to the dictionary.
The culmination of the preceding functions, it solves the optimization problem:
SimplexSolver.solve(self): Employing the Simplex algorithm, this function eventually concludes the optimization problem, returning the minimum objective function value and values of both basic (dependent) and non-basic (independent) variables.
A special application of the Simplex algorithm:
prob6(filename='productMix.npz'): Tailored for the product mix problem, it uses data from an integrated .npz file. By intertwining both resource and demand constraints, this function deduces an optimal solution detailing the quantities for various products.
- Start by importing the required functions from the module.
- Clearly define or feed the function, its derivative, the initial guess, and other ancillary parameters relevant to the chosen function.
- Invoke the function and subsequently interpret the outcomes.
- numpy
Two main exceptions can arise:
- If the problem fails to be feasible at the origin, a
ValueErrorciting "Origin not feasible" is dispatched. - In the event of an unbounded problem, a
ValueErrorhighlighting "Unbounded problem" is raised.
Venturing into the module's depths, it's essential to grasp the Simplex algorithm's mathematical scaffolding. Such understanding illuminates the pivoting strategies at play, and the holistic optimization route.