lemon-project-template-glpk

diff deps/glpk/src/glpapi04.c @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/deps/glpk/src/glpapi04.c	Sun Nov 06 20:59:10 2011 +0100
     1.3 @@ -0,0 +1,156 @@
     1.4 +/* glpapi04.c (problem scaling 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, 2011 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_rii - set (change) row scale factor
    1.34 +*
    1.35 +*  SYNOPSIS
    1.36 +*
    1.37 +*  void glp_set_rii(glp_prob *lp, int i, double rii);
    1.38 +*
    1.39 +*  DESCRIPTION
    1.40 +*
    1.41 +*  The routine glp_set_rii sets (changes) the scale factor r[i,i] for
    1.42 +*  i-th row of the specified problem object. */
    1.43 +
    1.44 +void glp_set_rii(glp_prob *lp, int i, double rii)
    1.45 +{     if (!(1 <= i && i <= lp->m))
    1.46 +         xerror("glp_set_rii: i = %d; row number out of range\n", i);
    1.47 +      if (rii <= 0.0)
    1.48 +         xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
    1.49 +            i, rii);
    1.50 +      if (lp->valid && lp->row[i]->rii != rii)
    1.51 +      {  GLPAIJ *aij;
    1.52 +         for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
    1.53 +         {  if (aij->col->stat == GLP_BS)
    1.54 +            {  /* invalidate the basis factorization */
    1.55 +               lp->valid = 0;
    1.56 +               break;
    1.57 +            }
    1.58 +         }
    1.59 +      }
    1.60 +      lp->row[i]->rii = rii;
    1.61 +      return;
    1.62 +}
    1.63 +
    1.64 +/***********************************************************************
    1.65 +*  NAME
    1.66 +*
    1.67 +*  glp_set sjj - set (change) column scale factor
    1.68 +*
    1.69 +*  SYNOPSIS
    1.70 +*
    1.71 +*  void glp_set_sjj(glp_prob *lp, int j, double sjj);
    1.72 +*
    1.73 +*  DESCRIPTION
    1.74 +*
    1.75 +*  The routine glp_set_sjj sets (changes) the scale factor s[j,j] for
    1.76 +*  j-th column of the specified problem object. */
    1.77 +
    1.78 +void glp_set_sjj(glp_prob *lp, int j, double sjj)
    1.79 +{     if (!(1 <= j && j <= lp->n))
    1.80 +         xerror("glp_set_sjj: j = %d; column number out of range\n", j);
    1.81 +      if (sjj <= 0.0)
    1.82 +         xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
    1.83 +            j, sjj);
    1.84 +      if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
    1.85 +         GLP_BS)
    1.86 +      {  /* invalidate the basis factorization */
    1.87 +         lp->valid = 0;
    1.88 +      }
    1.89 +      lp->col[j]->sjj = sjj;
    1.90 +      return;
    1.91 +}
    1.92 +
    1.93 +/***********************************************************************
    1.94 +*  NAME
    1.95 +*
    1.96 +*  glp_get_rii - retrieve row scale factor
    1.97 +*
    1.98 +*  SYNOPSIS
    1.99 +*
   1.100 +*  double glp_get_rii(glp_prob *lp, int i);
   1.101 +*
   1.102 +*  RETURNS
   1.103 +*
   1.104 +*  The routine glp_get_rii returns current scale factor r[i,i] for i-th
   1.105 +*  row of the specified problem object. */
   1.106 +
   1.107 +double glp_get_rii(glp_prob *lp, int i)
   1.108 +{     if (!(1 <= i && i <= lp->m))
   1.109 +         xerror("glp_get_rii: i = %d; row number out of range\n", i);
   1.110 +      return lp->row[i]->rii;
   1.111 +}
   1.112 +
   1.113 +/***********************************************************************
   1.114 +*  NAME
   1.115 +*
   1.116 +*  glp_get_sjj - retrieve column scale factor
   1.117 +*
   1.118 +*  SYNOPSIS
   1.119 +*
   1.120 +*  double glp_get_sjj(glp_prob *lp, int j);
   1.121 +*
   1.122 +*  RETURNS
   1.123 +*
   1.124 +*  The routine glp_get_sjj returns current scale factor s[j,j] for j-th
   1.125 +*  column of the specified problem object. */
   1.126 +
   1.127 +double glp_get_sjj(glp_prob *lp, int j)
   1.128 +{     if (!(1 <= j && j <= lp->n))
   1.129 +         xerror("glp_get_sjj: j = %d; column number out of range\n", j);
   1.130 +      return lp->col[j]->sjj;
   1.131 +}
   1.132 +
   1.133 +/***********************************************************************
   1.134 +*  NAME
   1.135 +*
   1.136 +*  glp_unscale_prob - unscale problem data
   1.137 +*
   1.138 +*  SYNOPSIS
   1.139 +*
   1.140 +*  void glp_unscale_prob(glp_prob *lp);
   1.141 +*
   1.142 +*  DESCRIPTION
   1.143 +*
   1.144 +*  The routine glp_unscale_prob performs unscaling of problem data for
   1.145 +*  the specified problem object.
   1.146 +*
   1.147 +*  "Unscaling" means replacing the current scaling matrices R and S by
   1.148 +*  unity matrices that cancels the scaling effect. */
   1.149 +
   1.150 +void glp_unscale_prob(glp_prob *lp)
   1.151 +{     int m = glp_get_num_rows(lp);
   1.152 +      int n = glp_get_num_cols(lp);
   1.153 +      int i, j;
   1.154 +      for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0);
   1.155 +      for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0);
   1.156 +      return;
   1.157 +}
   1.158 +
   1.159 +/* eof */