1 /* glpapi04.c (problem scaling routines) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
27 /***********************************************************************
30 * glp_set_rii - set (change) row scale factor
34 * void glp_set_rii(glp_prob *lp, int i, double rii);
38 * The routine glp_set_rii sets (changes) the scale factor r[i,i] for
39 * i-th row of the specified problem object. */
41 void glp_set_rii(glp_prob *lp, int i, double rii)
42 { if (!(1 <= i && i <= lp->m))
43 xerror("glp_set_rii: i = %d; row number out of range\n", i);
45 xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
47 if (lp->valid && lp->row[i]->rii != rii)
49 for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
50 { if (aij->col->stat == GLP_BS)
51 { /* invalidate the basis factorization */
57 lp->row[i]->rii = rii;
61 /***********************************************************************
64 * glp_set sjj - set (change) column scale factor
68 * void glp_set_sjj(glp_prob *lp, int j, double sjj);
72 * The routine glp_set_sjj sets (changes) the scale factor s[j,j] for
73 * j-th column of the specified problem object. */
75 void glp_set_sjj(glp_prob *lp, int j, double sjj)
76 { if (!(1 <= j && j <= lp->n))
77 xerror("glp_set_sjj: j = %d; column number out of range\n", j);
79 xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
81 if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
83 { /* invalidate the basis factorization */
86 lp->col[j]->sjj = sjj;
90 /***********************************************************************
93 * glp_get_rii - retrieve row scale factor
97 * double glp_get_rii(glp_prob *lp, int i);
101 * The routine glp_get_rii returns current scale factor r[i,i] for i-th
102 * row of the specified problem object. */
104 double glp_get_rii(glp_prob *lp, int i)
105 { if (!(1 <= i && i <= lp->m))
106 xerror("glp_get_rii: i = %d; row number out of range\n", i);
107 return lp->row[i]->rii;
110 /***********************************************************************
113 * glp_get_sjj - retrieve column scale factor
117 * double glp_get_sjj(glp_prob *lp, int j);
121 * The routine glp_get_sjj returns current scale factor s[j,j] for j-th
122 * column of the specified problem object. */
124 double glp_get_sjj(glp_prob *lp, int j)
125 { if (!(1 <= j && j <= lp->n))
126 xerror("glp_get_sjj: j = %d; column number out of range\n", j);
127 return lp->col[j]->sjj;
130 /***********************************************************************
133 * glp_unscale_prob - unscale problem data
137 * void glp_unscale_prob(glp_prob *lp);
141 * The routine glp_unscale_prob performs unscaling of problem data for
142 * the specified problem object.
144 * "Unscaling" means replacing the current scaling matrices R and S by
145 * unity matrices that cancels the scaling effect. */
147 void glp_unscale_prob(glp_prob *lp)
148 { int m = glp_get_num_rows(lp);
149 int n = glp_get_num_cols(lp);
151 for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0);
152 for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0);