|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Revised Simplex algorithm for linear programming. More...
#include <Simplex.H>
Classes | |
| struct | EtaMatrix |
Public Types | |
| enum | State { Not_Solved , Solving , Unbounded , Solved , Unfeasible } |
| Solution states for the linear program. More... | |
Public Member Functions | |
| RevisedSimplex (size_t num_vars, size_t num_constraints) | |
| Constructs a Revised Simplex solver. | |
| void | set_objective (size_t j, T coef) |
| Sets objective coefficient. | |
| void | set_objective (const T *coefs) |
| Sets all objective coefficients. | |
| void | set_constraint (size_t i, size_t j, T coef) |
| Sets constraint coefficient. | |
| void | set_rhs (size_t i, T rhs) |
| Sets RHS value for a constraint. | |
| void | set_constraint_row (size_t i, const T *coefs, T rhs) |
| Adds a complete constraint. | |
| void | set_refactorization_frequency (size_t freq) |
| Sets refactorization frequency. | |
| State | solve () |
| Solves the linear program. | |
| T | get_solution (size_t j) const |
| Gets solution value for variable j. | |
| T | objective_value () const |
| Computes objective function value. | |
| State | get_state () const noexcept |
| Gets current state. | |
| const SimplexStats & | get_stats () const noexcept |
| Gets execution statistics. | |
| size_t | get_num_vars () const noexcept |
| Gets number of variables. | |
| size_t | get_num_constraints () const noexcept |
| Gets number of constraints. | |
| bool | verify_solution () const |
| Verifies solution satisfies all constraints. | |
| void | print_stats () const |
| Prints statistics to stdout. | |
Private Member Functions | |
| void | ftran (const std::vector< T > &a, std::vector< T > &y) const |
| void | btran (const std::vector< T > &c_B, std::vector< T > &pi_out) const |
| T | compute_reduced_cost (size_t j) const |
| void | get_column (size_t j, std::vector< T > &col) const |
| int | select_entering_variable () |
| int | select_leaving_variable (int entering, T &theta) |
| void | update_basis_inverse (int leaving_row, const std::vector< T > &d_col) |
| void | refactorize () |
Private Attributes | |
| size_t | m |
| size_t | n |
| std::vector< T > | c |
| std::vector< std::vector< T > > | A |
| std::vector< T > | b |
| std::vector< int > | basic |
| std::vector< int > | nonbasic |
| std::vector< bool > | is_basic |
| std::vector< EtaMatrix > | eta_file |
| std::vector< std::vector< T > > | B_inv_explicit |
| std::vector< T > | x_B |
| std::vector< T > | solution |
| std::vector< T > | pi |
| std::vector< T > | d |
| std::vector< T > | work |
| T | eps |
| size_t | refactor_frequency |
| bool | use_steepest_edge |
| State | state |
| SimplexStats | stats |
Revised Simplex algorithm for linear programming.
The Revised Simplex method is an efficient variant of the standard Simplex algorithm that maintains only the basis inverse B⁻¹ instead of the full tableau. This provides significant memory and computational savings for larger problems.
| Aspect | Standard Simplex | Revised Simplex |
|---|---|---|
| Storage | Full tableau O((m+1)×(n+m+1)) | B⁻¹ + original data O(m² + mn) |
| Pivot | Update entire tableau | Update only B⁻¹ |
| Pricing | Read from tableau | Compute π = c_B·B⁻¹, then c̄_j = c_j - π·a_j |
| Best for | Small/dense problems | Large/sparse problems |
Instead of computing B⁻¹ directly, we maintain it as a product of elementary matrices (eta-matrices): B⁻¹ = E_k · E_{k-1} · ... · E_1 · B_0⁻¹
Periodic refactorization is performed to maintain numerical stability and reduce accumulated errors.
| T | Numeric type for coefficients (typically double). |
|
inline |
Constructs a Revised Simplex solver.
| [in] | num_vars | Number of decision variables. |
| [in] | num_constraints | Number of constraints. |
Definition at line 2047 of file Simplex.H.
References ah_invalid_argument_if, and Aleph::maps().
|
inlineprivate |
Definition at line 1809 of file Simplex.H.
References Aleph::RevisedSimplex< T >::B_inv_explicit, Aleph::RevisedSimplex< T >::m, Aleph::maps(), and Aleph::sum().
Referenced by Aleph::RevisedSimplex< T >::select_entering_variable().
|
inlineprivate |
Definition at line 1823 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, Aleph::RevisedSimplex< T >::c, Aleph::RevisedSimplex< T >::m, Aleph::maps(), Aleph::RevisedSimplex< T >::n, and Aleph::RevisedSimplex< T >::pi.
Referenced by Aleph::RevisedSimplex< T >::select_entering_variable().
|
inlineprivate |
Definition at line 1793 of file Simplex.H.
References Aleph::RevisedSimplex< T >::B_inv_explicit, Aleph::RevisedSimplex< T >::m, Aleph::sum(), and y.
Referenced by Aleph::RevisedSimplex< T >::select_leaving_variable().
|
inlineprivate |
Definition at line 1839 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, Aleph::RevisedSimplex< T >::m, Aleph::maps(), and Aleph::RevisedSimplex< T >::n.
Referenced by Aleph::RevisedSimplex< T >::select_leaving_variable().
|
inlinenoexcept |
Gets number of constraints.
Definition at line 2264 of file Simplex.H.
References Aleph::RevisedSimplex< T >::m.
|
inlinenoexcept |
Gets number of variables.
Definition at line 2261 of file Simplex.H.
References Aleph::RevisedSimplex< T >::n.
Gets solution value for variable j.
| [in] | j | Variable index. |
Definition at line 2236 of file Simplex.H.
References ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::n, and Aleph::RevisedSimplex< T >::solution.
|
inlinenoexcept |
Gets current state.
Definition at line 2255 of file Simplex.H.
References Aleph::RevisedSimplex< T >::state.
|
inlinenoexcept |
Gets execution statistics.
Definition at line 2258 of file Simplex.H.
References Aleph::RevisedSimplex< T >::stats.
|
inline |
Computes objective function value.
Definition at line 2246 of file Simplex.H.
References Aleph::RevisedSimplex< T >::c, Aleph::RevisedSimplex< T >::n, Aleph::RevisedSimplex< T >::solution, and Aleph::sum().
|
inline |
Prints statistics to stdout.
Definition at line 2284 of file Simplex.H.
References Aleph::SimplexStats::elapsed_ms, Aleph::RevisedSimplex< T >::eta_file, Aleph::SimplexStats::iterations, Aleph::RevisedSimplex< T >::m, Aleph::RevisedSimplex< T >::n, Aleph::SimplexStats::pivots, Aleph::RevisedSimplex< T >::refactor_frequency, and Aleph::RevisedSimplex< T >::stats.
|
inlineprivate |
Definition at line 1967 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, Aleph::RevisedSimplex< T >::B_inv_explicit, Aleph::RevisedSimplex< T >::basic, Aleph::RevisedSimplex< T >::eta_file, Aleph::RevisedSimplex< T >::m, Aleph::maps(), and Aleph::RevisedSimplex< T >::n.
|
inlineprivate |
Definition at line 1858 of file Simplex.H.
References Aleph::RevisedSimplex< T >::basic, Aleph::RevisedSimplex< T >::btran(), Aleph::RevisedSimplex< T >::c, Aleph::RevisedSimplex< T >::compute_reduced_cost(), Aleph::RevisedSimplex< T >::eps, Aleph::RevisedSimplex< T >::m, Aleph::maps(), Aleph::RevisedSimplex< T >::n, Aleph::RevisedSimplex< T >::nonbasic, and Aleph::RevisedSimplex< T >::pi.
Referenced by Aleph::RevisedSimplex< T >::solve().
|
inlineprivate |
Definition at line 1890 of file Simplex.H.
References Aleph::RevisedSimplex< T >::d, Aleph::RevisedSimplex< T >::eps, Aleph::RevisedSimplex< T >::ftran(), Aleph::RevisedSimplex< T >::get_column(), Aleph::RevisedSimplex< T >::m, Aleph::maps(), and Aleph::RevisedSimplex< T >::x_B.
Referenced by Aleph::RevisedSimplex< T >::solve().
Sets constraint coefficient.
| [in] | i | Constraint index. |
| [in] | j | Variable index. |
| [in] | coef | Coefficient value. |
Definition at line 2093 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::m, and Aleph::RevisedSimplex< T >::n.
Adds a complete constraint.
| [in] | i | Constraint index. |
| [in] | coefs | Array of n coefficients. |
| [in] | rhs | Right-hand side value. |
Definition at line 2117 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::b, Aleph::RevisedSimplex< T >::m, Aleph::maps(), and Aleph::RevisedSimplex< T >::n.
Sets all objective coefficients.
| [in] | coefs | Array of n coefficients. |
Definition at line 2081 of file Simplex.H.
References Aleph::RevisedSimplex< T >::c, Aleph::maps(), and Aleph::RevisedSimplex< T >::n.
Sets objective coefficient.
| [in] | j | Variable index. |
| [in] | coef | Coefficient value. |
Definition at line 2071 of file Simplex.H.
References ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::c, and Aleph::RevisedSimplex< T >::n.
|
inline |
Sets refactorization frequency.
B⁻¹ is recomputed explicitly every N iterations to maintain numerical stability.
| [in] | freq | Refactorization frequency (default: max(50, m)). |
Definition at line 2132 of file Simplex.H.
References Aleph::maps(), and Aleph::RevisedSimplex< T >::refactor_frequency.
Sets RHS value for a constraint.
| [in] | i | Constraint index. |
| [in] | rhs | Right-hand side value. |
Definition at line 2105 of file Simplex.H.
References ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::b, Aleph::RevisedSimplex< T >::m, and Aleph::maps().
|
inline |
Solves the linear program.
Definition at line 2141 of file Simplex.H.
References ah_logic_error_if, Aleph::RevisedSimplex< T >::b, Aleph::RevisedSimplex< T >::B_inv_explicit, Aleph::RevisedSimplex< T >::basic, Aleph::RevisedSimplex< T >::d, Aleph::SimplexStats::elapsed_ms, Aleph::RevisedSimplex< T >::is_basic, Aleph::SimplexStats::iterations, Aleph::RevisedSimplex< T >::m, Aleph::maps(), Aleph::RevisedSimplex< T >::n, Aleph::RevisedSimplex< T >::nonbasic, Aleph::RevisedSimplex< T >::Not_Solved, Aleph::SimplexStats::pivots, Aleph::SimplexStats::reset(), Aleph::RevisedSimplex< T >::select_entering_variable(), Aleph::RevisedSimplex< T >::select_leaving_variable(), Aleph::RevisedSimplex< T >::solution, Aleph::RevisedSimplex< T >::Solved, Aleph::RevisedSimplex< T >::Solving, Aleph::RevisedSimplex< T >::state, Aleph::RevisedSimplex< T >::stats, Aleph::RevisedSimplex< T >::Unbounded, Aleph::RevisedSimplex< T >::update_basis_inverse(), and Aleph::RevisedSimplex< T >::x_B.
|
inlineprivate |
Definition at line 1923 of file Simplex.H.
References Aleph::RevisedSimplex< T >::B_inv_explicit, Aleph::RevisedSimplex< T >::eps, Aleph::RevisedSimplex< T >::m, and Aleph::maps().
Referenced by Aleph::RevisedSimplex< T >::solve().
|
inline |
Verifies solution satisfies all constraints.
Definition at line 2270 of file Simplex.H.
References Aleph::RevisedSimplex< T >::A, Aleph::RevisedSimplex< T >::b, Aleph::RevisedSimplex< T >::eps, Aleph::RevisedSimplex< T >::m, Aleph::maps(), Aleph::RevisedSimplex< T >::n, and Aleph::RevisedSimplex< T >::solution.
|
private |
Definition at line 1754 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::compute_reduced_cost(), Aleph::RevisedSimplex< T >::get_column(), Aleph::RevisedSimplex< T >::refactorize(), Aleph::RevisedSimplex< T >::set_constraint(), Aleph::RevisedSimplex< T >::set_constraint_row(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1755 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::set_constraint_row(), Aleph::RevisedSimplex< T >::set_rhs(), Aleph::RevisedSimplex< T >::solve(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1769 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::btran(), Aleph::RevisedSimplex< T >::ftran(), Aleph::RevisedSimplex< T >::refactorize(), Aleph::RevisedSimplex< T >::solve(), and Aleph::RevisedSimplex< T >::update_basis_inverse().
|
private |
Definition at line 1758 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::refactorize(), Aleph::RevisedSimplex< T >::select_entering_variable(), and Aleph::RevisedSimplex< T >::solve().
|
private |
Definition at line 1753 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::compute_reduced_cost(), Aleph::RevisedSimplex< T >::objective_value(), Aleph::RevisedSimplex< T >::select_entering_variable(), Aleph::RevisedSimplex< T >::set_objective(), and Aleph::RevisedSimplex< T >::set_objective().
|
mutableprivate |
Definition at line 1777 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::select_leaving_variable(), and Aleph::RevisedSimplex< T >::solve().
|
private |
Definition at line 1781 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::select_entering_variable(), Aleph::RevisedSimplex< T >::select_leaving_variable(), Aleph::RevisedSimplex< T >::update_basis_inverse(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1768 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::print_stats(), and Aleph::RevisedSimplex< T >::refactorize().
|
private |
Definition at line 1760 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::solve().
|
private |
Definition at line 1751 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::btran(), Aleph::RevisedSimplex< T >::compute_reduced_cost(), Aleph::RevisedSimplex< T >::ftran(), Aleph::RevisedSimplex< T >::get_column(), Aleph::RevisedSimplex< T >::get_num_constraints(), Aleph::RevisedSimplex< T >::print_stats(), Aleph::RevisedSimplex< T >::refactorize(), Aleph::RevisedSimplex< T >::select_entering_variable(), Aleph::RevisedSimplex< T >::select_leaving_variable(), Aleph::RevisedSimplex< T >::set_constraint(), Aleph::RevisedSimplex< T >::set_constraint_row(), Aleph::RevisedSimplex< T >::set_rhs(), Aleph::RevisedSimplex< T >::solve(), Aleph::RevisedSimplex< T >::update_basis_inverse(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1752 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::compute_reduced_cost(), Aleph::RevisedSimplex< T >::get_column(), Aleph::RevisedSimplex< T >::get_num_vars(), Aleph::RevisedSimplex< T >::get_solution(), Aleph::RevisedSimplex< T >::objective_value(), Aleph::RevisedSimplex< T >::print_stats(), Aleph::RevisedSimplex< T >::refactorize(), Aleph::RevisedSimplex< T >::select_entering_variable(), Aleph::RevisedSimplex< T >::set_constraint(), Aleph::RevisedSimplex< T >::set_constraint_row(), Aleph::RevisedSimplex< T >::set_objective(), Aleph::RevisedSimplex< T >::set_objective(), Aleph::RevisedSimplex< T >::solve(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1759 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::select_entering_variable(), and Aleph::RevisedSimplex< T >::solve().
|
mutableprivate |
Definition at line 1776 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::compute_reduced_cost(), and Aleph::RevisedSimplex< T >::select_entering_variable().
|
private |
Definition at line 1782 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::print_stats(), and Aleph::RevisedSimplex< T >::set_refactorization_frequency().
|
private |
Definition at line 1773 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::get_solution(), Aleph::RevisedSimplex< T >::objective_value(), Aleph::RevisedSimplex< T >::solve(), and Aleph::RevisedSimplex< T >::verify_solution().
|
private |
Definition at line 1786 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::get_state(), and Aleph::RevisedSimplex< T >::solve().
|
mutableprivate |
Definition at line 1787 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::get_stats(), Aleph::RevisedSimplex< T >::print_stats(), and Aleph::RevisedSimplex< T >::solve().
|
private |
|
mutableprivate |
|
private |
Definition at line 1772 of file Simplex.H.
Referenced by Aleph::RevisedSimplex< T >::select_leaving_variable(), and Aleph::RevisedSimplex< T >::solve().