#include "Sm_lps5_5.h"
Static Public Member Functions | |
static double | get_accuracy () |
Get accuracy used by lp_solve. | |
static bool | get_dual_ray (Lp *lp, int &iyzray) |
Get dual improving ray. | |
static bool | get_primal_ray (Lp *lp, int &ixray) |
Get primal improving ray. | |
static const char * | get_version () |
Get module version string. | |
static bool | init (Report *report) |
Initialize the module. | |
static void | lp2solver (Lp *lp) |
Transform an lp into lp_solve's representation. | |
static void | print_brief_version () |
Print brief module version. | |
static void | print_options () |
Print supported options. | |
static void | print_version () |
Print module version. | |
static bool | read_lp (Lp *lp, FILE *in, const double relative_interval_radius, double &eta) |
Read lp. | |
static void | restore_dual (Lp *lp) |
Restore lp after dual perturbation. | |
static void | restore_dual_phase1 (Lp *) |
Restore lp after dual phase 1 perturbation. | |
static void | restore_primal (Lp *lp) |
Restore lp after primal perturbation. | |
static void | restore_primal_phase1 (Lp *) |
Restore lp after primal phase 1 perturbation. | |
static void | set_bounds (Lp *lp, int var, double lower, double upper) |
Set simple bounds on a variable. | |
static void | set_dual_phase1 (Lp *lp) |
Set dual phase 1 lp. | |
static bool | set_lp (Lp *lp, const double relative_interval_radius, double &eta) |
Set lp. | |
static bool | set_module_options (Lp *lp, int argc, char *argv[]) |
Set module options. | |
static void | set_primal_phase1 (Lp *lp) |
Set primal phase 1 lp. | |
static bool | solve_dual_perturbed (const VECTOR &deflation_c, Lp *lp, const int iteration) |
Compute solution of dual perturbed lp. | |
static bool | solve_original (Lp *lp, double &optimal_value) |
Compute solution of unperturbed lp. | |
static bool | solve_primal_perturbed (const Primal_deflation &deflation, Lp *lp, const int iteration) |
Compute solution of primal perturbed lp. | |
Static Private Member Functions | |
static void | dual_perturb (const VECTOR &d_c, const Lp *lp) |
Dual perturb lp. | |
static void __WINAPI | lps_log (lprec *lp_lps, void *userhandle, char *buf) |
Callback function for lp_solve's log messages. | |
static void | primal_perturb (const Primal_deflation &d, const Lp *lp) |
Primal perturb lp. | |
static bool | read_duals (Lp *lp) |
Read dual solution. | |
static bool | read_primals (Lp *lp) |
Read primal solution. | |
static bool | solve_lp (Lp *lp) |
Solve lp with lp_solve. | |
static void | write_lp (const char *sz_description, lprec *lp_lps, char *sz_file) |
Write an LP to file. | |
Lp transforming routines | |
The following routines read the lp from the data structures of lp_solve 5.5 and transform it into Lurupa's representation. | |
static void | adjust_eta (double &eta, const Lp *lp) |
Adjust eta to the lp. | |
static bool | build_constraint_maps (int &c_eq, int &c_le, const int rows, const int cols, Lp *lp) |
Build mapping between lp_solve's and Lurupa's constraint structures. | |
static void | find_free_variables (const int vars, Lp *lp, int *c_inf_bnd) |
Find free variables. | |
static void | inflate_lp (Lp *lp, const double r) |
Inflate lp parameters. | |
static void | read_general_data (Lp *lp) |
Read general data from lp_solve's structures. | |
static bool | read_lp_mat (const int rows, Lp *lp) |
Read lp_solve's lp_mat structure. | |
static void | read_right_hand_sides (Lp *lp) |
Read right hand sides of the constraints. | |
static void | read_simple_bounds (Lp *lp) |
Read simple bounds. | |
static void | resize_lp (Lp *lp, const int cols, const int c_eq, const int c_le) |
Resize Lurupa's data structures according to the lp dimensions. | |
static bool | transform_lp (Lp *lp, const double relative_interval_radius, double &eta) |
Transform lp from lp_solve to Lurupa. | |
Static Private Attributes | |
static bool | freset_bas = false |
Whether models are resolved with an all slack basis in case of numerical failure. | |
static long | timeout = 0 |
static MYBOOL | trace = FALSE |
static int | verbosity = 3 |
static Write_mps | write_mps = wm_none |
Whether intermediate models are saved. |
void Sm_lps5_5::adjust_eta | ( | double & | eta, | |
const Lp * | lp | |||
) | [static, private] |
Adjust eta to the lp.
Adjust the algorithm parameter eta
to be problem dependent. It becomes the maximum of its previous value and times the maximum norm of the right hand sides of the inequality constraints,
[out] | eta | parameter to be adjusted |
[in] | lp | lp eta is adjusted to |
References Lp::ia, Solver_module::preport, and Report::print().
Referenced by transform_lp().
bool Sm_lps5_5::build_constraint_maps | ( | int & | c_eq, | |
int & | c_le, | |||
const int | rows, | |||
const int | cols, | |||
Lp * | lp | |||
) | [static, private] |
Build mapping between lp_solve's and Lurupa's constraint structures.
Build a mapping from Lurupa's equality and inequality constraints to lp_solve's constraints, which is storing all constraints in one big matrix. Store the mapping in lp->module->mp_eq_con
and lp->module->mp_le_con
. Check if the number of constraints is less than the number of variables.
[out] | c_eq | number of equations in lp |
[out] | c_le | number of inequalities in lp |
[in] | rows | number of rows of constraint matrix |
[in] | cols | number of columns of constraint matrix |
[in] | lp | the lp |
true | if number of constraints is less than number of variables, | |
false | otherwise |
References Lp_lp_solve::lp, Lp::module, Lp_lp_solve::mp_eq_con, Lp_lp_solve::mp_le_con, Solver_module::preport, and Report::print().
Referenced by transform_lp().
void Sm_lps5_5::dual_perturb | ( | const VECTOR & | d_c, | |
const Lp * | lp | |||
) | [static, private] |
Dual perturb lp.
Perturb the lp in the cost vector.
[in] | d_c | deflation parameters |
[out] | lp | contains the base for the deflation |
References Lp::ic, Lp_lp_solve::lp, Lp::maximize, and Lp::module.
Referenced by solve_dual_perturbed().
void Sm_lps5_5::find_free_variables | ( | const int | vars, | |
Lp * | lp, | |||
int * | c_inf_bnd | |||
) | [static, private] |
Find free variables.
Find free variables in the lp. Store the indices of the free variables in lp->free_variables
and their number in lp->free_variables_size
.
[in] | vars | number of variables in lp |
[out] | lp | stores number and indices of the free variables |
[out] | c_inf_bnd | count of variables with infinite bounds |
References Lp::free_variables, Lp::free_variables_size, and Lp::module.
Referenced by transform_lp().
double Sm_lps5_5::get_accuracy | ( | ) | [static] |
Get accuracy used by lp_solve.
Get lp_solve's set accuracy
Reimplemented from Solver_module.
Referenced by get_func_pointers().
const char * Sm_lps5_5::get_version | ( | ) | [static] |
Get module version string.
Get the version information of the solver module.
Reimplemented from Solver_module.
References version.
Referenced by get_func_pointers().
void Sm_lps5_5::inflate_lp | ( | Lp * | lp, | |
const double | r | |||
) | [static, private] |
bool Sm_lps5_5::init | ( | Report * | report | ) | [static] |
Initialize the module.
Set preport to *report
. Check the version of lp_solve.
[in] | report | the Report instance to use |
true |
Reimplemented from Solver_module.
References Solver_module::preport, Report::print(), and version.
Referenced by get_func_pointers().
void __WINAPI Sm_lps5_5::lps_log | ( | lprec * | lp_lps, | |
void * | userhandle, | |||
char * | buf | |||
) | [static, private] |
Callback function for lp_solve's log messages.
Callback function for lp_solve's log functionality. Print the supplied log message marked as coming from lp_solve.
References Solver_module::preport, and Report::print().
Referenced by lp2solver(), and read_lp().
void Sm_lps5_5::primal_perturb | ( | const Primal_deflation & | d, | |
const Lp * | lp | |||
) | [static, private] |
Primal perturb lp.
Perturb the lp in the right hand sides of the inequalities and the simple bounds.
[in] | d | deflation parameters |
[out] | lp | contains the base for the deflation |
References Primal_deflation::a, Lp::ia, Lp_lp_solve::lp, Lp::module, Lp_lp_solve::mp_le_con, Lp::xl, Primal_deflation::xl, Lp::xu, and Primal_deflation::xu.
Referenced by solve_primal_perturbed().
void Sm_lps5_5::print_options | ( | ) | [static] |
Print supported options.
Print the command line options supported by the solver module.
Reimplemented from Solver_module.
References version.
Referenced by get_func_pointers().
bool Sm_lps5_5::read_duals | ( | Lp * | lp | ) | [static, private] |
Read dual solution.
Read the dual solution from lp_solve and store it in lp->iy
and lp->iz
. Lp_solve's convention to determine the sign of the duals is, that the costs must be a linear combination of the gradients of the constraints.
The duals returned by lp_solve, however, are the duals for the original lp, that is the duals for greater equal constraints are multiplied by , and all duals are again multiplied by
if the lp is a maximizing one. As Lurupa stores all linear programs as minimizing and all inequality constraints as less equal undo these multiplications.
[out] | lp | receives the dual solution |
true | if reading the dual solution succeeded, | |
false | otherwise, calling lp_solve's get_sensitivity_rhs returns false |
References Lp::iy, Lp::iz, Lp_lp_solve::lp, Lp::maximize, Lp::module, Lp_lp_solve::mp_eq_con, Lp_lp_solve::mp_le_con, Solver_module::preport, and Report::print().
Referenced by solve_dual_perturbed(), and solve_original().
void Sm_lps5_5::read_general_data | ( | Lp * | lp | ) | [static, private] |
Read general data from lp_solve's structures.
Read general lp properties from lp_solve's structures and store them in lp
. This includes the value representing infinity, the direction of optimization, and the name of the lp.
[out] | lp | stores the read data |
References Lp::infinite, Lp::maximize, Lp::module, and Lp::name.
Referenced by transform_lp().
bool Sm_lps5_5::read_lp | ( | Lp * | lp, | |
FILE * | in, | |||
const double | relative_interval_radius, | |||
double & | eta | |||
) | [static] |
Read lp.
Read an lp from a file into lp_solve and lp
. Inflate the lp to an interval valued one if relative_interval_radius
is greater than 0, and adjust eta
according to the lp's parameters.
[out] | lp | receives the lp |
[in] | in | file pointer to lp |
[in] | relative_interval_radius | interval radius to inflate lp parameters to |
[out] | eta | algorithm parameter to be adjusted |
true | if reading and transforming the lp succeeds, | |
false | otherwise, reading the lp fails or transform_lp returns false |
Reimplemented from Solver_module.
References Lp_lp_solve::lp, lps_log(), Lp::module, and transform_lp().
Referenced by get_func_pointers().
bool Sm_lps5_5::read_lp_mat | ( | const int | rows, | |
Lp * | lp | |||
) | [static, private] |
Read lp_solve's lp_mat structure.
Read lp_solve's lp_mat
structure. This stores the left hand sides of the constraints together with the objective function. Split the read coefficients into equality and inequality constraints, transform inequality constraints to all less equal, and the direction of optimization to minimize.
[in] | rows | number of rows in constraint matrix |
[out] | lp | stores the constraints and objective function |
true | if reading lp_mat succeeds, | |
false | otherwise, lp_solve's get_column returns false |
References Lp::IA, Lp::IB, Lp::ic, Lp_lp_solve::lp, Lp::module, Lp_lp_solve::mp_eq_con, and Lp_lp_solve::mp_le_con.
Referenced by transform_lp().
bool Sm_lps5_5::read_primals | ( | Lp * | lp | ) | [static, private] |
Read primal solution.
Read the primal solution from lp_solve and store it in lp->ix
.
[out] | lp | receives the primal solution |
true | if reading the primal solution succeeds, | |
false | otherwise, calling lp_solve's get_variables returns false |
References Lp::ic, Lp::ix, Lp_lp_solve::lp, Lp::module, Solver_module::preport, and Report::print().
Referenced by solve_original(), and solve_primal_perturbed().
void Sm_lps5_5::read_right_hand_sides | ( | Lp * | lp | ) | [static, private] |
Read right hand sides of the constraints.
Read the right hand sides of the constraints. Split the read right hand sides into equality and inequality constraints, transform inequality constraints to all less equal. Store the values in lp->ia
and lp->ib
.
[out] | lp | stores the right hand sides |
References Lp::ia, Lp::ib, Lp_lp_solve::lp, Lp::module, Lp_lp_solve::mp_eq_con, and Lp_lp_solve::mp_le_con.
Referenced by transform_lp().
void Sm_lps5_5::read_simple_bounds | ( | Lp * | lp | ) | [static, private] |
Read simple bounds.
Read the simple bounds of the variables and store them in lp->xl
and lp->xu
.
[out] | lp | stores the simple bounds |
References Lp::module, Lp::non_fixed_vars, Lp::xl, and Lp::xu.
Referenced by transform_lp().
void Sm_lps5_5::resize_lp | ( | Lp * | lp, | |
const int | cols, | |||
const int | c_eq, | |||
const int | c_le | |||
) | [static, private] |
Resize Lurupa's data structures according to the lp dimensions.
Resize the vectors and matrices in Lurupa's data structure to the sizes of the lp.
[out] | lp | Lurupa's structure with the vectors and matrices to be resized |
[in] | cols | number of variables in the lp |
[in] | c_eq | number of equality constraints in the lp |
[in] | c_le | number of inequality constraints in the lp |
References Lp::ia, Lp::IA, Lp::ib, Lp::IB, Lp::ic, Lp::ix, Lp::iy, Lp::iz, Lp::xl, and Lp::xu.
Referenced by restore_primal_phase1(), set_primal_phase1(), and transform_lp().
void Sm_lps5_5::restore_dual | ( | Lp * | lp | ) | [static] |
Restore lp after dual perturbation.
Take the model parameters for the costs from lp
and write to lp->module->lp
restoring the original model after computation of the lower bound.
[in] | lp | contains the original parameters |
Reimplemented from Solver_module.
References Lp::ic, Lp::maximize, Lp::module, Solver_module::preport, and Report::print().
Referenced by get_func_pointers().
void Sm_lps5_5::restore_primal | ( | Lp * | lp | ) | [static] |
Restore lp after primal perturbation.
Take the model parameters for the right hand sides and the simple bounds from lp
and write to lp->module->lp
restoring the original model after computation of the upper bound.
[in] | lp | contains the original parameters |
Reimplemented from Solver_module.
References Lp::ia, Lp::IA, Lp_lp_solve::lp, Lp::module, Lp_lp_solve::mp_le_con, Solver_module::preport, Report::print(), Lp::xl, and Lp::xu.
Referenced by get_func_pointers().
bool Sm_lps5_5::set_module_options | ( | Lp * | lp, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Set module options.
Set the specified module options. These are supplied in argc
and argv
in a command line version. Each option is supplied as one string entry in the string array argv
, argc
specifies the number of options.
The module supports the following options
-sm,resetbas
': Resolve lps in the case of numerical failure with a default basis of all slacks. This may enable lp_solve to find a solution at the expense of increased runtime.-sm,s
': Use lp_solve's default scaling (Numerical range-based scaling).-sm,timeout,n
': Set lp_solve's timeout to n
seconds.-sm,vn
': Set lp_solve's verbosity level to n
. The available levels arev0
NEUTRALv1
CRITICALv2
SEVEREv3
IMPORTANT (default)v4
NORMALv5
DETAILEDv6
FULL
[out] | lp | lp to set the options for |
[in] | argc | number of arguments |
[in] | argv | array of arguments |
true | if options are set | |
false | otherwise |
References freset_bas, Lp::module, Solver_module::preport, Report::print(), timeout, trace, verbosity, wm_all, wm_ask, wm_none, and write_mps.
Referenced by get_func_pointers().
bool Sm_lps5_5::solve_dual_perturbed | ( | const VECTOR & | d_c, | |
Lp * | lp, | |||
const int | iteration | |||
) | [static] |
Compute solution of dual perturbed lp.
Perturb the lp and solve the new one. Read the dual solution from lp_solve and store it in lp->iy
and lp->iz
. Save the perturbed lp as lpnamel-lbii.mps
according to the setting of write_mps. Substitute the name of the lp for lpname
and iteration
for ii
.
[in] | d_c | deflation parameter |
[out] | lp | receives the solver status and the dual solution |
[in] | iteration | number of the current iteration |
true | if solve_lp returns true and the solution is read | |
false | otherwise, solve_lp or read_duals returns false |
Reimplemented from Solver_module.
References dual_perturb(), Lp::feasibility, Lp::module, Lp::name, Solver_module::preport, Report::print(), read_duals(), solve_lp(), ss_feasible, and write_lp().
Referenced by get_func_pointers().
bool Sm_lps5_5::solve_lp | ( | Lp * | lp | ) | [static, private] |
Solve lp with lp_solve.
Solve an lp with lp_solve. Store lp_solve's status in lp->feasibility
.
[out] | lp | receives lp_solve's status |
true | if lp_solve returns a known status code (i.e., OPTIMAL, INFEASIBLE, UNBOUNDED, TIMEOUT, NUMFAILURE, DEGENERATE, or SUBOPTIMAL) | |
false | otherwise |
References Lp::feasibility, freset_bas, Lp::module, Solver_module::preport, Report::print(), ss_failure, ss_feasible, ss_infeasible, ss_timeout, and ss_unbounded.
Referenced by solve_dual_perturbed(), solve_original(), and solve_primal_perturbed().
bool Sm_lps5_5::solve_original | ( | Lp * | lp, | |
double & | optimal_value | |||
) | [static] |
Compute solution of unperturbed lp.
Solve the original unperturbed lp with lp_solve and read the primal and dual solution.
[out] | lp | receives the solver status and the solution |
[out] | optimal_value | receives the optimal value |
true | if solve_lp returns true and the solution is read | |
false | otherwise, solve_lp , read_primals , or read_duals returns false |
Reimplemented from Solver_module.
References Lp::module, Solver_module::preport, Report::print(), read_duals(), read_primals(), and solve_lp().
Referenced by get_func_pointers().
bool Sm_lps5_5::solve_primal_perturbed | ( | const Primal_deflation & | d, | |
Lp * | lp, | |||
const int | iteration | |||
) | [static] |
Compute solution of primal perturbed lp.
Perturb the lp and solve the new one. Read the primal solution and store it in lp->ix
. Save the perturbed lp to lpname-ubii.mps
according to setting of write_mps. Substitute the name of the lp for lpname
and iteration
for ii
.
[in] | d | deflation parameters |
[out] | lp | receives the solver status and the primal solution |
[in] | iteration | number of the current iteration |
true | if solve_lp returns true and the solution is read | |
false | otherwise, solve_lp or read_primals returns false |
Reimplemented from Solver_module.
References Lp::feasibility, Lp::module, Lp::name, Solver_module::preport, primal_perturb(), Report::print(), read_primals(), solve_lp(), ss_feasible, and write_lp().
Referenced by get_func_pointers().
bool Sm_lps5_5::transform_lp | ( | Lp * | lp, | |
const double | relative_interval_radius, | |||
double & | eta | |||
) | [static, private] |
Transform lp from lp_solve to Lurupa.
Transform lp from the data structure of lp_solve 5.5 into the representation used in Lurupa. Adjust algorithm parameters eta
according to the lp, and inflate the lp to an interval valued one if relative_interval_radius
is greater than 0.
Write the (midpoint) problem with preport if Report::write_vm is set.
[out] | lp | receives the transformed data |
[in] | relative_interval_radius | relative interval radius to inflate lp parameters to |
[out] | eta | gets adjusted to the model |
true | if the transformation succeeds, | |
false | otherwise, lp->module->lp is not set or build_constraint_maps returns false |
References adjust_eta(), build_constraint_maps(), find_free_variables(), Lp::free_variables_size, Report::get_write_vm(), Lp::ia, Lp::IA, Lp::ib, Lp::IB, Lp::ic, inflate_lp(), Lp::module, Lp::name, Solver_module::preport, Report::print(), read_general_data(), read_lp_mat(), read_right_hand_sides(), read_simple_bounds(), resize_lp(), Report::write_matrix(), Report::write_vector(), Lp::xl, and Lp::xu.
long Sm_lps5_5::timeout = 0 [static, private] |
Timeout setting
Referenced by lp2solver(), and set_module_options().
MYBOOL Sm_lps5_5::trace = FALSE [static, private] |
trace setting
Referenced by lp2solver(), and set_module_options().
int Sm_lps5_5::verbosity = 3 [static, private] |
Verbosity setting
Referenced by lp2solver(), and set_module_options().