lemon-project-template-glpk

annotate deps/glpk/src/glpapi05.c @ 11:4fc6ad2fb8a6

Test GLPK in src/main.cc
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 21:43:29 +0100
parents
children
rev   line source
alpar@9 1 /* glpapi05.c (LP basis constructing routines) */
alpar@9 2
alpar@9 3 /***********************************************************************
alpar@9 4 * This code is part of GLPK (GNU Linear Programming Kit).
alpar@9 5 *
alpar@9 6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@9 7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
alpar@9 8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@9 9 * E-mail: <mao@gnu.org>.
alpar@9 10 *
alpar@9 11 * GLPK is free software: you can redistribute it and/or modify it
alpar@9 12 * under the terms of the GNU General Public License as published by
alpar@9 13 * the Free Software Foundation, either version 3 of the License, or
alpar@9 14 * (at your option) any later version.
alpar@9 15 *
alpar@9 16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@9 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@9 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@9 19 * License for more details.
alpar@9 20 *
alpar@9 21 * You should have received a copy of the GNU General Public License
alpar@9 22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@9 23 ***********************************************************************/
alpar@9 24
alpar@9 25 #include "glpapi.h"
alpar@9 26
alpar@9 27 /***********************************************************************
alpar@9 28 * NAME
alpar@9 29 *
alpar@9 30 * glp_set_row_stat - set (change) row status
alpar@9 31 *
alpar@9 32 * SYNOPSIS
alpar@9 33 *
alpar@9 34 * void glp_set_row_stat(glp_prob *lp, int i, int stat);
alpar@9 35 *
alpar@9 36 * DESCRIPTION
alpar@9 37 *
alpar@9 38 * The routine glp_set_row_stat sets (changes) status of the auxiliary
alpar@9 39 * variable associated with i-th row.
alpar@9 40 *
alpar@9 41 * The new status of the auxiliary variable should be specified by the
alpar@9 42 * parameter stat as follows:
alpar@9 43 *
alpar@9 44 * GLP_BS - basic variable;
alpar@9 45 * GLP_NL - non-basic variable;
alpar@9 46 * GLP_NU - non-basic variable on its upper bound; if the variable is
alpar@9 47 * not double-bounded, this means the same as GLP_NL (only in
alpar@9 48 * case of this routine);
alpar@9 49 * GLP_NF - the same as GLP_NL (only in case of this routine);
alpar@9 50 * GLP_NS - the same as GLP_NL (only in case of this routine). */
alpar@9 51
alpar@9 52 void glp_set_row_stat(glp_prob *lp, int i, int stat)
alpar@9 53 { GLPROW *row;
alpar@9 54 if (!(1 <= i && i <= lp->m))
alpar@9 55 xerror("glp_set_row_stat: i = %d; row number out of range\n",
alpar@9 56 i);
alpar@9 57 if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU ||
alpar@9 58 stat == GLP_NF || stat == GLP_NS))
alpar@9 59 xerror("glp_set_row_stat: i = %d; stat = %d; invalid status\n",
alpar@9 60 i, stat);
alpar@9 61 row = lp->row[i];
alpar@9 62 if (stat != GLP_BS)
alpar@9 63 { switch (row->type)
alpar@9 64 { case GLP_FR: stat = GLP_NF; break;
alpar@9 65 case GLP_LO: stat = GLP_NL; break;
alpar@9 66 case GLP_UP: stat = GLP_NU; break;
alpar@9 67 case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break;
alpar@9 68 case GLP_FX: stat = GLP_NS; break;
alpar@9 69 default: xassert(row != row);
alpar@9 70 }
alpar@9 71 }
alpar@9 72 if (row->stat == GLP_BS && stat != GLP_BS ||
alpar@9 73 row->stat != GLP_BS && stat == GLP_BS)
alpar@9 74 { /* invalidate the basis factorization */
alpar@9 75 lp->valid = 0;
alpar@9 76 }
alpar@9 77 row->stat = stat;
alpar@9 78 return;
alpar@9 79 }
alpar@9 80
alpar@9 81 /***********************************************************************
alpar@9 82 * NAME
alpar@9 83 *
alpar@9 84 * glp_set_col_stat - set (change) column status
alpar@9 85 *
alpar@9 86 * SYNOPSIS
alpar@9 87 *
alpar@9 88 * void glp_set_col_stat(glp_prob *lp, int j, int stat);
alpar@9 89 *
alpar@9 90 * DESCRIPTION
alpar@9 91 *
alpar@9 92 * The routine glp_set_col_stat sets (changes) status of the structural
alpar@9 93 * variable associated with j-th column.
alpar@9 94 *
alpar@9 95 * The new status of the structural variable should be specified by the
alpar@9 96 * parameter stat as follows:
alpar@9 97 *
alpar@9 98 * GLP_BS - basic variable;
alpar@9 99 * GLP_NL - non-basic variable;
alpar@9 100 * GLP_NU - non-basic variable on its upper bound; if the variable is
alpar@9 101 * not double-bounded, this means the same as GLP_NL (only in
alpar@9 102 * case of this routine);
alpar@9 103 * GLP_NF - the same as GLP_NL (only in case of this routine);
alpar@9 104 * GLP_NS - the same as GLP_NL (only in case of this routine). */
alpar@9 105
alpar@9 106 void glp_set_col_stat(glp_prob *lp, int j, int stat)
alpar@9 107 { GLPCOL *col;
alpar@9 108 if (!(1 <= j && j <= lp->n))
alpar@9 109 xerror("glp_set_col_stat: j = %d; column number out of range\n"
alpar@9 110 , j);
alpar@9 111 if (!(stat == GLP_BS || stat == GLP_NL || stat == GLP_NU ||
alpar@9 112 stat == GLP_NF || stat == GLP_NS))
alpar@9 113 xerror("glp_set_col_stat: j = %d; stat = %d; invalid status\n",
alpar@9 114 j, stat);
alpar@9 115 col = lp->col[j];
alpar@9 116 if (stat != GLP_BS)
alpar@9 117 { switch (col->type)
alpar@9 118 { case GLP_FR: stat = GLP_NF; break;
alpar@9 119 case GLP_LO: stat = GLP_NL; break;
alpar@9 120 case GLP_UP: stat = GLP_NU; break;
alpar@9 121 case GLP_DB: if (stat != GLP_NU) stat = GLP_NL; break;
alpar@9 122 case GLP_FX: stat = GLP_NS; break;
alpar@9 123 default: xassert(col != col);
alpar@9 124 }
alpar@9 125 }
alpar@9 126 if (col->stat == GLP_BS && stat != GLP_BS ||
alpar@9 127 col->stat != GLP_BS && stat == GLP_BS)
alpar@9 128 { /* invalidate the basis factorization */
alpar@9 129 lp->valid = 0;
alpar@9 130 }
alpar@9 131 col->stat = stat;
alpar@9 132 return;
alpar@9 133 }
alpar@9 134
alpar@9 135 /***********************************************************************
alpar@9 136 * NAME
alpar@9 137 *
alpar@9 138 * glp_std_basis - construct standard initial LP basis
alpar@9 139 *
alpar@9 140 * SYNOPSIS
alpar@9 141 *
alpar@9 142 * void glp_std_basis(glp_prob *lp);
alpar@9 143 *
alpar@9 144 * DESCRIPTION
alpar@9 145 *
alpar@9 146 * The routine glp_std_basis builds the "standard" (trivial) initial
alpar@9 147 * basis for the specified problem object.
alpar@9 148 *
alpar@9 149 * In the "standard" basis all auxiliary variables are basic, and all
alpar@9 150 * structural variables are non-basic. */
alpar@9 151
alpar@9 152 void glp_std_basis(glp_prob *lp)
alpar@9 153 { int i, j;
alpar@9 154 /* make all auxiliary variables basic */
alpar@9 155 for (i = 1; i <= lp->m; i++)
alpar@9 156 glp_set_row_stat(lp, i, GLP_BS);
alpar@9 157 /* make all structural variables non-basic */
alpar@9 158 for (j = 1; j <= lp->n; j++)
alpar@9 159 { GLPCOL *col = lp->col[j];
alpar@9 160 if (col->type == GLP_DB && fabs(col->lb) > fabs(col->ub))
alpar@9 161 glp_set_col_stat(lp, j, GLP_NU);
alpar@9 162 else
alpar@9 163 glp_set_col_stat(lp, j, GLP_NL);
alpar@9 164 }
alpar@9 165 return;
alpar@9 166 }
alpar@9 167
alpar@9 168 /* eof */