src/glpapi05.c
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 06 Dec 2010 13:09:21 +0100
changeset 1 c445c931472f
permissions -rw-r--r--
Import glpk-4.45

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