1 /* prob4.c (problem scaling routines) */
2 
3 /***********************************************************************
4 *  This code is part of GLPK (GNU Linear Programming Kit).
5 *  Copyright (C) 2000-2013 Free Software Foundation, Inc.
6 *  Written by Andrew Makhorin <mao@gnu.org>.
7 *
8 *  GLPK is free software: you can redistribute it and/or modify it
9 *  under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation, either version 3 of the License, or
11 *  (at your option) any later version.
12 *
13 *  GLPK is distributed in the hope that it will be useful, but WITHOUT
14 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 *  License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "env.h"
23 #include "prob.h"
24 
25 /***********************************************************************
26 *  NAME
27 *
28 *  glp_set_rii - set (change) row scale factor
29 *
30 *  SYNOPSIS
31 *
32 *  void glp_set_rii(glp_prob *lp, int i, double rii);
33 *
34 *  DESCRIPTION
35 *
36 *  The routine glp_set_rii sets (changes) the scale factor r[i,i] for
37 *  i-th row of the specified problem object. */
38 
glp_set_rii(glp_prob * lp,int i,double rii)39 void glp_set_rii(glp_prob *lp, int i, double rii)
40 {     if (!(1 <= i && i <= lp->m))
41          xerror("glp_set_rii: i = %d; row number out of range\n", i);
42       if (rii <= 0.0)
43          xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
44             i, rii);
45       if (lp->valid && lp->row[i]->rii != rii)
46       {  GLPAIJ *aij;
47          for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
48          {  if (aij->col->stat == GLP_BS)
49             {  /* invalidate the basis factorization */
50                lp->valid = 0;
51                break;
52             }
53          }
54       }
55       lp->row[i]->rii = rii;
56       return;
57 }
58 
59 /***********************************************************************
60 *  NAME
61 *
62 *  glp_set sjj - set (change) column scale factor
63 *
64 *  SYNOPSIS
65 *
66 *  void glp_set_sjj(glp_prob *lp, int j, double sjj);
67 *
68 *  DESCRIPTION
69 *
70 *  The routine glp_set_sjj sets (changes) the scale factor s[j,j] for
71 *  j-th column of the specified problem object. */
72 
glp_set_sjj(glp_prob * lp,int j,double sjj)73 void glp_set_sjj(glp_prob *lp, int j, double sjj)
74 {     if (!(1 <= j && j <= lp->n))
75          xerror("glp_set_sjj: j = %d; column number out of range\n", j);
76       if (sjj <= 0.0)
77          xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
78             j, sjj);
79       if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
80          GLP_BS)
81       {  /* invalidate the basis factorization */
82          lp->valid = 0;
83       }
84       lp->col[j]->sjj = sjj;
85       return;
86 }
87 
88 /***********************************************************************
89 *  NAME
90 *
91 *  glp_get_rii - retrieve row scale factor
92 *
93 *  SYNOPSIS
94 *
95 *  double glp_get_rii(glp_prob *lp, int i);
96 *
97 *  RETURNS
98 *
99 *  The routine glp_get_rii returns current scale factor r[i,i] for i-th
100 *  row of the specified problem object. */
101 
glp_get_rii(glp_prob * lp,int i)102 double glp_get_rii(glp_prob *lp, int i)
103 {     if (!(1 <= i && i <= lp->m))
104          xerror("glp_get_rii: i = %d; row number out of range\n", i);
105       return lp->row[i]->rii;
106 }
107 
108 /***********************************************************************
109 *  NAME
110 *
111 *  glp_get_sjj - retrieve column scale factor
112 *
113 *  SYNOPSIS
114 *
115 *  double glp_get_sjj(glp_prob *lp, int j);
116 *
117 *  RETURNS
118 *
119 *  The routine glp_get_sjj returns current scale factor s[j,j] for j-th
120 *  column of the specified problem object. */
121 
glp_get_sjj(glp_prob * lp,int j)122 double glp_get_sjj(glp_prob *lp, int j)
123 {     if (!(1 <= j && j <= lp->n))
124          xerror("glp_get_sjj: j = %d; column number out of range\n", j);
125       return lp->col[j]->sjj;
126 }
127 
128 /***********************************************************************
129 *  NAME
130 *
131 *  glp_unscale_prob - unscale problem data
132 *
133 *  SYNOPSIS
134 *
135 *  void glp_unscale_prob(glp_prob *lp);
136 *
137 *  DESCRIPTION
138 *
139 *  The routine glp_unscale_prob performs unscaling of problem data for
140 *  the specified problem object.
141 *
142 *  "Unscaling" means replacing the current scaling matrices R and S by
143 *  unity matrices that cancels the scaling effect. */
144 
glp_unscale_prob(glp_prob * lp)145 void glp_unscale_prob(glp_prob *lp)
146 {     int m = glp_get_num_rows(lp);
147       int n = glp_get_num_cols(lp);
148       int i, j;
149       for (i = 1; i <= m; i++) glp_set_rii(lp, i, 1.0);
150       for (j = 1; j <= n; j++) glp_set_sjj(lp, j, 1.0);
151       return;
152 }
153 
154 /* eof */
155