lemon-project-template-glpk

view deps/glpk/src/glpapi04.c @ 11:4fc6ad2fb8a6

Test GLPK in src/main.cc
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 21:43:29 +0100
parents
children
line source
1 /* glpapi04.c (problem scaling routines) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
5 *
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
10 *
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.
15 *
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.
20 *
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 ***********************************************************************/
25 #include "glpapi.h"
27 /***********************************************************************
28 * NAME
29 *
30 * glp_set_rii - set (change) row scale factor
31 *
32 * SYNOPSIS
33 *
34 * void glp_set_rii(glp_prob *lp, int i, double rii);
35 *
36 * DESCRIPTION
37 *
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);
44 if (rii <= 0.0)
45 xerror("glp_set_rii: i = %d; rii = %g; invalid scale factor\n",
46 i, rii);
47 if (lp->valid && lp->row[i]->rii != rii)
48 { GLPAIJ *aij;
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 */
52 lp->valid = 0;
53 break;
54 }
55 }
56 }
57 lp->row[i]->rii = rii;
58 return;
59 }
61 /***********************************************************************
62 * NAME
63 *
64 * glp_set sjj - set (change) column scale factor
65 *
66 * SYNOPSIS
67 *
68 * void glp_set_sjj(glp_prob *lp, int j, double sjj);
69 *
70 * DESCRIPTION
71 *
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);
78 if (sjj <= 0.0)
79 xerror("glp_set_sjj: j = %d; sjj = %g; invalid scale factor\n",
80 j, sjj);
81 if (lp->valid && lp->col[j]->sjj != sjj && lp->col[j]->stat ==
82 GLP_BS)
83 { /* invalidate the basis factorization */
84 lp->valid = 0;
85 }
86 lp->col[j]->sjj = sjj;
87 return;
88 }
90 /***********************************************************************
91 * NAME
92 *
93 * glp_get_rii - retrieve row scale factor
94 *
95 * SYNOPSIS
96 *
97 * double glp_get_rii(glp_prob *lp, int i);
98 *
99 * RETURNS
100 *
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;
108 }
110 /***********************************************************************
111 * NAME
112 *
113 * glp_get_sjj - retrieve column scale factor
114 *
115 * SYNOPSIS
116 *
117 * double glp_get_sjj(glp_prob *lp, int j);
118 *
119 * RETURNS
120 *
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;
128 }
130 /***********************************************************************
131 * NAME
132 *
133 * glp_unscale_prob - unscale problem data
134 *
135 * SYNOPSIS
136 *
137 * void glp_unscale_prob(glp_prob *lp);
138 *
139 * DESCRIPTION
140 *
141 * The routine glp_unscale_prob performs unscaling of problem data for
142 * the specified problem object.
143 *
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);
150 int i, j;
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);
153 return;
154 }
156 /* eof */