Main class for loading and solving problems. More...
#include <BlockIP.h>
Classes | |
struct | BackupLnk |
Public Member Functions | |
BlockIP () | |
Constructor. | |
BlockIP (TYPE_PROBLEM type_objective, double *&cost, double *&qcost, void(*fobj)(int n, double x[], double &fx, double Gx[], double Hx[], void *params), void *params, double *&ub, double *&rhs, int numBlocks, bool sameN, MatrixBlockIP N[], bool sameL, MatrixBlockIP L[]) | |
Create an instance with problem in standard form: 0 <= variables <= ub and constraints = rhs. | |
BlockIP (TYPE_PROBLEM type_objective, double *&cost, double *&qcost, void(*fobj)(int n, double x[], double &fx, double Gx[], double Hx[], void *params), void *params, double *&lb, double *&ub, double *&lhs, double *&rhs, int numBlocks, bool sameN, MatrixBlockIP N[], bool sameL, MatrixBlockIP L[]) | |
Create an instance with general problem: lb <= variables <= ub and lhs <= constraints <= rhs. | |
~BlockIP () | |
Destructor. | |
void | initialize () |
Initializes class attributes. | |
void | free_memory () |
Free all the memory. | |
void | create_problem (TYPE_PROBLEM type_objective, double *&cost, double *&qcost, void(*fobj)(int n, double x[], double &fx, double Gx[], double Hx[], void *params), void *params, double *&ub, double *&rhs, int numBlocks, bool sameN, MatrixBlockIP N[], bool sameL, MatrixBlockIP L[]) |
Create a problem in standard form: 0 <= variables <= ub and constraints = rhs. | |
void | create_problem (TYPE_PROBLEM type_objective, double *&cost, double *&qcost, void(*fobj)(int n, double x[], double &fx, double Gx[], double Hx[], void *params), void *params, double *&lb, double *&ub, double *&lhs, double *&rhs, int numBlocks, bool sameN, MatrixBlockIP N[], bool sameL, MatrixBlockIP L[]) |
Create a general problem: lb <= variables <= ub and lhs <= constraints <= rhs. | |
void | convert_to_standard () |
Convert any problem to standard form, restrictions= rhs, variables >= 0, <= ub. | |
void | check_input_problem_and_compute_dimensions () |
Check the input problem and compute dimensions. | |
void | check_sameN () |
Check if the problems satisfies the conditions when using sameN. | |
void | set_defaults_minimize () |
int | get_it () |
Return number of IP iterations of minimization. | |
int | get_cgit () |
Return number of overall PCG iterations. | |
double | get_fobj () |
Return objective function. | |
double | get_dobj () |
Return dual objective function. | |
void | set_inf (double inf=INF) |
Set threshold value to be used as infinity (x>inf -> x is inf) | |
double | get_inf () |
Get infinity value to be considered. | |
void | set_m_pw_prec (int m_pw_prec=M_PW_PREC) |
Set number of terms used as preconditioner of the power series expansion of (D-C'*B^{-1}*B)^{-1}. | |
int | get_m_pw_prec () |
Get number of terms used as preconditioner of the power series expansion of (D-C'*B^{-1}*B)^{-1}. | |
void | set_sigma (double sigma=SIGMA) |
Set reduction of the centrality parameter at each IP iteration. | |
double | get_sigma () |
Get reduction of the centrality parameter at each IP iteration. | |
void | set_rho (double rho=RHO) |
Set reduction of the step-length for the primal and dual variables at each IP iteration. | |
double | get_rho () |
Get reduction of the step-length for the primal and dual variables at each IP iteration. | |
void | set_optim_gap (double optim_gap=OPTIM_GAP) |
Set optimality gap tolerance. | |
double | get_optim_gap () |
Get optimality gap tolerance. | |
void | set_optim_pfeas (double optim_pfeas=OPTIM_PFEAS) |
Set primal feasibility tolerance. | |
double | get_optim_pfeas () |
Get primal feasibility tolerance. | |
void | set_optim_dfeas (double optim_dfeas=OPTIM_DFEAS) |
Set dual feasibility tolerance. | |
double | get_optim_dfeas () |
Get dual feasibility tolerance. | |
void | set_output_freq (int output_freq=OUTPUT_FREQ) |
Set output information lines will be printed each output_freq IP iterations. | |
int | get_output_freq () |
Get output information lines will be printed each output_freq IP iterations. | |
void | set_output (OUTPUT output=SCREEN) |
Set type of output. | |
OUTPUT | get_output () |
Get type of output. | |
void | set_maxiter (int maxiter=MAXITER) |
Set maximum number of IP iterations. | |
int | get_maxiter () |
Get maximum number of IP iterations. | |
void | set_init_pcgtol (double init_pcgtol) |
Set initial tolerance for the conjugate gradient (by default PCG_TOL_LIN if linear problem, PCG_TOL_QUAD if quadratic or -convex- nonlinear) | |
double | get_init_pcgtol () |
Get initial tolerance for the conjugate gradient (by default PCG_TOL_LIN if linear problem, PCG_TOL_QUAD if quadratic or -convex- nonlinear) | |
void | set_min_pcgtol (double min_pcgtol=MIN_PCGTOL) |
Set minimum tolerance for the conjugate gradient. | |
double | get_min_pcgtol () |
Get minimum tolerance for the conjugate gradient. | |
void | set_maxit_pcg (double maxit_pcg=0) |
Set maximum number of pcg iterations (if 0, then the value will be computed by the code) | |
double | get_maxit_pcg () |
Get maximum number of pcg iterations (if 0, then the value will be computed by the code) | |
void | set_red_pcgtol (double red_pcgtol=RED_PCGTOL) |
Set reduction of pcg_tol at each IP iteration. | |
double | get_red_pcgtol () |
Get reduction of pcg_tol at each IP iteration. | |
void | set_show_specrad (bool show_specrad=false) |
Set show_specrad at each IP iteration. | |
bool | get_show_specrad () |
Get show_specrad. | |
void | set_type_comp_dy (TYPE_COMP_DY type_comp_dy=TYPE_COMP_DY_DEFAULT) |
Set how dy direction is computed. | |
TYPE_COMP_DY | get_type_comp_dy () |
Get how dy direction is computed. | |
void | set_type_direction (TYPE_DIRECTION type_direction=TYPE_DIRECTION_DEFAULT) |
Set which direction is computed. | |
TYPE_DIRECTION | get_type_direction () |
Get which direction is computed. | |
void | set_type_start_point (TYPE_START_POINT type_start_point=TYPE_START_POINT_DEFAULT) |
Set how starting point is computed. | |
TYPE_START_POINT | get_type_start_point () |
Get how starting point is computed. | |
void | set_type_reg (TYPE_REG type_reg=TYPE_REG_DEFAULT) |
Set type of regularization. | |
TYPE_REG | get_type_reg () |
Get type of regularization. | |
void | set_factor_reg (double factor_reg=FACTOR_REG_DEFAULT) |
Set factor of regularization. | |
double | get_factor_reg () |
Get factor of regularization. | |
void | set_deactivateLnk (bool deactivateLnk=DEACTIVATELNK) |
Set flag on deactivation of linking. | |
bool | get_deactivateLnk () |
Get flag on deactivation of linking. | |
int | get_k_blocks () |
Get the number of blocks. | |
int | get_km () |
Get the number of constraints without linking constraints. | |
int | get_kn () |
Get the number of variables without linking constraints. | |
int | get_l_link () |
Get the number of linking constraints. | |
int | get_n_vars () |
Get the number of variables of the problem to be optimized. | |
int | get_m_cons () |
Get the number of constraints of the problem to be optimized. | |
int | get_num_vars () |
Get the number of variables of the original problem. | |
int | get_num_cons () |
Get the number of constraints of the original problem. | |
void | set_whoperm (WHO_PERMUTES whoperm_=CHOLESKY) |
Set whopermutes constraints-related information: the Cholesky factorization of the user of it. | |
WHO_PERMUTES | get_whoperm () |
Get whopermutes constraints-related information: the Cholesky factorization of the user of it. | |
const double * | get_x () |
Get primal variables of problem optimized. | |
const double * | get_y () |
Get dual variables of problem optimized (of equality constraints) | |
const double * | get_z () |
Get dual variable of problem optimized (of x>=0) i=1..n_vars. | |
const double * | get_w () |
Get dual variable of problem optimized (of x<=u) i=1..n_vars. | |
double | get_x (int i) |
Get value of primal variable x(i) of problem optimized i=1..n_vars. | |
double | get_y (int i) |
Get value of dual variable y(i) of problem optimized (of equality constraints) i=1..m_cons. | |
double | get_z (int i) |
Get value of dual variable z(i) (of x>=0) of problem optimized i=1..n_vars. | |
double | get_w (int i) |
Get value of dual variable w(i) (of x<=u) of problem optimized i=1..n_vars. | |
int | min_PCG_Hv (int nn, double *v, double *Hv) |
int | min_PCG_Hz_eq_r (int nn, double *zz, double *rr) |
int | min_PCG_Theta0z_eq_r (int nn, double *zz, double *rr) |
void | set_constant_fobj (double constant) |
Set the constant to add to the objective function. | |
double | get_constant_fobj () |
Get the constant to add to the objective function. | |
void | set_names (string *blockNames, string *varNames, string *consNames, bool copy_vectors=true) |
Set the names of the problem TODO change copy_vectors. | |
void | get_names (const string *&blockNames, const string *&varNames, const string *&consNames) |
Get the names of the problem. | |
void | convert_to_std_and_write_mps (const char *filename) |
Convert the problem to standard form (if it is not already converted) and write a mps file. | |
void | write_mps (const char *filename) |
Write a mps file. | |
void | write_mps (const char *filename, TYPE_PROBLEM type_objective, double cost[], double qcost[], double lb[], double ub[], double lhs[], double rhs[], int numBlocks, bool sameN, MatrixBlockIP N[], bool sameL, MatrixBlockIP L[], string *blockNames=NULL, string *varNames=NULL, string *consNames=NULL, double constantFObj=0) |
Write a mps file. | |
void | read_mps (const char *filename) |
Create a problem from a mps file. | |
void | write_BlockIP_format (const char *filename) |
Write the problem in BlockIP format file. | |
void | read_BlockIP_format (const char *filename) |
Create a problem from a BlockIP format file. | |
void | write_problem (const char *filename) |
Write all data related to the problem into a file. | |
StdForm * | get_std_form (bool keepStdFormAfterDelete=false) |
Get the StdForm related to the problem. | |
void | create_names () |
Create names for blocks, variables and constraints if does not exist. | |
Public Attributes | |
int | k_blocks |
Number of diagonal blocks. | |
int | km |
Number of constraints without linking constraints. | |
int | kn |
Number of variables without slacks of linking. | |
int | m_cons |
Number of constraints including linking constraints. | |
int | n_vars |
Number of variables including slacks. | |
int | l_link |
Number of linking constraints. | |
int * | ini_n |
Begin to blocks 1..k and linking for variables. | |
int * | ini_m |
Begin to blocks 1..k and linking for constraints. | |
double * | cost |
Linear cost of variables including slacks. | |
double * | qcost |
Quadratic cost of variables including slacks. | |
double * | lb |
Lower bounds, including slack bounds. | |
double * | ub |
Upper bounds, including slack bounds. | |
double * | lhs |
Lower constraint limits, including linking constraints limits. | |
double * | rhs |
Upper constraint limits, including linking constraints limits. | |
bool | sameN |
Define if the same matrix is used for each N block. | |
bool | sameL |
Define if the same matrix is used for each L block. | |
MatrixBlockIP * | N |
Diagonal blocks. | |
MatrixBlockIP * | L |
Linking constraints blocks. | |
MatrixBlockIP * | A |
Full matrix (likely made from N and L) | |
MatrixBlockIP * | D |
D = Theta_(k+1) + sum{i..k} L_i*Theta_i*L_i'. | |
MatrixBlockIP * | Theta0 |
void(* | fobj )(int n, double x[], double &fx, double Gx[], double Hx[], void *params) |
User function to calculate the objective function in a point. | |
void * | params |
User parameters to perform objective function calculations. | |
double * | Hx |
Objective function value, Gradient and Hessian in the actual point. | |
double | dobj |
dual objective | |
bool | inStdForm |
To control if the problem is in standard form. | |
string * | blockNames |
Block names of N blocks. | |
string * | varNames |
Variable names including slacks. | |
string * | consNames |
Constraint names including linking constraints. | |
TYPE_PROBLEM | type_objective |
Type of objective function, linear, quadratic or non-linear. | |
StdForm * | stdForm |
Contains all the information to perform conversions between the original and standard problem. | |
double | constantFObj |
Constant to add in the objective function. | |
int * | origNVars |
Number of original variables for each block. | |
int * | origNCons |
Number of original constraints for each block. | |
Private Attributes | |
bool | initialized |
To control if the attributes have been initialized. | |
bool | keepStdFormAfterDelete |
To keep stdForm when BlockIP will delete. | |
bool | deleteMatrices |
To delete matrices when created by BlockIP (read_mps) | |
WHO_PERMUTES | whoperm |
double | inf |
Infinity value. | |
double | optim_gap |
Optimality gap tolerance. | |
double | optim_pfeas |
Primal feasibility tolerance. | |
double | optim_dfeas |
Dual feasibility tolerance. | |
int | maxiter |
Maximum number of IP iterations. | |
int | output_freq |
Output information lines will be printed each output_freq IP iterations. | |
OUTPUT | output |
Type of output. | |
double | epsmach |
Stores computed machine epsilon. | |
double | init_pcgtol |
Initial tolerance for the conjugate gradient (by default PCG_TOL_LIN if linear problem, PCG_TOL_QUAD if quadratic or -convex- nonlinear) | |
double | pcgtol |
Tolerance for conjugate gradient at current iteration. | |
double | min_pcgtol |
Minimum tolerance for the conjugate gradient. | |
double | maxit_pcg |
Maximum number of pcg iterations (if 0, then the value will be computed by the code) | |
double | red_pcgtol |
Reduction of pcg_tol at each IP iteration. | |
int | m_pw_prec |
Number of terms of the power series expansion of (D-C'*B^{-1}*B)^{-1} used as preconditioner. | |
int | totcgit |
Overall number of CG iterations. | |
int | cgit |
number of CG iterations of this IPM iteration | |
int | it |
IPM iterations. | |
double | est_specrad |
Estimation of spectral radius of D^{-1}C'*B^{-1}*B (computed through Ritz values) | |
bool | comp_specrad |
Whether the estimation of spectral radius has to be shown in the output. | |
TYPE_COMP_DY | type_comp_dy |
Whether the estimation of spectral radius has to be computed. | |
TYPE_DIRECTION | type_direction |
Type of direction (Newton, second order...) given by user. | |
TYPE_DIRECTION | this_type_direction |
Type of direction (Newton or second order) of this particular iteration. | |
TYPE_REG | type_reg |
How starting point will be computed. | |
double | factor_reg |
Type of regularization performed. | |
double * | x |
initial value for regularization | |
double * | s |
primal and dual optimization variables | |
double * | rsw |
residuals of KKT conditions | |
double * | dsdw |
for rhs of corrector system, from dx,dw,ds and dw of predictor direction | |
double | normrc |
norms of rhs, costs, rb, and rc | |
double | alpha_d |
step lengths | |
double | rho |
Reduction of the step-length for the primal and dual variables at each IP iteration. | |
double * | dw |
Primal and dual optimization directions. | |
double | gap |
Duality gap. | |
double | mu0 |
Centrality parameter; mu0 is value of mu at starting point. | |
double | sigma |
Reduction of the centrality parameter at each IP iteration. | |
double | psi |
Reduction of dx*dz vector in the rhs of corrector system (in predictor-corrector) | |
double * | Theta |
Theta diagonal matrix. | |
double * | Cvaux2 |
Auxiliary vectors for interior-point algorithm. | |
double * | p_cg |
Auxiliary vectors for PCG. | |
double | qreg |
Regularization term. | |
bool | deactivateLnk |
Vectors to store information from PCG to later compute Ritz values. | |
int | numActiveLnk |
Number of active lnk. | |
int | numInactiveLnk |
Number of inactive lnk. | |
int | numInactiveLnkWithUb |
Number of inactive lnk with upper bound. | |
bool * | isActiveLnk |
linking i is active if isActiveLnk[i] is true | |
int * | listActiveLnk |
list of active linking, j=listActiveLnk[i], i=1..numActiveLnk, j in {1,..,l_link}) | |
int * | listInactiveLnk |
list of inactive linking, j=listInactiveLnk[i], i=1..numInactiveLnk, j in {1,..,l_link}) | |
int | numFreeVars |
Number of variables marked as free. | |
int | numUnfreeVars |
Number of variables not marked as free. | |
bool * | isFreeVar |
Variable i is marked as free if isFreeVar[i] is true. | |
int * | listFreeVars |
List of variables marked as free, j=listFreeVars[i], i=1..numFreeVars, j in {1,..,n_vars}) | |
int * | listUnfreeVars |
List of variables not marked as free, j=listUnfreeVars[i], i=1..numUnfreeVars, j in {1,..,n_vars}) | |
int | numWithUb |
Number of variables with upper bound (not infinity) | |
Main class for loading and solving problems.
BlockIP::BlockIP | ( | TYPE_PROBLEM | type_objective, |
double *& | cost, | ||
double *& | qcost, | ||
void(*)(int n, double x[], double &fx, double Gx[], double Hx[], void *params) | fobj, | ||
void * | params, | ||
double *& | ub, | ||
double *& | rhs, | ||
int | numBlocks, | ||
bool | sameN, | ||
MatrixBlockIP | N[], | ||
bool | sameL, | ||
MatrixBlockIP | L[] | ||
) |
Create an instance with problem in standard form: 0 <= variables <= ub and constraints = rhs.
type_objective | Type of objective function, linear, quadratic or non-linear |
cost | Linear cost of variables including slacks |
qcost | Quadratic cost of variables including slacks |
fobj | User function to calculate the objective function in a point. If it is is not NULL, cost and qcost must be NULL |
params | User parameters to perform objective function calculations. Only can be used when fobj is not NULL |
ub | Upper bounds, including slack bounds |
rhs | Upper constraint limits, including linking constraints limits |
numBlocks | Number of diagonal blocks |
sameN | Define if the same matrix is used for each N block. If true array N must have dimension 1 |
N | Diagonal blocks |
sameL | Define if the same matrix is used for each L block If true array L must have dimension 1 |
L | Linking constraints blocks |
BlockIP::BlockIP | ( | TYPE_PROBLEM | type_objective, |
double *& | cost, | ||
double *& | qcost, | ||
void(*)(int n, double x[], double &fx, double Gx[], double Hx[], void *params) | fobj, | ||
void * | params, | ||
double *& | lb, | ||
double *& | ub, | ||
double *& | lhs, | ||
double *& | rhs, | ||
int | numBlocks, | ||
bool | sameN, | ||
MatrixBlockIP | N[], | ||
bool | sameL, | ||
MatrixBlockIP | L[] | ||
) |
Create an instance with general problem: lb <= variables <= ub and lhs <= constraints <= rhs.
type_objective | Type of objective function, linear, quadratic or non-linear |
cost | Linear cost of variables including slacks |
qcost | Quadratic cost of variables including slacks |
fobj | User function to calculate the objective function in a point. If it is is not NULL, cost and qcost must be NULL |
params | User parameters to perform objective function calculations. Only can be used when fobj is not NULL |
lb | Lower bounds, including slack bounds |
ub | Upper bounds, including slack bounds |
lhs | Lower constraint limits, including linking constraints limits |
rhs | Upper constraint limits, including linking constraints limits |
numBlocks | Number of diagonal blocks |
sameN | Define if the same matrix is used for each N block. If true array N must have dimension 1 |
N | Diagonal blocks |
sameL | Define if the same matrix is used for each L block If true array L must have dimension 1 |
L | Linking constraints blocks |
void BlockIP::convert_to_std_and_write_mps | ( | const char * | filename | ) |
Convert the problem to standard form (if it is not already converted) and write a mps file.
filename | File name without extension |
void BlockIP::create_problem | ( | TYPE_PROBLEM | type_objective, |
double *& | cost, | ||
double *& | qcost, | ||
void(*)(int n, double x[], double &fx, double Gx[], double Hx[], void *params) | fobj, | ||
void * | params, | ||
double *& | ub, | ||
double *& | rhs, | ||
int | numBlocks, | ||
bool | sameN, | ||
MatrixBlockIP | N[], | ||
bool | sameL, | ||
MatrixBlockIP | L[] | ||
) |
Create a problem in standard form: 0 <= variables <= ub and constraints = rhs.
type_objective | Type of objective function, linear, quadratic or non-linear |
cost | Linear cost of variables including slacks |
qcost | Quadratic cost of variables including slacks |
fobj | User function to calculate the objective function in a point. If it is is not NULL, cost and qcost must be NULL |
params | User parameters to perform objective function calculations. Only can be used when fobj is not NULL |
ub | Upper bounds, including slack bounds |
rhs | Upper constraint limits, including linking constraints limits |
numBlocks | Number of diagonal blocks |
sameN | Define if the same matrix is used for each N block. If true array N must have dimension 1 |
N | Diagonal blocks |
sameL | Define if the same matrix is used for each L block If true array L must have dimension 1 |
L | Linking constraints blocks ! |
void BlockIP::create_problem | ( | TYPE_PROBLEM | type_objective, |
double *& | cost, | ||
double *& | qcost, | ||
void(*)(int n, double x[], double &fx, double Gx[], double Hx[], void *params) | fobj, | ||
void * | params, | ||
double *& | lb, | ||
double *& | ub, | ||
double *& | lhs, | ||
double *& | rhs, | ||
int | numBlocks, | ||
bool | sameN, | ||
MatrixBlockIP | N[], | ||
bool | sameL, | ||
MatrixBlockIP | L[] | ||
) |
Create a general problem: lb <= variables <= ub and lhs <= constraints <= rhs.
type_objective | Type of objective function, linear, quadratic or non-linear |
cost | Linear cost of variables including slacks |
qcost | Quadratic cost of variables including slacks |
fobj | User function to calculate the objective function in a point. If it is is not NULL, cost and qcost must be NULL |
params | User parameters to perform objective function calculations. Only can be used when fobj is not NULL |
lb | Lower bounds, including slack bounds |
ub | Upper bounds, including slack bounds |
lhs | Lower constraint limits, including linking constraints limits |
rhs | Upper constraint limits, including linking constraints limits |
numBlocks | Number of diagonal blocks |
sameN | Define if the same matrix is used for each N block. If true array N must have dimension 1 |
N | Diagonal blocks |
sameL | Define if the same matrix is used for each L block If true array L must have dimension 1 |
L | Linking constraints blocks |
|
inline |
Get the number of blocks.
|
inline |
Get the number of constraints without linking constraints.
|
inline |
Get the number of variables without linking constraints.
|
inline |
Get the number of linking constraints.
|
inline |
Get the number of constraints of the problem to be optimized.
|
inline |
Get the number of variables of the problem to be optimized.
void BlockIP::get_names | ( | const string *& | blockNames, |
const string *& | varNames, | ||
const string *& | consNames | ||
) |
Get the names of the problem.
blockNames | Block names of N blocks, dimension k_blocks |
varNames | Variable names including slacks, dimension n_vars |
consNames | Constraint names including linking constraints, dimension m_cons |
|
inline |
Get the number of constraints of the original problem.
|
inline |
Get the number of variables of the original problem.
|
inline |
|
private |
Computes and returns A'*y A is the constraints matrix, formed by k diagonal blocks N and last rows with k L matrices plus the Identity for slacks. Computes Ni'*yi + Li'*y_{k+1} for all block i=1..k; and I*y_{k+1} for last block k+1.
y[1:km+l],: | dual variables. Values of duals y_{k+1} of inactive linking constraints must be 0. |
Aty[kn+l],: | result of A'*y. Only values of duals y_{k+1} of active linking constraints are added (equivalently, the components of y_{k+1} of inactives are 0). |
|
private |
Computes and returns A*x A is the constraints matrix, formed by k diagonal blocks N and last rows with k L matrices plus the Identity for slacks. Computes Ni*xi for all block i=1..k; and sum{1..k}Li*xi + x_{k+1}, for the active constraints
x[1:kn+l],: | primal variables |
Ax[km+l],: | result of A*x. Only values of active linking onstraints are filled |
|
private |
For debugging purposes, checks direction satisfies Newton system
| -H A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |rxz| | -W S | |dw| |rsw|
If QUAD_REG then it considers H:= H+qreg for block variables
|
private |
For debugging purposes, checks predictor-corrector direction satisfies system
| -H A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |sigma*mu-XZe-Dx_p Dz_p e| | -W S | |dw| |sigma*mu-SWe-Ds_p Dw_p e|
If QUAD_REG then it considers H:= H+qreg for block variables
|
private |
For debugging purposes, checks predictor direction satisfies system
| -H A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |-XZe| | -W S | |dw| |-SWe|
If QUAD_REG then it considers H:= H+qreg for block variables
|
private |
Decides whether to use standard Newton direction or second order direction (Mehrotra direction).
|
private |
Solves (A*Theta*A')dy = rhsdy by Cholesky for blocks and PCG for linking constraints. The structure of (A*Theta*A') dy = rhsdy is
| B C | |dy1| |rhsdy1| | C' D | |dy2| = |rhsdy2|
so it can be solved as
(D-C'*B^{-1}*C) dy2 = rhsdy2-C'*B^{-1}*rhsdy1 B dy1= rhsdy1-C*dy2
where B is made of k_blocks N_i*Theta_i*N_i'.
Note that system (A*Theta*A') is really of dimension km+numActiveLnk, then we need to implicitly consider only the active linking constraints when applying the PCG.
dy[1:km+l],: | on input is the last dy solution computed, to be used as starting solution fof PCG; on output is the solution of (A*Theta*A)dy= rhsdy |
rhsdy[1:km+l],: | right-hand-side of PCG system. |
only_solve,: | if true, only numeric solve (neither symbolic nor numeric factorization are needed) since a previous call with the same A*Theta*A' but different rhsdy was made (for instance, in corrector step of predictor-corrector heuristic) |
|
private |
Solves (A*Theta*A')dy = rhsdy by Cholesky of full system. Note that system (A*Theta*A') is really of dimension km+numActiveLnk, but we reuse the initial symbolic factorization, where the dimension of the system was km+l_link. Instead of using a row of the identity matrix for the rows of inactive constraints to avoid a nonsingular system, we consider a 0, since Cholesky deals with 0 pivots (semidefinie matrices). This way, the values of dy are correctly computed.
dy[1:km+l],: | on output is the solution of (A*Theta*A)dy= rhsdy |
rhsdy[1:km+l],: | on input right-hand-side of (A*Theta*A)dy= rhsdy |
only_solve,: | if true, only numeric solve (neither symbolic nor numeric factorization are needed) since a previous call with the same A*Theta*A' but different rhsdy was made (for instance, in corrector step of predictor-corrector heuristic) |
|
private |
Computes and returns the centrality at current point, computed as mu= (x'z+s'w)/( (kn+number_of_active_linking) + (number of variables with upper bounds)). For efficiency of the implementation, w and s of variables without upper bound are 0 and a finite (large number)
|
private |
Computes the slacks of upper bounds of block variables and slacks of linking constraints: s= u-x. Only slacks of upper bounds of slacks of active linking constraints filled (for inactive linking, s is 0). If some u=inf, then s=u-x~=inf which is OK for deactivating the complementarity constraints s*w=sigma*mu. There is no need in setting s=inf for vars in listWithoutUb since s=u-x will be very close (if not equal) to inf. This also applies to (non-splitted) free vars, whose upper bound is also inf.
|
private |
Computes sigma (reduction of the centrality parameter at each IP iteration) and psi (reduction of dx*dz vector in the rhs of corrector system of predictor-corrector heuristic)
|
private |
Given v[1:km], this routine computes C'*v= sum{i in 1..k} L_i*Theta_i*N_i'*v_i, which is a vector of dimension l_link. The result vector Ctv only contains values of active linking, components of inactive constraints are 0.
v[1:km],: | input vector |
Ctv[1:l_link],: | output vector containing C'*v |
|
private |
Given v[l], this routine computes C*v= [N_i*Theta_i*L_i'*v i=1..k], C*v is a vector [1:km]. Product L_i'*v for all components is made assuming that inactive components of v or inactive rows of L are 0 (otherwise, there is a bug in the code and the function will provide wrong results...)
v[1:l_link],: | input vector |
Cv[1:km],: | output vector containing C*v |
|
private |
For debugging purposes, check variables and data of inactive slacks and constraints are 0
|
private |
For debugging purposes, check variables and data of variables without upper bounds are 0
|
private |
For debugging purposes, write variables to file
|
private |
Deletes arrays locally needed for the interior-point algorithm
|
private |
Compute the residuals of mu-KKT equations Ax=b (primal feasibility) A'*y+z-w-Gx=0 (dual feasibility) XZe= sigma*mu*e (complementarity x*z) SWe= sigma*mu*e (complementarity s*w)
The residuals are:
Residuals rxz and rsw only needed if NEWTON direction is used. SECOND ORDER direction do not need rxz and rsw (predictor-corrector will compute later their own right-hand-sides for the complementarity equations).
|
private |
Computes the standard Newton direction by solving normal equations A*Theta*A' according to type_comp_dy:
The procedure:
For the primal convex nonlinear problem
(P) min f(x) subject to Ax=b, -x<=0, x-u<=0
the Lagrangian is
L(x,y,z,w)= f(x)+y'*(b-Ax)+z'*(-x)+w'*(x-u)
and the gradient respect to x is (Gx is gradient of f(x); Gx=c if f(x) is linear, Gx= Qx+c if f(x) is quadratic):
L(x,y,z,w)= Gx - A'*y - z + w
and the dual problem is
(D) min L(x,y,z,w) s. to L(x,y,z,w)=0 w>=0, z>=0
The condition L(x,y,z,w)=0 is the dual feasibility below.
The mu-KKT conditions are (Gx is gradienf of f(x)):
A'*y+z-w-Gx=0 (dual feasibility) Ax=b (primal feasibility) XZe= sigma*mu*e (complementarity x*z) SWe= sigma*mu*e (complementarity s*w)
The Newton system is (S= U-X, and Hx is Hessian of f(x))
| -Hx A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |rxz| | -W S | |dw| |rsw|
which is solved by:
Theta= (Hx + S^{-1}*W + X^{-1}*Z)^{-1}
r= rc + S^{-1}*rsw - X^{-1}*rxz (A*Theta*A')dy= rb+A*Theta*r dx= Theta*(A'dy-r) dw= S^{-1}(rsw + W*dx) dz= rc + dw + Hx*dx - A'*dy
If QUAD_REG regularization is applied then Gx is (Gx+Qreg*x) and Hx is (Hx+Qreg). rc and Theta were previosuly computed considering (Gx+Qreg*x) and (Hx+Qreg). Here we have to use (Hx+Qreg) too.
|
private |
Compute the L2 norm of b[] and c[]. For the linking constraints, only the active are considered.
int BlockIP::min_PCG_Hv | ( | int | nn, |
double * | v, | ||
double * | Hv | ||
) |
Computes Hv=(D-C'*B^(-1)*C)v Returns vector Hv of dimension l_link, assuming components of inactives are 0 (if there is no error in the code). Then we avoid using (packing and unpacking) a vector of dimension numActiveLnk.
v[1:l_link],: | input vector |
Hv[1:l_link],: | output vector containing H*v |
int BlockIP::min_PCG_Hz_eq_r | ( | int | nn, |
double * | zz, | ||
double * | rr | ||
) |
Approximate solution of H*zz = rr, using m_pw_prec terms of the power series expansion H^{-1}= [sum{i=0..infinity} (D^{-1}*(C'B^{-1}B)C)^i]*D^{-1} Recommended values are m_pw_prec= 1 or 2, to avoid expensive computations We use vectors of dimension l_link, assuming components of inactives are 0 (if there is no error in the code). Then we avoid using (packing and unpacking) a vector of dimension numActiveLnk.
rr[1:l_link],: | rhs of system of equations |
zz[1:l_link],: | solution of the system |
int BlockIP::min_PCG_Theta0z_eq_r | ( | int | nn, |
double * | zz, | ||
double * | rr | ||
) |
Solves Theta0*zz = rr, where Theta0 are the components of Theta associated to active linking constraints. This preconditioner may be useful when the space of linking constraints is "close" (principal angles not large) to the space of block constraints. We use vectors of dimension l_link, assuming components of inactives are 0 (if there is no error in the code). Then we avoid using (packing and unpacking) a vector of dimension numActiveLnk.
rr[1:l_link],: | rhs of system of equations |
zz[1:l_link],: | solution of the system |
|
private |
Simple check for
|
private |
Computes the second order predictor-corrector Mehrotra direction by solving normal equations A*Theta*A' according to type_comp_dy:
The procedure:
For the primal convex nonlinear problem
(P) min f(x) subject to Ax=b, -x<=0, x-u<=0
the Lagrangian is
L(x,y,z,w)= f(x)+y'*(b-Ax)+z'*(-x)+w'*(x-u)
and the gradient respect to x is (Gx is gradient of f(x); Gx=c if f(x) is linear, Gx= Qx+c if f(x) is quadratic):
L(x,y,z,w)= Gx - A'*y - z + w
and the dual problem is
(D) min L(x,y,z,w) s. to L(x,y,z,w)=0 w>=0, z>=0
The condition L(x,y,z,w)=0 is the dual feasibility below.
The mu-KKT conditions are (Gx is gradienf of f(x)):
A'*y+z-w-Gx=0 (dual feasibility) Ax=b (primal feasibility) XZe= sigma*mu*e (complementarity x*z) SWe= sigma*mu*e (complementarity s*w)
The predictor-corrector direction is computed as (S= U-X, and Hx is Hessian of f(x)):
| -Hx A' I -I | |dx_p| |rc | | A | |dy_p| = |rb | | Z X | |dz_p| |-XZe| | -W S | |dw_p| |-SWe|
| -Hx A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |sigma*mu-XZe-Dx_p Dz_p e| | -W S | |dw| |sigma*mu-SWe-Ds_p Dw_p e|
Each of the above Newton-like systems are solved as:
| -Hx A' I -I | |dx| |rc | | A | |dy| = |rb | | Z X | |dz| |rhs_xz| | -W S | |dw| |rhs_sw|
Theta= (Hx + S^{-1}*W + X^{-1}*Z)^{-1}
r= rc + S^{-1}*rhs_sw - X^{-1}*rhs_xz (A*Theta*A')dy= rb+A*Theta*r dx= Theta*(A'dy-r) dw= S^{-1}(rhs_sw + W*dx) dz= rc + dw + Hx*dx - A'*dy
If QUAD_REG regularization is applied then Gx is (Gx+Qreg*x) and Hx is (Hx+Qreg). rc and Theta were previosuly computed considering (Gx+Qreg*x) and (Hx+Qreg). Here we have to use (Hx+Qreg) too.
|
private |
Solves k_blocks systems N_i*Theta_i*N_i' dy_i= rhsdy_i i=1..k_blocks where N_i can be different matrices or the same one (if sameN).
v[1:km],: | on input contains the righ-hand-side for the k_blocks systems |
v[1:km],: | on output it contain the solutions to the k_blocks systems |
|
private |
Computation of starting point:
|
private |
Detect if new linking constraints must be considered inactive This is only done if we are close enough to the optimal solution; we use (gap < 1.0), where gap was computed before as abs(pobj-dobj)/(1+abs(pobj)). This only works for linear/quadr. functions, but for nonlinear ones this update is not used (see below an explanation). Constraint i inactived if its slack x(i) is out of bounds and lagrange multiplier is close to 0: (x(i)>>0 and x(i)<<u(i) and y(i)~0) and ( c(i)==0 and q(i)==0). The term (c(i)==0 and q(i)==0) guarantees that slacks appearing in the objective function are not removed. This could even work for nonlinear functions: if component of gradient and Hessian of slack is 0, the slack could be removed (**** be careful: this can provide strange results if for some reason the first and second derivatives are 0 only in that iteration; for safety, the inactivation is not performed for nonlinear objective functions ***) We also avoid inactivation of constraints with small bounds on slacks (i.e, u<0.1), since these constraints are always quasi-active
|
private |
Updates regularization term
void BlockIP::read_BlockIP_format | ( | const char * | filename | ) |
Create a problem from a BlockIP format file.
filename | File name with extension |
void BlockIP::read_mps | ( | const char * | filename | ) |
Create a problem from a mps file.
filename | File name with extension |
void BlockIP::set_defaults_minimize | ( | ) |
Set to default values all the parameters that control the interior-point algorithm
void BlockIP::set_names | ( | string * | blockNames, |
string * | varNames, | ||
string * | consNames, | ||
bool | copy_vectors = true |
||
) |
Set the names of the problem TODO change copy_vectors.
blockNames | Block names of N blocks |
varNames | Variable names including slacks |
consNames | Constraint names including linking constraints |
copy_vectors | If is true the user must free the memory of arguments (arrays), If false the user must allocate the memory with new, after this call the user will not have control of the arguments (arrays) anymore and MatrixBlockIP will delete the arguments |
void BlockIP::write_BlockIP_format | ( | const char * | filename | ) |
Write the problem in BlockIP format file.
filename | File name without extension |
void BlockIP::write_mps | ( | const char * | filename, |
TYPE_PROBLEM | type_objective, | ||
double | cost[], | ||
double | qcost[], | ||
double | lb[], | ||
double | ub[], | ||
double | lhs[], | ||
double | rhs[], | ||
int | numBlocks, | ||
bool | sameN, | ||
MatrixBlockIP | N[], | ||
bool | sameL, | ||
MatrixBlockIP | L[], | ||
string * | blockNames = NULL , |
||
string * | varNames = NULL , |
||
string * | consNames = NULL , |
||
double | constantFObj = 0 |
||
) |
Write a mps file.
filename | File name without extension |
type_objective | Type of objective function, linear or quadratic |
cost | Linear cost of variables including slacks |
qcost | Quadratic cost of variables including slacks |
lb | Lower bounds, including slack bounds |
ub | Upper bounds, including slack bounds |
lhs | Lower constraint limits, including linking constraints limits |
rhs | Upper constraint limits, including linking constraints limits |
numBlocks | Number of diagonal blocks |
sameN | Define if the same matrix is used for each N block. If true array N must have dimension 1 |
N | Diagonal blocks |
sameL | Define if the same matrix is used for each L block If true array L must have dimension 1 |
L | Linking constraints blocks |
blockNames | Block names of N blocks |
varNames | Variable names including slacks |
consNames | Constraint names including linking constraints |
void BlockIP::write_problem | ( | const char * | filename | ) |
Write all data related to the problem into a file.
filename | File name where output the data |
|
private |
Vectors to store information from PCG to later compute Ritz values.
Setting deactivateLnk= false the user may avoid the deactivation of linking
|
private |
Infinity value.
For the default values see the constant terms in BlockIP.h
MatrixBlockIP* BlockIP::Theta0 |
Stores Theta0 preconditioner (Theta_(k+1)) of active linking constraints)
|
private |
Whether the estimation of spectral radius has to be computed.
How dy direction is computed
|
private |
for matrix factorizations