📄 glpk02.tex
字号:
assigning appropriate statuses to auxiliary and structural variables.Another way to construct an initial basis is to use API routines like\verb|glp_adv_basis|, which implement so called{\it crashing}.\footnote{This term is from early linear programmingsystems and means a heuristic to construct a valid initial basis.} Notethat on normal exit the simplex solver remains the basis valid, so incase of reoptimization there is no need to construct an initial basisfrom scratch.\subsection{glp\_set\_row\_stat---set (change) row status}\subsubsection*{Synopsis}\begin{verbatim}void glp_set_row_stat(glp_prob *lp, int i, int stat);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_set_row_stat| sets (changes) the current statusof \verb|i|-th row (auxiliary variable) as specified by the parameter\verb|stat|:\begin{tabular}{@{}lp{104.2mm}@{}}\verb|GLP_BS| & make the row basic (make the constraint inactive); \\\verb|GLP_NL| & make the row non-basic (make the constraint active); \\\end{tabular}\newpage\begin{tabular}{@{}lp{104.2mm}@{}}\verb|GLP_NU| & make the row non-basic and set it to the upper bound; if the row is not double-bounded, this status is equivalent to \verb|GLP_NL| (only in the case of this routine); \\\verb|GLP_NF| & the same as \verb|GLP_NL| (only in the case of this routine); \\\verb|GLP_NS| & the same as \verb|GLP_NL| (only in the case of this routine). \\\end{tabular}\subsection{glp\_set\_col\_stat---set (change) column status}\subsubsection*{Synopsis}\begin{verbatim}void glp_set_col_stat(glp_prob *lp, int j, int stat);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_set_col_stat sets| (changes) the current statusof \verb|j|-th column (structural variable) as specified by theparameter \verb|stat|:\begin{tabular}{@{}lp{104.2mm}@{}}\verb|GLP_BS| & make the column basic; \\\verb|GLP_NL| & make the column non-basic; \\\verb|GLP_NU| & make the column non-basic and set it to the upper bound; if the column is not double-bounded, this status is equivalent to \verb|GLP_NL| (only in the case of this routine); \\\verb|GLP_NF| & the same as \verb|GLP_NL| (only in the case of this routine); \\\verb|GLP_NS| & the same as \verb|GLP_NL| (only in the case of this routine).\end{tabular}\subsection{glp\_std\_basis---construct standard initial LP basis}\subsubsection*{Synopsis}\begin{verbatim}void glp_std_basis(glp_prob *lp);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_std_basis| constructs the ``standard'' (trivial)initial LP basis for the specified problem object.In the ``standard'' LP basis all auxiliary variables (rows) are basic,and all structural variables (columns) are non-basic (so thecorresponding basis matrix is unity).\newpage\subsection{glp\_adv\_basis---construct advanced initial LP basis}\subsubsection*{Synopsis}\begin{verbatim}void glp_adv_basis(glp_prob *lp, int flags);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_adv_basis| constructs an advanced initial LPbasis for the specified problem object.The parameter \verb|flags| is reserved for use in the future and mustbe specified as zero.In order to construct the advanced initial LP basis the routine doesthe following:1) includes in the basis all non-fixed auxiliary variables;2) includes in the basis as many non-fixed structural variables aspossible keeping the triangular form of the basis matrix;3) includes in the basis appropriate (fixed) auxiliary variables tocomplete the basis.As a result the initial LP basis has as few fixed variables as possibleand the corresponding basis matrix is triangular.\subsection{glp\_cpx\_basis---construct Bixby's initial LP basis}\subsubsection*{Synopsis}\begin{verbatim}void glp_cpx_basis(glp_prob *lp);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_cpx_basis| constructs an initial basis for thespecified problem object with the algorithm proposed byR.~Bixby.\footnote{Robert E. Bixby, ``Implementing the Simplex Method:The Initial Basis.'' ORSA Journal on Computing, Vol. 4, No. 3, 1992,pp. 267-84.}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\newpage\section{Simplex method routines}The {\it simplex method} is a well known efficient numerical procedureto solve LP problems.On each iteration the simplex method transforms the original system ofequaility constraints (1.2) resolving them through different sets ofvariables to an equivalent system called {\it the simplex table} (orsometimes {\it the simplex tableau}), which has the following form:$$\begin{array}{r@{\:}c@{\:}r@{\:}c@{\:}r@{\:}c@{\:}r}z&=&d_1(x_N)_1&+&d_2(x_N)_2&+ \dots +&d_n(x_N)_n \\(x_B)_1&=&\xi_{11}(x_N)_1& +& \xi_{12}(x_N)_2& + \dots +& \xi_{1n}(x_N)_n \\(x_B)_2&=& \xi_{21}(x_N)_1& +& \xi_{22}(x_N)_2& + \dots +& \xi_{2n}(x_N)_n \\\multicolumn{7}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .} \\(x_B)_m&=&\xi_{m1}(x_N)_1& +& \xi_{m2}(x_N)_2& + \dots +& \xi_{mn}(x_N)_n \\\end{array} \eqno (2.1)$$where: $(x_B)_1, (x_B)_2, \dots, (x_B)_m$ are basic variables;$(x_N)_1, (x_N)_2, \dots, (x_N)_n$ are non-basic variables;$d_1, d_2, \dots, d_n$ are reduced costs;$\xi_{11}, \xi_{12}, \dots, \xi_{mn}$ are coefficients of thesimplex table. (May note that the original LP problem (1.1)---(1.3) alsohas the form of a simplex table, where all equalities are resolvedthrough auxiliary variables.)From the linear programming theory it is known that if an optimalsolution of the LP problem (1.1)---(1.3) exists, it can always bewritten in the form (2.1), where non-basic variables are set on theirbounds while values of the objective function and basic variables aredetermined by the corresponding equalities of the simplex table.A set of values of all basic and non-basic variables determined by thesimplex table is called {\it basic solution}. If all basic variables arewithin their bounds, the basic solution is called {\it (primal)feasible}, otherwise it is called {\it (primal) infeasible}. A feasiblebasic solution, which provides a smallest (in case of minimization) ora largest (in case of maximization) value of the objective function iscalled {\it optimal}. Therefore, for solving LP problem the simplexmethod tries to find its optimal basic solution.Primal feasibility of some basic solution may be stated by simplechecking if all basic variables are within their bounds. Basic solutionis optimal if additionally the following optimality conditions aresatisfied for all non-basic variables:\begin{center}\begin{tabular}{lcc}Status of $(x_N)_j$ & Minimization & Maximization \\\hline$(x_N)_j$ is free & $d_j = 0$ & $d_j = 0$ \\$(x_N)_j$ is on its lower bound & $d_j \geq 0$ & $d_j \leq 0$ \\$(x_N)_j$ is on its upper bound & $d_j \leq 0$ & $d_j \geq 0$ \\\end{tabular}\end{center}In other words, basic solution is optimal if there is no non-basicvariable, which changing in the feasible direction (i.e. increasing ifit is free or on its lower bound, or decreasing if it is free or on itsupper bound) can improve (i.e. decrease in case of minimization orincrease in case of maximization) the objective function.If all non-basic variables satisfy to the optimality conditions shownabove (independently on whether basic variables are within their boundsor not), the basic solution is called {\it dual feasible}, otherwise itis called {\it dual infeasible}.It may happen that some LP problem has no primal feasible solution dueto incorrect formulation---this means that its constraints conflictwith each other. It also may happen that some LP problem has unboundedsolution again due to incorrect formulation---this means that somenon-basic variable can improve the objective function, i.e. theoptimality conditions are violated, and at the same time this variablecan infinitely change in the feasible direction meeting no resistancefrom basic variables. (May note that in the latter case the LP problemhas no dual feasible solution.)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\subsection{glp\_simplex---solve LP problem with the primal or dualsimplex method}\subsubsection*{Synopsis}\begin{verbatim}int glp_simplex(glp_prob *lp, const glp_smcp *parm);\end{verbatim}\subsubsection*{Description}The routine \verb|glp_simplex| is a driver to the LP solver based onthe simplex method. This routine retrieves problem data from thespecified problem object, calls the solver to solve the probleminstance, and stores results of computations back into the problemobject.The simplex solver has a set of control parameters. Values of thecontrol parameters can be passed in the structure \verb|glp_smcp|,which the parameter \verb|parm| points to. For detailed description ofthis structure see paragraph ``Control parameters'' below.Before specifying some control parameters the application programshould initialize the structure \verb|glp_smcp| by default values ofall control parameters using the routine \verb|glp_init_smcp| (see thenext subsection). This is needed for backward compatibility, because inthe future there may appear new members in the structure\verb|glp_smcp|.The parameter \verb|parm| can be specified as \verb|NULL|, in whichcase the solver uses default settings.\subsubsection*{Returns}\def\arraystretch{1}\begin{tabular}{@{}p{25mm}p{97.3mm}@{}}0 & The LP problem instance has been successfully solved. (This codedoes {\it not} necessarily mean that the solver has found optimalsolution. It only means that the solution process was successful.) \\\verb|GLP_EBADB| & Unable to start the search, because the initial basisspecified in the problem object is invalid---the number of basic(auxiliary and structural) variables is not the same as the number ofrows in the problem object.\\\verb|GLP_ESING| & Unable to start the search, because the basis matrixcorresponding to the initial basis is singular within the workingprecision.\\\verb|GLP_ECOND| & Unable to start the search, because the basis matrixcorresponding to the initial basis is ill-conditioned, i.e. itscondition number is too large.\\\verb|GLP_EBOUND| & Unable to start the search, because somedouble-bounded (auxiliary or structural) variables have incorrectbounds.\\\verb|GLP_EFAIL| & The search was prematurely terminated due to thesolver failure.\\\verb|GLP_EOBJLL| & The search was prematurely terminated, because theobjective function being maximized has reached its lower limit andcontinues decreasing (the dual simplex only).\\\verb|GLP_EOBJUL| & The search was prematurely terminated, because theobjective function being minimized has reached its upper limit andcontinues increasing (the dual simplex only).\\\verb|GLP_EITLIM| & The search was prematurely terminated, because thesimplex iteration limit has been exceeded.\\\verb|GLP_ETMLIM| & The search was prematurely terminated, because thetime limit has been exceeded.\\\verb|GLP_ENOPFS| & The LP problem instance has no primal feasiblesolution (only if the LP presolver is used).\\\verb|GLP_ENODFS| & The LP problem instance has no dual feasiblesolution (only if the LP presolver is used).\\\end{tabular}\subsubsection*{Built-in LP presolver}The simplex solver has {\it built-in LP presolver}. It is a subprogramthat transforms the original LP problem specified in the problem objectto an equivalent LP problem, which may be easier for solving with thesimplex method than the original one. This is attained mainly due toreducing the problem size and improving its numeric properties (forexample, by removing some inactive constraints or by fixing somenon-basic variables). Once the transformed LP problem has been solved,the presolver transforms its basic solution back to the correspondingbasic solution of the original problem.Presolving is an optional feature of the routine \verb|glp_simplex|,and by default it is disabled. In order to enable the LP presolver thecontrol parameter \verb|presolve| should be set to \verb|GLP_ON| (seeparagraph ``Control parameters'' below). Presolving may be used whenthe problem instance is solved for the first time. However, onperforming re-optimization the presolver should be disabled.The presolving procedure is transparent to the API user in the sensethat all necessary processing is performed internally, and a basicsolution of the original problem recovered by the presolver is the sameas if it were computed directly, i.e. without presolving.Note that the presolver is able to recover only optimal solutions. Ifa computed solution is infeasible or non-optimal, the correspondingsolution of the original problem cannot be recovered and thereforeremains undefined. If you need to know a basic solution even if it isinfeasible or non-optimal, the presolver should be disabled.\subsubsection*{Terminal output}Solving large problem instances may take a long time, so the solverreports some information about the current basic solution, which is sentto the terminal. This information has the following format:\begin{verbatim}nnn: obj = xxx infeas = yyy (ddd)\end{verbatim}\noindentwhere: `\verb|nnn|' is the iteration number, `\verb|xxx|' is thecurrent value of the objective function (it is is unscaled and hascorrect sign); `\verb|yyy|' is the current sum of primal or dualinfeasibilities (it is scaled and therefore may be used only for visualestimating), `\verb|ddd|' is the current number of fixed basicvariables.The symbol preceding the iteration number indicates which phase of thesimplex method is in effect:{\it Blank} means that the solver is searching for primal feasiblesolution using the primal simplex or for dual feasible solution usingthe dual simplex;{\it Asterisk} (\verb|*|) means that the solver is searching foroptimal solution using the primal simplex;{\it Vertical dash} (\verb/|/) means that the solver is searching foroptimal solution using the dual simplex.\subsubsection*{Control parameters}This paragraph describes all control parameters currently used in thesimplex solver. Symbolic names of control parameters are names ofcorresponding members in the structure \verb|glp_smcp|.\medskip\noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}}\multicolumn{2}{@{}l}{{\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})}\\&Message level for terminal output:\\&\verb|GLP_MSG_OFF|---no output;\\&\verb|GLP_MSG_ERR|---error and warning messages only;\\&\verb|GLP_MSG_ON |---normal output;\\&\verb|GLP_MSG_ALL|---full output (including informational messages).\\\end{tabular}\medskip\noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}}\multicolumn{2}{@{}l}{{\tt int meth} (default: {\tt GLP\_PRIMAL})}\\&Simplex method option:\\&\verb|GLP_PRIMAL|---use two-phase primal simplex;\\&\verb|GLP_DUAL |---use two-phase dual simplex;\\&\verb|GLP_DUALP |---use two-phase dual simplex, and if it fails,switch to the\\&\verb| |$\:$ primal simplex.\\\end{tabular}\medskip\noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}}\multicolumn{2}{@{}l}{{\tt int pricing} (default: {\tt GLP\_PT\_PSE})}\\&Pricing technique:\\&\verb|GLP_PT_STD|---standard (textbook);\\&\verb|GLP_PT_PSE|---projected steepest edge.\\\end{tabular}\medskip\noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}}\multicolumn{2}{@{}l}{{\tt int r\_test} (default: {\tt GLP\_RT\_HAR})}\\&Ratio test technique:\\&\verb|GLP_RT_STD|---standard (textbook);\\&\verb|GLP_RT_HAR|---Harris' two-pass ratio test.\\\end{tabular}\medskip\noindent\begin{tabular}{@{}p{17pt}@{}p{120.5mm}@{}}\multicolumn{2}{@{}l}{{\tt double tol\_bnd} (default: {\tt 1e-7})}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -