Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::RevisedSimplex< T > Class Template Reference

Revised Simplex algorithm for linear programming. More...

#include <Simplex.H>

Collaboration diagram for Aleph::RevisedSimplex< T >:
[legend]

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 SimplexStatsget_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< Tc
 
std::vector< std::vector< T > > A
 
std::vector< Tb
 
std::vector< intbasic
 
std::vector< intnonbasic
 
std::vector< boolis_basic
 
std::vector< EtaMatrixeta_file
 
std::vector< std::vector< T > > B_inv_explicit
 
std::vector< Tx_B
 
std::vector< Tsolution
 
std::vector< Tpi
 
std::vector< Td
 
std::vector< Twork
 
T eps
 
size_t refactor_frequency
 
bool use_steepest_edge
 
State state
 
SimplexStats stats
 

Detailed Description

template<typename T>
class Aleph::RevisedSimplex< T >

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.

Key Differences from Standard Simplex

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

Algorithm Overview

  1. Initialize: Set up initial basis (slack variables)
  2. Pricing: Compute dual prices π = c_B · B⁻¹
  3. Select entering: Find j with most negative c̄_j = c_j - π · a_j
  4. FTRAN: Compute d = B⁻¹ · a_j (tableau column)
  5. Ratio test: Find leaving variable using d
  6. BTRAN/Update: Update B⁻¹ using eta-matrix product form
  7. Repeat until optimal or unbounded

Eta-Matrix Updates

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.

Performance

  • Memory: O(m² + mn) vs O(mn + m²) for standard
  • Time per iteration: O(m²) for dense, O(nnz) for sparse
  • Best for: n >> m (many variables, few constraints)
Template Parameters
TNumeric type for coefficients (typically double).
See also
Simplex

Definition at line 1743 of file Simplex.H.

Member Enumeration Documentation

◆ State

Solution states for the linear program.

Enumerator
Not_Solved 
Solving 
Unbounded 
Solved 
Unfeasible 

Definition at line 1747 of file Simplex.H.

Constructor & Destructor Documentation

◆ RevisedSimplex()

template<typename T >
Aleph::RevisedSimplex< T >::RevisedSimplex ( size_t  num_vars,
size_t  num_constraints 
)
inline

Constructs a Revised Simplex solver.

Parameters
[in]num_varsNumber of decision variables.
[in]num_constraintsNumber of constraints.

Definition at line 2047 of file Simplex.H.

References ah_invalid_argument_if, and Aleph::maps().

Member Function Documentation

◆ btran()

template<typename T >
void Aleph::RevisedSimplex< T >::btran ( const std::vector< T > &  c_B,
std::vector< T > &  pi_out 
) const
inlineprivate

◆ compute_reduced_cost()

◆ ftran()

template<typename T >
void Aleph::RevisedSimplex< T >::ftran ( const std::vector< T > &  a,
std::vector< T > &  y 
) const
inlineprivate

◆ get_column()

template<typename T >
void Aleph::RevisedSimplex< T >::get_column ( size_t  j,
std::vector< T > &  col 
) const
inlineprivate

◆ get_num_constraints()

template<typename T >
size_t Aleph::RevisedSimplex< T >::get_num_constraints ( ) const
inlinenoexcept

Gets number of constraints.

Definition at line 2264 of file Simplex.H.

References Aleph::RevisedSimplex< T >::m.

◆ get_num_vars()

template<typename T >
size_t Aleph::RevisedSimplex< T >::get_num_vars ( ) const
inlinenoexcept

Gets number of variables.

Definition at line 2261 of file Simplex.H.

References Aleph::RevisedSimplex< T >::n.

◆ get_solution()

template<typename T >
T Aleph::RevisedSimplex< T >::get_solution ( size_t  j) const
inline

Gets solution value for variable j.

Parameters
[in]jVariable index.
Returns
Optimal value of variable x_j.

Definition at line 2236 of file Simplex.H.

References ah_out_of_range_error_if, Aleph::RevisedSimplex< T >::n, and Aleph::RevisedSimplex< T >::solution.

◆ get_state()

template<typename T >
State Aleph::RevisedSimplex< T >::get_state ( ) const
inlinenoexcept

Gets current state.

Definition at line 2255 of file Simplex.H.

References Aleph::RevisedSimplex< T >::state.

◆ get_stats()

template<typename T >
const SimplexStats & Aleph::RevisedSimplex< T >::get_stats ( ) const
inlinenoexcept

