Debian Codegraph @

external/glpk/glpapi14.c

raw symbols SCIP
1 /* glpapi14.c (processing models in GNU MathProg language) */cxx . . $ `<file>/external/glpk/glpapi14.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 #define GLP_TRAN_DEFINEDcxx . . $ `external/glpk/glpapi14.c:25:9`!
26 typedef struct MPLcxx . . $ MPL# glp_trancxx . . $ glp_tran#;
27
28 #include "glpmpl.h"cxx . . $ `<file>/external/glpk/glpmpl.h`/
29 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
30
31 glp_trancxx . . $ glp_tran# *glp_mpl_alloc_wkspcxx . . $ glp_mpl_alloc_wksp(4cfdd4ad397df771).(void)
32 { /* allocate the MathProg translator workspace */
33 glp_trancxx . . $ glp_tran# *tran;
34 tran = mpl_initializecxx . . $ `external/glpk/glpmpl.h:2489:9`!();
35 return tran;
36 }
37
38 #if 1 /* 08/XII-2009 */
39 void _glp_mpl_init_randcxx . . $ _glp_mpl_init_rand(e014ada434cacc95).(glp_trancxx . . $ glp_tran# *tran, int seed)
40 { if (tran->phasecxx . . $ MPL#phase. != 0)
41 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_init_rand: invalid call sequence\n");
42 rng_init_randcxx . . $ `external/glpk/glprng.h:42:9`!(tran->randcxx . . $ MPL#rand., seed);
43 return;
44 }
45 #endif
46
47 int glp_mpl_read_modelcxx . . $ glp_mpl_read_model(141e7e32402b5890).(glp_trancxx . . $ glp_tran# *tran, const char *fname, int skip)
48 { /* read and translate model section */
49 int ret;
50 if (tran->phasecxx . . $ MPL#phase. != 0)
51 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_read_model: invalid call sequence\n");
52 ret = mpl_read_modelcxx . . $ `external/glpk/glpmpl.h:2493:9`!(tran, (char *)fname, skip);
53 if (ret == 1 || ret == 2)
54 ret = 0;
55 else if (ret == 4)
56 ret = 1;
57 else
58 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(ret != ret);
59 return ret;
60 }
61
62 int glp_mpl_read_datacxx . . $ glp_mpl_read_data(3c9e05fb42525675).(glp_trancxx . . $ glp_tran# *tran, const char *fname)
63 { /* read and translate data section */
64 int ret;
65 if (!(tran->phasecxx . . $ MPL#phase. == 1 || tran->phasecxx . . $ MPL#phase. == 2))
66 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_read_data: invalid call sequence\n");
67 ret = mpl_read_datacxx . . $ `external/glpk/glpmpl.h:2497:9`!(tran, (char *)fname);
68 if (ret == 2)
69 ret = 0;
70 else if (ret == 4)
71 ret = 1;
72 else
73 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(ret != ret);
74 return ret;
75 }
76
77 int glp_mpl_generatecxx . . $ glp_mpl_generate(3c9e05fb42525675).(glp_trancxx . . $ glp_tran# *tran, const char *fname)
78 { /* generate the model */
79 int ret;
80 if (!(tran->phasecxx . . $ MPL#phase. == 1 || tran->phasecxx . . $ MPL#phase. == 2))
81 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_generate: invalid call sequence\n");
82 ret = mpl_generatecxx . . $ `external/glpk/glpmpl.h:2501:9`!(tran, (char *)fname);
83 if (ret == 3)
84 ret = 0;
85 else if (ret == 4)
86 ret = 1;
87 return ret;
88 }
89
90 void glp_mpl_build_probcxx . . $ glp_mpl_build_prob(aa70daeda12ef7af).(glp_trancxx . . $ glp_tran# *tran, glp_probcxx . . $ glp_prob# *prob)
91 { /* build LP/MIP problem instance from the model */
92 int m, n, i, j, t, kind, type, len, *ind;
93 double lb, ub, *val;
94 if (tran->phasecxx . . $ MPL#phase. != 3)
95 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_build_prob: invalid call sequence\n");
96 /* erase the problem object */
97 glp_erase_probcxx . . $ glp_erase_prob(84c60d68cac39b9a).(prob);
98 /* set problem name */
99 glp_set_prob_namecxx . . $ glp_set_prob_name(d84c0d6c877919f6).(prob, mpl_get_prob_namecxx . . $ `external/glpk/glpmpl.h:2505:9`!(tran));
100 /* build rows (constraints) */
101 m = mpl_get_num_rowscxx . . $ `external/glpk/glpmpl.h:2509:9`!(tran);
102 if (m > 0)
103 glp_add_rowscxx . . $ glp_add_rows(423829e847ef1a83).(prob, m);
104 for (i = 1; i <= m; i++)
105 { /* set row name */
106 glp_set_row_namecxx . . $ glp_set_row_name(7764df469f6d9ace).(prob, i, mpl_get_row_namecxx . . $ `external/glpk/glpmpl.h:2517:9`!(tran, i));
107 /* set row bounds */
108 type = mpl_get_row_bndscxx . . $ `external/glpk/glpmpl.h:2525:9`!(tran, i, &lb, &ub);
109 switch (type)
110 { case MPL_FRcxx . . $ `external/glpk/glpmpl.h:2467:9`!: type = GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!; break;
111 case MPL_LOcxx . . $ `external/glpk/glpmpl.h:2468:9`!: type = GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!; break;
112 case MPL_UPcxx . . $ `external/glpk/glpmpl.h:2469:9`!: type = GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!; break;
113 case MPL_DBcxx . . $ `external/glpk/glpmpl.h:2470:9`!: type = GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!; break;
114 case MPL_FXcxx . . $ `external/glpk/glpmpl.h:2471:9`!: type = GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!; break;
115 default: xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(type != type);
116 }
117 if (type == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && fabs(lb - ub) < 1e-9 * (1.0 + fabs(lb)))
118 { type = GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!;
119 if (fabs(lb) <= fabs(ub)) ub = lb; else lb = ub;
120 }
121 glp_set_row_bndscxx . . $ glp_set_row_bnds(9376c6e48e598b7a).(prob, i, type, lb, ub);
122 /* warn about non-zero constant term */
123 if (mpl_get_row_c0cxx . . $ `external/glpk/glpmpl.h:2533:9`!(tran, i) != 0.0)
124 xprintfcxx . . $ `external/glpk/glpenv.h:145:9`!("glp_mpl_build_prob: row %s; constant term %.12g ig"
125 "nored\n",
126 mpl_get_row_namecxx . . $ `external/glpk/glpmpl.h:2517:9`!(tran, i), mpl_get_row_c0cxx . . $ `external/glpk/glpmpl.h:2533:9`!(tran, i));
127 }
128 /* build columns (variables) */
129 n = mpl_get_num_colscxx . . $ `external/glpk/glpmpl.h:2513:9`!(tran);
130 if (n > 0)
131 glp_add_colscxx . . $ glp_add_cols(423829e847ef1a83).(prob, n);
132 for (j = 1; j <= n; j++)
133 { /* set column name */
134 glp_set_col_namecxx . . $ glp_set_col_name(7764df469f6d9ace).(prob, j, mpl_get_col_namecxx . . $ `external/glpk/glpmpl.h:2537:9`!(tran, j));
135 /* set column kind */
136 kind = mpl_get_col_kindcxx . . $ `external/glpk/glpmpl.h:2541:9`!(tran, j);
137 switch (kind)
138 { case MPL_NUMcxx . . $ `external/glpk/glpmpl.h:2477:9`!:
139 break;
140 case MPL_INTcxx . . $ `external/glpk/glpmpl.h:2478:9`!:
141 case MPL_BINcxx . . $ `external/glpk/glpmpl.h:2479:9`!:
142 glp_set_col_kindcxx . . $ glp_set_col_kind(b083f42914639ad0).(prob, j, GLP_IVcxx . . $ `external/glpk/glpk.h:55:9`!);
143 break;
144 default:
145 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(kind != kind);
146 }
147 /* set column bounds */
148 type = mpl_get_col_bndscxx . . $ `external/glpk/glpmpl.h:2545:9`!(tran, j, &lb, &ub);
149 switch (type)
150 { case MPL_FRcxx . . $ `external/glpk/glpmpl.h:2467:9`!: type = GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!; break;
151 case MPL_LOcxx . . $ `external/glpk/glpmpl.h:2468:9`!: type = GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!; break;
152 case MPL_UPcxx . . $ `external/glpk/glpmpl.h:2469:9`!: type = GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!; break;
153 case MPL_DBcxx . . $ `external/glpk/glpmpl.h:2470:9`!: type = GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!; break;
154 case MPL_FXcxx . . $ `external/glpk/glpmpl.h:2471:9`!: type = GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!; break;
155 default: xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(type != type);
156 }
157 if (kind == MPL_BINcxx . . $ `external/glpk/glpmpl.h:2479:9`!)
158 { if (type == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || type == GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`! || lb < 0.0) lb = 0.0;
159 if (type == GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`! || type == GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`! || ub > 1.0) ub = 1.0;
160 type = GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!;
161 }
162 if (type == GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`! && fabs(lb - ub) < 1e-9 * (1.0 + fabs(lb)))
163 { type = GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!;
164 if (fabs(lb) <= fabs(ub)) ub = lb; else lb = ub;
165 }
166 glp_set_col_bndscxx . . $ glp_set_col_bnds(9376c6e48e598b7a).(prob, j, type, lb, ub);
167 }
168 /* load the constraint matrix */
169 ind = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+n, sizeof(int));
170 val = xcalloccxx . . $ `external/glpk/glpenv.h:171:9`!(1+n, sizeof(double));
171 for (i = 1; i <= m; i++)
172 { len = mpl_get_mat_rowcxx . . $ `external/glpk/glpmpl.h:2529:9`!(tran, i, ind, val);
173 glp_set_mat_rowcxx . . $ glp_set_mat_row(9cc64c3737aa01c2).(prob, i, len, ind, val);
174 }
175 /* build objective function (the first objective is used) */
176 for (i = 1; i <= m; i++)
177 { kind = mpl_get_row_kindcxx . . $ `external/glpk/glpmpl.h:2521:9`!(tran, i);
178 if (kind == MPL_MINcxx . . $ `external/glpk/glpmpl.h:2474:9`! || kind == MPL_MAXcxx . . $ `external/glpk/glpmpl.h:2475:9`!)
179 { /* set objective name */
180 glp_set_obj_namecxx . . $ glp_set_obj_name(d84c0d6c877919f6).(prob, mpl_get_row_namecxx . . $ `external/glpk/glpmpl.h:2517:9`!(tran, i));
181 /* set optimization direction */
182 glp_set_obj_dircxx . . $ glp_set_obj_dir(e00ef8be97973834).(prob, kind == MPL_MINcxx . . $ `external/glpk/glpmpl.h:2474:9`! ? GLP_MINcxx . . $ `external/glpk/glpk.h:50:9`! : GLP_MAXcxx . . $ `external/glpk/glpk.h:51:9`!);
183 /* set constant term */
184 glp_set_obj_coefcxx . . $ glp_set_obj_coef(d60e14834b632e5e).(prob, 0, mpl_get_row_c0cxx . . $ `external/glpk/glpmpl.h:2533:9`!(tran, i));
185 /* set objective coefficients */
186 len = mpl_get_mat_rowcxx . . $ `external/glpk/glpmpl.h:2529:9`!(tran, i, ind, val);
187 for (t = 1; t <= len; t++)
188 glp_set_obj_coefcxx . . $ glp_set_obj_coef(d60e14834b632e5e).(prob, ind[t], val[t]);
189 break;
190 }
191 }
192 /* free working arrays */
193 xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(ind);
194 xfreecxx . . $ `external/glpk/glpenv.h:175:9`!(val);
195 return;
196 }
197
198 int glp_mpl_postsolvecxx . . $ glp_mpl_postsolve(2c6c5d528128b9f).(glp_trancxx . . $ glp_tran# *tran, glp_probcxx . . $ glp_prob# *prob, int sol)
199 { /* postsolve the model */
200 int i, j, m, n, stat, ret;
201 double prim, dual;
202 if (!(tran->phasecxx . . $ MPL#phase. == 3 && !tran->flag_pcxx . . $ MPL#flag_p.))
203 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_postsolve: invalid call sequence\n");
204 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`!))
205 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_postsolve: sol = %d; invalid parameter\n",
206 sol);
207 m = mpl_get_num_rowscxx . . $ `external/glpk/glpmpl.h:2509:9`!(tran);
208 n = mpl_get_num_colscxx . . $ `external/glpk/glpmpl.h:2513:9`!(tran);
209 if (!(m == glp_get_num_rowscxx . . $ glp_get_num_rows(317ecc1aeadfe2b7).(prob) &&
210 n == glp_get_num_colscxx . . $ glp_get_num_cols(317ecc1aeadfe2b7).(prob)))
211 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mpl_postsolve: wrong problem object\n");
212 if (!mpl_has_solve_stmtcxx . . $ `external/glpk/glpmpl.h:2549:9`!(tran))
213 { ret = 0;
214 goto done;
215 }
216 for (i = 1; i <= m; i++)
217 { if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
218 { stat = glp_get_row_statcxx . . $ glp_get_row_stat(423829e847ef1a83).(prob, i);
219 prim = glp_get_row_primcxx . . $ glp_get_row_prim(68c5770eb0f32231).(prob, i);
220 dual = glp_get_row_dualcxx . . $ glp_get_row_dual(68c5770eb0f32231).(prob, i);
221 }
222 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
223 { stat = 0;
224 prim = glp_ipt_row_primcxx . . $ glp_ipt_row_prim(68c5770eb0f32231).(prob, i);
225 dual = glp_ipt_row_dualcxx . . $ glp_ipt_row_dual(68c5770eb0f32231).(prob, i);
226 }
227 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
228 { stat = 0;
229 prim = glp_mip_row_valcxx . . $ glp_mip_row_val(68c5770eb0f32231).(prob, i);
230 dual = 0.0;
231 }
232 else
233 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
234 if (fabs(prim) < 1e-9) prim = 0.0;
235 if (fabs(dual) < 1e-9) dual = 0.0;
236 mpl_put_row_solncxx . . $ `external/glpk/glpmpl.h:2554:9`!(tran, i, stat, prim, dual);
237 }
238 for (j = 1; j <= n; j++)
239 { if (sol == GLP_SOLcxx . . $ `external/glpk/glpk.h:80:9`!)
240 { stat = glp_get_col_statcxx . . $ glp_get_col_stat(423829e847ef1a83).(prob, j);
241 prim = glp_get_col_primcxx . . $ glp_get_col_prim(68c5770eb0f32231).(prob, j);
242 dual = glp_get_col_dualcxx . . $ glp_get_col_dual(68c5770eb0f32231).(prob, j);
243 }
244 else if (sol == GLP_IPTcxx . . $ `external/glpk/glpk.h:81:9`!)
245 { stat = 0;
246 prim = glp_ipt_col_primcxx . . $ glp_ipt_col_prim(68c5770eb0f32231).(prob, j);
247 dual = glp_ipt_col_dualcxx . . $ glp_ipt_col_dual(68c5770eb0f32231).(prob, j);
248 }
249 else if (sol == GLP_MIPcxx . . $ `external/glpk/glpk.h:82:9`!)
250 { stat = 0;
251 prim = glp_mip_col_valcxx . . $ glp_mip_col_val(68c5770eb0f32231).(prob, j);
252 dual = 0.0;
253 }
254 else
255 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(sol != sol);
256 if (fabs(prim) < 1e-9) prim = 0.0;
257 if (fabs(dual) < 1e-9) dual = 0.0;
258 mpl_put_col_solncxx . . $ `external/glpk/glpmpl.h:2561:9`!(tran, j, stat, prim, dual);
259 }
260 ret = mpl_postsolvecxx . . $ `external/glpk/glpmpl.h:2573:9`!(tran);
261 if (ret == 3)
262 ret = 0;
263 else if (ret == 4)
264 ret = 1;
265 done: return ret;
266 }
267
268 void glp_mpl_free_wkspcxx . . $ glp_mpl_free_wksp(6f2045aaff867cb6).(glp_trancxx . . $ glp_tran# *tran)
269 { /* free the MathProg translator workspace */
270 mpl_terminatecxx . . $ `external/glpk/glpmpl.h:2577:9`!(tran);
271 return;
272 }
273
274 /* eof */