Debian Codegraph @

external/glpk/glplpx02.c

raw symbols SCIP
1 #cxx . . $ `<file>/external/glpk/glplpx02.c`/pragma GCC diagnostic ignored "-Wall"
2 /* glplpx02.c */
3
4 /***********************************************************************
5 * This code is part of GLPK (GNU Linear Programming Kit).
6 *
7 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
8 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
9 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
10 * E-mail: <[email protected]>.
11 *
12 * GLPK is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * GLPK is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 * License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
24 ***********************************************************************/
25
26 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
27
28 /***********************************************************************
29 * NAME
30 *
31 * lpx_put_solution - store basic solution components
32 *
33 * SYNOPSIS
34 *
35 * void lpx_put_solution(glp_prob *lp, int inval, const int *p_stat,
36 * const int *d_stat, const double *obj_val, const int r_stat[],
37 * const double r_prim[], const double r_dual[], const int c_stat[],
38 * const double c_prim[], const double c_dual[])
39 *
40 * DESCRIPTION
41 *
42 * The routine lpx_put_solution stores basic solution components to the
43 * specified problem object.
44 *
45 * The parameter inval is the basis factorization invalidity flag.
46 * If this flag is clear, the current status of the basis factorization
47 * remains unchanged. If this flag is set, the routine invalidates the
48 * basis factorization.
49 *
50 * The parameter p_stat is a pointer to the status of primal basic
51 * solution, which should be specified as follows:
52 *
53 * GLP_UNDEF - primal solution is undefined;
54 * GLP_FEAS - primal solution is feasible;
55 * GLP_INFEAS - primal solution is infeasible;
56 * GLP_NOFEAS - no primal feasible solution exists.
57 *
58 * If the parameter p_stat is NULL, the current status of primal basic
59 * solution remains unchanged.
60 *
61 * The parameter d_stat is a pointer to the status of dual basic
62 * solution, which should be specified as follows:
63 *
64 * GLP_UNDEF - dual solution is undefined;
65 * GLP_FEAS - dual solution is feasible;
66 * GLP_INFEAS - dual solution is infeasible;
67 * GLP_NOFEAS - no dual feasible solution exists.
68 *
69 * If the parameter d_stat is NULL, the current status of dual basic
70 * solution remains unchanged.
71 *
72 * The parameter obj_val is a pointer to the objective function value.
73 * If it is NULL, the current value of the objective function remains
74 * unchanged.
75 *
76 * The array element r_stat[i], 1 <= i <= m (where m is the number of
77 * rows in the problem object), specifies the status of i-th auxiliary
78 * variable, which should be specified as follows:
79 *
80 * GLP_BS - basic variable;
81 * GLP_NL - non-basic variable on lower bound;
82 * GLP_NU - non-basic variable on upper bound;
83 * GLP_NF - non-basic free variable;
84 * GLP_NS - non-basic fixed variable.
85 *
86 * If the parameter r_stat is NULL, the current statuses of auxiliary
87 * variables remain unchanged.
88 *
89 * The array element r_prim[i], 1 <= i <= m (where m is the number of
90 * rows in the problem object), specifies a primal value of i-th
91 * auxiliary variable. If the parameter r_prim is NULL, the current
92 * primal values of auxiliary variables remain unchanged.
93 *
94 * The array element r_dual[i], 1 <= i <= m (where m is the number of
95 * rows in the problem object), specifies a dual value (reduced cost)
96 * of i-th auxiliary variable. If the parameter r_dual is NULL, the
97 * current dual values of auxiliary variables remain unchanged.
98 *
99 * The array element c_stat[j], 1 <= j <= n (where n is the number of
100 * columns in the problem object), specifies the status of j-th
101 * structural variable, which should be specified as follows:
102 *
103 * GLP_BS - basic variable;
104 * GLP_NL - non-basic variable on lower bound;
105 * GLP_NU - non-basic variable on upper bound;
106 * GLP_NF - non-basic free variable;
107 * GLP_NS - non-basic fixed variable.
108 *
109 * If the parameter c_stat is NULL, the current statuses of structural
110 * variables remain unchanged.
111 *
112 * The array element c_prim[j], 1 <= j <= n (where n is the number of
113 * columns in the problem object), specifies a primal value of j-th
114 * structural variable. If the parameter c_prim is NULL, the current
115 * primal values of structural variables remain unchanged.
116 *
117 * The array element c_dual[j], 1 <= j <= n (where n is the number of
118 * columns in the problem object), specifies a dual value (reduced cost)
119 * of j-th structural variable. If the parameter c_dual is NULL, the
120 * current dual values of structural variables remain unchanged. */
121
122 void lpx_put_solutioncxx . . $ `external/glpk/glpapi.h:280:9`!(glp_probcxx . . $ glp_prob# *lp, int inval, const int *p_stat,
123 const int *d_stat, const double *obj_val, const int r_stat[],
124 const double r_prim[], const double r_dual[], const int c_stat[],
125 const double c_prim[], const double c_dual[])
126 { GLPROWcxx . . $ GLPROW# *row;
127 GLPCOLcxx . . $ GLPCOL# *col;
128 int i, j;
129 /* invalidate the basis factorization, if required */
130 if (inval) lp->validcxx . . $ glp_prob#valid. = 0;
131 /* store primal status */
132 if (p_stat != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
133 { if (!(*p_stat == GLP_UNDEFcxx . . $ `external/glpk/glpk.h:85:9`! || *p_stat == GLP_FEAScxx . . $ `external/glpk/glpk.h:86:9`! ||
134 *p_stat == GLP_INFEAScxx . . $ `external/glpk/glpk.h:87:9`! || *p_stat == GLP_NOFEAScxx . . $ `external/glpk/glpk.h:88:9`!))
135 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_solution: p_stat = %d; invalid primal statu"
136 "s\n", *p_stat);
137 lp->pbs_statcxx . . $ glp_prob#pbs_stat. = *p_stat;
138 }
139 /* store dual status */
140 if (d_stat != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
141 { if (!(*d_stat == GLP_UNDEFcxx . . $ `external/glpk/glpk.h:85:9`! || *d_stat == GLP_FEAScxx . . $ `external/glpk/glpk.h:86:9`! ||
142 *d_stat == GLP_INFEAScxx . . $ `external/glpk/glpk.h:87:9`! || *d_stat == GLP_NOFEAScxx . . $ `external/glpk/glpk.h:88:9`!))
143 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_solution: d_stat = %d; invalid dual status "
144 "\n", *d_stat);
145 lp->dbs_statcxx . . $ glp_prob#dbs_stat. = *d_stat;
146 }
147 /* store objective function value */
148 if (obj_val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) lp->obj_valcxx . . $ glp_prob#obj_val. = *obj_val;
149 /* store row solution components */
150 for (i = 1; i <= lp->mcxx . . $ glp_prob#m.; i++)
151 { row = lp->rowcxx . . $ glp_prob#row.[i];
152 if (r_stat != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
153 { if (!(r_stat[i] == GLP_BScxx . . $ `external/glpk/glpk.h:66:9`! ||
154 row->typecxx . . $ GLPROW#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! && r_stat[i] == GLP_NFcxx . . $ `external/glpk/glpk.h:69:9`! ||
155 row->typecxx . . $ GLPROW#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`! && r_stat[i] == GLP_NLcxx . . $ `external/glpk/glpk.h:67:9`! ||
156 row->typecxx . . $ GLPROW#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`! && r_stat[i] == GLP_NUcxx . . $ `external/glpk/glpk.h:68:9`! ||
157 row->typecxx . . $ GLPROW#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && r_stat[i] == GLP_NLcxx . . $ `external/glpk/glpk.h:67:9`! ||
158 row->typecxx . . $ GLPROW#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && r_stat[i] == GLP_NUcxx . . $ `external/glpk/glpk.h:68:9`! ||
159 row->typecxx . . $ GLPROW#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`! && r_stat[i] == GLP_NScxx . . $ `external/glpk/glpk.h:70:9`!))
160 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_solution: r_stat[%d] = %d; invalid row s"
161 "tatus\n", i, r_stat[i]);
162 row->statcxx . . $ GLPROW#stat. = r_stat[i];
163 }
164 if (r_prim != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) row->primcxx . . $ GLPROW#prim. = r_prim[i];
165 if (r_dual != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) row->dualcxx . . $ GLPROW#dual. = r_dual[i];
166 }
167 /* store column solution components */
168 for (j = 1; j <= lp->ncxx . . $ glp_prob#n.; j++)
169 { col = lp->colcxx . . $ glp_prob#col.[j];
170 if (c_stat != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
171 { if (!(c_stat[j] == GLP_BScxx . . $ `external/glpk/glpk.h:66:9`! ||
172 col->typecxx . . $ GLPCOL#type. == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! && c_stat[j] == GLP_NFcxx . . $ `external/glpk/glpk.h:69:9`! ||
173 col->typecxx . . $ GLPCOL#type. == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`! && c_stat[j] == GLP_NLcxx . . $ `external/glpk/glpk.h:67:9`! ||
174 col->typecxx . . $ GLPCOL#type. == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`! && c_stat[j] == GLP_NUcxx . . $ `external/glpk/glpk.h:68:9`! ||
175 col->typecxx . . $ GLPCOL#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && c_stat[j] == GLP_NLcxx . . $ `external/glpk/glpk.h:67:9`! ||
176 col->typecxx . . $ GLPCOL#type. == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && c_stat[j] == GLP_NUcxx . . $ `external/glpk/glpk.h:68:9`! ||
177 col->typecxx . . $ GLPCOL#type. == GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`! && c_stat[j] == GLP_NScxx . . $ `external/glpk/glpk.h:70:9`!))
178 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_solution: c_stat[%d] = %d; invalid colum"
179 "n status\n", j, c_stat[j]);
180 col->statcxx . . $ GLPCOL#stat. = c_stat[j];
181 }
182 if (c_prim != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) col->primcxx . . $ GLPCOL#prim. = c_prim[j];
183 if (c_dual != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) col->dualcxx . . $ GLPCOL#dual. = c_dual[j];
184 }
185 return;
186 }
187
188 /*----------------------------------------------------------------------
189 -- lpx_put_mip_soln - store mixed integer solution components.
190 --
191 -- *Synopsis*
192 --
193 -- #include "glplpx.h"
194 -- void lpx_put_mip_soln(glp_prob *lp, int i_stat, double row_mipx[],
195 -- double col_mipx[]);
196 --
197 -- *Description*
198 --
199 -- The routine lpx_put_mip_soln stores solution components obtained by
200 -- branch-and-bound solver into the specified problem object.
201 --
202 -- NOTE: This routine is intended for internal use only. */
203
204 void lpx_put_mip_solncxx . . $ `external/glpk/glpapi.h:287:9`!(glp_probcxx . . $ glp_prob# *lp, int i_stat, double row_mipx[],
205 double col_mipx[])
206 { GLPROWcxx . . $ GLPROW# *row;
207 GLPCOLcxx . . $ GLPCOL# *col;
208 int i, j;
209 double sum;
210 /* store mixed integer status */
211 #if 0
212 if (!(i_stat == LPX_I_UNDEF || i_stat == LPX_I_OPT ||
213 i_stat == LPX_I_FEAS || i_stat == LPX_I_NOFEAS))
214 fault("lpx_put_mip_soln: i_stat = %d; invalid mixed integer st"
215 "atus", i_stat);
216 lp->i_stat = i_stat;
217 #else
218 switch (i_stat)
219 { case LPX_I_UNDEFcxx . . $ `external/glpk/glpk.h:1132:9`!:
220 lp->mip_statcxx . . $ glp_prob#mip_stat. = GLP_UNDEFcxx . . $ `external/glpk/glpk.h:85:9`!; break;
221 case LPX_I_OPTcxx . . $ `external/glpk/glpk.h:1133:9`!:
222 lp->mip_statcxx . . $ glp_prob#mip_stat. = GLP_OPTcxx . . $ `external/glpk/glpk.h:89:9`!; break;
223 case LPX_I_FEAScxx . . $ `external/glpk/glpk.h:1134:9`!:
224 lp->mip_statcxx . . $ glp_prob#mip_stat. = GLP_FEAScxx . . $ `external/glpk/glpk.h:86:9`!; break;
225 case LPX_I_NOFEAScxx . . $ `external/glpk/glpk.h:1135:9`!:
226 lp->mip_statcxx . . $ glp_prob#mip_stat. = GLP_NOFEAScxx . . $ `external/glpk/glpk.h:88:9`!; break;
227 default:
228 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_mip_soln: i_stat = %d; invalid mixed intege"
229 "r status\n", i_stat);
230 }
231 #endif
232 /* store row solution components */
233 if (row_mipx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
234 { for (i = 1; i <= lp->mcxx . . $ glp_prob#m.; i++)
235 { row = lp->rowcxx . . $ glp_prob#row.[i];
236 row->mipxcxx . . $ GLPROW#mipx. = row_mipx[i];
237 }
238 }
239 /* store column solution components */
240 if (col_mipx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
241 { for (j = 1; j <= lp->ncxx . . $ glp_prob#n.; j++)
242 { col = lp->colcxx . . $ glp_prob#col.[j];
243 col->mipxcxx . . $ GLPCOL#mipx. = col_mipx[j];
244 }
245 }
246 /* if the solution is claimed to be integer feasible, check it */
247 if (lp->mip_statcxx . . $ glp_prob#mip_stat. == GLP_OPTcxx . . $ `external/glpk/glpk.h:89:9`! || lp->mip_statcxx . . $ glp_prob#mip_stat. == GLP_FEAScxx . . $ `external/glpk/glpk.h:86:9`!)
248 { for (j = 1; j <= lp->ncxx . . $ glp_prob#n.; j++)
249 { col = lp->colcxx . . $ glp_prob#col.[j];
250 if (col->kindcxx . . $ GLPCOL#kind. == GLP_IVcxx . . $ `external/glpk/glpk.h:55:9`! && col->mipxcxx . . $ GLPCOL#mipx. != floor(col->mipxcxx . . $ GLPCOL#mipx.))
251 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("lpx_put_mip_soln: col_mipx[%d] = %.*g; must be i"
252 "ntegral\n", j, DBL_DIGcxx . . $ `<external>/18143172452841944454/float.h:54:9`!, col->mipxcxx . . $ GLPCOL#mipx.);
253 }
254 }
255 /* compute the objective function value */
256 sum = lp->c0cxx . . $ glp_prob#c0.;
257 for (j = 1; j <= lp->ncxx . . $ glp_prob#n.; j++)
258 { col = lp->colcxx . . $ glp_prob#col.[j];
259 sum += col->coefcxx . . $ GLPCOL#coef. * col->mipxcxx . . $ GLPCOL#mipx.;
260 }
261 lp->mip_objcxx . . $ glp_prob#mip_obj. = sum;
262 return;
263 }
264
265 /* eof */