1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/glpapi05.c Mon Dec 06 13:09:21 2010 +0100
1.3 @@ -0,0 +1,168 @@
1.4 +/* glpapi05.c (LP basis constructing routines) */
1.5 +
1.6 +/***********************************************************************
1.7 +* This code is part of GLPK (GNU Linear Programming Kit).
1.8 +*
1.9 +* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
1.10 +* 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
1.11 +* Moscow Aviation Institute, Moscow, Russia. All rights reserved.
1.12 +* E-mail: <mao@gnu.org>.
1.13 +*
1.14 +* GLPK is free software: you can redistribute it and/or modify it
1.15 +* under the terms of the GNU General Public License as published by
1.16 +* the Free Software Foundation, either version 3 of the License, or
1.17 +* (at your option) any later version.
1.18 +*
1.19 +* GLPK is distributed in the hope that it will be useful, but WITHOUT
1.20 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1.21 +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
1.22 +* License for more details.
1.23 +*
1.24 +* You should have received a copy of the GNU General Public License
1.25 +* along with GLPK. If not, see <http://www.gnu.org/licenses/>.
1.26 +***********************************************************************/
1.27 +
1.28 +#include "glpapi.h"
1.29 +
1.30 +/***********************************************************************
1.31 +* NAME
1.32 +*
1.33 +* glp_set_row_stat - set (change) row status
1.34 +*
1.35 +* SYNOPSIS
1.36 +*
1.37 +* void glp_set_row_stat(glp_prob *lp, int i, int stat);
1.38 +*
1.39 +* DESCRIPTION
1.40 +*
1.41 +* The routine glp_set_row_stat sets (changes) status of the auxiliary
1.42 +* variable associated with i-th row.
1.43 +*
1.44 +* The new status of the auxiliary variable should be specified by the
1.45 +* parameter stat as follows:
1.46 +*
1.47 +* GLP_BS - basic variable;
1.48 +* GLP_NL - non-basic variable;
1.49 +* GLP_NU - non-basic variable on its upper bound; if the variable is
1.50 +* not double-bounded, this means the same as GLP_NL (only in
1.51 +* case of this routine);
1.52 +* GLP_NF - the same as GLP_NL (only in case of this routine);
1.53 +* GLP_NS - the same as GLP_NL (only in case of this routine). */
1.54 +
1.55 +void glp_set_row_stat(glp_prob *lp, int i, int stat)
1.56 +{ GLPROW *row;
1.57 + if (!(1 <= i && i <= lp->m))
1.58 + xerror("glp_set_row_stat: i = %d; row number out of range\n",
1.59 + i);
1.60 + if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU ||
1.61 + stat == GLP_NF || stat == GLP_NS))
1.62 + xerror("glp_set_row_stat: i = %d; stat = %d; invalid status\n",
1.63 + i, stat);
1.64 + row = lp->row[i];
1.65 + if (stat != GLP_BS)
1.66 + { switch (row->type)
1.67 + { case GLP_FR: stat = GLP_NF; break;
1.68 + case GLP_LO: stat = GLP_NL; break;
1.69 + case GLP_UP: stat = GLP_NU; break;
1.70 + case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break;
1.71 + case GLP_FX: stat = GLP_NS; break;
1.72 + default: xassert(row != row);
1.73 + }
1.74 + }
1.75 + if (row->stat == GLP_BS && stat != GLP_BS ||
1.76 + row->stat != GLP_BS && stat == GLP_BS)
1.77 + { /* invalidate the basis factorization */
1.78 + lp->valid = 0;
1.79 + }
1.80 + row->stat = stat;
1.81 + return;
1.82 +}
1.83 +
1.84 +/***********************************************************************
1.85 +* NAME
1.86 +*
1.87 +* glp_set_col_stat - set (change) column status
1.88 +*
1.89 +* SYNOPSIS
1.90 +*
1.91 +* void glp_set_col_stat(glp_prob *lp, int j, int stat);
1.92 +*
1.93 +* DESCRIPTION
1.94 +*
1.95 +* The routine glp_set_col_stat sets (changes) status of the structural
1.96 +* variable associated with j-th column.
1.97 +*
1.98 +* The new status of the structural variable should be specified by the
1.99 +* parameter stat as follows:
1.100 +*
1.101 +* GLP_BS - basic variable;
1.102 +* GLP_NL - non-basic variable;
1.103 +* GLP_NU - non-basic variable on its upper bound; if the variable is
1.104 +* not double-bounded, this means the same as GLP_NL (only in
1.105 +* case of this routine);
1.106 +* GLP_NF - the same as GLP_NL (only in case of this routine);
1.107 +* GLP_NS - the same as GLP_NL (only in case of this routine). */
1.108 +
1.109 +void glp_set_col_stat(glp_prob *lp, int j, int stat)
1.110 +{ GLPCOL *col;
1.111 + if (!(1 <= j && j <= lp->n))
1.112 + xerror("glp_set_col_stat: j = %d; column number out of range\n"
1.113 + , j);
1.114 + if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU ||
1.115 + stat == GLP_NF || stat == GLP_NS))
1.116 + xerror("glp_set_col_stat: j = %d; stat = %d; invalid status\n",
1.117 + j, stat);
1.118 + col = lp->col[j];
1.119 + if (stat != GLP_BS)
1.120 + { switch (col->type)
1.121 + { case GLP_FR: stat = GLP_NF; break;
1.122 + case GLP_LO: stat = GLP_NL; break;
1.123 + case GLP_UP: stat = GLP_NU; break;
1.124 + case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break;
1.125 + case GLP_FX: stat = GLP_NS; break;
1.126 + default: xassert(col != col);
1.127 + }
1.128 + }
1.129 + if (col->stat == GLP_BS && stat != GLP_BS ||
1.130 + col->stat != GLP_BS && stat == GLP_BS)
1.131 + { /* invalidate the basis factorization */
1.132 + lp->valid = 0;
1.133 + }
1.134 + col->stat = stat;
1.135 + return;
1.136 +}
1.137 +
1.138 +/***********************************************************************
1.139 +* NAME
1.140 +*
1.141 +* glp_std_basis - construct standard initial LP basis
1.142 +*
1.143 +* SYNOPSIS
1.144 +*
1.145 +* void glp_std_basis(glp_prob *lp);
1.146 +*
1.147 +* DESCRIPTION
1.148 +*
1.149 +* The routine glp_std_basis builds the "standard" (trivial) initial
1.150 +* basis for the specified problem object.
1.151 +*
1.152 +* In the "standard" basis all auxiliary variables are basic, and all
1.153 +* structural variables are non-basic. */
1.154 +
1.155 +void glp_std_basis(glp_prob *lp)
1.156 +{ int i, j;
1.157 + /* make all auxiliary variables basic */
1.158 + for (i = 1; i <= lp->m; i++)
1.159 + glp_set_row_stat(lp, i, GLP_BS);
1.160 + /* make all structural variables non-basic */
1.161 + for (j = 1; j <= lp->n; j++)
1.162 + { GLPCOL *col = lp->col[j];
1.163 + if (col->type == GLP_DB && fabs(col->lb) > fabs(col->ub))
1.164 + glp_set_col_stat(lp, j, GLP_NU);
1.165 + else
1.166 + glp_set_col_stat(lp, j, GLP_NL);
1.167 + }
1.168 + return;
1.169 +}
1.170 +
1.171 +/* eof */