alpar@1: %* glpk02.tex *% alpar@1: alpar@1: \chapter{Basic API Routines} alpar@1: alpar@1: This chapter describes GLPK API routines intended for using in alpar@1: application programs. alpar@1: alpar@1: \subsubsection*{Library header} alpar@1: alpar@1: All GLPK API data types and routines are defined in the header file alpar@1: \verb|glpk.h|. It should be included in all source files which use alpar@1: GLPK API, either directly or indirectly through some other header file alpar@1: as follows: alpar@1: alpar@1: \begin{verbatim} alpar@1: #include alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Error handling} alpar@1: alpar@1: If some GLPK API routine detects erroneous or incorrect data passed by alpar@1: the application program, it writes appropriate diagnostic messages to alpar@1: the terminal and then abnormally terminates the application program. alpar@1: In most practical cases this allows to simplify programming by avoiding alpar@1: numerous checks of return codes. Thus, in order to prevent crashing the alpar@1: application program should check all data, which are suspected to be alpar@1: incorrect, before calling GLPK API routines. alpar@1: alpar@1: Should note that this kind of error handling is used only in cases of alpar@1: incorrect data passed by the application program. If, for example, the alpar@1: application program calls some GLPK API routine to read data from an alpar@1: input file and these data are incorrect, the GLPK API routine reports alpar@1: about error in the usual way by means of the return code. alpar@1: alpar@1: \subsubsection*{Thread safety} alpar@1: alpar@1: Currently GLPK API routines are non-reentrant and therefore cannot be alpar@1: used in multi-threaded programs. alpar@1: alpar@1: \subsubsection*{Array indexing} alpar@1: alpar@1: Normally all GLPK API routines start array indexing from 1, not from 0 alpar@1: (except the specially stipulated cases). This means, for example, that alpar@1: if some vector $x$ of the length $n$ is passed as an array to some GLPK alpar@1: API routine, the latter expects vector components to be placed in alpar@1: locations \verb|x[1]|, \verb|x[2]|, \dots, \verb|x[n]|, and the location alpar@1: \verb|x[0]| normally is not used. alpar@1: alpar@1: In order to avoid indexing errors it is most convenient and most alpar@1: reliable to declare the array \verb|x| as follows: alpar@1: alpar@1: \begin{verbatim} alpar@1: double x[1+n]; alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: or to allocate it as follows: alpar@1: alpar@1: \begin{verbatim} alpar@1: double *x; alpar@1: . . . alpar@1: x = calloc(1+n, sizeof(double)); alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: In both cases one extra location \verb|x[0]| is reserved that allows alpar@1: passing the array to GLPK routines in a usual way. alpar@1: alpar@1: \section{Problem object} alpar@1: alpar@1: All GLPK API routines deal with so called {\it problem object}, which alpar@1: is a program object of type \verb|glp_prob| and intended to represent alpar@1: a particular LP or MIP instance. alpar@1: alpar@1: The type \verb|glp_prob| is a data structure declared in the header alpar@1: file \verb|glpk.h| as follows: alpar@1: alpar@1: \begin{verbatim} alpar@1: typedef struct { ... } glp_prob; alpar@1: \end{verbatim} alpar@1: alpar@1: Problem objects (i.e. program objects of the \verb|glp_prob| type) are alpar@1: allocated and managed internally by the GLPK API routines. The alpar@1: application program should never use any members of the \verb|glp_prob| alpar@1: structure directly and should deal only with pointers to these objects alpar@1: (that is, \verb|glp_prob *| values). alpar@1: alpar@1: \pagebreak alpar@1: alpar@1: The problem object consists of five segments, which are: alpar@1: alpar@1: $\bullet$ problem segment, alpar@1: alpar@1: $\bullet$ basis segment, alpar@1: alpar@1: $\bullet$ interior point segment, alpar@1: alpar@1: $\bullet$ MIP segment, and alpar@1: alpar@1: $\bullet$ control parameters and statistics segment. alpar@1: alpar@1: \subsubsection*{Problem segment} alpar@1: alpar@1: The {\it problem segment} contains original LP/MIP data, which alpar@1: corresponds to the problem formulation (1.1)---(1.3) (see Section alpar@1: \ref{seclp}, page \pageref{seclp}). It includes the following alpar@1: components: alpar@1: alpar@1: $\bullet$ rows (auxiliary variables), alpar@1: alpar@1: $\bullet$ columns (structural variables), alpar@1: alpar@1: $\bullet$ objective function, and alpar@1: alpar@1: $\bullet$ constraint matrix. alpar@1: alpar@1: Rows and columns have the same set of the following attributes: alpar@1: alpar@1: $\bullet$ ordinal number, alpar@1: alpar@1: $\bullet$ symbolic name (1 up to 255 arbitrary graphic characters), alpar@1: alpar@1: $\bullet$ type (free, lower bound, upper bound, double bound, fixed), alpar@1: alpar@1: $\bullet$ numerical values of lower and upper bounds, alpar@1: alpar@1: $\bullet$ scale factor. alpar@1: alpar@1: {\it Ordinal numbers} are intended for referencing rows and columns. alpar@1: Row ordinal numbers are integers $1, 2, \dots, m$, and column ordinal alpar@1: numbers are integers $1, 2, \dots, n$, where $m$ and $n$ are, alpar@1: respectively, the current number of rows and columns in the problem alpar@1: object. alpar@1: alpar@1: {\it Symbolic names} are intended for informational purposes. They also alpar@1: can be used for referencing rows and columns. alpar@1: alpar@1: {\it Types and bounds} of rows (auxiliary variables) and columns alpar@1: (structural variables) are explained above (see Section \ref{seclp}, alpar@1: page \pageref{seclp}). alpar@1: alpar@1: {\it Scale factors} are used internally for scaling rows and columns of alpar@1: the constraint matrix. alpar@1: alpar@1: Information about the {\it objective function} includes numerical alpar@1: values of objective coefficients and a flag, which defines the alpar@1: optimization direction (i.e. minimization or maximization). alpar@1: alpar@1: The {\it constraint matrix} is a $m \times n$ rectangular matrix built alpar@1: of constraint coefficients $a_{ij}$, which defines the system of linear alpar@1: constraints (1.2) (see Section \ref{seclp}, page \pageref{seclp}). This alpar@1: matrix is stored in the problem object in both row-wise and column-wise alpar@1: sparse formats. alpar@1: alpar@1: Once the problem object has been created, the application program can alpar@1: access and modify any components of the problem segment in arbitrary alpar@1: order. alpar@1: alpar@1: \subsubsection*{Basis segment} alpar@1: alpar@1: The {\it basis segment} of the problem object keeps information related alpar@1: to the current basic solution. It includes: alpar@1: alpar@1: $\bullet$ row and column statuses, alpar@1: alpar@1: $\bullet$ basic solution statuses, alpar@1: alpar@1: $\bullet$ factorization of the current basis matrix, and alpar@1: alpar@1: $\bullet$ basic solution components. alpar@1: alpar@1: The {\it row and column statuses} define which rows and columns are alpar@1: basic and which are non-basic. These statuses may be assigned either by alpar@1: the application program of by some API routines. Note that these alpar@1: statuses are always defined independently on whether the corresponding alpar@1: basis is valid or not. alpar@1: alpar@1: The {\it basic solution statuses} include the {\it primal status} and alpar@1: the {\it dual status}, which are set by the simplex-based solver once alpar@1: the problem has been solved. The primal status shows whether a primal alpar@1: basic solution is feasible, infeasible, or undefined. The dual status alpar@1: shows the same for a dual basic solution. alpar@1: alpar@1: The {\it factorization of the basis matrix} is some factorized form alpar@1: (like LU-factorization) of the current basis matrix (defined by the alpar@1: current row and column statuses). The factorization is used by the alpar@1: simplex-based solver and kept when the solver terminates the search. alpar@1: This feature allows efficiently reoptimizing the problem after some alpar@1: modifications (for example, after changing some bounds or objective alpar@1: coefficients). It also allows performing the post-optimal analysis (for alpar@1: example, computing components of the simplex table, etc.). alpar@1: alpar@1: The {\it basic solution components} include primal and dual values of alpar@1: all auxiliary and structural variables for the most recently obtained alpar@1: basic solution. alpar@1: alpar@1: \subsubsection*{Interior point segment} alpar@1: alpar@1: The {\it interior point segment} is automatically allocated after the alpar@1: problem has been solved using the interior point solver. It contains alpar@1: interior point solution components, which include the solution status, alpar@1: and primal and dual values of all auxiliary and structural variables. alpar@1: alpar@1: \subsubsection*{MIP segment} alpar@1: alpar@1: The {\it MIP segment} is used only for MIP problems. This segment alpar@1: includes: alpar@1: alpar@1: $\bullet$ column kinds, alpar@1: alpar@1: $\bullet$ MIP solution status, and alpar@1: alpar@1: $\bullet$ MIP solution components. alpar@1: alpar@1: The {\it column kinds} define which columns (i.e. structural variables) alpar@1: are integer and which are continuous. alpar@1: alpar@1: The {\it MIP solution status} is set by the MIP solver and shows whether alpar@1: a MIP solution is integer optimal, integer feasible (non-optimal), or alpar@1: undefined. alpar@1: alpar@1: The {\it MIP solution components} are computed by the MIP solver and alpar@1: include primal values of all auxiliary and structural variables for the alpar@1: most recently obtained MIP solution. alpar@1: alpar@1: Note that in case of MIP problem the basis segment corresponds to alpar@1: the optimal solution of LP relaxation, which is also available to the alpar@1: application program. alpar@1: alpar@1: Currently the search tree is not kept in the MIP segment. Therefore if alpar@1: the search has been terminated, it cannot be continued. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Problem creating and modifying routines} alpar@1: alpar@1: \subsection{glp\_create\_prob---create problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: glp_prob *glp_create_prob(void); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_create_prob| creates a new problem object, which alpar@1: initially is ``empty'', i.e. has no rows and columns. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine returns a pointer to the created object, which should be alpar@1: used in any subsequent operations on this object. alpar@1: alpar@1: \subsection{glp\_set\_prob\_name---assign (change) problem name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_prob_name(glp_prob *lp, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_prob_name| assigns a given symbolic alpar@1: \verb|name| (1 up to 255 characters) to the specified problem object. alpar@1: alpar@1: If the parameter \verb|name| is \verb|NULL| or empty string, the routine alpar@1: erases an existing symbolic name of the problem object. alpar@1: alpar@1: \subsection{glp\_set\_obj\_name---assign (change) objective function alpar@1: name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_obj_name(glp_prob *lp, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_obj_name| assigns a given symbolic alpar@1: \verb|name| (1 up to 255 characters) to the objective function of the alpar@1: specified problem object. alpar@1: alpar@1: If the parameter \verb|name| is \verb|NULL| or empty string, the routine alpar@1: erases an existing symbolic name of the objective function. alpar@1: alpar@1: \subsection{glp\_set\_obj\_dir---set (change) optimization direction\\ alpar@1: flag} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_obj_dir(glp_prob *lp, int dir); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_obj_dir| sets (changes) the optimization alpar@1: direction flag (i.e. ``sense'' of the objective function) as specified alpar@1: by the parameter \verb|dir|: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_MIN| & minimization; \\ alpar@1: \verb|GLP_MAX| & maximization. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \noindent alpar@1: (Note that by default the problem is minimization.) alpar@1: alpar@1: \subsection{glp\_add\_rows---add new rows to problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_add_rows(glp_prob *lp, int nrs); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_add_rows| adds \verb|nrs| rows (constraints) to alpar@1: the specified problem object. New rows are always added to the end of alpar@1: the row list, so the ordinal numbers of existing rows are not changed. alpar@1: alpar@1: Being added each new row is initially free (unbounded) and has empty alpar@1: list of the constraint coefficients. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_add_rows| returns the ordinal number of the first alpar@1: new row added to the problem object. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_add\_cols---add new columns to problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_add_cols(glp_prob *lp, int ncs); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_add_cols| adds \verb|ncs| columns (structural alpar@1: variables) to the specified problem object. New columns are always added alpar@1: to the end of the column list, so the ordinal numbers of existing alpar@1: columns are not changed. alpar@1: alpar@1: Being added each new column is initially fixed at zero and has empty alpar@1: list of the constraint coefficients. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_add_cols| returns the ordinal number of the first alpar@1: new column added to the problem object. alpar@1: alpar@1: \subsection{glp\_set\_row\_name---assign (change) row name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_row_name(glp_prob *lp, int i, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_row_name| assigns a given symbolic alpar@1: \verb|name| (1 up to 255 characters) to \verb|i|-th row (auxiliary alpar@1: variable) of the specified problem object. alpar@1: alpar@1: If the parameter \verb|name| is \verb|NULL| or empty string, the routine alpar@1: erases an existing name of $i$-th row. alpar@1: alpar@1: \subsection{glp\_set\_col\_name---assign (change) column name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_col_name(glp_prob *lp, int j, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_col_name| assigns a given symbolic alpar@1: \verb|name| (1 up to 255 characters) to \verb|j|-th column (structural alpar@1: variable) of the specified problem object. alpar@1: alpar@1: If the parameter \verb|name| is \verb|NULL| or empty string, the routine alpar@1: erases an existing name of $j$-th column. alpar@1: alpar@1: \subsection{glp\_set\_row\_bnds---set (change) row bounds} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_row_bnds(glp_prob *lp, int i, int type, alpar@1: double lb, double ub); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_row_bnds| sets (changes) the type and bounds alpar@1: of \verb|i|-th row (auxiliary variable) of the specified problem object. alpar@1: alpar@1: The parameters \verb|type|, \verb|lb|, and \verb|ub| specify the type, alpar@1: lower bound, and upper bound, respectively, as follows: alpar@1: alpar@1: \begin{center} alpar@1: \begin{tabular}{cr@{}c@{}ll} alpar@1: Type & \multicolumn{3}{c}{Bounds} & Comment \\ alpar@1: \hline alpar@1: \verb|GLP_FR| & $-\infty <$ &$\ x\ $& $< +\infty$ alpar@1: & Free (unbounded) variable \\ alpar@1: \verb|GLP_LO| & $lb \leq$ &$\ x\ $& $< +\infty$ alpar@1: & Variable with lower bound \\ alpar@1: \verb|GLP_UP| & $-\infty <$ &$\ x\ $& $\leq ub$ alpar@1: & Variable with upper bound \\ alpar@1: \verb|GLP_DB| & $lb \leq$ &$\ x\ $& $\leq ub$ alpar@1: & Double-bounded variable \\ alpar@1: \verb|GLP_FX| & $lb =$ &$\ x\ $& $= ub$ alpar@1: & Fixed variable \\ alpar@1: \end{tabular} alpar@1: \end{center} alpar@1: alpar@1: \noindent alpar@1: where $x$ is the auxiliary variable associated with $i$-th row. alpar@1: alpar@1: If the row has no lower bound, the parameter \verb|lb| is ignored. If alpar@1: the row has no upper bound, the parameter \verb|ub| is ignored. If the alpar@1: row is an equality constraint (i.e. the corresponding auxiliary variable alpar@1: is of fixed type), only the parameter \verb|lb| is used while the alpar@1: parameter \verb|ub| is ignored. alpar@1: alpar@1: Being added to the problem object each row is initially free, i.e. its alpar@1: type is \verb|GLP_FR|. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_set\_col\_bnds---set (change) column bounds} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_col_bnds(glp_prob *lp, int j, int type, alpar@1: double lb, double ub); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_col_bnds| sets (changes) the type and bounds alpar@1: of \verb|j|-th column (structural variable) of the specified problem alpar@1: object. alpar@1: alpar@1: The parameters \verb|type|, \verb|lb|, and \verb|ub| specify the type, alpar@1: lower bound, and upper bound, respectively, as follows: alpar@1: alpar@1: \begin{center} alpar@1: \begin{tabular}{cr@{}c@{}ll} alpar@1: Type & \multicolumn{3}{c}{Bounds} & Comment \\ alpar@1: \hline alpar@1: \verb|GLP_FR| & $-\infty <$ &$\ x\ $& $< +\infty$ alpar@1: & Free (unbounded) variable \\ alpar@1: \verb|GLP_LO| & $lb \leq$ &$\ x\ $& $< +\infty$ alpar@1: & Variable with lower bound \\ alpar@1: \verb|GLP_UP| & $-\infty <$ &$\ x\ $& $\leq ub$ alpar@1: & Variable with upper bound \\ alpar@1: \verb|GLP_DB| & $lb \leq$ &$\ x\ $& $\leq ub$ alpar@1: & Double-bounded variable \\ alpar@1: \verb|GLP_FX| & $lb =$ &$\ x\ $& $= ub$ alpar@1: & Fixed variable \\ alpar@1: \end{tabular} alpar@1: \end{center} alpar@1: alpar@1: \noindent alpar@1: where $x$ is the structural variable associated with $j$-th column. alpar@1: alpar@1: If the column has no lower bound, the parameter \verb|lb| is ignored. alpar@1: If the column has no upper bound, the parameter \verb|ub| is ignored. alpar@1: If the column is of fixed type, only the parameter \verb|lb| is used alpar@1: while the parameter \verb|ub| is ignored. alpar@1: alpar@1: Being added to the problem object each column is initially fixed at alpar@1: zero, i.e. its type is \verb|GLP_FX| and both bounds are 0. alpar@1: alpar@1: \subsection{glp\_set\_obj\_coef---set (change) objective coefficient alpar@1: or constant term} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_obj_coef(glp_prob *lp, int j, double coef); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_obj_coef| sets (changes) the objective alpar@1: coefficient at \verb|j|-th column (structural variable). A new value of alpar@1: the objective coefficient is specified by the parameter \verb|coef|. alpar@1: alpar@1: If the parameter \verb|j| is 0, the routine sets (changes) the constant alpar@1: term (``shift'') of the objective function. alpar@1: alpar@1: \subsection{glp\_set\_mat\_row---set (replace) row of the constraint alpar@1: matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_mat_row(glp_prob *lp, int i, int len, alpar@1: const int ind[], const double val[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_mat_row| stores (replaces) the contents of alpar@1: \verb|i|-th row of the constraint matrix of the specified problem alpar@1: object. alpar@1: alpar@1: Column indices and numerical values of new row elements must be placed alpar@1: in locations \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|, alpar@1: \dots, \verb|val[len]|, respectively, where $0 \leq$ \verb|len| $\leq n$ alpar@1: is the new length of $i$-th row, $n$ is the current number of columns in alpar@1: the problem object. Elements with identical column indices are not alpar@1: allowed. Zero elements are allowed, but they are not stored in the alpar@1: constraint matrix. alpar@1: alpar@1: If the parameter \verb|len| is 0, the parameters \verb|ind| and/or alpar@1: \verb|val| can be specified as \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_set\_mat\_col---set (replace) column of the alpar@1: constr\-aint matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_mat_col(glp_prob *lp, int j, int len, alpar@1: const int ind[], const double val[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_mat_col| stores (replaces) the contents of alpar@1: \verb|j|-th column of the constraint matrix of the specified problem alpar@1: object. alpar@1: alpar@1: Row indices and numerical values of new column elements must be placed alpar@1: in locations \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|, alpar@1: \dots, \verb|val[len]|, respectively, where $0 \leq$ \verb|len| $\leq m$ alpar@1: is the new length of $j$-th column, $m$ is the current number of rows in alpar@1: the problem object. Elements with identical row indices are not allowed. alpar@1: Zero elements are allowed, but they are not stored in the constraint alpar@1: matrix. alpar@1: alpar@1: If the parameter \verb|len| is 0, the parameters \verb|ind| and/or alpar@1: \verb|val| can be specified as \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_load\_matrix---load (replace) the whole constraint alpar@1: matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_load_matrix(glp_prob *lp, int ne, const int ia[], alpar@1: const int ja[], const double ar[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_load_matrix| loads the constraint matrix passed alpar@1: in the arrays \verb|ia|, \verb|ja|, and \verb|ar| into the specified alpar@1: problem object. Before loading the current contents of the constraint alpar@1: matrix is destroyed. alpar@1: alpar@1: Constraint coefficients (elements of the constraint matrix) must be alpar@1: specified as triplets (\verb|ia[k]|, \verb|ja[k]|, \verb|ar[k]|) for alpar@1: $k=1,\dots,ne$, where \verb|ia[k]| is the row index, \verb|ja[k]| is alpar@1: the column index, and \verb|ar[k]| is a numeric value of corresponding alpar@1: constraint coefficient. The parameter \verb|ne| specifies the total alpar@1: number of (non-zero) elements in the matrix to be loaded. Coefficients alpar@1: with identical indices are not allowed. Zero coefficients are allowed, alpar@1: however, they are not stored in the constraint matrix. alpar@1: alpar@1: If the parameter \verb|ne| is 0, the parameters \verb|ia|, \verb|ja|, alpar@1: and/or \verb|ar| can be specified as \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_check\_dup---check for duplicate elements in sparse alpar@1: matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_check_dup(int m, int n, int ne, const int ia[], alpar@1: const int ja[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_check_dup checks| for duplicate elements (that alpar@1: is, elements with identical indices) in a sparse matrix specified in alpar@1: the coordinate format. alpar@1: alpar@1: The parameters $m$ and $n$ specifies, respectively, the number of rows alpar@1: and columns in the matrix, $m\geq 0$, $n\geq 0$. alpar@1: alpar@1: The parameter {\it ne} specifies the number of (structurally) non-zero alpar@1: elements in the matrix, {\it ne} $\geq 0$. alpar@1: alpar@1: Elements of the matrix are specified as doublets $(ia[k],ja[k])$ for alpar@1: $k=1,\dots,ne$, where $ia[k]$ is a row index, $ja[k]$ is a column index. alpar@1: alpar@1: The routine \verb|glp_check_dup| can be used prior to a call to the alpar@1: routine \verb|glp_load_matrix| to check that the constraint matrix to alpar@1: be loaded has no duplicate elements. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_check_dup| returns one of the following values: alpar@1: alpar@1: \noindent alpar@1: \begin{tabular}{@{}r@{\ }c@{\ }l@{}} alpar@1: 0&---&the matrix has no duplicate elements;\\ alpar@1: $-k$&---&indices $ia[k]$ or/and $ja[k]$ are out of range;\\ alpar@1: $+k$&---&element $(ia[k],ja[k])$ is duplicate.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_sort\_matrix---sort elements of the constraint matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_sort_matrix(glp_prob *P); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_sort_matrix| sorts elements of the constraint alpar@1: matrix rebuilding its row and column linked lists. On exit from the alpar@1: routine the constraint matrix is not changed, however, elements in the alpar@1: row linked lists become ordered by ascending column indices, and the alpar@1: elements in the column linked lists become ordered by ascending row alpar@1: indices. alpar@1: alpar@1: \subsection{glp\_del\_rows---delete rows from problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_del_rows(glp_prob *lp, int nrs, const int num[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_del_rows| deletes rows from the specified problem alpar@1: ob-\linebreak ject. Ordinal numbers of rows to be deleted should be alpar@1: placed in locations \verb|num[1]|, \dots, \verb|num[nrs]|, where alpar@1: ${\tt nrs}>0$. alpar@1: alpar@1: Note that deleting rows involves changing ordinal numbers of other alpar@1: rows remaining in the problem object. New ordinal numbers of the alpar@1: remaining rows are assigned under the assumption that the original alpar@1: order of rows is not changed. Let, for example, before deletion there alpar@1: be five rows $a$, $b$, $c$, $d$, $e$ with ordinal numbers 1, 2, 3, 4, 5, alpar@1: and let rows $b$ and $d$ have been deleted. Then after deletion the alpar@1: remaining rows $a$, $c$, $e$ are assigned new oridinal numbers 1, 2, 3. alpar@1: alpar@1: \subsection{glp\_del\_cols---delete columns from problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_del_cols(glp_prob *lp, int ncs, const int num[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_del_cols| deletes columns from the specified alpar@1: problem object. Ordinal numbers of columns to be deleted should be alpar@1: placed in locations \verb|num[1]|, \dots, \verb|num[ncs]|, where alpar@1: ${\tt ncs}>0$. alpar@1: alpar@1: Note that deleting columns involves changing ordinal numbers of other alpar@1: columns remaining in the problem object. New ordinal numbers of the alpar@1: remaining columns are assigned under the assumption that the original alpar@1: order of columns is not changed. Let, for example, before deletion there alpar@1: be six columns $p$, $q$, $r$, $s$, $t$, $u$ with ordinal numbers 1, 2, alpar@1: 3, 4, 5, 6, and let columns $p$, $q$, $s$ have been deleted. Then after alpar@1: deletion the remaining columns $r$, $t$, $u$ are assigned new ordinal alpar@1: numbers 1, 2, 3. alpar@1: alpar@1: \subsection{glp\_copy\_prob---copy problem object content} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_copy_prob(glp_prob *dest, glp_prob *prob, int names); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_copy_prob| copies the content of the problem alpar@1: object \verb|prob| to the problem object \verb|dest|. alpar@1: alpar@1: The parameter \verb|names| is a flag. If it is \verb|GLP_ON|, alpar@1: the routine also copies all symbolic names; otherwise, if it is alpar@1: \verb|GLP_OFF|, no symbolic names are copied. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_erase\_prob---erase problem object content} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_erase_prob(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_erase_prob| erases the content of the specified alpar@1: problem object. The effect of this operation is the same as if the alpar@1: problem object would be deleted with the routine \verb|glp_delete_prob| alpar@1: and then created anew with the routine \verb|glp_create_prob|, with the alpar@1: only exception that the handle (pointer) to the problem object remains alpar@1: valid. alpar@1: alpar@1: \subsection{glp\_delete\_prob---delete problem object} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_delete_prob(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_delete_prob| deletes a problem object, which the alpar@1: parameter \verb|lp| points to, freeing all the memory allocated to this alpar@1: object. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Problem retrieving routines} alpar@1: alpar@1: \subsection{glp\_get\_prob\_name---retrieve problem name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: const char *glp_get_prob_name(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_prob_name| returns a pointer to an internal alpar@1: buffer, which contains symbolic name of the problem. However, if the alpar@1: problem has no assigned name, the routine returns \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_get\_obj\_name---retrieve objective function name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: const char *glp_get_obj_name(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_obj_name| returns a pointer to an internal alpar@1: buffer, which contains symbolic name assigned to the objective alpar@1: function. However, if the objective function has no assigned name, the alpar@1: routine returns \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_get\_obj\_dir---retrieve optimization direction flag} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_obj_dir(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_obj_dir| returns the optimization direction alpar@1: flag (i.e. ``sense'' of the objective function): alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_MIN| & minimization; \\ alpar@1: \verb|GLP_MAX| & maximization. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \pagebreak alpar@1: alpar@1: \subsection{glp\_get\_num\_rows---retrieve number of rows} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_num_rows(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_num_rows| returns the current number of rows alpar@1: in the specified problem object. alpar@1: alpar@1: \subsection{glp\_get\_num\_cols---retrieve number of columns} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_num_cols(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_num_cols| returns the current number of alpar@1: columns the specified problem object. alpar@1: alpar@1: \subsection{glp\_get\_row\_name---retrieve row name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: const char *glp_get_row_name(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_name| returns a pointer to an internal alpar@1: buffer, which contains a symbolic name assigned to \verb|i|-th row. alpar@1: However, if the row has no assigned name, the routine returns alpar@1: \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_get\_col\_name---retrieve column name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: const char *glp_get_col_name(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_name| returns a pointer to an internal alpar@1: buffer, which contains a symbolic name assigned to \verb|j|-th column. alpar@1: However, if the column has no assigned name, the routine returns alpar@1: \verb|NULL|. alpar@1: alpar@1: \subsection{glp\_get\_row\_type---retrieve row type} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_row_type(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_type| returns the type of \verb|i|-th alpar@1: row, i.e. the type of corresponding auxiliary variable, as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_FR| & free (unbounded) variable; \\ alpar@1: \verb|GLP_LO| & variable with lower bound; \\ alpar@1: \verb|GLP_UP| & variable with upper bound; \\ alpar@1: \verb|GLP_DB| & double-bounded variable; \\ alpar@1: \verb|GLP_FX| & fixed variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_row\_lb---retrieve row lower bound} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_row_lb(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_lb| returns the lower bound of alpar@1: \verb|i|-th row, i.e. the lower bound of corresponding auxiliary alpar@1: variable. However, if the row has no lower bound, the routine returns alpar@1: \verb|-DBL_MAX|. alpar@1: alpar@1: \subsection{glp\_get\_row\_ub---retrieve row upper bound} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_row_ub(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_ub| returns the upper bound of alpar@1: \verb|i|-th row, i.e. the upper bound of corresponding auxiliary alpar@1: variable. However, if the row has no upper bound, the routine returns alpar@1: \verb|+DBL_MAX|. alpar@1: alpar@1: \subsection{glp\_get\_col\_type---retrieve column type} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_col_type(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_type| returns the type of \verb|j|-th alpar@1: column, i.e. the type of corresponding structural variable, as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_FR| & free (unbounded) variable; \\ alpar@1: \verb|GLP_LO| & variable with lower bound; \\ alpar@1: \verb|GLP_UP| & variable with upper bound; \\ alpar@1: \verb|GLP_DB| & double-bounded variable; \\ alpar@1: \verb|GLP_FX| & fixed variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_col\_lb---retrieve column lower bound} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_col_lb(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_lb| returns the lower bound of alpar@1: \verb|j|-th column, i.e. the lower bound of corresponding structural alpar@1: variable. However, if the column has no lower bound, the routine returns alpar@1: \verb|-DBL_MAX|. alpar@1: alpar@1: \subsection{glp\_get\_col\_ub---retrieve column upper bound} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_col_ub(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_ub| returns the upper bound of alpar@1: \verb|j|-th column, i.e. the upper bound of corresponding structural alpar@1: variable. However, if the column has no upper bound, the routine returns alpar@1: \verb|+DBL_MAX|. alpar@1: alpar@1: \subsection{glp\_get\_obj\_coef---retrieve objective coefficient or\\ alpar@1: constant term} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_obj_coef(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_obj_coef| returns the objective coefficient alpar@1: at \verb|j|-th structural variable (column). alpar@1: alpar@1: If the parameter \verb|j| is 0, the routine returns the constant term alpar@1: (``shift'') of the objective function. alpar@1: alpar@1: \subsection{glp\_get\_num\_nz---retrieve number of constraint alpar@1: coefficients} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_num_nz(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_num_nz| returns the number of non-zero alpar@1: elements in the constraint matrix of the specified problem object. alpar@1: alpar@1: \subsection{glp\_get\_mat\_row---retrieve row of the constraint alpar@1: matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_mat_row(glp_prob *lp, int i, int ind[], alpar@1: double val[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_get_mat_row| scans (non-zero) elements of alpar@1: \verb|i|-th row of the constraint matrix of the specified problem object alpar@1: and stores their column indices and numeric values to locations alpar@1: \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|, \dots, alpar@1: \verb|val[len]|, respectively, where $0\leq{\tt len}\leq n$ is the alpar@1: number of elements in $i$-th row, $n$ is the number of columns. alpar@1: alpar@1: The parameter \verb|ind| and/or \verb|val| can be specified as alpar@1: \verb|NULL|, in which case corresponding information is not stored. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_mat_row| returns the length \verb|len|, i.e. alpar@1: the number of (non-zero) elements in \verb|i|-th row. alpar@1: alpar@1: \subsection{glp\_get\_mat\_col---retrieve column of the constraint\\ alpar@1: matrix} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_mat_col(glp_prob *lp, int j, int ind[], alpar@1: double val[]); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_get_mat_col| scans (non-zero) elements of alpar@1: \verb|j|-th column of the constraint matrix of the specified problem alpar@1: object and stores their row indices and numeric values to locations alpar@1: \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|, \dots, alpar@1: \verb|val[len]|, respectively, where $0\leq{\tt len}\leq m$ is the alpar@1: number of elements in $j$-th column, $m$ is the number of rows. alpar@1: alpar@1: The parameter \verb|ind| and/or \verb|val| can be specified as alpar@1: \verb|NULL|, in which case corresponding information is not stored. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_mat_col| returns the length \verb|len|, i.e. alpar@1: the number of (non-zero) elements in \verb|j|-th column. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Row and column searching routines} alpar@1: alpar@1: \subsection{glp\_create\_index---create the name index} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_create_index(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_create_index| creates the name index for the alpar@1: specified problem object. The name index is an auxiliary data structure, alpar@1: which is intended to quickly (i.e. for logarithmic time) find rows and alpar@1: columns by their names. alpar@1: alpar@1: This routine can be called at any time. If the name index already alpar@1: exists, the routine does nothing. alpar@1: alpar@1: \subsection{glp\_find\_row---find row by its name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_find_row(glp_prob *lp, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_find_row| returns the ordinal number of a row, alpar@1: which is assigned (by the routine \verb|glp_set_row_name|) the specified alpar@1: symbolic \verb|name|. If no such row exists, the routine returns 0. alpar@1: alpar@1: \subsection{glp\_find\_col---find column by its name} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_find_col(glp_prob *lp, const char *name); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_find_col| returns the ordinal number of a column, alpar@1: which is assigned (by the routine \verb|glp_set_col_name|) the specified alpar@1: symbolic \verb|name|. If no such column exists, the routine returns 0. alpar@1: alpar@1: \subsection{glp\_delete\_index---delete the name index} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_delete_index(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_delete_index| deletes the name index previously alpar@1: created by the routine \verb|glp_create_index| and frees the memory alpar@1: allocated to this auxiliary data structure. alpar@1: alpar@1: This routine can be called at any time. If the name index does not alpar@1: exist, the routine does nothing. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Problem scaling routines} alpar@1: alpar@1: \subsection{Background} alpar@1: alpar@1: In GLPK the {\it scaling} means a linear transformation applied to the alpar@1: constraint matrix to improve its numerical properties.\footnote{In many alpar@1: cases a proper scaling allows making the constraint matrix to be better alpar@1: conditioned, i.e. decreasing its condition number, that makes alpar@1: computations numerically more stable.} alpar@1: alpar@1: The main equality is the following: alpar@1: $$\widetilde{A}=RAS,\eqno(2.1)$$ alpar@1: where $A=(a_{ij})$ is the original constraint matrix, $R=(r_{ii})>0$ is alpar@1: a diagonal matrix used to scale rows (constraints), $S=(s_{jj})>0$ is a alpar@1: diagonal matrix used to scale columns (variables), $\widetilde{A}$ is alpar@1: the scaled constraint matrix. alpar@1: alpar@1: From (2.1) it follows that in the {\it scaled} problem instance each alpar@1: original constraint coefficient $a_{ij}$ is replaced by corresponding alpar@1: scaled constraint coefficient: alpar@1: $$\widetilde{a}_{ij}=r_{ii}a_{ij}s_{jj}.\eqno(2.2)$$ alpar@1: alpar@1: Note that the scaling is performed internally and therefore alpar@1: transparently to the user. This means that on API level the user always alpar@1: deal with unscaled data. alpar@1: alpar@1: Scale factors $r_{ii}$ and $s_{jj}$ can be set or changed at any time alpar@1: either directly by the application program in a problem specific way alpar@1: (with the routines \verb|glp_set_rii| and \verb|glp_set_sjj|), or by alpar@1: some API routines intended for automatic scaling. alpar@1: alpar@1: \subsection{glp\_set\_rii---set (change) row scale factor} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_rii(glp_prob *lp, int i, double rii); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_rii| sets (changes) the scale factor $r_{ii}$ alpar@1: for $i$-th row of the specified problem object. alpar@1: alpar@1: \subsection{glp\_set\_sjj---set (change) column scale factor} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_sjj(glp_prob *lp, int j, double sjj); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_sjj| sets (changes) the scale factor $s_{jj}$ alpar@1: for $j$-th column of the specified problem object. alpar@1: alpar@1: \subsection{glp\_get\_rii---retrieve row scale factor} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_rii(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_rii| returns current scale factor $r_{ii}$ for alpar@1: $i$-th row of the specified problem object. alpar@1: alpar@1: \subsection{glp\_get\_sjj---retrieve column scale factor} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_sjj(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_sjj| returns current scale factor $s_{jj}$ for alpar@1: $j$-th column of the specified problem object. alpar@1: alpar@1: \subsection{glp\_scale\_prob---scale problem data} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_scale_prob(glp_prob *lp, int flags); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_scale_prob| performs automatic scaling of problem alpar@1: data for the specified problem object. alpar@1: alpar@1: The parameter \verb|flags| specifies scaling options used by the alpar@1: routine. The options can be combined with the bitwise OR operator and alpar@1: may be the following: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_SF_GM| & perform geometric mean scaling;\\ alpar@1: \verb|GLP_SF_EQ| & perform equilibration scaling;\\ alpar@1: \verb|GLP_SF_2N| & round scale factors to nearest power of two;\\ alpar@1: \verb|GLP_SF_SKIP| & skip scaling, if the problem is well scaled.\\ alpar@1: \end{tabular} alpar@1: alpar@1: The parameter \verb|flags| may be specified as \verb|GLP_SF_AUTO|, in alpar@1: which case the routine chooses the scaling options automatically. alpar@1: alpar@1: \subsection{glp\_unscale\_prob---unscale problem data} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_unscale_prob(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: The routine \verb|glp_unscale_prob| performs unscaling of problem data alpar@1: for the specified problem object. alpar@1: alpar@1: ``Unscaling'' means replacing the current scaling matrices $R$ and $S$ alpar@1: by unity matrices that cancels the scaling effect. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{LP basis constructing routines} alpar@1: alpar@1: \subsection{Background} alpar@1: alpar@1: To start the search the simplex method needs a valid initial basis. In alpar@1: GLPK the basis is completely defined by a set of {\it statuses} assigned alpar@1: to {\it all} (auxiliary and structural) variables, where the status may alpar@1: be one of the following: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_BS| & basic variable;\\ alpar@1: \verb|GLP_NL| & non-basic variable having active lower bound;\\ alpar@1: \verb|GLP_NU| & non-basic variable having active upper bound;\\ alpar@1: \verb|GLP_NF| & non-basic free variable;\\ alpar@1: \verb|GLP_NS| & non-basic fixed variable.\\ alpar@1: \end{tabular} alpar@1: alpar@1: The basis is {\it valid}, if the basis matrix, which is a matrix built alpar@1: of columns of the augmented constraint matrix $(I\:|-A)$ corresponding alpar@1: to basic variables, is non-singular. This, in particular, means that alpar@1: the number of basic variables must be the same as the number of rows in alpar@1: the problem object. (For more details see Section \ref{lpbasis}, page alpar@1: \pageref{lpbasis}.) alpar@1: alpar@1: Any initial basis may be constructed (or restored) with the API alpar@1: routines \verb|glp_set_row_stat| and \verb|glp_set_col_stat| by alpar@1: assigning appropriate statuses to auxiliary and structural variables. alpar@1: Another way to construct an initial basis is to use API routines like alpar@1: \verb|glp_adv_basis|, which implement so called alpar@1: {\it crashing}.\footnote{This term is from early linear programming alpar@1: systems and means a heuristic to construct a valid initial basis.} Note alpar@1: that on normal exit the simplex solver remains the basis valid, so in alpar@1: case of reoptimization there is no need to construct an initial basis alpar@1: from scratch. alpar@1: alpar@1: \subsection{glp\_set\_row\_stat---set (change) row status} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_row_stat(glp_prob *lp, int i, int stat); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_row_stat| sets (changes) the current status alpar@1: of \verb|i|-th row (auxiliary variable) as specified by the parameter alpar@1: \verb|stat|: alpar@1: alpar@1: \begin{tabular}{@{}lp{104.2mm}@{}} alpar@1: \verb|GLP_BS| & make the row basic (make the constraint inactive); \\ alpar@1: \verb|GLP_NL| & make the row non-basic (make the constraint active); \\ alpar@1: \end{tabular} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{tabular}{@{}lp{104.2mm}@{}} alpar@1: \verb|GLP_NU| & make the row non-basic and set it to the upper bound; alpar@1: if the row is not double-bounded, this status is equivalent to alpar@1: \verb|GLP_NL| (only in the case of this routine); \\ alpar@1: \verb|GLP_NF| & the same as \verb|GLP_NL| (only in the case of this alpar@1: routine); \\ alpar@1: \verb|GLP_NS| & the same as \verb|GLP_NL| (only in the case of this alpar@1: routine). \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_set\_col\_stat---set (change) column status} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_col_stat(glp_prob *lp, int j, int stat); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_col_stat sets| (changes) the current status alpar@1: of \verb|j|-th column (structural variable) as specified by the alpar@1: parameter \verb|stat|: alpar@1: alpar@1: \begin{tabular}{@{}lp{104.2mm}@{}} alpar@1: \verb|GLP_BS| & make the column basic; \\ alpar@1: \verb|GLP_NL| & make the column non-basic; \\ alpar@1: \verb|GLP_NU| & make the column non-basic and set it to the upper alpar@1: bound; if the column is not double-bounded, this status is equivalent alpar@1: to \verb|GLP_NL| (only in the case of this routine); \\ alpar@1: \verb|GLP_NF| & the same as \verb|GLP_NL| (only in the case of this alpar@1: routine); \\ alpar@1: \verb|GLP_NS| & the same as \verb|GLP_NL| (only in the case of this alpar@1: routine). alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_std\_basis---construct standard initial LP basis} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_std_basis(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_std_basis| constructs the ``standard'' (trivial) alpar@1: initial LP basis for the specified problem object. alpar@1: alpar@1: In the ``standard'' LP basis all auxiliary variables (rows) are basic, alpar@1: and all structural variables (columns) are non-basic (so the alpar@1: corresponding basis matrix is unity). alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_adv\_basis---construct advanced initial LP basis} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_adv_basis(glp_prob *lp, int flags); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_adv_basis| constructs an advanced initial LP alpar@1: basis for the specified problem object. alpar@1: alpar@1: The parameter \verb|flags| is reserved for use in the future and must alpar@1: be specified as zero. alpar@1: alpar@1: In order to construct the advanced initial LP basis the routine does alpar@1: the following: alpar@1: alpar@1: 1) includes in the basis all non-fixed auxiliary variables; alpar@1: alpar@1: 2) includes in the basis as many non-fixed structural variables as alpar@1: possible keeping the triangular form of the basis matrix; alpar@1: alpar@1: 3) includes in the basis appropriate (fixed) auxiliary variables to alpar@1: complete the basis. alpar@1: alpar@1: As a result the initial LP basis has as few fixed variables as possible alpar@1: and the corresponding basis matrix is triangular. alpar@1: alpar@1: \subsection{glp\_cpx\_basis---construct Bixby's initial LP basis} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_cpx_basis(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_cpx_basis| constructs an initial basis for the alpar@1: specified problem object with the algorithm proposed by alpar@1: R.~Bixby.\footnote{Robert E. Bixby, ``Implementing the Simplex Method: alpar@1: The Initial Basis.'' ORSA Journal on Computing, Vol. 4, No. 3, 1992, alpar@1: pp. 267-84.} alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Simplex method routines} alpar@1: alpar@1: The {\it simplex method} is a well known efficient numerical procedure alpar@1: to solve LP problems. alpar@1: alpar@1: On each iteration the simplex method transforms the original system of alpar@1: equaility constraints (1.2) resolving them through different sets of alpar@1: variables to an equivalent system called {\it the simplex table} (or alpar@1: sometimes {\it the simplex tableau}), which has the following form: alpar@1: $$ alpar@1: \begin{array}{r@{\:}c@{\:}r@{\:}c@{\:}r@{\:}c@{\:}r} alpar@1: z&=&d_1(x_N)_1&+&d_2(x_N)_2&+ \dots +&d_n(x_N)_n \\ alpar@1: (x_B)_1&=&\xi_{11}(x_N)_1& +& \xi_{12}(x_N)_2& + \dots +& alpar@1: \xi_{1n}(x_N)_n \\ alpar@1: (x_B)_2&=& \xi_{21}(x_N)_1& +& \xi_{22}(x_N)_2& + \dots +& alpar@1: \xi_{2n}(x_N)_n \\ alpar@1: \multicolumn{7}{c} alpar@1: {.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .} \\ alpar@1: (x_B)_m&=&\xi_{m1}(x_N)_1& +& \xi_{m2}(x_N)_2& + \dots +& alpar@1: \xi_{mn}(x_N)_n \\ alpar@1: \end{array} \eqno (2.3) alpar@1: $$ alpar@1: where: $(x_B)_1, (x_B)_2, \dots, (x_B)_m$ are basic variables; alpar@1: $(x_N)_1, (x_N)_2, \dots, (x_N)_n$ are non-basic variables; alpar@1: $d_1, d_2, \dots, d_n$ are reduced costs; alpar@1: $\xi_{11}, \xi_{12}, \dots, \xi_{mn}$ are coefficients of the alpar@1: simplex table. (May note that the original LP problem (1.1)---(1.3) also alpar@1: has the form of a simplex table, where all equalities are resolved alpar@1: through auxiliary variables.) alpar@1: alpar@1: From the linear programming theory it is known that if an optimal alpar@1: solution of the LP problem (1.1)---(1.3) exists, it can always be alpar@1: written in the form (2.3), where non-basic variables are set on their alpar@1: bounds while values of the objective function and basic variables are alpar@1: determined by the corresponding equalities of the simplex table. alpar@1: alpar@1: A set of values of all basic and non-basic variables determined by the alpar@1: simplex table is called {\it basic solution}. If all basic variables are alpar@1: within their bounds, the basic solution is called {\it (primal) alpar@1: feasible}, otherwise it is called {\it (primal) infeasible}. A feasible alpar@1: basic solution, which provides a smallest (in case of minimization) or alpar@1: a largest (in case of maximization) value of the objective function is alpar@1: called {\it optimal}. Therefore, for solving LP problem the simplex alpar@1: method tries to find its optimal basic solution. alpar@1: alpar@1: Primal feasibility of some basic solution may be stated by simple alpar@1: checking if all basic variables are within their bounds. Basic solution alpar@1: is optimal if additionally the following optimality conditions are alpar@1: satisfied for all non-basic variables: alpar@1: \begin{center} alpar@1: \begin{tabular}{lcc} alpar@1: Status of $(x_N)_j$ & Minimization & Maximization \\ alpar@1: \hline alpar@1: $(x_N)_j$ is free & $d_j = 0$ & $d_j = 0$ \\ alpar@1: $(x_N)_j$ is on its lower bound & $d_j \geq 0$ & $d_j \leq 0$ \\ alpar@1: $(x_N)_j$ is on its upper bound & $d_j \leq 0$ & $d_j \geq 0$ \\ alpar@1: \end{tabular} alpar@1: \end{center} alpar@1: In other words, basic solution is optimal if there is no non-basic alpar@1: variable, which changing in the feasible direction (i.e. increasing if alpar@1: it is free or on its lower bound, or decreasing if it is free or on its alpar@1: upper bound) can improve (i.e. decrease in case of minimization or alpar@1: increase in case of maximization) the objective function. alpar@1: alpar@1: If all non-basic variables satisfy to the optimality conditions shown alpar@1: above (independently on whether basic variables are within their bounds alpar@1: or not), the basic solution is called {\it dual feasible}, otherwise it alpar@1: is called {\it dual infeasible}. alpar@1: alpar@1: It may happen that some LP problem has no primal feasible solution due alpar@1: to incorrect formulation---this means that its constraints conflict alpar@1: with each other. It also may happen that some LP problem has unbounded alpar@1: solution again due to incorrect formulation---this means that some alpar@1: non-basic variable can improve the objective function, i.e. the alpar@1: optimality conditions are violated, and at the same time this variable alpar@1: can infinitely change in the feasible direction meeting no resistance alpar@1: from basic variables. (May note that in the latter case the LP problem alpar@1: has no dual feasible solution.) alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \subsection{glp\_simplex---solve LP problem with the primal or dual alpar@1: simplex method} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_simplex(glp_prob *lp, const glp_smcp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_simplex| is a driver to the LP solver based on alpar@1: the simplex method. This routine retrieves problem data from the alpar@1: specified problem object, calls the solver to solve the problem alpar@1: instance, and stores results of computations back into the problem alpar@1: object. alpar@1: alpar@1: The simplex solver has a set of control parameters. Values of the alpar@1: control parameters can be passed in the structure \verb|glp_smcp|, alpar@1: which the parameter \verb|parm| points to. For detailed description of alpar@1: this structure see paragraph ``Control parameters'' below. alpar@1: Before specifying some control parameters the application program alpar@1: should initialize the structure \verb|glp_smcp| by default values of alpar@1: all control parameters using the routine \verb|glp_init_smcp| (see the alpar@1: next subsection). This is needed for backward compatibility, because in alpar@1: the future there may appear new members in the structure alpar@1: \verb|glp_smcp|. alpar@1: alpar@1: The parameter \verb|parm| can be specified as \verb|NULL|, in which alpar@1: case the solver uses default settings. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: \def\arraystretch{1} alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{97.3mm}@{}} alpar@1: 0 & The LP problem instance has been successfully solved. (This code alpar@1: does {\it not} necessarily mean that the solver has found optimal alpar@1: solution. It only means that the solution process was successful.) \\ alpar@1: \verb|GLP_EBADB| & Unable to start the search, because the initial basis alpar@1: specified in the problem object is invalid---the number of basic alpar@1: (auxiliary and structural) variables is not the same as the number of alpar@1: rows in the problem object.\\ alpar@1: \verb|GLP_ESING| & Unable to start the search, because the basis matrix alpar@1: corresponding to the initial basis is singular within the working alpar@1: precision.\\ alpar@1: \verb|GLP_ECOND| & Unable to start the search, because the basis matrix alpar@1: corresponding to the initial basis is ill-conditioned, i.e. its alpar@1: condition number is too large.\\ alpar@1: \verb|GLP_EBOUND| & Unable to start the search, because some alpar@1: double-bounded (auxiliary or structural) variables have incorrect alpar@1: bounds.\\ alpar@1: \verb|GLP_EFAIL| & The search was prematurely terminated due to the alpar@1: solver failure.\\ alpar@1: \verb|GLP_EOBJLL| & The search was prematurely terminated, because the alpar@1: objective function being maximized has reached its lower limit and alpar@1: continues decreasing (the dual simplex only).\\ alpar@1: \verb|GLP_EOBJUL| & The search was prematurely terminated, because the alpar@1: objective function being minimized has reached its upper limit and alpar@1: continues increasing (the dual simplex only).\\ alpar@1: \verb|GLP_EITLIM| & The search was prematurely terminated, because the alpar@1: simplex iteration limit has been exceeded.\\ alpar@1: \verb|GLP_ETMLIM| & The search was prematurely terminated, because the alpar@1: time limit has been exceeded.\\ alpar@1: \verb|GLP_ENOPFS| & The LP problem instance has no primal feasible alpar@1: solution (only if the LP presolver is used).\\ alpar@1: \verb|GLP_ENODFS| & The LP problem instance has no dual feasible alpar@1: solution (only if the LP presolver is used).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Built-in LP presolver} alpar@1: alpar@1: The simplex solver has {\it built-in LP presolver}. It is a subprogram alpar@1: that transforms the original LP problem specified in the problem object alpar@1: to an equivalent LP problem, which may be easier for solving with the alpar@1: simplex method than the original one. This is attained mainly due to alpar@1: reducing the problem size and improving its numeric properties (for alpar@1: example, by removing some inactive constraints or by fixing some alpar@1: non-basic variables). Once the transformed LP problem has been solved, alpar@1: the presolver transforms its basic solution back to the corresponding alpar@1: basic solution of the original problem. alpar@1: alpar@1: Presolving is an optional feature of the routine \verb|glp_simplex|, alpar@1: and by default it is disabled. In order to enable the LP presolver the alpar@1: control parameter \verb|presolve| should be set to \verb|GLP_ON| (see alpar@1: paragraph ``Control parameters'' below). Presolving may be used when alpar@1: the problem instance is solved for the first time. However, on alpar@1: performing re-optimization the presolver should be disabled. alpar@1: alpar@1: The presolving procedure is transparent to the API user in the sense alpar@1: that all necessary processing is performed internally, and a basic alpar@1: solution of the original problem recovered by the presolver is the same alpar@1: as if it were computed directly, i.e. without presolving. alpar@1: alpar@1: Note that the presolver is able to recover only optimal solutions. If alpar@1: a computed solution is infeasible or non-optimal, the corresponding alpar@1: solution of the original problem cannot be recovered and therefore alpar@1: remains undefined. If you need to know a basic solution even if it is alpar@1: infeasible or non-optimal, the presolver should be disabled. alpar@1: alpar@1: \subsubsection*{Terminal output} alpar@1: alpar@1: Solving large problem instances may take a long time, so the solver alpar@1: reports some information about the current basic solution, which is sent alpar@1: to the terminal. This information has the following format: alpar@1: alpar@1: \begin{verbatim} alpar@1: nnn: obj = xxx infeas = yyy (ddd) alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: where: `\verb|nnn|' is the iteration number, `\verb|xxx|' is the alpar@1: current value of the objective function (it is is unscaled and has alpar@1: correct sign); `\verb|yyy|' is the current sum of primal or dual alpar@1: infeasibilities (it is scaled and therefore may be used only for visual alpar@1: estimating), `\verb|ddd|' is the current number of fixed basic alpar@1: variables. alpar@1: alpar@1: The symbol preceding the iteration number indicates which phase of the alpar@1: simplex method is in effect: alpar@1: alpar@1: {\it Blank} means that the solver is searching for primal feasible alpar@1: solution using the primal simplex or for dual feasible solution using alpar@1: the dual simplex; alpar@1: alpar@1: {\it Asterisk} (\verb|*|) means that the solver is searching for alpar@1: optimal solution using the primal simplex; alpar@1: alpar@1: {\it Vertical dash} (\verb/|/) means that the solver is searching for alpar@1: optimal solution using the dual simplex. alpar@1: alpar@1: \subsubsection*{Control parameters} alpar@1: alpar@1: This paragraph describes all control parameters currently used in the alpar@1: simplex solver. Symbolic names of control parameters are names of alpar@1: corresponding members in the structure \verb|glp_smcp|. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})} alpar@1: \\ alpar@1: &Message level for terminal output:\\ alpar@1: &\verb|GLP_MSG_OFF|---no output;\\ alpar@1: &\verb|GLP_MSG_ERR|---error and warning messages only;\\ alpar@1: &\verb|GLP_MSG_ON |---normal output;\\ alpar@1: &\verb|GLP_MSG_ALL|---full output (including informational messages). alpar@1: \\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int meth} (default: {\tt GLP\_PRIMAL})} alpar@1: \\ alpar@1: &Simplex method option:\\ alpar@1: &\verb|GLP_PRIMAL|---use two-phase primal simplex;\\ alpar@1: &\verb|GLP_DUAL |---use two-phase dual simplex;\\ alpar@1: &\verb|GLP_DUALP |---use two-phase dual simplex, and if it fails, alpar@1: switch to the\\ alpar@1: &\verb| |$\:$ primal simplex.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int pricing} (default: {\tt GLP\_PT\_PSE})} alpar@1: \\ alpar@1: &Pricing technique:\\ alpar@1: &\verb|GLP_PT_STD|---standard (textbook);\\ alpar@1: &\verb|GLP_PT_PSE|---projected steepest edge.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int r\_test} (default: {\tt GLP\_RT\_HAR})} alpar@1: \\ alpar@1: &Ratio test technique:\\ alpar@1: &\verb|GLP_RT_STD|---standard (textbook);\\ alpar@1: &\verb|GLP_RT_HAR|---Harris' two-pass ratio test.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double tol\_bnd} (default: {\tt 1e-7})} alpar@1: \\ alpar@1: &Tolerance used to check if the basic solution is primal feasible. alpar@1: (Do not change this parameter without detailed understanding its alpar@1: purpose.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double tol\_dj} (default: {\tt 1e-7})} alpar@1: \\ alpar@1: &Tolerance used to check if the basic solution is dual feasible. alpar@1: (Do not change this parameter without detailed understanding its alpar@1: purpose.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double tol\_piv} (default: {\tt 1e-10})} alpar@1: \\ alpar@1: &Tolerance used to choose eligble pivotal elements of the simplex table. alpar@1: (Do not change this parameter without detailed understanding its alpar@1: purpose.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double obj\_ll} (default: {\tt -DBL\_MAX})} alpar@1: \\ alpar@1: &Lower limit of the objective function. If the objective function alpar@1: reaches this limit and continues decreasing, the solver terminates the alpar@1: search. (Used in the dual simplex only.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double obj\_ul} (default: {\tt +DBL\_MAX})} alpar@1: \\ alpar@1: &Upper limit of the objective function. If the objective function alpar@1: reaches this limit and continues increasing, the solver terminates the alpar@1: search. (Used in the dual simplex only.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int it\_lim} (default: {\tt INT\_MAX})} alpar@1: \\ alpar@1: &Simplex iteration limit.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int tm\_lim} (default: {\tt INT\_MAX})} alpar@1: \\ alpar@1: &Searching time limit, in milliseconds.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int out\_frq} (default: {\tt 500})} alpar@1: \\ alpar@1: &Output frequency, in iterations. This parameter specifies how alpar@1: frequently the solver sends information about the solution process to alpar@1: the terminal.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int out\_dly} (default: {\tt 0})} alpar@1: \\ alpar@1: &Output delay, in milliseconds. This parameter specifies how long the alpar@1: solver should delay sending information about the solution process to alpar@1: the terminal.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int presolve} (default: {\tt GLP\_OFF})} alpar@1: \\ alpar@1: &LP presolver option:\\ alpar@1: &\verb|GLP_ON |---enable using the LP presolver;\\ alpar@1: &\verb|GLP_OFF|---disable using the LP presolver.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Example 1} alpar@1: alpar@1: The following main program reads LP problem instance in fixed MPS alpar@1: format from file \verb|25fv47.mps|,\footnote{This instance in fixed MPS alpar@1: format can be found in the Netlib LP collection; see alpar@1: {\tt ftp://ftp.netlib.org/lp/data/}.} constructs an advanced initial alpar@1: basis, solves the instance with the primal simplex method (by default), alpar@1: and writes the solution to file \verb|25fv47.txt|. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: /* spxsamp1.c */ alpar@1: alpar@1: #include alpar@1: #include alpar@1: #include alpar@1: alpar@1: int main(void) alpar@1: { glp_prob *P; alpar@1: P = glp_create_prob(); alpar@1: glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps"); alpar@1: glp_adv_basis(P, 0); alpar@1: glp_simplex(P, NULL); alpar@1: glp_print_sol(P, "25fv47.txt"); alpar@1: glp_delete_prob(P); alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /* eof */ alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \noindent alpar@1: Below here is shown the terminal output from this example program. alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: Reading problem data from `25fv47.mps'... alpar@1: Problem: 25FV47 alpar@1: Objective: R0000 alpar@1: 822 rows, 1571 columns, 11127 non-zeros alpar@1: 6919 records were read alpar@1: Crashing... alpar@1: Size of triangular part = 799 alpar@1: 0: obj = 1.627307307e+04 infeas = 5.194e+04 (23) alpar@1: 200: obj = 1.474901610e+04 infeas = 1.233e+04 (19) alpar@1: 400: obj = 1.343909995e+04 infeas = 3.648e+03 (13) alpar@1: 600: obj = 1.756052217e+04 infeas = 4.179e+02 (7) alpar@1: * 775: obj = 1.789251591e+04 infeas = 4.982e-14 (1) alpar@1: * 800: obj = 1.663354510e+04 infeas = 2.857e-14 (1) alpar@1: * 1000: obj = 1.024935068e+04 infeas = 1.958e-12 (1) alpar@1: * 1200: obj = 7.860174791e+03 infeas = 2.810e-29 (1) alpar@1: * 1400: obj = 6.642378184e+03 infeas = 2.036e-16 (1) alpar@1: * 1600: obj = 6.037014568e+03 infeas = 0.000e+00 (1) alpar@1: * 1800: obj = 5.662171307e+03 infeas = 6.447e-15 (1) alpar@1: * 2000: obj = 5.528146165e+03 infeas = 9.764e-13 (1) alpar@1: * 2125: obj = 5.501845888e+03 infeas = 0.000e+00 (1) alpar@1: OPTIMAL SOLUTION FOUND alpar@1: Writing basic solution to `25fv47.txt'... alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsubsection*{Example 2} alpar@1: alpar@1: The following main program solves the same LP problem instance as in alpar@1: Example 1 above, however, it uses the dual simplex method, which starts alpar@1: from the standard initial basis. alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: /* spxsamp2.c */ alpar@1: alpar@1: #include alpar@1: #include alpar@1: #include alpar@1: alpar@1: int main(void) alpar@1: { glp_prob *P; alpar@1: glp_smcp parm; alpar@1: P = glp_create_prob(); alpar@1: glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps"); alpar@1: glp_init_smcp(&parm); alpar@1: parm.meth = GLP_DUAL; alpar@1: glp_simplex(P, &parm); alpar@1: glp_print_sol(P, "25fv47.txt"); alpar@1: glp_delete_prob(P); alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /* eof */ alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \noindent alpar@1: Below here is shown the terminal output from this example program. alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: Reading problem data from `25fv47.mps'... alpar@1: Problem: 25FV47 alpar@1: Objective: R0000 alpar@1: 822 rows, 1571 columns, 11127 non-zeros alpar@1: 6919 records were read alpar@1: 0: infeas = 1.223e+03 (516) alpar@1: 200: infeas = 7.000e+00 (471) alpar@1: 240: infeas = 1.106e-14 (461) alpar@1: | 400: obj = -5.394267152e+03 infeas = 5.571e-16 (391) alpar@1: | 600: obj = -4.586395752e+03 infeas = 1.389e-15 (340) alpar@1: | 800: obj = -4.158268146e+03 infeas = 1.640e-15 (264) alpar@1: | 1000: obj = -3.725320045e+03 infeas = 5.181e-15 (245) alpar@1: | 1200: obj = -3.104802163e+03 infeas = 1.019e-14 (210) alpar@1: | 1400: obj = -2.584190499e+03 infeas = 8.865e-15 (178) alpar@1: | 1600: obj = -2.073852927e+03 infeas = 7.867e-15 (142) alpar@1: | 1800: obj = -1.164037407e+03 infeas = 8.792e-15 (109) alpar@1: | 2000: obj = -4.370590250e+02 infeas = 2.591e-14 (85) alpar@1: | 2200: obj = 1.068240144e+03 infeas = 1.025e-13 (70) alpar@1: | 2400: obj = 1.607481126e+03 infeas = 3.272e-14 (67) alpar@1: | 2600: obj = 3.038230551e+03 infeas = 4.850e-14 (52) alpar@1: | 2800: obj = 4.316238187e+03 infeas = 2.622e-14 (36) alpar@1: | 3000: obj = 5.443842629e+03 infeas = 3.976e-15 (11) alpar@1: | 3060: obj = 5.501845888e+03 infeas = 8.806e-15 (2) alpar@1: OPTIMAL SOLUTION FOUND alpar@1: Writing basic solution to `25fv47.txt'... alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \subsection{glp\_exact---solve LP problem in exact arithmetic} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_exact(glp_prob *lp, const glp_smcp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_exact| is a tentative implementation of the alpar@1: primal two-phase simplex method based on exact (rational) arithmetic. alpar@1: It is similar to the routine \verb|glp_simplex|, however, for all alpar@1: internal computations it uses arithmetic of rational numbers, which is alpar@1: exact in mathematical sense, i.e. free of round-off errors unlike alpar@1: floating-point arithmetic. alpar@1: alpar@1: Note that the routine \verb|glp_exact| uses only two control parameters alpar@1: passed in the structure \verb|glp_smcp|, namely, \verb|it_lim| and alpar@1: \verb|tm_lim|. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: \def\arraystretch{1} alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{97.3mm}@{}} alpar@1: 0 & The LP problem instance has been successfully solved. (This code alpar@1: does {\it not} necessarily mean that the solver has found optimal alpar@1: solution. It only means that the solution process was successful.) \\ alpar@1: \verb|GLP_EBADB| & Unable to start the search, because the initial basis alpar@1: specified in the problem object is invalid---the number of basic alpar@1: (auxiliary and structural) variables is not the same as the number of alpar@1: rows in the problem object.\\ alpar@1: \verb|GLP_ESING| & Unable to start the search, because the basis matrix alpar@1: corresponding to the initial basis is exactly singular.\\ alpar@1: \verb|GLP_EBOUND| & Unable to start the search, because some alpar@1: double-bounded (auxiliary or structural) variables have incorrect alpar@1: bounds.\\ alpar@1: \verb|GLP_EFAIL| & The problem instance has no rows/columns.\\ alpar@1: \verb|GLP_EITLIM| & The search was prematurely terminated, because the alpar@1: simplex iteration limit has been exceeded.\\ alpar@1: \verb|GLP_ETMLIM| & The search was prematurely terminated, because the alpar@1: time limit has been exceeded.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Comments} alpar@1: alpar@1: Computations in exact arithmetic are very time consuming, so solving alpar@1: LP problem with the routine \verb|glp_exact| from the very beginning is alpar@1: not a good idea. It is much better at first to find an optimal basis alpar@1: with the routine \verb|glp_simplex| and only then to call alpar@1: \verb|glp_exact|, in which case only a few simplex iterations need to alpar@1: be performed in exact arithmetic. alpar@1: alpar@1: \subsection{glp\_init\_smcp---initialize simplex solver control alpar@1: parameters} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_init_smcp(glp_smcp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_init_smcp| initializes control parameters, which alpar@1: are used by the simplex solver, with default values. alpar@1: alpar@1: Default values of the control parameters are stored in a \verb|glp_smcp| alpar@1: structure, which the parameter \verb|parm| points to. alpar@1: alpar@1: \subsection{glp\_get\_status---determine generic status of basic alpar@1: solution} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_status(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_status| reports the generic status of the alpar@1: current basic solution for the specified problem object as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_OPT| & solution is optimal; \\ alpar@1: \verb|GLP_FEAS| & solution is feasible; \\ alpar@1: \verb|GLP_INFEAS| & solution is infeasible; \\ alpar@1: \verb|GLP_NOFEAS| & problem has no feasible solution; \\ alpar@1: \verb|GLP_UNBND| & problem has unbounded solution; \\ alpar@1: \verb|GLP_UNDEF| & solution is undefined. \\ alpar@1: \end{tabular} alpar@1: alpar@1: More detailed information about the status of basic solution can be alpar@1: retrieved with the routines \verb|glp_get_prim_stat| and alpar@1: \verb|glp_get_dual_stat|. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_get\_prim\_stat---retrieve status of primal basic alpar@1: solution} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_prim_stat(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_prim_stat| reports the status of the primal alpar@1: basic solution for the specified problem object as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_UNDEF| & primal solution is undefined; \\ alpar@1: \verb|GLP_FEAS| & primal solution is feasible; \\ alpar@1: \verb|GLP_INFEAS| & primal solution is infeasible; \\ alpar@1: \verb|GLP_NOFEAS| & no primal feasible solution exists. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_dual\_stat---retrieve status of dual basic alpar@1: solution} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_dual_stat(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_dual_stat| reports the status of the dual alpar@1: basic solution for the specified problem object as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_UNDEF| & dual solution is undefined; \\ alpar@1: \verb|GLP_FEAS| & dual solution is feasible; \\ alpar@1: \verb|GLP_INFEAS| & dual solution is infeasible; \\ alpar@1: \verb|GLP_NOFEAS| & no dual feasible solution exists. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_obj\_val---retrieve objective value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_obj_val(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_obj_val| returns current value of the alpar@1: objective function. alpar@1: alpar@1: \subsection{glp\_get\_row\_stat---retrieve row status} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_row_stat(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_stat| returns current status assigned to alpar@1: the auxiliary variable associated with \verb|i|-th row as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_BS| & basic variable; \\ alpar@1: \verb|GLP_NL| & non-basic variable on its lower bound; \\ alpar@1: \verb|GLP_NU| & non-basic variable on its upper bound; \\ alpar@1: \verb|GLP_NF| & non-basic free (unbounded) variable; \\ alpar@1: \verb|GLP_NS| & non-basic fixed variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_row\_prim---retrieve row primal value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_row_prim(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_prim| returns primal value of the alpar@1: auxiliary variable associated with \verb|i|-th row. alpar@1: alpar@1: \subsection{glp\_get\_row\_dual---retrieve row dual value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_row_dual(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_row_dual| returns dual value (i.e. reduced alpar@1: cost) of the auxiliary variable associated with \verb|i|-th row. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_get\_col\_stat---retrieve column status} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_col_stat(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_stat| returns current status assigned to alpar@1: the structural variable associated with \verb|j|-th column as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_BS| & basic variable; \\ alpar@1: \verb|GLP_NL| & non-basic variable on its lower bound; \\ alpar@1: \verb|GLP_NU| & non-basic variable on its upper bound; \\ alpar@1: \verb|GLP_NF| & non-basic free (unbounded) variable; \\ alpar@1: \verb|GLP_NS| & non-basic fixed variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_col\_prim---retrieve column primal value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_col_prim(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_prim| returns primal value of the alpar@1: structural variable associated with \verb|j|-th column. alpar@1: alpar@1: \subsection{glp\_get\_col\_dual---retrieve column dual value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_get_col_dual(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_dual| returns dual value (i.e. reduced alpar@1: cost) of the structural variable associated with \verb|j|-th column. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_get\_unbnd\_ray---determine variable causing\\ alpar@1: unboundedness} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_unbnd_ray(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_unbnd_ray| returns the number $k$ of alpar@1: a variable, which causes primal or dual unboundedness. alpar@1: If $1\leq k\leq m$, it is $k$-th auxiliary variable, and if alpar@1: $m+1\leq k\leq m+n$, it is $(k-m)$-th structural variable, where $m$ is alpar@1: the number of rows, $n$ is the number of columns in the problem object. alpar@1: If such variable is not defined, the routine returns 0. alpar@1: alpar@1: \subsubsection*{Comments} alpar@1: alpar@1: If it is not exactly known which version of the simplex solver alpar@1: detected unboundedness, i.e. whether the unboundedness is primal or alpar@1: dual, it is sufficient to check the status of the variable alpar@1: with the routine \verb|glp_get_row_stat| or \verb|glp_get_col_stat|. alpar@1: If the variable is non-basic, the unboundedness is primal, otherwise, alpar@1: if the variable is basic, the unboundedness is dual (the latter case alpar@1: means that the problem has no primal feasible dolution). alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Interior-point method routines} alpar@1: alpar@1: {\it Interior-point methods} (also known as {\it barrier methods}) are alpar@1: more modern and powerful numerical methods for large-scale linear alpar@1: programming. Such methods are especially efficient for very sparse LP alpar@1: problems and allow solving such problems much faster than the simplex alpar@1: method. alpar@1: alpar@1: In brief, the GLPK interior-point solver works as follows. alpar@1: alpar@1: At first, the solver transforms the original LP to a {\it working} LP alpar@1: in the standard format: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \hspace{.5in} minimize alpar@1: $$z = c_1x_{m+1} + c_2x_{m+2} + \dots + c_nx_{m+n} + c_0 \eqno (2.4)$$ alpar@1: \hspace{.5in} subject to linear constraints alpar@1: $$ alpar@1: \begin{array}{r@{\:}c@{\:}r@{\:}c@{\:}r@{\:}c@{\:}l} alpar@1: a_{11}x_{m+1}&+&a_{12}x_{m+2}&+ \dots +&a_{1n}x_{m+n}&=&b_1 \\ alpar@1: a_{21}x_{m+1}&+&a_{22}x_{m+2}&+ \dots +&a_{2n}x_{m+n}&=&b_2 \\ alpar@1: \multicolumn{7}{c} alpar@1: {.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .} \\ alpar@1: a_{m1}x_{m+1}&+&a_{m2}x_{m+2}&+ \dots +&a_{mn}x_{m+n}&=&b_m \\ alpar@1: \end{array} \eqno (2.5) alpar@1: $$ alpar@1: \hspace{.5in} and non-negative variables alpar@1: $$x_1\geq 0,\ \ x_2\geq 0,\ \ \dots,\ \ x_n\geq 0 \eqno(2.6)$$ alpar@1: where: $z$ is the objective function; $x_1$, \dots, $x_n$ are variables; alpar@1: $c_1$, \dots, $c_n$ are objective coefficients; $c_0$ is a constant term alpar@1: of the objective function;\linebreak $a_{11}$, \dots, $a_{mn}$ are alpar@1: constraint coefficients; $b_1$, \dots, $b_m$ are right-hand sides. alpar@1: alpar@1: Using vector and matrix notations the working LP (2.4)---(2.6) can be alpar@1: written as follows: alpar@1: $$z=c^Tx+c_0\ \rightarrow\ \min,\eqno(2.7)$$ alpar@1: $$Ax=b,\eqno(2.8)$$ alpar@1: $$x\geq 0,\eqno(2.9)$$ alpar@1: where: $x=(x_j)$ is $n$-vector of variables, $c=(c_j)$ is $n$-vector of alpar@1: objective coefficients, $A=(a_{ij})$ is $m\times n$-matrix of alpar@1: constraint coefficients, and $b=(b_i)$ is $m$-vector of right-hand alpar@1: sides. alpar@1: alpar@1: Karush--Kuhn--Tucker optimality conditions for LP (2.7)---(2.9) are the alpar@1: following: alpar@1: alpar@1: \newpage alpar@1: alpar@1: $$Ax=b,\eqno(2.10)$$ alpar@1: $$A^T\pi+\lambda=c,\eqno(2.11)$$ alpar@1: $$\lambda^Tx=0,\eqno(2.12)$$ alpar@1: $$x\geq 0,\ \ \lambda\geq 0,\eqno(2.13)$$ alpar@1: where: $\pi$ is $m$-vector of Lagrange multipliers (dual variables) for alpar@1: equality constraints (2.8), $\lambda$ is $n$-vector of Lagrange alpar@1: multipliers (dual variables) for non-negativity constraints (2.9), alpar@1: (2.10) is the primal feasibility condition, (2.11) is the dual alpar@1: feasibility condition, (2.12) is the primal-dual complementarity alpar@1: condition, and (2.13) is the non-negativity conditions. alpar@1: alpar@1: The main idea of the primal-dual interior-point method is based on alpar@1: finding a point in the primal-dual space (i.e. in the space of all alpar@1: primal and dual variables $x$, $\pi$, and $\lambda$), which satisfies alpar@1: to all optimality conditions (2.10)---(2.13). Obviously, $x$-component alpar@1: of such point then provides an optimal solution to the working LP alpar@1: (2.7)---(2.9). alpar@1: alpar@1: To find the optimal point $(x^*,\pi^*,\lambda^*)$ the interior-point alpar@1: method attempts to solve the system of equations (2.10)---(2.12), which alpar@1: is closed in the sense that the number of variables $x_j$, $\pi_i$, and alpar@1: $\lambda_j$ and the number equations are the same and equal to $m+2n$. alpar@1: Due to condition (2.12) this system of equations is non-linear, so it alpar@1: can be solved with a version of {\it Newton's method} provided with alpar@1: additional rules to keep the current point within the positive orthant alpar@1: as required by the non-negativity conditions (2.13). alpar@1: alpar@1: Finally, once the optimal point $(x^*,\pi^*,\lambda^*)$ has been found, alpar@1: the solver performs inverse transformations to recover corresponding alpar@1: solution to the original LP passed to the solver from the application alpar@1: program. alpar@1: alpar@1: \subsection{glp\_interior---solve LP problem with the interior-point alpar@1: method} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_interior(glp_prob *P, const glp_iptcp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_interior| is a driver to the LP solver based on alpar@1: the primal-dual interior-point method. This routine retrieves problem alpar@1: data from the specified problem object, calls the solver to solve the alpar@1: problem instance, and stores results of computations back into the alpar@1: problem object. alpar@1: alpar@1: The interior-point solver has a set of control parameters. Values of alpar@1: the control parameters can be passed in the structure \verb|glp_iptcp|, alpar@1: which the parameter \verb|parm| points to. For detailed description of alpar@1: this structure see paragraph ``Control parameters'' below. Before alpar@1: specifying some control parameters the application program should alpar@1: initialize the structure \verb|glp_iptcp| by default values of all alpar@1: control parameters using the routine \verb|glp_init_iptcp| (see the alpar@1: next subsection). This is needed for backward compatibility, because in alpar@1: the future there may appear new members in the structure alpar@1: \verb|glp_iptcp|. alpar@1: alpar@1: The parameter \verb|parm| can be specified as \verb|NULL|, in which alpar@1: case the solver uses default settings. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: \def\arraystretch{1} alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{97.3mm}@{}} alpar@1: 0 & The LP problem instance has been successfully solved. (This code alpar@1: does {\it not} necessarily mean that the solver has found optimal alpar@1: solution. It only means that the solution process was successful.) \\ alpar@1: \verb|GLP_EFAIL| & The problem has no rows/columns.\\ alpar@1: \verb|GLP_ENOCVG| & Very slow convergence or divergence.\\ alpar@1: \verb|GLP_EITLIM| & Iteration limit exceeded.\\ alpar@1: \verb|GLP_EINSTAB| & Numerical instability on solving Newtonian alpar@1: system.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Comments} alpar@1: alpar@1: The routine \verb|glp_interior| implements an easy version of alpar@1: the primal-dual interior-point method based on Mehrotra's alpar@1: technique.\footnote{S. Mehrotra. On the implementation of a primal-dual alpar@1: interior point method. SIAM J. on Optim., 2(4), pp. 575-601, 1992.} alpar@1: alpar@1: Note that currently the GLPK interior-point solver does not include alpar@1: many important features, in particular: alpar@1: alpar@1: $\bullet$ it is not able to process dense columns. Thus, if the alpar@1: constraint matrix of the LP problem has dense columns, the solving alpar@1: process may be inefficient; alpar@1: alpar@1: $\bullet$ it has no features against numerical instability. For some alpar@1: LP problems premature termination may happen if the matrix $ADA^T$ alpar@1: becomes singular or ill-conditioned; alpar@1: alpar@1: $\bullet$ it is not able to identify the optimal basis, which alpar@1: corresponds to the interior-point solution found. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsubsection*{Terminal output} alpar@1: alpar@1: Solving large LP problems may take a long time, so the solver reports alpar@1: some information about every interior-point iteration,\footnote{Unlike alpar@1: the simplex method the interior point method usually needs 30---50 alpar@1: iterations (independently on the problem size) in order to find an alpar@1: optimal solution.} which is sent to the terminal. This information has alpar@1: the following format: alpar@1: alpar@1: \begin{verbatim} alpar@1: nnn: obj = fff; rpi = ppp; rdi = ddd; gap = ggg alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent where: \verb|nnn| is iteration number, \verb|fff| is the alpar@1: current value of the objective function (in the case of maximization it alpar@1: has wrong sign), \verb|ppp| is the current relative primal alpar@1: infeasibility (cf. (2.10)): alpar@1: $$\frac{\|Ax^{(k)}-b\|}{1+\|b\|},\eqno(2.14)$$ alpar@1: \verb|ddd| is the current relative dual infeasibility (cf. (2.11)): alpar@1: $$\frac{\|A^T\pi^{(k)}+\lambda^{(k)}-c\|}{1+\|c\|},\eqno(2.15)$$ alpar@1: \verb|ggg| is the current primal-dual gap (cf. (2.12)): alpar@1: $$\frac{|c^Tx^{(k)}-b^T\pi^{(k)}|}{1+|c^Tx^{(k)}|},\eqno(2.16)$$ alpar@1: and $[x^{(k)},\pi^{(k)},\lambda^{(k)}]$ is the current point on $k$-th alpar@1: iteration, $k=0,1,2,\dots$\ . Note that all solution components are alpar@1: internally scaled, so information sent to the terminal is suitable only alpar@1: for visual inspection. alpar@1: alpar@1: \subsubsection*{Control parameters} alpar@1: alpar@1: This paragraph describes all control parameters currently used in the alpar@1: interior-point solver. Symbolic names of control parameters are names of alpar@1: corresponding members in the structure \verb|glp_iptcp|. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})} alpar@1: \\ alpar@1: &Message level for terminal output:\\ alpar@1: &\verb|GLP_MSG_OFF|---no output;\\ alpar@1: &\verb|GLP_MSG_ERR|---error and warning messages only;\\ alpar@1: &\verb|GLP_MSG_ON |---normal output;\\ alpar@1: &\verb|GLP_MSG_ALL|---full output (including informational messages). alpar@1: \\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int ord\_alg} (default: {\tt GLP\_ORD\_AMD})} alpar@1: \\ alpar@1: &Ordering algorithm used prior to Cholesky factorization:\\ alpar@1: &\verb|GLP_ORD_NONE |---use natural (original) ordering;\\ alpar@1: &\verb|GLP_ORD_QMD |---quotient minimum degree (QMD);\\ alpar@1: &\verb|GLP_ORD_AMD |---approximate minimum degree (AMD);\\ alpar@1: &\verb|GLP_ORD_SYMAMD|---approximate minimum degree (SYMAMD).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Example} alpar@1: alpar@1: The following main program reads LP problem instance in fixed MPS alpar@1: format from file \verb|25fv47.mps|,\footnote{This instance in fixed MPS alpar@1: format can be found in the Netlib LP collection; see alpar@1: {\tt ftp://ftp.netlib.org/lp/data/}.} solves it with the interior-point alpar@1: solver, and writes the solution to file \verb|25fv47.txt|. alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: /* iptsamp.c */ alpar@1: alpar@1: #include alpar@1: #include alpar@1: #include alpar@1: alpar@1: int main(void) alpar@1: { glp_prob *P; alpar@1: P = glp_create_prob(); alpar@1: glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps"); alpar@1: glp_interior(P, NULL); alpar@1: glp_print_ipt(P, "25fv47.txt"); alpar@1: glp_delete_prob(P); alpar@1: return 0; alpar@1: } alpar@1: alpar@1: /* eof */ alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \noindent alpar@1: Below here is shown the terminal output from this example program. alpar@1: alpar@1: \begin{footnotesize} alpar@1: \begin{verbatim} alpar@1: Reading problem data from `25fv47.mps'... alpar@1: Problem: 25FV47 alpar@1: Objective: R0000 alpar@1: 822 rows, 1571 columns, 11127 non-zeros alpar@1: 6919 records were read alpar@1: Original LP has 822 row(s), 1571 column(s), and 11127 non-zero(s) alpar@1: Working LP has 821 row(s), 1876 column(s), and 10705 non-zero(s) alpar@1: Matrix A has 10705 non-zeros alpar@1: Matrix S = A*A' has 11895 non-zeros (upper triangle) alpar@1: Minimal degree ordering... alpar@1: Computing Cholesky factorization S = L'*L... alpar@1: Matrix L has 35411 non-zeros alpar@1: Guessing initial point... alpar@1: Optimization begins... alpar@1: 0: obj = 1.823377629e+05; rpi = 1.3e+01; rdi = 1.4e+01; gap = 9.3e-01 alpar@1: 1: obj = 9.260045192e+04; rpi = 5.3e+00; rdi = 5.6e+00; gap = 6.8e+00 alpar@1: 2: obj = 3.596999742e+04; rpi = 1.5e+00; rdi = 1.2e+00; gap = 1.8e+01 alpar@1: 3: obj = 1.989627568e+04; rpi = 4.7e-01; rdi = 3.0e-01; gap = 1.9e+01 alpar@1: 4: obj = 1.430215557e+04; rpi = 1.1e-01; rdi = 8.6e-02; gap = 1.4e+01 alpar@1: 5: obj = 1.155716505e+04; rpi = 2.3e-02; rdi = 2.4e-02; gap = 6.8e+00 alpar@1: 6: obj = 9.660273208e+03; rpi = 6.7e-03; rdi = 4.6e-03; gap = 3.9e+00 alpar@1: 7: obj = 8.694348283e+03; rpi = 3.7e-03; rdi = 1.7e-03; gap = 2.0e+00 alpar@1: 8: obj = 8.019543639e+03; rpi = 2.4e-03; rdi = 3.9e-04; gap = 1.0e+00 alpar@1: 9: obj = 7.122676293e+03; rpi = 1.2e-03; rdi = 1.5e-04; gap = 6.6e-01 alpar@1: 10: obj = 6.514534518e+03; rpi = 6.1e-04; rdi = 4.3e-05; gap = 4.1e-01 alpar@1: 11: obj = 6.361572203e+03; rpi = 4.8e-04; rdi = 2.2e-05; gap = 3.0e-01 alpar@1: 12: obj = 6.203355508e+03; rpi = 3.2e-04; rdi = 1.7e-05; gap = 2.6e-01 alpar@1: 13: obj = 6.032943411e+03; rpi = 2.0e-04; rdi = 9.3e-06; gap = 2.1e-01 alpar@1: 14: obj = 5.796553021e+03; rpi = 9.8e-05; rdi = 3.2e-06; gap = 1.0e-01 alpar@1: 15: obj = 5.667032431e+03; rpi = 4.4e-05; rdi = 1.1e-06; gap = 5.6e-02 alpar@1: 16: obj = 5.613911867e+03; rpi = 2.5e-05; rdi = 4.1e-07; gap = 3.5e-02 alpar@1: 17: obj = 5.560572626e+03; rpi = 9.9e-06; rdi = 2.3e-07; gap = 2.1e-02 alpar@1: 18: obj = 5.537276001e+03; rpi = 5.5e-06; rdi = 8.4e-08; gap = 1.1e-02 alpar@1: 19: obj = 5.522746942e+03; rpi = 2.2e-06; rdi = 4.0e-08; gap = 6.7e-03 alpar@1: 20: obj = 5.509956679e+03; rpi = 7.5e-07; rdi = 1.8e-08; gap = 2.9e-03 alpar@1: 21: obj = 5.504571733e+03; rpi = 1.6e-07; rdi = 5.8e-09; gap = 1.1e-03 alpar@1: 22: obj = 5.502576367e+03; rpi = 3.4e-08; rdi = 1.0e-09; gap = 2.5e-04 alpar@1: 23: obj = 5.502057119e+03; rpi = 8.1e-09; rdi = 3.0e-10; gap = 7.7e-05 alpar@1: 24: obj = 5.501885996e+03; rpi = 9.4e-10; rdi = 1.2e-10; gap = 2.4e-05 alpar@1: 25: obj = 5.501852464e+03; rpi = 1.4e-10; rdi = 1.2e-11; gap = 3.0e-06 alpar@1: 26: obj = 5.501846549e+03; rpi = 1.4e-11; rdi = 1.2e-12; gap = 3.0e-07 alpar@1: 27: obj = 5.501845954e+03; rpi = 1.4e-12; rdi = 1.2e-13; gap = 3.0e-08 alpar@1: 28: obj = 5.501845895e+03; rpi = 1.5e-13; rdi = 1.2e-14; gap = 3.0e-09 alpar@1: OPTIMAL SOLUTION FOUND alpar@1: Writing interior-point solution to `25fv47.txt'... alpar@1: \end{verbatim} alpar@1: \end{footnotesize} alpar@1: alpar@1: \subsection{glp\_init\_iptcp---initialize interior-point solver control alpar@1: parameters} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_init_iptcp(glp_iptcp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_init_iptcp| initializes control parameters, which alpar@1: are used by the interior-point solver, with default values. alpar@1: alpar@1: Default values of the control parameters are stored in the structure alpar@1: \verb|glp_iptcp|, which the parameter \verb|parm| points to. alpar@1: alpar@1: \subsection{glp\_ipt\_status---determine solution status} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_ipt_status(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_status| reports the status of a solution alpar@1: found by the interior-point solver as follows: alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{91.3mm}@{}} alpar@1: \verb|GLP_UNDEF| & interior-point solution is undefined. \\ alpar@1: \verb|GLP_OPT| & interior-point solution is optimal. \\ alpar@1: \verb|GLP_INFEAS|& interior-point solution is infeasible. \\ alpar@1: \verb|GLP_NOFEAS|& no feasible primal-dual solution exists.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_ipt\_obj\_val---retrieve objective value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_ipt_obj_val(glp_prob *lp); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_obj_val| returns value of the objective alpar@1: function for interior-point solution. alpar@1: alpar@1: \subsection{glp\_ipt\_row\_prim---retrieve row primal value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_ipt_row_prim(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_row_prim| returns primal value of the alpar@1: auxiliary variable associated with \verb|i|-th row. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsection{glp\_ipt\_row\_dual---retrieve row dual value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_ipt_row_dual(glp_prob *lp, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_row_dual| returns dual value (i.e. reduced alpar@1: cost) of the auxiliary variable associated with \verb|i|-th row. alpar@1: alpar@1: \subsection{glp\_ipt\_col\_prim---retrieve column primal value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_ipt_col_prim(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_col_prim| returns primal value of the alpar@1: structural variable associated with \verb|j|-th column. alpar@1: alpar@1: \subsection{glp\_ipt\_col\_dual---retrieve column dual value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_ipt_col_dual(glp_prob *lp, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_ipt_col_dual| returns dual value (i.e. reduced alpar@1: cost) of the structural variable associated with \verb|j|-th column. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Mixed integer programming routines} alpar@1: alpar@1: \subsection{glp\_set\_col\_kind---set (change) column kind} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_set_col_kind(glp_prob *mip, int j, int kind); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_set_col_kind| sets (changes) the kind of alpar@1: \verb|j|-th column (structural variable) as specified by the parameter alpar@1: \verb|kind|: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_CV| & continuous variable; \\ alpar@1: \verb|GLP_IV| & integer variable; \\ alpar@1: \verb|GLP_BV| & binary variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: %If a column is set to \verb|GLP_IV|, its bounds must be exact integer alpar@1: %numbers with no tolerance, such that the condition alpar@1: %\verb|bnd == floor(bnd)| would hold. alpar@1: alpar@1: Setting a column to \verb|GLP_BV| has the same effect as if it were alpar@1: set to \verb|GLP_IV|, its lower bound were set 0, and its upper bound alpar@1: were set to 1. alpar@1: alpar@1: \subsection{glp\_get\_col\_kind---retrieve column kind} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_col_kind(glp_prob *mip, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_col_kind| returns the kind of \verb|j|-th alpar@1: column (structural variable) as follows: alpar@1: alpar@1: \begin{tabular}{@{}ll} alpar@1: \verb|GLP_CV| & continuous variable; \\ alpar@1: \verb|GLP_IV| & integer variable; \\ alpar@1: \verb|GLP_BV| & binary variable. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_get\_num\_int---retrieve number of integer columns} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_num_int(glp_prob *mip); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_num_int| returns the number of columns alpar@1: (structural variables), which are marked as integer. Note that this alpar@1: number {\it does} include binary columns. alpar@1: alpar@1: \subsection{glp\_get\_num\_bin---retrieve number of binary columns} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_get_num_bin(glp_prob *mip); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_get_num_bin| returns the number of columns alpar@1: (structural variables), which are marked as integer and whose lower alpar@1: bound is zero and upper bound is one. alpar@1: alpar@1: \subsection{glp\_intopt---solve MIP problem with the branch-and-cut alpar@1: method} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_intopt(glp_prob *mip, const glp_iocp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_intopt| is a driver to the MIP solver based on alpar@1: the branch-and-cut method, which is a hybrid of branch-and-bound and alpar@1: cutting plane methods. alpar@1: alpar@1: If the presolver is disabled (see paragraph ``Control parameters'' alpar@1: below), on entry to the routine \verb|glp_intopt| the problem object, alpar@1: which the parameter \verb|mip| points to, should contain optimal alpar@1: solution to LP relaxation (it can be obtained, for example, with the alpar@1: routine \verb|glp_simplex|). Otherwise, if the presolver is enabled, it alpar@1: is not necessary. alpar@1: alpar@1: The MIP solver has a set of control parameters. Values of the control alpar@1: parameters can be passed in the structure \verb|glp_iocp|, which the alpar@1: parameter \verb|parm| points to. For detailed description of this alpar@1: structure see paragraph ``Control parameters'' below. Before specifying alpar@1: some control parameters the application program should initialize the alpar@1: structure \verb|glp_iocp| by default values of all control parameters alpar@1: using the routine \verb|glp_init_iocp| (see the next subsection). This alpar@1: is needed for backward compatibility, because in the future there may alpar@1: appear new members in the structure \verb|glp_iocp|. alpar@1: alpar@1: The parameter \verb|parm| can be specified as \verb|NULL|, in which case alpar@1: the solver uses default settings. alpar@1: alpar@1: Note that the GLPK branch-and-cut solver is not perfect, so it is unable alpar@1: to solve hard or very large scale MIP instances for a reasonable time. alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: \def\arraystretch{1} alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{97.3mm}@{}} alpar@1: 0 & The MIP problem instance has been successfully solved. (This code alpar@1: does {\it not} necessarily mean that the solver has found optimal alpar@1: solution. It only means that the solution process was successful.) \\ alpar@1: \verb|GLP_EBOUND| & Unable to start the search, because some alpar@1: double-bounded variables have incorrect bounds or some integer variables alpar@1: have non-integer (fractional) bounds.\\ alpar@1: \verb|GLP_EROOT| & Unable to start the search, because optimal basis for alpar@1: initial LP relaxation is not provided. (This code may appear only if the alpar@1: presolver is disabled.)\\ alpar@1: \verb|GLP_ENOPFS| & Unable to start the search, because LP relaxation alpar@1: of the MIP problem instance has no primal feasible solution. (This code alpar@1: may appear only if the presolver is enabled.)\\ alpar@1: \verb|GLP_ENODFS| & Unable to start the search, because LP relaxation alpar@1: of the MIP problem instance has no dual feasible solution. In other alpar@1: word, this code means that if the LP relaxation has at least one primal alpar@1: feasible solution, its optimal solution is unbounded, so if the MIP alpar@1: problem has at least one integer feasible solution, its (integer) alpar@1: optimal solution is also unbounded. (This code may appear only if the alpar@1: presolver is enabled.)\\ alpar@1: \verb|GLP_EFAIL| & The search was prematurely terminated due to the alpar@1: solver failure.\\ alpar@1: \verb|GLP_EMIPGAP| & The search was prematurely terminated, because the alpar@1: relative mip gap tolerance has been reached.\\ alpar@1: \verb|GLP_ETMLIM| & The search was prematurely terminated, because the alpar@1: time limit has been exceeded.\\ alpar@1: \verb|GLP_ESTOP| & The search was prematurely terminated by application. alpar@1: (This code may appear only if the advanced solver interface is used.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection*{Built-in MIP presolver} alpar@1: alpar@1: The branch-and-cut solver has {\it built-in MIP presolver}. It is alpar@1: a subprogram that transforms the original MIP problem specified in the alpar@1: problem object to an equivalent MIP problem, which may be easier for alpar@1: solving with the branch-and-cut method than the original one. For alpar@1: example, the presolver can remove redundant constraints and variables, alpar@1: whose optimal values are known, perform bound and coefficient reduction, alpar@1: etc. Once the transformed MIP problem has been solved, the presolver alpar@1: transforms its solution back to corresponding solution of the original alpar@1: problem. alpar@1: alpar@1: Presolving is an optional feature of the routine \verb|glp_intopt|, and alpar@1: by default it is disabled. In order to enable the MIP presolver, the alpar@1: control parameter \verb|presolve| should be set to \verb|GLP_ON| (see alpar@1: paragraph ``Control parameters'' below). alpar@1: alpar@1: \subsubsection*{Advanced solver interface} alpar@1: alpar@1: The routine \verb|glp_intopt| allows the user to control the alpar@1: branch-and-cut search by passing to the solver a user-defined callback alpar@1: routine. For more details see Chapter ``Branch-and-Cut API Routines''. alpar@1: alpar@1: \subsubsection*{Terminal output} alpar@1: alpar@1: Solving a MIP problem may take a long time, so the solver reports some alpar@1: information about best known solutions, which is sent to the terminal. alpar@1: This information has the following format: alpar@1: alpar@1: \begin{verbatim} alpar@1: +nnn: mip = xxx yyy gap (ppp; qqq) alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: where: `\verb|nnn|' is the simplex iteration number; `\verb|xxx|' is a alpar@1: value of the objective function for the best known integer feasible alpar@1: solution (if no integer feasible solution has been found yet, alpar@1: `\verb|xxx|' is the text `\verb|not found yet|'); `\verb|rho|' is the alpar@1: string `\verb|>=|' (in case of minimization) or `\verb|<=|' (in case of alpar@1: maximization); `\verb|yyy|' is a global bound for exact integer optimum alpar@1: (i.e. the exact integer optimum is always in the range from `\verb|xxx|' alpar@1: to `\verb|yyy|'); `\verb|gap|' is the relative mip gap, in percents, alpar@1: computed as $gap=|xxx-yyy|/(|xxx|+{\tt DBL\_EPSILON})\cdot 100\%$ (if alpar@1: $gap$ is greater than $999.9\%$, it is not printed); `\verb|ppp|' is the alpar@1: number of subproblems in the active list, `\verb|qqq|' is the number of alpar@1: subproblems which have been already fathomed and therefore removed from alpar@1: the branch-and-bound search tree. alpar@1: alpar@1: \subsubsection{Control parameters} alpar@1: alpar@1: This paragraph describes all control parameters currently used in the alpar@1: MIP solver. Symbolic names of control parameters are names of alpar@1: corresponding members in the structure \verb|glp_iocp|. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})} alpar@1: \\ alpar@1: &Message level for terminal output:\\ alpar@1: &\verb|GLP_MSG_OFF|---no output;\\ alpar@1: &\verb|GLP_MSG_ERR|---error and warning messages only;\\ alpar@1: &\verb|GLP_MSG_ON |---normal output;\\ alpar@1: &\verb|GLP_MSG_ALL|---full output (including informational messages). alpar@1: \\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int br\_tech} (default: {\tt GLP\_BR\_DTH})} alpar@1: \\ alpar@1: &Branching technique option:\\ alpar@1: &\verb|GLP_BR_FFV|---first fractional variable;\\ alpar@1: &\verb|GLP_BR_LFV|---last fractional variable;\\ alpar@1: &\verb|GLP_BR_MFV|---most fractional variable;\\ alpar@1: &\verb|GLP_BR_DTH|---heuristic by Driebeck and Tomlin;\\ alpar@1: &\verb|GLP_BR_PCH|---hybrid pseudocost heuristic.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int bt\_tech} (default: {\tt GLP\_BT\_BLB})} alpar@1: \\ alpar@1: &Backtracking technique option:\\ alpar@1: &\verb|GLP_BT_DFS|---depth first search;\\ alpar@1: &\verb|GLP_BT_BFS|---breadth first search;\\ alpar@1: &\verb|GLP_BT_BLB|---best local bound;\\ alpar@1: &\verb|GLP_BT_BPH|---best projection heuristic.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int pp\_tech} (default: {\tt GLP\_PP\_ALL})} alpar@1: \\ alpar@1: &Preprocessing technique option:\\ alpar@1: &\verb|GLP_PP_NONE|---disable preprocessing;\\ alpar@1: &\verb|GLP_PP_ROOT|---perform preprocessing only on the root level;\\ alpar@1: &\verb|GLP_PP_ALL |---perform preprocessing on all levels.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int fp\_heur} (default: {\tt GLP\_OFF})} alpar@1: \\ alpar@1: &Feasibility pump heuristic option:\\ alpar@1: &\verb|GLP_ON |---enable applying the feasibility pump heuristic;\\ alpar@1: &\verb|GLP_OFF|---disable applying the feasibility pump heuristic.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int gmi\_cuts} (default: {\tt GLP\_OFF})}\\ alpar@1: &Gomory's mixed integer cut option:\\ alpar@1: &\verb|GLP_ON |---enable generating Gomory's cuts;\\ alpar@1: &\verb|GLP_OFF|---disable generating Gomory's cuts.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int mir\_cuts} (default: {\tt GLP\_OFF})}\\ alpar@1: &Mixed integer rounding (MIR) cut option:\\ alpar@1: &\verb|GLP_ON |---enable generating MIR cuts;\\ alpar@1: &\verb|GLP_OFF|---disable generating MIR cuts.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int cov\_cuts} (default: {\tt GLP\_OFF})}\\ alpar@1: &Mixed cover cut option:\\ alpar@1: &\verb|GLP_ON |---enable generating mixed cover cuts;\\ alpar@1: &\verb|GLP_OFF|---disable generating mixed cover cuts.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int clq\_cuts} (default: {\tt GLP\_OFF})}\\ alpar@1: &Clique cut option:\\ alpar@1: &\verb|GLP_ON |---enable generating clique cuts;\\ alpar@1: &\verb|GLP_OFF|---disable generating clique cuts.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double tol\_int} (default: {\tt 1e-5})}\\ alpar@1: &Absolute tolerance used to check if optimal solution to the current LP alpar@1: relaxation is integer feasible. (Do not change this parameter without alpar@1: detailed understanding its purpose.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double tol\_obj} (default: {\tt 1e-7})}\\ alpar@1: &Relative tolerance used to check if the objective value in optimal alpar@1: solution to the current LP relaxation is not better than in the best alpar@1: known integer feasible solution. (Do not change this parameter without alpar@1: detailed understanding its purpose.)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt double mip\_gap} (default: {\tt 0.0})}\\ alpar@1: &The relative mip gap tolerance. If the relative mip gap for currently alpar@1: known best integer feasible solution falls below this tolerance, the alpar@1: solver terminates the search. This allows obtainig suboptimal integer alpar@1: feasible solutions if solving the problem to optimality takes too long alpar@1: time.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int tm\_lim} (default: {\tt INT\_MAX})}\\ alpar@1: &Searching time limit, in milliseconds.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int out\_frq} (default: {\tt 5000})}\\ alpar@1: &Output frequency, in milliseconds. This parameter specifies how alpar@1: frequently the solver sends information about the solution process to alpar@1: the terminal.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int out\_dly} (default: {\tt 10000})}\\ alpar@1: &Output delay, in milliseconds. This parameter specifies how long the alpar@1: solver should delay sending information about solution of the current alpar@1: LP relaxation with the simplex method to the terminal.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l} alpar@1: {{\tt void (*cb\_func)(glp\_tree *tree, void *info)} alpar@1: (default: {\tt NULL})}\\ alpar@1: &Entry point to the user-defined callback routine. \verb|NULL| means alpar@1: the advanced solver interface is not used. For more details see Chapter alpar@1: ``Branch-and-Cut API Routines''.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt void *cb\_info} (default: {\tt NULL})}\\ alpar@1: &Transit pointer passed to the routine \verb|cb_func| (see above).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int cb\_size} (default: {\tt 0})}\\ alpar@1: &The number of extra (up to 256) bytes allocated for each node of the alpar@1: branch-and-bound tree to store application-specific data. On creating alpar@1: a node these bytes are initialized by binary zeros.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int presolve} (default: {\tt GLP\_OFF})}\\ alpar@1: &MIP presolver option:\\ alpar@1: &\verb|GLP_ON |---enable using the MIP presolver;\\ alpar@1: &\verb|GLP_OFF|---disable using the MIP presolver.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}} alpar@1: \multicolumn{2}{@{}l}{{\tt int binarize} (default: {\tt GLP\_OFF})}\\ alpar@1: &Binarization option (used only if the presolver is enabled):\\ alpar@1: &\verb|GLP_ON |---replace general integer variables by binary ones;\\ alpar@1: &\verb|GLP_OFF|---do not use binarization.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_init\_iocp---initialize integer optimizer control alpar@1: parameters} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void glp_init_iocp(glp_iocp *parm); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|glp_init_iocp| initializes control parameters, which alpar@1: are used by the branch-and-cut solver, with default values. alpar@1: alpar@1: Default values of the control parameters are stored in a \verb|glp_iocp| alpar@1: structure, which the parameter \verb|parm| points to. alpar@1: alpar@1: \subsection{glp\_mip\_status---determine status of MIP solution} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: int glp_mip_status(glp_prob *mip); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_mip_status| reports the status of a MIP solution alpar@1: found by the MIP solver as follows: alpar@1: alpar@1: \smallskip alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{91.3mm}@{}} alpar@1: \verb|GLP_UNDEF| & MIP solution is undefined. \\ alpar@1: \verb|GLP_OPT| & MIP solution is integer optimal. \\ alpar@1: \verb|GLP_FEAS| & MIP solution is integer feasible, however, its alpar@1: optimality (or non-optimality) has not been proven, perhaps due to alpar@1: premature termination of the search. \\ alpar@1: \end{tabular} alpar@1: alpar@1: \begin{tabular}{@{}p{25mm}p{91.3mm}@{}} alpar@1: \verb|GLP_NOFEAS| & problem has no integer feasible solution (proven by alpar@1: the solver). \\ alpar@1: \end{tabular} alpar@1: alpar@1: \subsection{glp\_mip\_obj\_val---retrieve objective value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_mip_obj_val(glp_prob *mip); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_mip_obj_val| returns value of the objective alpar@1: function for MIP solution. alpar@1: alpar@1: \subsection{glp\_mip\_row\_val---retrieve row value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_mip_row_val(glp_prob *mip, int i); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_mip_row_val| returns value of the auxiliary alpar@1: variable associated with \verb|i|-th row for MIP solution. alpar@1: alpar@1: \subsection{glp\_mip\_col\_val---retrieve column value} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: double glp_mip_col_val(glp_prob *mip, int j); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Returns} alpar@1: alpar@1: The routine \verb|glp_mip_col_val| returns value of the structural alpar@1: variable associated with \verb|j|-th column for MIP solution. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Additional routines} alpar@1: alpar@1: \subsection{lpx\_check\_kkt---check Karush-Kuhn-Tucker optimality alpar@1: conditions} alpar@1: alpar@1: \subsubsection*{Synopsis} alpar@1: alpar@1: \begin{verbatim} alpar@1: void lpx_check_kkt(glp_prob *lp, int scaled, LPXKKT *kkt); alpar@1: \end{verbatim} alpar@1: alpar@1: \subsubsection*{Description} alpar@1: alpar@1: The routine \verb|lpx_check_kkt| checks Karush-Kuhn-Tucker optimality alpar@1: conditions for basic solution. It is assumed that both primal and dual alpar@1: components of basic solution are valid. alpar@1: alpar@1: If the parameter \verb|scaled| is zero, the optimality conditions are alpar@1: checked for the original, unscaled LP problem. Otherwise, if the alpar@1: parameter \verb|scaled| is non-zero, the routine checks the conditions alpar@1: for an internally scaled LP problem. alpar@1: alpar@1: The parameter \verb|kkt| is a pointer to the structure \verb|LPXKKT|, alpar@1: to which the routine stores results of the check. Members of this alpar@1: structure are shown in the table below. alpar@1: alpar@1: \begin{table}[h] alpar@1: \begin{center} alpar@1: \begin{tabular}{@{}c|l|l@{}} alpar@1: Condition & Member & Comment \\ alpar@1: \hline alpar@1: (KKT.PE) & \verb|pe_ae_max| & alpar@1: Largest absolute error \\ alpar@1: & \verb|pe_ae_row| & alpar@1: Number of row with largest absolute error \\ alpar@1: & \verb|pe_re_max| & alpar@1: Largest relative error \\ alpar@1: & \verb|pe_re_row| & alpar@1: Number of row with largest relative error \\ alpar@1: & \verb|pe_quality| & alpar@1: Quality of primal solution \\ alpar@1: \hline alpar@1: (KKT.PB) & \verb|pb_ae_max| & alpar@1: Largest absolute error \\ alpar@1: & \verb|pb_ae_ind| & alpar@1: Number of variable with largest absolute error \\ alpar@1: & \verb|pb_re_max| & alpar@1: Largest relative error \\ alpar@1: & \verb|pb_re_ind| & alpar@1: Number of variable with largest relative error \\ alpar@1: & \verb|pb_quality| & alpar@1: Quality of primal feasibility \\ alpar@1: \hline alpar@1: (KKT.DE) & \verb|de_ae_max| & alpar@1: Largest absolute error \\ alpar@1: & \verb|de_ae_col| & alpar@1: Number of column with largest absolute error \\ alpar@1: & \verb|de_re_max| & alpar@1: Largest relative error \\ alpar@1: & \verb|de_re_col| & alpar@1: Number of column with largest relative error \\ alpar@1: & \verb|de_quality| & alpar@1: Quality of dual solution \\ alpar@1: \hline alpar@1: (KKT.DB) & \verb|db_ae_max| & alpar@1: Largest absolute error \\ alpar@1: & \verb|db_ae_ind| & alpar@1: Number of variable with largest absolute error \\ alpar@1: & \verb|db_re_max| & alpar@1: Largest relative error \\ alpar@1: & \verb|db_re_ind| & alpar@1: Number of variable with largest relative error \\ alpar@1: & \verb|db_quality| & alpar@1: Quality of dual feasibility \\ alpar@1: \end{tabular} alpar@1: \end{center} alpar@1: \end{table} alpar@1: alpar@1: The routine performs all computations using only components of the alpar@1: given LP problem and the current basic solution. alpar@1: alpar@1: \subsubsection*{Background} alpar@1: alpar@1: The first condition checked by the routine is: alpar@1: $$x_R - A x_S = 0, \eqno{\rm (KKT.PE)}$$ alpar@1: where $x_R$ is the subvector of auxiliary variables (rows), $x_S$ is the alpar@1: subvector of structural variables (columns), $A$ is the constraint alpar@1: matrix. This condition expresses the requirement that all primal alpar@1: variables must satisfy to the system of equality constraints of the alpar@1: original LP problem. In case of exact arithmetic this condition would be alpar@1: satisfied for any basic solution; however, in case of inexact alpar@1: (floating-point) arithmetic, this condition shows how accurate the alpar@1: primal basic solution is, that depends on accuracy of a representation alpar@1: of the basis matrix used by the simplex method routines. alpar@1: alpar@1: The second condition checked by the routine is: alpar@1: $$l_k \leq x_k \leq u_k {\rm \ \ \ for\ all}\ k=1,\dots,m+n, alpar@1: \eqno{\rm (KKT.PB)}$$ alpar@1: where $x_k$ is auxiliary ($1\leq k\leq m$) or structural alpar@1: ($m+1\leq k\leq m+n$) variable, $l_k$ and $u_k$ are, respectively, alpar@1: lower and upper bounds of the variable $x_k$ (including cases of alpar@1: infinite bounds). This condition expresses the requirement that all alpar@1: primal variables must satisfy to bound constraints of the original LP alpar@1: problem. Since in case of basic solution all non-basic variables are alpar@1: placed on their bounds, actually the condition (KKT.PB) needs to be alpar@1: checked for basic variables only. If the primal basic solution has alpar@1: sufficient accuracy, this condition shows primal feasibility of the alpar@1: solution. alpar@1: alpar@1: The third condition checked by the routine is: alpar@1: $${\rm grad}\;Z = c = (\tilde{A})^T \pi + d,$$ alpar@1: where $Z$ is the objective function, $c$ is the vector of objective alpar@1: coefficients, $(\tilde{A})^T$ is a matrix transposed to the expanded alpar@1: constraint matrix $\tilde{A} = (I|-A)$, $\pi$ is a vector of Lagrange alpar@1: multipliers that correspond to equality constraints of the original LP alpar@1: problem, $d$ is a vector of Lagrange multipliers that correspond to alpar@1: bound constraints for all (auxiliary and structural) variables of the alpar@1: original LP problem. Geometrically the third condition expresses the alpar@1: requirement that the gradient of the objective function must belong to alpar@1: the orthogonal complement of a linear subspace defined by the equality alpar@1: and active bound constraints, i.e. that the gradient must be a linear alpar@1: combination of normals to the constraint planes, where Lagrange alpar@1: multipliers $\pi$ and $d$ are coefficients of that linear combination. alpar@1: alpar@1: To eliminate the vector $\pi$ the third condition can be rewritten as: alpar@1: $$ alpar@1: \left(\begin{array}{@{}c@{}}I \\ -A^T\end{array}\right) \pi = alpar@1: \left(\begin{array}{@{}c@{}}d_R \\ d_S\end{array}\right) + alpar@1: \left(\begin{array}{@{}c@{}}c_R \\ c_S\end{array}\right), alpar@1: $$ alpar@1: or, equivalently: alpar@1: $$ alpar@1: \begin{array}{r@{}c@{}c} alpar@1: \pi + d_R&\ =\ &c_R, \\ alpar@1: -A^T\pi + d_S&\ =\ &c_S. \\ alpar@1: \end{array} alpar@1: $$ alpar@1: Then substituting the vector $\pi$ from the first equation into the alpar@1: second one we have: alpar@1: $$A^T (d_R - c_R) + (d_S - c_S) = 0, \eqno{\rm (KKT.DE)}$$ alpar@1: where $d_R$ is the subvector of reduced costs of auxiliary variables alpar@1: (rows), $d_S$ is the subvector of reduced costs of structural variables alpar@1: (columns), $c_R$ and $c_S$ are subvectors of objective coefficients at, alpar@1: respectively, auxiliary and structural variables, $A^T$ is a matrix alpar@1: transposed to the constraint matrix of the original LP problem. In case alpar@1: of exact arithmetic this condition would be satisfied for any basic alpar@1: solution; however, in case of inexact (floating-point) arithmetic, this alpar@1: condition shows how accurate the dual basic solution is, that depends on alpar@1: accuracy of a representation of the basis matrix used by the simplex alpar@1: method routines. alpar@1: alpar@1: The last, fourth condition checked by the routine is (KKT.DB): alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{r@{}c@{}ll} alpar@1: &$\ d_k\ $& $=0,$&if $x_k$ is basic or free non-basic variable \\ alpar@1: $0\leq$&$\ d_k\ $&$<+\infty$&if $x_k$ is non-basic on its lower alpar@1: (minimization) \\ alpar@1: &&&or upper (maximization) bound \\ alpar@1: $-\infty<$&$\ d_k\ $&$\leq 0$&if $x_k$ is non-basic on its upper alpar@1: (minimization) \\ alpar@1: &&&or lower (maximization) bound \\ alpar@1: $-\infty<$&$\ d_k\ $&$<+\infty$&if $x_k$ is non-basic fixed variable \\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: for all $k=1,\dots,m+n$, where $d_k$ is a reduced cost (Lagrange alpar@1: multiplier) of auxiliary ($1\leq k\leq m$) or structural alpar@1: ($m+1\leq k\leq m+n$) variable $x_k$. Geometrically this condition alpar@1: expresses the requirement that constraints of the original problem must alpar@1: "hold" the point preventing its movement along the anti-gradient (in alpar@1: case of minimization) or the gradient (in case of maximization) of the alpar@1: objective function. Since in case of basic solution reduced costs of alpar@1: all basic variables are placed on their (zero) bounds, actually the alpar@1: condition (KKT.DB) needs to be checked for non-basic variables only. alpar@1: If the dual basic solution has sufficient accuracy, this condition shows alpar@1: dual feasibility of the solution. alpar@1: alpar@1: Should note that the complete set of Karush-Kuhn-Tucker optimality alpar@1: conditions also includes the fifth, so called complementary slackness alpar@1: condition, which expresses the requirement that at least either a primal alpar@1: variable $x_k$ or its dual counterpart $d_k$ must be on its bound for alpar@1: all $k=1,\dots,m+n$. However, being always satisfied by definition for alpar@1: any basic solution that condition is not checked by the routine. alpar@1: alpar@1: To check the first condition (KKT.PE) the routine computes a vector of alpar@1: residuals: alpar@1: $$g = x_R - A x_S,$$ alpar@1: determines component of this vector that correspond to largest absolute alpar@1: and relative errors: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|pe_ae_max| $\displaystyle{= \max_{1\leq i\leq m}|g_i|}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|pe_re_max| $\displaystyle{= \max_{1\leq i\leq m} alpar@1: \frac{|g_i|}{1+|(x_R)_i|}}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: and stores these quantities and corresponding row indices to the alpar@1: structure \verb|LPXKKT|. alpar@1: alpar@1: To check the second condition (KKT.PB) the routine computes a vector alpar@1: of residuals: alpar@1: $$ alpar@1: h_k = \left\{ alpar@1: \begin{array}{ll} alpar@1: 0, & {\rm if}\ l_k \leq x_k \leq u_k \\ alpar@1: x_k - l_k, & {\rm if}\ x_k < l_k \\ alpar@1: x_k - u_k, & {\rm if}\ x_k > u_k \\ alpar@1: \end{array} alpar@1: \right. alpar@1: $$ alpar@1: for all $k=1,\dots,m+n$, determines components of this vector that alpar@1: correspond to largest absolute and relative errors: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|pb_ae_max| $\displaystyle{= \max_{1\leq k \leq m+n}|h_k|}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|pb_re_max| $\displaystyle{= \max_{1\leq k \leq m+n} alpar@1: \frac{|h_k|}{1+|x_k|}}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: and stores these quantities and corresponding variable indices to the alpar@1: structure \verb|LPXKKT|. alpar@1: alpar@1: To check the third condition (KKT.DE) the routine computes a vector of alpar@1: residuals: alpar@1: $$u = A^T (d_R - c_R) + (d_S - c_S),$$ alpar@1: determines components of this vector that correspond to largest alpar@1: absolute and relative errors: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|de_ae_max| $\displaystyle{= \max_{1\leq j\leq n}|u_j|}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|de_re_max| $\displaystyle{= \max_{1\leq j\leq n} alpar@1: \frac{|u_j|}{1+|(d_S)_j - (c_S)_j|}}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: and stores these quantities and corresponding column indices to the alpar@1: structure \verb|LPXKKT|. alpar@1: alpar@1: To check the fourth condition (KKT.DB) the routine computes a vector alpar@1: of residuals: alpar@1: alpar@1: $$ alpar@1: v_k = \left\{ alpar@1: \begin{array}{ll} alpar@1: 0, & {\rm if}\ d_k\ {\rm has\ correct\ sign} \\ alpar@1: d_k, & {\rm if}\ d_k\ {\rm has\ wrong\ sign} \\ alpar@1: \end{array} alpar@1: \right. alpar@1: $$ alpar@1: for all $k=1,\dots,m+n$, determines components of this vector that alpar@1: correspond to largest absolute and relative errors: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|db_ae_max| $\displaystyle{= \max_{1\leq k\leq m+n}|v_k|}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{30mm} alpar@1: \verb|db_re_max| $\displaystyle{= \max_{1\leq k\leq m+n} alpar@1: \frac{|v_k|}{1+|d_k - c_k|}}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: and stores these quantities and corresponding variable indices to the alpar@1: structure \verb|LPXKKT|. alpar@1: alpar@1: Using the relative errors for all the four conditions listed above the alpar@1: routine alpar@1: \verb|lpx_check_kkt| also estimates a "quality" of the basic solution alpar@1: from the standpoint of these conditions and stores corresponding alpar@1: quality indicators to the structure \verb|LPXKKT|: alpar@1: alpar@1: \verb|pe_quality|---quality of primal solution; alpar@1: alpar@1: \verb|pb_quality|---quality of primal feasibility; alpar@1: alpar@1: \verb|de_quality|---quality of dual solution; alpar@1: alpar@1: \verb|db_quality|---quality of dual feasibility. alpar@1: alpar@1: Each of these indicators is assigned to one of the following four alpar@1: values: alpar@1: alpar@1: \verb|'H'| means high quality, alpar@1: alpar@1: \verb|'M'| means medium quality, alpar@1: alpar@1: \verb|'L'| means low quality, or alpar@1: alpar@1: \verb|'?'| means wrong or infeasible solution. alpar@1: alpar@1: If all the indicators show high or medium quality (for an internally alpar@1: scaled LP problem, i.e. when the parameter \verb|scaled| in a call to alpar@1: the routine \verb|lpx_check_kkt| is non-zero), the user can be sure that alpar@1: the obtained basic solution is quite accurate. alpar@1: alpar@1: If some of the indicators show low quality, the solution can still be alpar@1: considered as relevant, though an additional analysis is needed alpar@1: depending on which indicator shows low quality. alpar@1: alpar@1: If the indicator \verb|pe_quality| is assigned to \verb|'?'|, the alpar@1: primal solution is wrong. If the indicator \verb|de_quality| is assigned alpar@1: to \verb|'?'|, the dual solution is wrong. alpar@1: alpar@1: If the indicator \verb|db_quality| is assigned to \verb|'?'| while alpar@1: other indicators show a good quality, this means that the current alpar@1: basic solution being primal feasible is not dual feasible. Similarly, alpar@1: if the indicator \verb|pb_quality| is assigned to \verb|'?'| while alpar@1: other indicators are not, this means that the current basic solution alpar@1: being dual feasible is not primal feasible. alpar@1: alpar@1: %* eof *%