src/glpapi04.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
/* glpapi04.c (problem scaling 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_rii - set (change) row scale factor
alpar@1
    31
*
alpar@1
    32
*  SYNOPSIS
alpar@1
    33
*
alpar@1
    34
*  void glp_set_rii(glp_prob *lp, int i, double rii);
alpar@1
    35
*
alpar@1
    36
*  DESCRIPTION
alpar@1
    37
*
alpar@1
    38
*  The routine glp_set_rii sets (changes) the scale factor r[i,i] for
alpar@1
    39
*  i-th row of the specified problem object. */
alpar@1
    40
alpar@1
    41
void glp_set_rii(glp_prob *lp, int i, double rii)
alpar@1
    42
{     if (!(1 <= i && i <= lp->m))
alpar@1
    43
         xerror("glp_set_rii: i = %d; row number out of range\n", i);
alpar@1
    44
      if (rii <= 0.0)
alpar@1
    45
         xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
alpar@1
    46
            i, rii);
alpar@1
    47
      if (lp->valid && lp->row[i]->rii != rii)
alpar@1
    48
      {  GLPAIJ *aij;
alpar@1
    49
         for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
alpar@1
    50
         {  if (aij->col->stat == GLP_BS)
alpar@1
    51
            {  /* invalidate the basis factorization */
alpar@1
    52
               lp->valid = 0;
alpar@1
    53
               break;
alpar@1
    54
            }
alpar@1
    55
         }
alpar@1
    56
      }
alpar@1
    57
      lp->row[i]->rii = rii;
alpar@1
    58
      return;
alpar@1
    59
}
alpar@1
    60
alpar@1
    61
/***********************************************************************
alpar@1
    62
*  NAME
alpar@1
    63
*
alpar@1
    64
*  glp_set sjj - set (change) column scale factor
alpar@1
    65
*
alpar@1
    66
*  SYNOPSIS
alpar@1
    67
*
alpar@1
    68
*  void glp_set_sjj(glp_prob *lp, int j, double sjj);
alpar@1
    69
*
alpar@1
    70
*  DESCRIPTION
alpar@1
    71
*
alpar@1
    72
*  The routine glp_set_sjj sets (changes) the scale factor s[j,j] for
alpar@1
    73
*  j-th column of the specified problem object. */
alpar@1
    74
alpar@1
    75
void glp_set_sjj(glp_prob *lp, int j, double sjj)
alpar@1
    76
{     if (!(1 <= j && j <= lp->n))
alpar@1
    77
         xerror("glp_set_sjj: j = %d; column number out of range\n", j);
alpar@1
    78
      if (sjj <= 0.0)
alpar@1
    79
         xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
alpar@1
    80
            j, sjj);
alpar@1
    81
      if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
alpar@1
    82
         GLP_BS)
alpar@1
    83
      {  /* invalidate the basis factorization */
alpar@1
    84
         lp->valid = 0;
alpar@1
    85
      }
alpar@1
    86
      lp->col[j]->sjj = sjj;
alpar@1
    87
      return;
alpar@1
    88
}
alpar@1
    89
alpar@1
    90
/***********************************************************************
alpar@1
    91
*  NAME
alpar@1
    92
*
alpar@1
    93
*  glp_get_rii - retrieve row scale factor
alpar@1
    94
*
alpar@1
    95
*  SYNOPSIS
alpar@1
    96
*
alpar@1
    97
*  double glp_get_rii(glp_prob *lp, int i);
alpar@1
    98
*
alpar@1
    99
*  RETURNS
alpar@1
   100
*
alpar@1
   101
*  The routine glp_get_rii returns current scale factor r[i,i] for i-th
alpar@1
   102
*  row of the specified problem object. */
alpar@1
   103
alpar@1
   104
double glp_get_rii(glp_prob *lp, int i)
alpar@1
   105
{     if (!(1 <= i && i <= lp->m))
alpar@1
   106
         xerror("glp_get_rii: i = %d; row number out of range\n", i);
alpar@1
   107
      return lp->row[i]->rii;
alpar@1
   108
}
alpar@1
   109
alpar@1
   110
/***********************************************************************
alpar@1
   111
*  NAME
alpar@1
   112
*
alpar@1
   113
*  glp_get_sjj - retrieve column scale factor
alpar@1
   114
*
alpar@1
   115
*  SYNOPSIS
alpar@1
   116
*
alpar@1
   117
*  double glp_get_sjj(glp_prob *lp, int j);
alpar@1
   118
*
alpar@1
   119
*  RETURNS
alpar@1
   120
*
alpar@1
   121
*  The routine glp_get_sjj returns current scale factor s[j,j] for j-th
alpar@1
   122
*  column of the specified problem object. */
alpar@1
   123
alpar@1
   124
double glp_get_sjj(glp_prob *lp, int j)
alpar@1
   125
{     if (!(1 <= j && j <= lp->n))
alpar@1
   126
         xerror("glp_get_sjj: j = %d; column number out of range\n", j);
alpar@1
   127
      return lp->col[j]->sjj;
alpar@1
   128
}
alpar@1
   129
alpar@1
   130
/***********************************************************************
alpar@1
   131
*  NAME
alpar@1
   132
*
alpar@1
   133
*  glp_unscale_prob - unscale problem data
alpar@1
   134
*
alpar@1
   135
*  SYNOPSIS
alpar@1
   136
*
alpar@1
   137
*  void glp_unscale_prob(glp_prob *lp);
alpar@1
   138
*
alpar@1
   139
*  DESCRIPTION
alpar@1
   140
*
alpar@1
   141
*  The routine glp_unscale_prob performs unscaling of problem data for
alpar@1
   142
*  the specified problem object.
alpar@1
   143
*
alpar@1
   144
*  "Unscaling" means replacing the current scaling matrices R and S by
alpar@1
   145
*  unity matrices that cancels the scaling effect. */
alpar@1
   146
alpar@1
   147
void glp_unscale_prob(glp_prob *lp)
alpar@1
   148
{     int m = glp_get_num_rows(lp);
alpar@1
   149
      int n = glp_get_num_cols(lp);
alpar@1
   150
      int i, j;
alpar@1
   151
      for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0);
alpar@1
   152
      for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0);
alpar@1
   153
      return;
alpar@1
   154
}
alpar@1
   155
alpar@1
   156
/* eof */