Gets execution statistics.

Definition at line 2258 of file Simplex.H.

References Aleph::RevisedSimplex< T >::stats.

◆ objective_value()

template<typename T >
T Aleph::RevisedSimplex< T >::objective_value ( ) const
inline

Computes objective function value.

Returns
Optimal objective 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().

◆ print_stats()

◆ refactorize()

◆ select_entering_variable()

◆ select_leaving_variable()

◆ set_constraint()

template<typename T >
void Aleph::RevisedSimplex< T >::set_constraint ( size_t  i,
size_t  j,
T  coef 
)
inline

Sets constraint coefficient.

Parameters
[in]iConstraint index.
[in]jVariable index.
[in]coefCoefficient 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.

◆ set_constraint_row()

template<typename T >
void Aleph::RevisedSimplex< T >::set_constraint_row ( size_t  i,
const T coefs,
T  rhs 
)
inline

Adds a complete constraint.

Parameters
[in]iConstraint index.
[in]coefsArray of n coefficients.
[in]rhsRight-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.

◆ set_objective() [1/2]

template<typename T >
void Aleph::RevisedSimplex< T >::set_objective ( const T coefs)
inline

Sets all objective coefficients.

Parameters
[in]coefsArray of n coefficients.

Definition at line 2081 of file Simplex.H.

References Aleph::RevisedSimplex< T >::c, Aleph::maps(), and Aleph::RevisedSimplex< T >::n.

◆ set_objective() [2/2]

template<typename T >
void Aleph::RevisedSimplex< T >::set_objective ( size_t  j,
T  coef 
)
inline

Sets objective coefficient.

Parameters
[in]jVariable index.
[in]coefCoefficient 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.

◆ set_refactorization_frequency()

template<typename T >
void Aleph::RevisedSimplex< T >::set_refactorization_frequency ( size_t  freq)
inline

Sets refactorization frequency.

B⁻¹ is recomputed explicitly every N iterations to maintain numerical stability.

Parameters
[in]freqRefactorization frequency (default: max(50, m)).

Definition at line 2132 of file Simplex.H.

References Aleph::maps(), and Aleph::RevisedSimplex< T >::refactor_frequency.

◆ set_rhs()

template<typename T >
void Aleph::RevisedSimplex< T >::set_rhs ( size_t  i,
T  rhs 
)
inline

Sets RHS value for a constraint.

Parameters
[in]iConstraint index.
[in]rhsRight-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().

◆ solve()

◆ update_basis_inverse()

template<typename T >
void Aleph::RevisedSimplex< T >::update_basis_inverse ( int  leaving_row,
const std::vector< T > &  d_col 
)
inlineprivate

◆ verify_solution()

template<typename T >
bool Aleph::RevisedSimplex< T >::verify_solution ( ) const
inline

Verifies solution satisfies all constraints.

Returns
true if feasible, false otherwise.

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.

Member Data Documentation

◆ A

◆ b

◆ B_inv_explicit

◆ basic

◆ c

◆ d

template<typename T >
std::vector<T> Aleph::RevisedSimplex< T >::d
mutableprivate

◆ eps

◆ eta_file

template<typename T >
std::vector<EtaMatrix> Aleph::RevisedSimplex< T >::eta_file
private

◆ is_basic

template<typename T >
std::vector<bool> Aleph::RevisedSimplex< T >::is_basic
private

Definition at line 1760 of file Simplex.H.

Referenced by Aleph::RevisedSimplex< T >::solve().

◆ m

◆ n

◆ nonbasic

template<typename T >
std::vector<int> Aleph::RevisedSimplex< T >::nonbasic
private

◆ pi

template<typename T >
std::vector<T> Aleph::RevisedSimplex< T >::pi
mutableprivate

◆ refactor_frequency

template<typename T >
size_t Aleph::RevisedSimplex< T >::refactor_frequency
private

◆ solution

◆ state

template<typename T >
State Aleph::RevisedSimplex< T >::state
private

◆ stats

◆ use_steepest_edge

template<typename T >
bool Aleph::RevisedSimplex< T >::use_steepest_edge
private

Definition at line 1783 of file Simplex.H.

◆ work

template<typename T >
std::vector<T> Aleph::RevisedSimplex< T >::work
mutableprivate

Definition at line 1778 of file Simplex.H.

◆ x_B

template<typename T >
std::vector<T> Aleph::RevisedSimplex< T >::x_B
private

The documentation for this class was generated from the following file: