Debian Codegraph @

external/glpk/glpapi10.c

raw symbols SCIP
1 /* glpapi10.c (solution checking routines) */cxx . . $ `<file>/external/glpk/glpapi10.c`/
2
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 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <[email protected]>.
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 ***********************************************************************/
24
25 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
26
27 void _glp_check_kktcxx . . $ _glp_check_kkt(d20aa8e221df6422).(glp_probcxx . . $ glp_prob# *P, int sol, int cond, double *_ae_max,
28 int *_ae_ind, double *_re_max, int *_re_ind)
29 { /* check feasibility and optimality conditions */
30 int m = P->mcxx . . $ glp_prob#m.;
31 int n = P->ncxx . . $ glp_prob#n.;
32 GLPROWcxx . . $ GLPROW# *row;
33 GLPCOLcxx . . $ GLPCOL# *col;
34 GLPAIJcxx . . $ GLPAIJ# *aij;
35 int i, j, ae_ind, re_ind;
36 double e, sp, sn, t, ae_max, re_max;
37 if (!(sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`! || sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`! || sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!))
38 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_check_kkt: sol = %d; invalid solution indicator\n",
39 sol);
40 if (!(cond == GLP_KKT_PEcxx . . $ `external/glpk/glpk.h:260:9`! || cond == GLP_KKT_PBcxx . . $ `external/glpk/glpk.h:261:9`! ||
41 cond == GLP_KKT_DEcxx . . $ `external/glpk/glpk.h:262:9`! || cond == GLP_KKT_DBcxx . . $ `external/glpk/glpk.h:263:9`! ||
42 cond == GLP_KKT_CScxx . . $ `external/glpk/glpk.h:264:9`!))
43 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_check_kkt: cond = %d; invalid condition indicator "
44 "\n", cond);
45 ae_max = re_max = 0.0;
46 ae_ind = re_ind = 0;
47 if (cond == GLP_KKT_PEcxx . . $ `external/glpk/glpk.h:260:9`!)
48 { /* xR - A * xS = 0 */
49 for (i = 1; i <= m; i++)
50 { row = P->rowcxx . . $ glp_prob#row.[i];
51 sp = sn = 0.0;
52 /* t := xR[i] */
53 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
54 t = row->primcxx . . $ GLPROW#prim.;
55 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
56 t = row->pvalcxx . . $ GLPROW#pval.;
57 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
58 t = row->mipxcxx . . $ GLPROW#mipx.;
59 else
60 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
61 if (t >= 0.0) sp += t; else sn -= t;
62 for (aij = row->ptrcxx . . $ GLPROW#ptr.; aij != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; aij = aij->r_nextcxx . . $ GLPAIJ#r_next.)
63 { col = aij->colcxx . . $ GLPAIJ#col.;
64 /* t := - a[i,j] * xS[j] */
65 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
66 t = - aij->valcxx . . $ GLPAIJ#val. * col->primcxx . . $ GLPCOL#prim.;
67 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
68 t = - aij->valcxx . . $ GLPAIJ#val. * col->pvalcxx . . $ GLPCOL#pval.;
69 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
70 t = - aij->valcxx . . $ GLPAIJ#val. * col->mipxcxx . . $ GLPCOL#mipx.;
71 else
72 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
73 if (t >= 0.0) sp += t; else sn -= t;
74 }
75 /* absolute error */
76 e = fabscxx . . $ fabs(447c67c6676f75c3).(sp - sn);
77 if (ae_max < e)
78 ae_max = e, ae_ind = i;
79 /* relative error */
80 e /= (1.0 + sp + sn);
81 if (re_max < e)
82 re_max = e, re_ind = i;
83 }
84 }
85 else if (cond == GLP_KKT_PBcxx . . $ `external/glpk/glpk.h:261:9`!)
86 { /* lR <= xR <= uR */
87 for (i = 1; i <= m; i++)
88 { row = P->rowcxx . . $ glp_prob#row.[i];
89 /* t := xR[i] */
90 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
91 t = row->primcxx . . $ GLPROW#prim.;
92 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
93 t = row->pvalcxx . . $ GLPROW#pval.;
94 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
95 t = row->mipxcxx . . $ GLPROW#mipx.;
96 else
97 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
98 /* check lower bound */
99 if (row->typecxx . . $ GLPROW#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`! || row->typecxx . . $ GLPROW#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! ||
100 row->typecxx . . $ GLPROW#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!)
101 { if (t < row->lbcxx . . $ GLPROW#lb.)
102 { /* absolute error */
103 e = row->lbcxx . . $ GLPROW#lb. - t;
104 if (ae_max < e)
105 ae_max = e, ae_ind = i;
106 /* relative error */
107 e /= (1.0 + fabscxx . . $ fabs(447c67c6676f75c3).(row->lbcxx . . $ GLPROW#lb.));
108 if (re_max < e)
109 re_max = e, re_ind = i;
110 }
111 }
112 /* check upper bound */
113 if (row->typecxx . . $ GLPROW#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`! || row->typecxx . . $ GLPROW#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! ||
114 row->typecxx . . $ GLPROW#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!)
115 { if (t > row->ubcxx . . $ GLPROW#ub.)
116 { /* absolute error */
117 e = t - row->ubcxx . . $ GLPROW#ub.;
118 if (ae_max < e)
119 ae_max = e, ae_ind = i;
120 /* relative error */
121 e /= (1.0 + fabscxx . . $ fabs(447c67c6676f75c3).(row->ubcxx . . $ GLPROW#ub.));
122 if (re_max < e)
123 re_max = e, re_ind = i;
124 }
125 }
126 }
127 /* lS <= xS <= uS */
128 for (j = 1; j <= n; j++)
129 { col = P->colcxx . . $ glp_prob#col.[j];
130 /* t := xS[j] */
131 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
132 t = col->primcxx . . $ GLPCOL#prim.;
133 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
134 t = col->pvalcxx . . $ GLPCOL#pval.;
135 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
136 t = col->mipxcxx . . $ GLPCOL#mipx.;
137 else
138 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
139 /* check lower bound */
140 if (col->typecxx . . $ GLPCOL#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`! || col->typecxx . . $ GLPCOL#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! ||
141 col->typecxx . . $ GLPCOL#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!)
142 { if (t < col->lbcxx . . $ GLPCOL#lb.)
143 { /* absolute error */
144 e = col->lbcxx . . $ GLPCOL#lb. - t;
145 if (ae_max < e)
146 ae_max = e, ae_ind = m+j;
147 /* relative error */
148 e /= (1.0 + fabscxx . . $ fabs(447c67c6676f75c3).(col->lbcxx . . $ GLPCOL#lb.));
149 if (re_max < e)
150 re_max = e, re_ind = m+j;
151 }
152 }
153 /* check upper bound */
154 if (col->typecxx . . $ GLPCOL#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`! || col->typecxx . . $ GLPCOL#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! ||
155 col->typecxx . . $ GLPCOL#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!)
156 { if (t > col->ubcxx . . $ GLPCOL#ub.)
157 { /* absolute error */
158 e = t - col->ubcxx . . $ GLPCOL#ub.;
159 if (ae_max < e)
160 ae_max = e, ae_ind = m+j;
161 /* relative error */
162 e /= (1.0 + fabscxx . . $ fabs(447c67c6676f75c3).(col->ubcxx . . $ GLPCOL#ub.));
163 if (re_max < e)
164 re_max = e, re_ind = m+j;
165 }
166 }
167 }
168 }
169 else if (cond == GLP_KKT_DEcxx . . $ `external/glpk/glpk.h:262:9`!)
170 { /* A' * (lambdaR - cR) + (lambdaS - cS) = 0 */
171 for (j = 1; j <= n; j++)
172 { col = P->colcxx . . $ glp_prob#col.[j];
173 sp = sn = 0.0;
174 /* t := lambdaS[j] - cS[j] */
175 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
176 t = col->dualcxx . . $ GLPCOL#dual. - col->coefcxx . . $ GLPCOL#coef.;
177 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
178 t = col->dvalcxx . . $ GLPCOL#dval. - col->coefcxx . . $ GLPCOL#coef.;
179 else
180 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
181 if (t >= 0.0) sp += t; else sn -= t;
182 for (aij = col->ptrcxx . . $ GLPCOL#ptr.; aij != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; aij = aij->c_nextcxx . . $ GLPAIJ#c_next.)
183 { row = aij->rowcxx . . $ GLPAIJ#row.;
184 /* t := a[i,j] * (lambdaR[i] - cR[i]) */
185 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
186 t = aij->valcxx . . $ GLPAIJ#val. * row->dualcxx . . $ GLPROW#dual.;
187 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
188 t = aij->valcxx . . $ GLPAIJ#val. * row->dvalcxx . . $ GLPROW#dval.;
189 else
190 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
191 if (t >= 0.0) sp += t; else sn -= t;
192 }
193 /* absolute error */
194 e = fabscxx . . $ fabs(447c67c6676f75c3).(sp - sn);
195 if (ae_max < e)
196 ae_max = e, ae_ind = m+j;
197 /* relative error */
198 e /= (1.0 + sp + sn);
199 if (re_max < e)
200 re_max = e, re_ind = m+j;
201 }
202 }
203 else if (cond == GLP_KKT_DBcxx . . $ `external/glpk/glpk.h:263:9`!)
204 { /* check lambdaR */
205 for (i = 1; i <= m; i++)
206 { row = P->rowcxx . . $ glp_prob#row.[i];
207 /* t := lambdaR[i] */
208 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
209 t = row->dualcxx . . $ GLPROW#dual.;
210 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
211 t = row->dvalcxx . . $ GLPROW#dval.;
212 else
213 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
214 /* correct sign */
215 if (P->dircxx . . $ glp_prob#dir. == GLP_MINcxx . . $ `external/glpk/glpk.h:50:9`!)
216 t = + t;
217 else if (P->dircxx . . $ glp_prob#dir. == GLP_MAXcxx . . $ `external/glpk/glpk.h:51:9`!)
218 t = - t;
219 else
220 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(P != P);
221 /* check for positivity */
222 if (row->typecxx . . $ GLPROW#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || row->typecxx . . $ GLPROW#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!)
223 { if (t < 0.0)
224 { e = - t;
225 if (ae_max < e)
226 ae_max = re_max = e, ae_ind = re_ind = i;
227 }
228 }
229 /* check for negativity */
230 if (row->typecxx . . $ GLPROW#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || row->typecxx . . $ GLPROW#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!)
231 { if (t > 0.0)
232 { e = + t;
233 if (ae_max < e)
234 ae_max = re_max = e, ae_ind = re_ind = i;
235 }
236 }
237 }
238 /* check lambdaS */
239 for (j = 1; j <= n; j++)
240 { col = P->colcxx . . $ glp_prob#col.[j];
241 /* t := lambdaS[j] */
242 if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
243 t = col->dualcxx . . $ GLPCOL#dual.;
244 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
245 t = col->dvalcxx . . $ GLPCOL#dval.;
246 else
247 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
248 /* correct sign */
249 if (P->dircxx . . $ glp_prob#dir. == GLP_MINcxx . . $ `external/glpk/glpk.h:50:9`!)
250 t = + t;
251 else if (P->dircxx . . $ glp_prob#dir. == GLP_MAXcxx . . $ `external/glpk/glpk.h:51:9`!)
252 t = - t;
253 else
254 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(P != P);
255 /* check for positivity */
256 if (col->typecxx . . $ GLPCOL#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || col->typecxx . . $ GLPCOL#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!)
257 { if (t < 0.0)
258 { e = - t;
259 if (ae_max < e)
260 ae_max = re_max = e, ae_ind = re_ind = m+j;
261 }
262 }
263 /* check for negativity */
264 if (col->typecxx . . $ GLPCOL#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || col->typecxx . . $ GLPCOL#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!)
265 { if (t > 0.0)
266 { e = + t;
267 if (ae_max < e)
268 ae_max = re_max = e, ae_ind = re_ind = m+j;
269 }
270 }
271 }
272 }
273 else
274 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(cond != cond);
275 if (_ae_max != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *_ae_max = ae_max;
276 if (_ae_ind != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *_ae_ind = ae_ind;
277 if (_re_max != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *_re_max = re_max;
278 if (_re_ind != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *_re_ind = re_ind;
279 return;
280 }
281
282 /* eof */