|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Linear program solver using the Simplex method. More...
#include <Simplex.H>
Public Types | |
| enum | State { Not_Solved , Solving , Unbounded , Solved , Unfeasible } |
| Solution states for the linear program. More... | |
| enum class | PivotRule { Dantzig , Bland } |
| Pivot selection rule. More... | |
Public Member Functions | |
| Simplex (const size_t n, OptimizationType type=OptimizationType::Maximize) | |
| Constructs a Simplex solver for n variables. | |
| ~Simplex () | |
| Destructor. | |
| Simplex (const Simplex &)=delete | |
| Simplex & | operator= (const Simplex &)=delete |
| Simplex (Simplex &&)=default | |
| Simplex & | operator= (Simplex &&)=default |
| void | set_optimization_type (OptimizationType type) noexcept |
| Sets the optimization type. | |
| void | set_minimize () noexcept |
| Sets minimization mode. | |
| void | set_maximize () noexcept |
| Sets maximization mode. | |
| void | set_pivot_rule (PivotRule rule) noexcept |
| Sets the pivot selection rule. | |
| void | enable_bland_rule () noexcept |
| Enables Bland's anti-cycling rule. | |
| void | set_epsilon (T epsilon) noexcept |
| Sets the floating-point comparison tolerance. | |
| OptimizationType | get_optimization_type () const noexcept |
| Gets the current optimization type. | |
| void | put_objetive_function_coef (size_t i, const T &coef) |
| Sets a coefficient in the objective function. | |
| const T & | get_objetive_function_coef (size_t i) const |
| Gets a coefficient from the objective function. | |
| void | put_objetive_function (const DynArray< T > &coefs) |
| Sets all objective function coefficients from a DynArray. | |
| void | put_objetive_function (const T coefs[]) |
| Sets all objective function coefficients from a C array. | |
| T * | put_restriction (const T *coefs=nullptr, ConstraintType type=ConstraintType::LE) |
| Adds a constraint to the linear program. | |
| T * | put_ge_restriction (const T *coefs) |
| Adds a ≥ constraint. | |
| T * | put_eq_restriction (const T *coefs) |
| Adds an = constraint. | |
| T * | put_restriction (const DynArray< T > &coefs, ConstraintType type=ConstraintType::LE) |
| Adds a constraint from a DynArray. | |
| T * | get_restriction (const size_t rest_num) |
| Gets a pointer to a constraint array. | |
| size_t | get_num_restrictions () const noexcept |
| Gets the number of constraints. | |
| size_t | get_num_vars () const noexcept |
| Gets the number of decision variables. | |
| T * | get_objetive_function () noexcept |
| Gets the objective function coefficients array. | |
| const T * | get_objetive_function () const noexcept |
| Gets the objective function coefficients array (const). | |
| T & | get_restriction_coef (const size_t rest_num, size_t idx) |
| Gets a specific coefficient from a constraint. | |
| void | put_restriction_coef (const size_t rest_num, const size_t idx, const T &coef) |
| Sets a specific coefficient in a constraint. | |
| void | prepare_linear_program () |
| Prepares the linear program for solving. | |
| State | solve () |
| Solves the linear program. | |
| State | get_state () const noexcept |
| Gets the current state of the solver. | |
| void | load_solution () noexcept |
| Loads the solution values into the solution array. | |
| const T & | get_solution (size_t i) const noexcept |
| Gets the solution value for a specific variable. | |
| T | objetive_value () const noexcept |
| Computes and returns the objective function value. | |
| bool | verify_solution () const |
| Verifies that the solution satisfies all constraints. | |
| void | print_matrix () const |
| Prints the simplex tableau to stdout. | |
| void | latex_matrix (const std::string &name, const int d=2, const int p=-1, const int q=-1) const |
| Exports the simplex tableau to a LaTeX file. | |
| void | latex_linear_program (const std::string &name) const |
| Exports the linear program to a LaTeX file. | |
| State | latex_solve (const char *name=nullptr) |
| Solves with LaTeX output at each iteration. | |
| const SimplexStats & | get_stats () const noexcept |
| Gets execution statistics. | |
| size_t | get_iteration_count () const noexcept |
| Gets the number of iterations performed. | |
| size_t | get_pivot_count () const noexcept |
| Gets the number of pivot operations. | |
| size_t | get_degenerate_pivot_count () const noexcept |
| Gets the number of degenerate pivots. | |
| double | get_elapsed_time_ms () const noexcept |
| Gets the elapsed solving time. | |
| SensitivityRange< T > | objective_sensitivity (size_t var_idx) const |
| Computes sensitivity range for an objective coefficient. | |
| SensitivityRange< T > | rhs_sensitivity (size_t rest_idx) const |
| Computes sensitivity range for a RHS value. | |
| T | shadow_price (size_t rest_idx) const |
| Gets the shadow price (dual value) for a constraint. | |
| T | reduced_cost (size_t var_idx) const |
| Gets the reduced cost for a variable. | |
| bool | is_basic_variable (size_t var_idx) const |
| Checks if a variable is basic in the optimal solution. | |
| std::vector< T > | get_all_shadow_prices () const |
| Gets all shadow prices as a vector. | |
| std::vector< T > | get_all_reduced_costs () const |
| Gets all reduced costs as a vector. | |
| State | dual_solve () |
| Performs dual simplex iteration. | |
| State | update_rhs_and_reoptimize (size_t rest_idx, T new_rhs) |
| Updates RHS value and re-optimizes using dual simplex. | |
| void | print_stats () const |
| Prints a summary of statistics to stdout. | |
| void | print_sensitivity_analysis () const |
| Prints sensitivity analysis to stdout. | |
Private Member Functions | |
| int | compute_pivot_col () const noexcept |
| int | compute_pivot_row (int p) const noexcept |
| State | select_pivot (int &p, int &q) noexcept |
| void | to_pivot (size_t p, size_t q) |
| T | find_value (const size_t j) const noexcept |
| void | verify_var_index (const size_t i) const |
| void | verify_rest_index (const size_t i) const |
| T * | create_restriction (ConstraintType type=ConstraintType::LE) |
| size_t | count_artificial_vars () const noexcept |
| void | create_matrix () |
Private Attributes | |
| std::unique_ptr< DynMatrix< T > > | m |
| std::unique_ptr< T[]> | objetive |
| DynDlist< T * > | rest_list |
| DynDlist< ConstraintType > | rest_types |
| size_t | num_var |
| size_t | num_rest |
| size_t | num_artificial |
| std::unique_ptr< T[]> | solution |
| State | state |
| OptimizationType | opt_type |
| PivotRule | pivot_rule |
| T | eps |
| SimplexStats | stats |
| std::vector< T > | pivot_row_buffer |
| std::vector< T > | pivot_col_buffer |
| std::vector< int > | basic_vars |
Linear program solver using the Simplex method.
Simplex<T> allows expressing linear programs in standard or non-standard forms, supporting both maximization and minimization, as well as ≤, ≥, and = constraints directly.
The standard form of a linear program is:
This implementation now handles non-standard forms directly:
set_minimize() instead of negating coefficientsput_restriction(coefs, ConstraintType::GE)put_restriction(coefs, ConstraintType::EQ)A factory produces two products (A and B) with limited resources:
Mathematical formulation:
Code:
Where n = number of variables, m = number of constraints.
| T | Numeric type for coefficients and values (typically double). |
|
strong |
Solution states for the linear program.
Not_Solved: Initial state, solve() has not been called yet.Solving: Algorithm is in progress (internal state).Unbounded: The system is unbounded (design error in constraints).Solved: An optimal solution has been found.Unfeasible: No feasible solution exists. | Enumerator | |
|---|---|
| Not_Solved | |
| Solving | |
| Unbounded | |
| Solved | |
| Unfeasible | |
|
inlineexplicit |
Constructs a Simplex solver for n variables.
Initializes a linear program in standard form without constraints and with all objective function coefficients set to zero.
| [in] | n | Number of decision variables in the system. |
| [in] | type | Optimization type: Maximize (default) or Minimize. |
| std::bad_alloc | If memory allocation fails. |
| std::invalid_argument | If n is zero. |
Definition at line 605 of file Simplex.H.
References ah_invalid_argument_if, and Aleph::Simplex< T >::objetive.
|
inline |
Destructor.
Frees all allocated restriction arrays.
Definition at line 624 of file Simplex.H.
References FunctionalMethods< Container, T >::for_each(), and Aleph::Simplex< T >::rest_list.
|
inlineprivatenoexcept |
Definition at line 250 of file Simplex.H.
References Aleph::Simplex< T >::Bland, Aleph::Simplex< T >::eps, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::pivot_rule.
Referenced by Aleph::Simplex< T >::select_pivot().
|
inlineprivatenoexcept |
Definition at line 282 of file Simplex.H.
References Aleph::Simplex< T >::Bland, Aleph::Simplex< T >::eps, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::pivot_rule.
Referenced by Aleph::Simplex< T >::select_pivot().
|
inlineprivatenoexcept |
Definition at line 471 of file Simplex.H.
References Aleph::count(), LocateFunctions< Container, Type >::get_it(), Aleph::LE, and Aleph::Simplex< T >::rest_types.
Referenced by Aleph::Simplex< T >::create_matrix().
|
inlineprivate |
Definition at line 482 of file Simplex.H.
References Aleph::Simplex< T >::basic_vars, Aleph::Simplex< T >::count_artificial_vars(), Aleph::EQ, Aleph::GE, LocateFunctions< Container, Type >::get_it(), Aleph::LE, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Maximize, Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::objetive, Aleph::Simplex< T >::opt_type, Aleph::Simplex< T >::rest_list, and Aleph::Simplex< T >::rest_types.
Referenced by Aleph::Simplex< T >::prepare_linear_program().
|
inlineprivate |
Definition at line 459 of file Simplex.H.
References Aleph::DynDlist< T >::append(), Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::rest_list, and Aleph::Simplex< T >::rest_types.
Referenced by Aleph::Simplex< T >::put_restriction(), and Aleph::Simplex< T >::put_restriction().
|
inline |
Performs dual simplex iteration.
Used for re-optimization when the RHS values change. The current solution must be dual feasible (reduced costs ≥ 0 for max).
Definition at line 1525 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::basic_vars, Aleph::SimplexStats::elapsed_ms, Aleph::Simplex< T >::eps, Aleph::SimplexStats::iterations, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::SimplexStats::pivots, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::Solving, Aleph::Simplex< T >::state, Aleph::Simplex< T >::stats, Aleph::Simplex< T >::to_pivot(), and Aleph::Simplex< T >::Unfeasible.
Referenced by Aleph::Simplex< T >::update_rhs_and_reoptimize().
|
inlinenoexcept |
Enables Bland's anti-cycling rule.
Use this when dealing with potentially degenerate problems.
Definition at line 684 of file Simplex.H.
References Aleph::Simplex< T >::Bland, Aleph::SimplexStats::bland_rule_used, Aleph::Simplex< T >::pivot_rule, and Aleph::Simplex< T >::stats.
|
inlineprivatenoexcept |
Definition at line 390 of file Simplex.H.
References Aleph::count(), Aleph::Simplex< T >::eps, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, and Aleph::Simplex< T >::num_var.
Referenced by Aleph::Simplex< T >::load_solution().
|
inline |
Gets all reduced costs as a vector.
Definition at line 1505 of file Simplex.H.
References ah_logic_error_if, Aleph::maps(), Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::Solved, and Aleph::Simplex< T >::state.
|
inline |
Gets all shadow prices as a vector.
Definition at line 1490 of file Simplex.H.
References ah_logic_error_if, Aleph::maps(), Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::shadow_price(), Aleph::Simplex< T >::Solved, and Aleph::Simplex< T >::state.
|
inlinenoexcept |
Gets the number of degenerate pivots.
A degenerate pivot is one that doesn't improve the objective.
Definition at line 1271 of file Simplex.H.
References Aleph::SimplexStats::degenerate_pivots, and Aleph::Simplex< T >::stats.
|
inlinenoexcept |
Gets the elapsed solving time.
Definition at line 1280 of file Simplex.H.
References Aleph::SimplexStats::elapsed_ms, and Aleph::Simplex< T >::stats.
|
inlinenoexcept |
Gets the number of iterations performed.
Definition at line 1251 of file Simplex.H.
References Aleph::SimplexStats::iterations, and Aleph::Simplex< T >::stats.
|
inlinenoexcept |
Gets the number of constraints.
Definition at line 852 of file Simplex.H.
References Aleph::Simplex< T >::num_rest.
|
inlinenoexcept |
Gets the number of decision variables.
Definition at line 861 of file Simplex.H.
References Aleph::Simplex< T >::num_var.
Gets the objective function coefficients array (const).
Definition at line 879 of file Simplex.H.
References Aleph::DynList< T >::get(), and Aleph::Simplex< T >::objetive.
|
inlinenoexcept |
Gets the objective function coefficients array.
Definition at line 870 of file Simplex.H.
References Aleph::DynList< T >::get(), and Aleph::Simplex< T >::objetive.
|
inline |
Gets a coefficient from the objective function.
| [in] | i | Variable index (0-based). |
| std::out_of_range | If i >= number of variables. |
Definition at line 730 of file Simplex.H.
References Aleph::Simplex< T >::objetive, and Aleph::Simplex< T >::verify_var_index().
|
inlinenoexcept |
Gets the current optimization type.
Definition at line 703 of file Simplex.H.
References Aleph::Simplex< T >::opt_type.
|
inlinenoexcept |
Gets the number of pivot operations.
Definition at line 1260 of file Simplex.H.
References Aleph::SimplexStats::pivots, and Aleph::Simplex< T >::stats.
Gets a pointer to a constraint array.
| [in] | rest_num | Constraint index (0-based). |
| std::out_of_range | If rest_num >= number of constraints. |
Definition at line 836 of file Simplex.H.
References LocateFunctions< Container, Type >::get_it(), Aleph::maps(), Aleph::Simplex< T >::rest_list, and Aleph::Simplex< T >::verify_rest_index().
Referenced by Aleph::Simplex< T >::get_restriction_coef().
Gets a specific coefficient from a constraint.
| [in] | rest_num | Constraint index. |
| [in] | idx | Variable index within the constraint. |
| std::out_of_range | If indices are out of range. |
Definition at line 892 of file Simplex.H.
References Aleph::Simplex< T >::get_restriction(), Aleph::maps(), and Aleph::Simplex< T >::verify_var_index().
Referenced by Aleph::Simplex< T >::put_restriction_coef().
Gets the solution value for a specific variable.
| [in] | i | Variable index (0-based). |
Definition at line 1025 of file Simplex.H.
References Aleph::maps(), Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::solution.
|
inlinenoexcept |
Gets the current state of the solver.
Definition at line 1000 of file Simplex.H.
References Aleph::Simplex< T >::state.
|
inlinenoexcept |
Gets execution statistics.
Returns statistics about the most recent solve() call.
Definition at line 1242 of file Simplex.H.
References Aleph::Simplex< T >::stats.
Checks if a variable is basic in the optimal solution.
| [in] | var_idx | Variable index (0-based). |
Definition at line 1475 of file Simplex.H.
References Aleph::Simplex< T >::basic_vars, Aleph::maps(), Aleph::Simplex< T >::num_rest, and Aleph::Simplex< T >::verify_var_index().
Referenced by Aleph::Simplex< T >::print_sensitivity_analysis().
|
inline |
Exports the linear program to a LaTeX file.
Generates a LaTeX representation of the objective function and all constraints.
| [in] | name | Output file name. |
Definition at line 1149 of file Simplex.H.
References LocateFunctions< Container, Type >::get_it(), Aleph::maps(), Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::objetive, and Aleph::Simplex< T >::rest_list.
|
inline |
Exports the simplex tableau to a LaTeX file.
| [in] | name | Output file name. |
| [in] | d | Number of decimal places (default 2). |
| [in] | p | Pivot row to highlight (-1 for none). |
| [in] | q | Pivot column to highlight (-1 for none). |
Definition at line 1110 of file Simplex.H.
References Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_rest, and Aleph::Simplex< T >::num_var.
Referenced by Aleph::Simplex< T >::latex_solve().
Solves with LaTeX output at each iteration.
Similar to solve(), but outputs LaTeX files showing each pivot operation for educational purposes.
| [in] | name | Base name for output files. |
Definition at line 1211 of file Simplex.H.
References Aleph::Simplex< T >::latex_matrix(), Aleph::maps(), Aleph::Simplex< T >::select_pivot(), Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::to_pivot(), and Aleph::Simplex< T >::Unbounded.
|
inlinenoexcept |
Loads the solution values into the solution array.
Must be called after solve() returns Solved state. After this, individual variable values can be retrieved with get_solution().
Definition at line 1010 of file Simplex.H.
References Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::solution.
Referenced by Aleph::Simplex< T >::solve().
|
inline |
Computes sensitivity range for an objective coefficient.
Determines the range [lower, upper] within which the objective coefficient c_j can vary without changing the optimal basis.
| [in] | var_idx | Variable index (0-based). |
| std::out_of_range | If var_idx is out of range. |
| std::logic_error | If not solved yet. |
Definition at line 1299 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::basic_vars, Aleph::SensitivityRange< T >::current_value, Aleph::Simplex< T >::eps, Aleph::SensitivityRange< T >::lower_bound, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Maximize, Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::objetive, Aleph::Simplex< T >::opt_type, Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, Aleph::SensitivityRange< T >::upper_bound, and Aleph::Simplex< T >::verify_var_index().
Referenced by Aleph::Simplex< T >::print_sensitivity_analysis().
|
inlinenoexcept |
Computes and returns the objective function value.
Calculates Z = sum(c_i * x_i) using the current solution.
Definition at line 1039 of file Simplex.H.
References Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::objetive, Aleph::Simplex< T >::solution, and Aleph::sum().
|
delete |
|
default |
|
inline |
Prepares the linear program for solving.
Must be called after all objective function coefficients and constraints have been set, and before calling solve().
Creates the internal simplex tableau matrix with slack variables.
| std::bad_alloc | If memory allocation fails. |
| std::logic_error | If no constraints have been added. |
Definition at line 921 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::create_matrix(), and Aleph::Simplex< T >::num_rest.
|
inline |
Prints the simplex tableau to stdout.
Useful for debugging and understanding the algorithm's progress.
Definition at line 1092 of file Simplex.H.
References Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_rest, and Aleph::Simplex< T >::num_var.
|
inline |
Prints sensitivity analysis to stdout.
Definition at line 1655 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::is_basic_variable(), Aleph::maps(), Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::objective_sensitivity(), Aleph::range(), Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::shadow_price(), Aleph::Simplex< T >::Solved, and Aleph::Simplex< T >::state.
|
inline |
Prints a summary of statistics to stdout.
Definition at line 1641 of file Simplex.H.
References Aleph::SimplexStats::bland_rule_used, Aleph::SimplexStats::degenerate_pivots, Aleph::SimplexStats::elapsed_ms, Aleph::SimplexStats::iterations, Aleph::SimplexStats::pivots, and Aleph::Simplex< T >::stats.
Adds an = constraint.
Convenience method for adding equality constraints.
| [in] | coefs | Array of n+1 coefficients. |
Definition at line 805 of file Simplex.H.
References Aleph::EQ, Aleph::maps(), and Aleph::Simplex< T >::put_restriction().
Adds a ≥ constraint.
Convenience method for adding greater-than-or-equal constraints.
| [in] | coefs | Array of n+1 coefficients. |
Definition at line 793 of file Simplex.H.
References Aleph::GE, Aleph::maps(), and Aleph::Simplex< T >::put_restriction().
Sets all objective function coefficients from a DynArray.
| [in] | coefs | Array of coefficients. Must have at least num_var elements. |
Definition at line 740 of file Simplex.H.
References Aleph::maps(), Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::objetive.
Sets all objective function coefficients from a C array.
| [in] | coefs | Array of coefficients. Must have at least num_var elements. |
Definition at line 750 of file Simplex.H.
References Aleph::maps(), Aleph::Simplex< T >::num_var, and Aleph::Simplex< T >::objetive.
Sets a coefficient in the objective function.
Sets the coefficient of variable x_i in the objective function.
| [in] | i | Variable index (0-based). |
| [in] | coef | Coefficient value. |
| std::out_of_range | If i >= number of variables. |
Definition at line 717 of file Simplex.H.
References Aleph::Simplex< T >::objetive, and Aleph::Simplex< T >::verify_var_index().
|
inline |
Adds a constraint from a DynArray.
| [in] | coefs | Array of n+1 coefficients. |
| [in] | type | Constraint type: LE (≤), GE (≥), or EQ (=). Default is LE. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 818 of file Simplex.H.
References Aleph::Simplex< T >::create_restriction(), Aleph::maps(), and Aleph::Simplex< T >::num_var.
|
inline |
Adds a constraint to the linear program.
Adds a constraint of the form: c[0]*x_0 + c[1]*x_1 + ... + c[n-1]*x_{n-1} [op] c[n]
where c[n] is the RHS (right-hand side) bound and [op] is determined by the constraint type (≤, ≥, or =).
| [in] | coefs | Array of n+1 coefficients (n variable coefficients + RHS). If nullptr, creates a zero-initialized constraint. |
| [in] | type | Constraint type: LE (≤), GE (≥), or EQ (=). Default is LE. |
| std::bad_alloc | If memory allocation fails. |
Definition at line 772 of file Simplex.H.
References Aleph::Simplex< T >::create_restriction(), Aleph::maps(), and Aleph::Simplex< T >::num_var.
Referenced by Aleph::Simplex< T >::put_eq_restriction(), and Aleph::Simplex< T >::put_ge_restriction().
|
inline |
Sets a specific coefficient in a constraint.
| [in] | rest_num | Constraint index. |
| [in] | idx | Variable index within the constraint. |
| [in] | coef | New coefficient value. |
| std::out_of_range | If indices are out of range. |
Definition at line 906 of file Simplex.H.
References Aleph::Simplex< T >::get_restriction_coef(), and Aleph::maps().
Gets the reduced cost for a variable.
The reduced cost indicates how much the objective would improve per unit increase in a non-basic variable.
| [in] | var_idx | Variable index (0-based). |
| std::out_of_range | If var_idx is out of range. |
| std::logic_error | If not solved yet. |
Definition at line 1454 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Maximize, Aleph::Simplex< T >::opt_type, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, and Aleph::Simplex< T >::verify_var_index().
Referenced by Aleph::Simplex< T >::get_all_reduced_costs(), Aleph::Simplex< T >::objective_sensitivity(), and Aleph::Simplex< T >::print_sensitivity_analysis().
|
inline |
Computes sensitivity range for a RHS value.
Determines the range within which the right-hand side value b_i can vary without changing the optimal basis.
| [in] | rest_idx | Constraint index (0-based). |
| std::out_of_range | If rest_idx is out of range. |
| std::logic_error | If not solved yet. |
Definition at line 1368 of file Simplex.H.
References ah_logic_error_if, Aleph::SensitivityRange< T >::current_value, Aleph::Simplex< T >::eps, LocateFunctions< Container, Type >::get_it(), Aleph::SensitivityRange< T >::lower_bound, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::rest_list, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, Aleph::SensitivityRange< T >::upper_bound, and Aleph::Simplex< T >::verify_rest_index().
Referenced by Aleph::Simplex< T >::print_sensitivity_analysis().
|
inlineprivatenoexcept |
Definition at line 321 of file Simplex.H.
References Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::maps(), Aleph::Simplex< T >::Not_Solved, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::Solving, Aleph::Simplex< T >::state, and Aleph::Simplex< T >::Unbounded.
Referenced by Aleph::Simplex< T >::latex_solve(), and Aleph::Simplex< T >::solve().
Sets the floating-point comparison tolerance.
| [in] | epsilon | Tolerance for comparing values to zero. |
Definition at line 694 of file Simplex.H.
References Aleph::Simplex< T >::eps.
|
inlinenoexcept |
Sets maximization mode.
Convenience method equivalent to set_optimization_type(Maximize).
Definition at line 663 of file Simplex.H.
References Aleph::Maximize, and Aleph::Simplex< T >::opt_type.
|
inlinenoexcept |
Sets minimization mode.
Convenience method equivalent to set_optimization_type(Minimize).
Definition at line 654 of file Simplex.H.
References Aleph::Minimize, and Aleph::Simplex< T >::opt_type.
|
inlinenoexcept |
Sets the optimization type.
| [in] | type | Maximize or Minimize. |
Definition at line 645 of file Simplex.H.
References Aleph::Simplex< T >::opt_type.
Sets the pivot selection rule.
| [in] | rule | Dantzig (default, faster) or Bland (anti-cycling). |
Bland's rule guarantees termination on degenerate problems but may be slower on non-degenerate problems.
Definition at line 675 of file Simplex.H.
References Aleph::maps(), and Aleph::Simplex< T >::pivot_rule.
Gets the shadow price (dual value) for a constraint.
The shadow price represents the marginal value of relaxing a constraint by one unit.
| [in] | rest_idx | Constraint index (0-based). |
| std::out_of_range | If rest_idx is out of range. |
| std::logic_error | If not solved yet. |
Definition at line 1426 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Minimize, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::opt_type, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, and Aleph::Simplex< T >::verify_rest_index().
Referenced by Aleph::Simplex< T >::get_all_shadow_prices(), and Aleph::Simplex< T >::print_sensitivity_analysis().
|
inline |
Solves the linear program.
Solves a correctly and completely specified linear program using the simplex algorithm.
Unbounded: System is unbounded (constraint error).Solved: Optimal solution found.Unfeasible: No feasible solution exists.| std::logic_error | If solve() has already been called. |
| std::logic_error | If no constraints have been added. |
| std::logic_error | If prepare_linear_program() was not called. |
Definition at line 947 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::basic_vars, Aleph::SimplexStats::degenerate_pivots, Aleph::SimplexStats::elapsed_ms, Aleph::Simplex< T >::eps, Aleph::SimplexStats::iterations, Aleph::Simplex< T >::load_solution(), Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::Not_Solved, Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::SimplexStats::pivots, Aleph::SimplexStats::reset(), Aleph::Simplex< T >::select_pivot(), Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, Aleph::Simplex< T >::stats, Aleph::Simplex< T >::to_pivot(), and Aleph::Simplex< T >::Unbounded.
Definition at line 341 of file Simplex.H.
References Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::pivot_col_buffer, and Aleph::Simplex< T >::pivot_row_buffer.
Referenced by Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::latex_solve(), and Aleph::Simplex< T >::solve().
|
inline |
Updates RHS value and re-optimizes using dual simplex.
Efficiently re-solves the problem when only RHS values change.
| [in] | rest_idx | Constraint index to update. |
| [in] | new_rhs | New right-hand side value. |
Definition at line 1605 of file Simplex.H.
References ah_logic_error_if, Aleph::Simplex< T >::dual_solve(), LocateFunctions< Container, Type >::get_it(), Aleph::Simplex< T >::m, Aleph::maps(), Aleph::Simplex< T >::num_artificial, Aleph::Simplex< T >::num_rest, Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::rest_list, Aleph::Simplex< T >::Solved, Aleph::Simplex< T >::state, and Aleph::Simplex< T >::verify_rest_index().
|
inlineprivate |
Definition at line 452 of file Simplex.H.
References ah_out_of_range_error_if, and Aleph::Simplex< T >::num_rest.
Referenced by Aleph::Simplex< T >::get_restriction(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::shadow_price(), and Aleph::Simplex< T >::update_rhs_and_reoptimize().
|
inline |
Verifies that the solution satisfies all constraints.
Checks each constraint to ensure the solution does not violate any less-than-or-equal-to bounds.
Definition at line 1056 of file Simplex.H.
References Aleph::Simplex< T >::eps, Aleph::EQ, Aleph::GE, LocateFunctions< Container, Type >::get_it(), Aleph::LE, Aleph::maps(), Aleph::Simplex< T >::num_var, Aleph::Simplex< T >::rest_list, Aleph::Simplex< T >::rest_types, Aleph::Simplex< T >::solution, and Aleph::sum().
|
inlineprivate |
Definition at line 445 of file Simplex.H.
References ah_out_of_range_error_if, and Aleph::Simplex< T >::num_var.
Referenced by Aleph::Simplex< T >::get_objetive_function_coef(), Aleph::Simplex< T >::get_restriction_coef(), Aleph::Simplex< T >::is_basic_variable(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::put_objetive_function_coef(), and Aleph::Simplex< T >::reduced_cost().
|
mutableprivate |
Definition at line 442 of file Simplex.H.
Referenced by Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::is_basic_variable(), Aleph::Simplex< T >::objective_sensitivity(), and Aleph::Simplex< T >::solve().
|
private |
Definition at line 432 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::set_epsilon(), Aleph::Simplex< T >::solve(), and Aleph::Simplex< T >::verify_solution().
Definition at line 421 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::latex_matrix(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::print_matrix(), Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::shadow_price(), Aleph::Simplex< T >::solve(), Aleph::Simplex< T >::to_pivot(), and Aleph::Simplex< T >::update_rhs_and_reoptimize().
|
private |
Definition at line 427 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::solve(), Aleph::Simplex< T >::to_pivot(), and Aleph::Simplex< T >::update_rhs_and_reoptimize().
|
private |
Definition at line 426 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::create_restriction(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::get_all_shadow_prices(), Aleph::Simplex< T >::get_num_restrictions(), Aleph::Simplex< T >::is_basic_variable(), Aleph::Simplex< T >::latex_matrix(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::prepare_linear_program(), Aleph::Simplex< T >::print_matrix(), Aleph::Simplex< T >::print_sensitivity_analysis(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::solve(), Aleph::Simplex< T >::to_pivot(), Aleph::Simplex< T >::update_rhs_and_reoptimize(), and Aleph::Simplex< T >::verify_rest_index().
|
private |
Definition at line 425 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::create_restriction(), Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::find_value(), Aleph::Simplex< T >::get_all_reduced_costs(), Aleph::Simplex< T >::get_num_vars(), Aleph::Simplex< T >::get_solution(), Aleph::Simplex< T >::latex_linear_program(), Aleph::Simplex< T >::latex_matrix(), Aleph::Simplex< T >::load_solution(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::objetive_value(), Aleph::Simplex< T >::print_matrix(), Aleph::Simplex< T >::print_sensitivity_analysis(), Aleph::Simplex< T >::put_objetive_function(), Aleph::Simplex< T >::put_objetive_function(), Aleph::Simplex< T >::put_restriction(), Aleph::Simplex< T >::put_restriction(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::shadow_price(), Aleph::Simplex< T >::solve(), Aleph::Simplex< T >::to_pivot(), Aleph::Simplex< T >::update_rhs_and_reoptimize(), Aleph::Simplex< T >::verify_solution(), and Aleph::Simplex< T >::verify_var_index().
|
private |
Definition at line 422 of file Simplex.H.
Referenced by Aleph::Simplex< T >::Simplex(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::get_objetive_function(), Aleph::Simplex< T >::get_objetive_function(), Aleph::Simplex< T >::get_objetive_function_coef(), Aleph::Simplex< T >::latex_linear_program(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::objetive_value(), Aleph::Simplex< T >::put_objetive_function(), Aleph::Simplex< T >::put_objetive_function(), and Aleph::Simplex< T >::put_objetive_function_coef().
|
private |
Definition at line 430 of file Simplex.H.
Referenced by Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::get_optimization_type(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::set_maximize(), Aleph::Simplex< T >::set_minimize(), Aleph::Simplex< T >::set_optimization_type(), and Aleph::Simplex< T >::shadow_price().
|
mutableprivate |
Definition at line 439 of file Simplex.H.
Referenced by Aleph::Simplex< T >::to_pivot().
|
mutableprivate |
Definition at line 438 of file Simplex.H.
Referenced by Aleph::Simplex< T >::to_pivot().
|
private |
Definition at line 431 of file Simplex.H.
Referenced by Aleph::Simplex< T >::compute_pivot_col(), Aleph::Simplex< T >::compute_pivot_row(), Aleph::Simplex< T >::enable_bland_rule(), and Aleph::Simplex< T >::set_pivot_rule().
Definition at line 423 of file Simplex.H.
Referenced by Aleph::Simplex< T >::~Simplex(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::create_restriction(), Aleph::Simplex< T >::get_restriction(), Aleph::Simplex< T >::latex_linear_program(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::update_rhs_and_reoptimize(), and Aleph::Simplex< T >::verify_solution().
|
private |
Definition at line 424 of file Simplex.H.
Referenced by Aleph::Simplex< T >::count_artificial_vars(), Aleph::Simplex< T >::create_matrix(), Aleph::Simplex< T >::create_restriction(), and Aleph::Simplex< T >::verify_solution().
|
private |
Definition at line 428 of file Simplex.H.
Referenced by Aleph::Simplex< T >::get_solution(), Aleph::Simplex< T >::load_solution(), Aleph::Simplex< T >::objetive_value(), and Aleph::Simplex< T >::verify_solution().
|
private |
Definition at line 429 of file Simplex.H.
Referenced by Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::get_all_reduced_costs(), Aleph::Simplex< T >::get_all_shadow_prices(), Aleph::Simplex< T >::get_state(), Aleph::Simplex< T >::objective_sensitivity(), Aleph::Simplex< T >::print_sensitivity_analysis(), Aleph::Simplex< T >::reduced_cost(), Aleph::Simplex< T >::rhs_sensitivity(), Aleph::Simplex< T >::select_pivot(), Aleph::Simplex< T >::shadow_price(), Aleph::Simplex< T >::solve(), and Aleph::Simplex< T >::update_rhs_and_reoptimize().
|
mutableprivate |
Definition at line 435 of file Simplex.H.
Referenced by Aleph::Simplex< T >::dual_solve(), Aleph::Simplex< T >::enable_bland_rule(), Aleph::Simplex< T >::get_degenerate_pivot_count(), Aleph::Simplex< T >::get_elapsed_time_ms(), Aleph::Simplex< T >::get_iteration_count(), Aleph::Simplex< T >::get_pivot_count(), Aleph::Simplex< T >::get_stats(), Aleph::Simplex< T >::print_stats(), and Aleph::Simplex< T >::solve().