lemon-project-template-glpk

annotate deps/glpk/src/glplpx01.c @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
rev   line source
alpar@9 1 /* glplpx01.c (obsolete API routines) */
alpar@9 2
alpar@9 3 /***********************************************************************
alpar@9 4 * This code is part of GLPK (GNU Linear Programming Kit).
alpar@9 5 *
alpar@9 6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@9 7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
alpar@9 8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@9 9 * E-mail: <mao@gnu.org>.
alpar@9 10 *
alpar@9 11 * GLPK is free software: you can redistribute it and/or modify it
alpar@9 12 * under the terms of the GNU General Public License as published by
alpar@9 13 * the Free Software Foundation, either version 3 of the License, or
alpar@9 14 * (at your option) any later version.
alpar@9 15 *
alpar@9 16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@9 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@9 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@9 19 * License for more details.
alpar@9 20 *
alpar@9 21 * You should have received a copy of the GNU General Public License
alpar@9 22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@9 23 ***********************************************************************/
alpar@9 24
alpar@9 25 #include "glpapi.h"
alpar@9 26
alpar@9 27 struct LPXCPS
alpar@9 28 { /* control parameters and statistics */
alpar@9 29 int msg_lev;
alpar@9 30 /* level of messages output by the solver:
alpar@9 31 0 - no output
alpar@9 32 1 - error messages only
alpar@9 33 2 - normal output
alpar@9 34 3 - full output (includes informational messages) */
alpar@9 35 int scale;
alpar@9 36 /* scaling option:
alpar@9 37 0 - no scaling
alpar@9 38 1 - equilibration scaling
alpar@9 39 2 - geometric mean scaling
alpar@9 40 3 - geometric mean scaling, then equilibration scaling */
alpar@9 41 int dual;
alpar@9 42 /* dual simplex option:
alpar@9 43 0 - use primal simplex
alpar@9 44 1 - use dual simplex */
alpar@9 45 int price;
alpar@9 46 /* pricing option (for both primal and dual simplex):
alpar@9 47 0 - textbook pricing
alpar@9 48 1 - steepest edge pricing */
alpar@9 49 double relax;
alpar@9 50 /* relaxation parameter used in the ratio test; if it is zero,
alpar@9 51 the textbook ratio test is used; if it is non-zero (should be
alpar@9 52 positive), Harris' two-pass ratio test is used; in the latter
alpar@9 53 case on the first pass basic variables (in the case of primal
alpar@9 54 simplex) or reduced costs of non-basic variables (in the case
alpar@9 55 of dual simplex) are allowed to slightly violate their bounds,
alpar@9 56 but not more than (relax * tol_bnd) or (relax * tol_dj) (thus,
alpar@9 57 relax is a percentage of tol_bnd or tol_dj) */
alpar@9 58 double tol_bnd;
alpar@9 59 /* relative tolerance used to check if the current basic solution
alpar@9 60 is primal feasible */
alpar@9 61 double tol_dj;
alpar@9 62 /* absolute tolerance used to check if the current basic solution
alpar@9 63 is dual feasible */
alpar@9 64 double tol_piv;
alpar@9 65 /* relative tolerance used to choose eligible pivotal elements of
alpar@9 66 the simplex table in the ratio test */
alpar@9 67 int round;
alpar@9 68 /* solution rounding option:
alpar@9 69 0 - report all computed values and reduced costs "as is"
alpar@9 70 1 - if possible (allowed by the tolerances), replace computed
alpar@9 71 values and reduced costs which are close to zero by exact
alpar@9 72 zeros */
alpar@9 73 double obj_ll;
alpar@9 74 /* lower limit of the objective function; if on the phase II the
alpar@9 75 objective function reaches this limit and continues decreasing,
alpar@9 76 the solver stops the search */
alpar@9 77 double obj_ul;
alpar@9 78 /* upper limit of the objective function; if on the phase II the
alpar@9 79 objective function reaches this limit and continues increasing,
alpar@9 80 the solver stops the search */
alpar@9 81 int it_lim;
alpar@9 82 /* simplex iterations limit; if this value is positive, it is
alpar@9 83 decreased by one each time when one simplex iteration has been
alpar@9 84 performed, and reaching zero value signals the solver to stop
alpar@9 85 the search; negative value means no iterations limit */
alpar@9 86 double tm_lim;
alpar@9 87 /* searching time limit, in seconds; if this value is positive,
alpar@9 88 it is decreased each time when one simplex iteration has been
alpar@9 89 performed by the amount of time spent for the iteration, and
alpar@9 90 reaching zero value signals the solver to stop the search;
alpar@9 91 negative value means no time limit */
alpar@9 92 int out_frq;
alpar@9 93 /* output frequency, in iterations; this parameter specifies how
alpar@9 94 frequently the solver sends information about the solution to
alpar@9 95 the standard output */
alpar@9 96 double out_dly;
alpar@9 97 /* output delay, in seconds; this parameter specifies how long
alpar@9 98 the solver should delay sending information about the solution
alpar@9 99 to the standard output; zero value means no delay */
alpar@9 100 int branch; /* MIP */
alpar@9 101 /* branching heuristic:
alpar@9 102 0 - branch on first variable
alpar@9 103 1 - branch on last variable
alpar@9 104 2 - branch using heuristic by Driebeck and Tomlin
alpar@9 105 3 - branch on most fractional variable */
alpar@9 106 int btrack; /* MIP */
alpar@9 107 /* backtracking heuristic:
alpar@9 108 0 - select most recent node (depth first search)
alpar@9 109 1 - select earliest node (breadth first search)
alpar@9 110 2 - select node using the best projection heuristic
alpar@9 111 3 - select node with best local bound */
alpar@9 112 double tol_int; /* MIP */
alpar@9 113 /* absolute tolerance used to check if the current basic solution
alpar@9 114 is integer feasible */
alpar@9 115 double tol_obj; /* MIP */
alpar@9 116 /* relative tolerance used to check if the value of the objective
alpar@9 117 function is not better than in the best known integer feasible
alpar@9 118 solution */
alpar@9 119 int mps_info; /* lpx_write_mps */
alpar@9 120 /* if this flag is set, the routine lpx_write_mps outputs several
alpar@9 121 comment cards that contains some information about the problem;
alpar@9 122 otherwise the routine outputs no comment cards */
alpar@9 123 int mps_obj; /* lpx_write_mps */
alpar@9 124 /* this parameter tells the routine lpx_write_mps how to output
alpar@9 125 the objective function row:
alpar@9 126 0 - never output objective function row
alpar@9 127 1 - always output objective function row
alpar@9 128 2 - output objective function row if and only if the problem
alpar@9 129 has no free rows */
alpar@9 130 int mps_orig; /* lpx_write_mps */
alpar@9 131 /* if this flag is set, the routine lpx_write_mps uses original
alpar@9 132 row and column symbolic names; otherwise the routine generates
alpar@9 133 plain names using ordinal numbers of rows and columns */
alpar@9 134 int mps_wide; /* lpx_write_mps */
alpar@9 135 /* if this flag is set, the routine lpx_write_mps uses all data
alpar@9 136 fields; otherwise the routine keeps fields 5 and 6 empty */
alpar@9 137 int mps_free; /* lpx_write_mps */
alpar@9 138 /* if this flag is set, the routine lpx_write_mps omits column
alpar@9 139 and vector names everytime if possible (free style); otherwise
alpar@9 140 the routine never omits these names (pedantic style) */
alpar@9 141 int mps_skip; /* lpx_write_mps */
alpar@9 142 /* if this flag is set, the routine lpx_write_mps skips empty
alpar@9 143 columns (i.e. which has no constraint coefficients); otherwise
alpar@9 144 the routine outputs all columns */
alpar@9 145 int lpt_orig; /* lpx_write_lpt */
alpar@9 146 /* if this flag is set, the routine lpx_write_lpt uses original
alpar@9 147 row and column symbolic names; otherwise the routine generates
alpar@9 148 plain names using ordinal numbers of rows and columns */
alpar@9 149 int presol; /* lpx_simplex */
alpar@9 150 /* LP presolver option:
alpar@9 151 0 - do not use LP presolver
alpar@9 152 1 - use LP presolver */
alpar@9 153 int binarize; /* lpx_intopt */
alpar@9 154 /* if this flag is set, the routine lpx_intopt replaces integer
alpar@9 155 columns by binary ones */
alpar@9 156 int use_cuts; /* lpx_intopt */
alpar@9 157 /* if this flag is set, the routine lpx_intopt tries generating
alpar@9 158 cutting planes:
alpar@9 159 LPX_C_COVER - mixed cover cuts
alpar@9 160 LPX_C_CLIQUE - clique cuts
alpar@9 161 LPX_C_GOMORY - Gomory's mixed integer cuts
alpar@9 162 LPX_C_ALL - all cuts */
alpar@9 163 double mip_gap; /* MIP */
alpar@9 164 /* relative MIP gap tolerance */
alpar@9 165 };
alpar@9 166
alpar@9 167 LPX *lpx_create_prob(void)
alpar@9 168 { /* create problem object */
alpar@9 169 return glp_create_prob();
alpar@9 170 }
alpar@9 171
alpar@9 172 void lpx_set_prob_name(LPX *lp, const char *name)
alpar@9 173 { /* assign (change) problem name */
alpar@9 174 glp_set_prob_name(lp, name);
alpar@9 175 return;
alpar@9 176 }
alpar@9 177
alpar@9 178 void lpx_set_obj_name(LPX *lp, const char *name)
alpar@9 179 { /* assign (change) objective function name */
alpar@9 180 glp_set_obj_name(lp, name);
alpar@9 181 return;
alpar@9 182 }
alpar@9 183
alpar@9 184 void lpx_set_obj_dir(LPX *lp, int dir)
alpar@9 185 { /* set (change) optimization direction flag */
alpar@9 186 glp_set_obj_dir(lp, dir - LPX_MIN + GLP_MIN);
alpar@9 187 return;
alpar@9 188 }
alpar@9 189
alpar@9 190 int lpx_add_rows(LPX *lp, int nrs)
alpar@9 191 { /* add new rows to problem object */
alpar@9 192 return glp_add_rows(lp, nrs);
alpar@9 193 }
alpar@9 194
alpar@9 195 int lpx_add_cols(LPX *lp, int ncs)
alpar@9 196 { /* add new columns to problem object */
alpar@9 197 return glp_add_cols(lp, ncs);
alpar@9 198 }
alpar@9 199
alpar@9 200 void lpx_set_row_name(LPX *lp, int i, const char *name)
alpar@9 201 { /* assign (change) row name */
alpar@9 202 glp_set_row_name(lp, i, name);
alpar@9 203 return;
alpar@9 204 }
alpar@9 205
alpar@9 206 void lpx_set_col_name(LPX *lp, int j, const char *name)
alpar@9 207 { /* assign (change) column name */
alpar@9 208 glp_set_col_name(lp, j, name);
alpar@9 209 return;
alpar@9 210 }
alpar@9 211
alpar@9 212 void lpx_set_row_bnds(LPX *lp, int i, int type, double lb, double ub)
alpar@9 213 { /* set (change) row bounds */
alpar@9 214 glp_set_row_bnds(lp, i, type - LPX_FR + GLP_FR, lb, ub);
alpar@9 215 return;
alpar@9 216 }
alpar@9 217
alpar@9 218 void lpx_set_col_bnds(LPX *lp, int j, int type, double lb, double ub)
alpar@9 219 { /* set (change) column bounds */
alpar@9 220 glp_set_col_bnds(lp, j, type - LPX_FR + GLP_FR, lb, ub);
alpar@9 221 return;
alpar@9 222 }
alpar@9 223
alpar@9 224 void lpx_set_obj_coef(glp_prob *lp, int j, double coef)
alpar@9 225 { /* set (change) obj. coefficient or constant term */
alpar@9 226 glp_set_obj_coef(lp, j, coef);
alpar@9 227 return;
alpar@9 228 }
alpar@9 229
alpar@9 230 void lpx_set_mat_row(LPX *lp, int i, int len, const int ind[],
alpar@9 231 const double val[])
alpar@9 232 { /* set (replace) row of the constraint matrix */
alpar@9 233 glp_set_mat_row(lp, i, len, ind, val);
alpar@9 234 return;
alpar@9 235 }
alpar@9 236
alpar@9 237 void lpx_set_mat_col(LPX *lp, int j, int len, const int ind[],
alpar@9 238 const double val[])
alpar@9 239 { /* set (replace) column of the constraint matrix */
alpar@9 240 glp_set_mat_col(lp, j, len, ind, val);
alpar@9 241 return;
alpar@9 242 }
alpar@9 243
alpar@9 244 void lpx_load_matrix(LPX *lp, int ne, const int ia[], const int ja[],
alpar@9 245 const double ar[])
alpar@9 246 { /* load (replace) the whole constraint matrix */
alpar@9 247 glp_load_matrix(lp, ne, ia, ja, ar);
alpar@9 248 return;
alpar@9 249 }
alpar@9 250
alpar@9 251 void lpx_del_rows(LPX *lp, int nrs, const int num[])
alpar@9 252 { /* delete specified rows from problem object */
alpar@9 253 glp_del_rows(lp, nrs, num);
alpar@9 254 return;
alpar@9 255 }
alpar@9 256
alpar@9 257 void lpx_del_cols(LPX *lp, int ncs, const int num[])
alpar@9 258 { /* delete specified columns from problem object */
alpar@9 259 glp_del_cols(lp, ncs, num);
alpar@9 260 return;
alpar@9 261 }
alpar@9 262
alpar@9 263 void lpx_delete_prob(LPX *lp)
alpar@9 264 { /* delete problem object */
alpar@9 265 glp_delete_prob(lp);
alpar@9 266 return;
alpar@9 267 }
alpar@9 268
alpar@9 269 const char *lpx_get_prob_name(LPX *lp)
alpar@9 270 { /* retrieve problem name */
alpar@9 271 return glp_get_prob_name(lp);
alpar@9 272 }
alpar@9 273
alpar@9 274 const char *lpx_get_obj_name(LPX *lp)
alpar@9 275 { /* retrieve objective function name */
alpar@9 276 return glp_get_obj_name(lp);
alpar@9 277 }
alpar@9 278
alpar@9 279 int lpx_get_obj_dir(LPX *lp)
alpar@9 280 { /* retrieve optimization direction flag */
alpar@9 281 return glp_get_obj_dir(lp) - GLP_MIN + LPX_MIN;
alpar@9 282 }
alpar@9 283
alpar@9 284 int lpx_get_num_rows(LPX *lp)
alpar@9 285 { /* retrieve number of rows */
alpar@9 286 return glp_get_num_rows(lp);
alpar@9 287 }
alpar@9 288
alpar@9 289 int lpx_get_num_cols(LPX *lp)
alpar@9 290 { /* retrieve number of columns */
alpar@9 291 return glp_get_num_cols(lp);
alpar@9 292 }
alpar@9 293
alpar@9 294 const char *lpx_get_row_name(LPX *lp, int i)
alpar@9 295 { /* retrieve row name */
alpar@9 296 return glp_get_row_name(lp, i);
alpar@9 297 }
alpar@9 298
alpar@9 299 const char *lpx_get_col_name(LPX *lp, int j)
alpar@9 300 { /* retrieve column name */
alpar@9 301 return glp_get_col_name(lp, j);
alpar@9 302 }
alpar@9 303
alpar@9 304 int lpx_get_row_type(LPX *lp, int i)
alpar@9 305 { /* retrieve row type */
alpar@9 306 return glp_get_row_type(lp, i) - GLP_FR + LPX_FR;
alpar@9 307 }
alpar@9 308
alpar@9 309 double lpx_get_row_lb(glp_prob *lp, int i)
alpar@9 310 { /* retrieve row lower bound */
alpar@9 311 double lb;
alpar@9 312 lb = glp_get_row_lb(lp, i);
alpar@9 313 if (lb == -DBL_MAX) lb = 0.0;
alpar@9 314 return lb;
alpar@9 315 }
alpar@9 316
alpar@9 317 double lpx_get_row_ub(glp_prob *lp, int i)
alpar@9 318 { /* retrieve row upper bound */
alpar@9 319 double ub;
alpar@9 320 ub = glp_get_row_ub(lp, i);
alpar@9 321 if (ub == +DBL_MAX) ub = 0.0;
alpar@9 322 return ub;
alpar@9 323 }
alpar@9 324
alpar@9 325 void lpx_get_row_bnds(glp_prob *lp, int i, int *typx, double *lb,
alpar@9 326 double *ub)
alpar@9 327 { /* retrieve row bounds */
alpar@9 328 if (typx != NULL) *typx = lpx_get_row_type(lp, i);
alpar@9 329 if (lb != NULL) *lb = lpx_get_row_lb(lp, i);
alpar@9 330 if (ub != NULL) *ub = lpx_get_row_ub(lp, i);
alpar@9 331 return;
alpar@9 332 }
alpar@9 333
alpar@9 334 int lpx_get_col_type(LPX *lp, int j)
alpar@9 335 { /* retrieve column type */
alpar@9 336 return glp_get_col_type(lp, j) - GLP_FR + LPX_FR;
alpar@9 337 }
alpar@9 338
alpar@9 339 double lpx_get_col_lb(glp_prob *lp, int j)
alpar@9 340 { /* retrieve column lower bound */
alpar@9 341 double lb;
alpar@9 342 lb = glp_get_col_lb(lp, j);
alpar@9 343 if (lb == -DBL_MAX) lb = 0.0;
alpar@9 344 return lb;
alpar@9 345 }
alpar@9 346
alpar@9 347 double lpx_get_col_ub(glp_prob *lp, int j)
alpar@9 348 { /* retrieve column upper bound */
alpar@9 349 double ub;
alpar@9 350 ub = glp_get_col_ub(lp, j);
alpar@9 351 if (ub == +DBL_MAX) ub = 0.0;
alpar@9 352 return ub;
alpar@9 353 }
alpar@9 354
alpar@9 355 void lpx_get_col_bnds(glp_prob *lp, int j, int *typx, double *lb,
alpar@9 356 double *ub)
alpar@9 357 { /* retrieve column bounds */
alpar@9 358 if (typx != NULL) *typx = lpx_get_col_type(lp, j);
alpar@9 359 if (lb != NULL) *lb = lpx_get_col_lb(lp, j);
alpar@9 360 if (ub != NULL) *ub = lpx_get_col_ub(lp, j);
alpar@9 361 return;
alpar@9 362 }
alpar@9 363
alpar@9 364 double lpx_get_obj_coef(LPX *lp, int j)
alpar@9 365 { /* retrieve obj. coefficient or constant term */
alpar@9 366 return glp_get_obj_coef(lp, j);
alpar@9 367 }
alpar@9 368
alpar@9 369 int lpx_get_num_nz(LPX *lp)
alpar@9 370 { /* retrieve number of constraint coefficients */
alpar@9 371 return glp_get_num_nz(lp);
alpar@9 372 }
alpar@9 373
alpar@9 374 int lpx_get_mat_row(LPX *lp, int i, int ind[], double val[])
alpar@9 375 { /* retrieve row of the constraint matrix */
alpar@9 376 return glp_get_mat_row(lp, i, ind, val);
alpar@9 377 }
alpar@9 378
alpar@9 379 int lpx_get_mat_col(LPX *lp, int j, int ind[], double val[])
alpar@9 380 { /* retrieve column of the constraint matrix */
alpar@9 381 return glp_get_mat_col(lp, j, ind, val);
alpar@9 382 }
alpar@9 383
alpar@9 384 void lpx_create_index(LPX *lp)
alpar@9 385 { /* create the name index */
alpar@9 386 glp_create_index(lp);
alpar@9 387 return;
alpar@9 388 }
alpar@9 389
alpar@9 390 int lpx_find_row(LPX *lp, const char *name)
alpar@9 391 { /* find row by its name */
alpar@9 392 return glp_find_row(lp, name);
alpar@9 393 }
alpar@9 394
alpar@9 395 int lpx_find_col(LPX *lp, const char *name)
alpar@9 396 { /* find column by its name */
alpar@9 397 return glp_find_col(lp, name);
alpar@9 398 }
alpar@9 399
alpar@9 400 void lpx_delete_index(LPX *lp)
alpar@9 401 { /* delete the name index */
alpar@9 402 glp_delete_index(lp);
alpar@9 403 return;
alpar@9 404 }
alpar@9 405
alpar@9 406 void lpx_scale_prob(LPX *lp)
alpar@9 407 { /* scale problem data */
alpar@9 408 switch (lpx_get_int_parm(lp, LPX_K_SCALE))
alpar@9 409 { case 0:
alpar@9 410 /* no scaling */
alpar@9 411 glp_unscale_prob(lp);
alpar@9 412 break;
alpar@9 413 case 1:
alpar@9 414 /* equilibration scaling */
alpar@9 415 glp_scale_prob(lp, GLP_SF_EQ);
alpar@9 416 break;
alpar@9 417 case 2:
alpar@9 418 /* geometric mean scaling */
alpar@9 419 glp_scale_prob(lp, GLP_SF_GM);
alpar@9 420 break;
alpar@9 421 case 3:
alpar@9 422 /* geometric mean scaling, then equilibration scaling */
alpar@9 423 glp_scale_prob(lp, GLP_SF_GM | GLP_SF_EQ);
alpar@9 424 break;
alpar@9 425 default:
alpar@9 426 xassert(lp != lp);
alpar@9 427 }
alpar@9 428 return;
alpar@9 429 }
alpar@9 430
alpar@9 431 void lpx_unscale_prob(LPX *lp)
alpar@9 432 { /* unscale problem data */
alpar@9 433 glp_unscale_prob(lp);
alpar@9 434 return;
alpar@9 435 }
alpar@9 436
alpar@9 437 void lpx_set_row_stat(LPX *lp, int i, int stat)
alpar@9 438 { /* set (change) row status */
alpar@9 439 glp_set_row_stat(lp, i, stat - LPX_BS + GLP_BS);
alpar@9 440 return;
alpar@9 441 }
alpar@9 442
alpar@9 443 void lpx_set_col_stat(LPX *lp, int j, int stat)
alpar@9 444 { /* set (change) column status */
alpar@9 445 glp_set_col_stat(lp, j, stat - LPX_BS + GLP_BS);
alpar@9 446 return;
alpar@9 447 }
alpar@9 448
alpar@9 449 void lpx_std_basis(LPX *lp)
alpar@9 450 { /* construct standard initial LP basis */
alpar@9 451 glp_std_basis(lp);
alpar@9 452 return;
alpar@9 453 }
alpar@9 454
alpar@9 455 void lpx_adv_basis(LPX *lp)
alpar@9 456 { /* construct advanced initial LP basis */
alpar@9 457 glp_adv_basis(lp, 0);
alpar@9 458 return;
alpar@9 459 }
alpar@9 460
alpar@9 461 void lpx_cpx_basis(LPX *lp)
alpar@9 462 { /* construct Bixby's initial LP basis */
alpar@9 463 glp_cpx_basis(lp);
alpar@9 464 return;
alpar@9 465 }
alpar@9 466
alpar@9 467 static void fill_smcp(LPX *lp, glp_smcp *parm)
alpar@9 468 { glp_init_smcp(parm);
alpar@9 469 switch (lpx_get_int_parm(lp, LPX_K_MSGLEV))
alpar@9 470 { case 0: parm->msg_lev = GLP_MSG_OFF; break;
alpar@9 471 case 1: parm->msg_lev = GLP_MSG_ERR; break;
alpar@9 472 case 2: parm->msg_lev = GLP_MSG_ON; break;
alpar@9 473 case 3: parm->msg_lev = GLP_MSG_ALL; break;
alpar@9 474 default: xassert(lp != lp);
alpar@9 475 }
alpar@9 476 switch (lpx_get_int_parm(lp, LPX_K_DUAL))
alpar@9 477 { case 0: parm->meth = GLP_PRIMAL; break;
alpar@9 478 case 1: parm->meth = GLP_DUAL; break;
alpar@9 479 default: xassert(lp != lp);
alpar@9 480 }
alpar@9 481 switch (lpx_get_int_parm(lp, LPX_K_PRICE))
alpar@9 482 { case 0: parm->pricing = GLP_PT_STD; break;
alpar@9 483 case 1: parm->pricing = GLP_PT_PSE; break;
alpar@9 484 default: xassert(lp != lp);
alpar@9 485 }
alpar@9 486 if (lpx_get_real_parm(lp, LPX_K_RELAX) == 0.0)
alpar@9 487 parm->r_test = GLP_RT_STD;
alpar@9 488 else
alpar@9 489 parm->r_test = GLP_RT_HAR;
alpar@9 490 parm->tol_bnd = lpx_get_real_parm(lp, LPX_K_TOLBND);
alpar@9 491 parm->tol_dj = lpx_get_real_parm(lp, LPX_K_TOLDJ);
alpar@9 492 parm->tol_piv = lpx_get_real_parm(lp, LPX_K_TOLPIV);
alpar@9 493 parm->obj_ll = lpx_get_real_parm(lp, LPX_K_OBJLL);
alpar@9 494 parm->obj_ul = lpx_get_real_parm(lp, LPX_K_OBJUL);
alpar@9 495 if (lpx_get_int_parm(lp, LPX_K_ITLIM) < 0)
alpar@9 496 parm->it_lim = INT_MAX;
alpar@9 497 else
alpar@9 498 parm->it_lim = lpx_get_int_parm(lp, LPX_K_ITLIM);
alpar@9 499 if (lpx_get_real_parm(lp, LPX_K_TMLIM) < 0.0)
alpar@9 500 parm->tm_lim = INT_MAX;
alpar@9 501 else
alpar@9 502 parm->tm_lim =
alpar@9 503 (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_TMLIM));
alpar@9 504 parm->out_frq = lpx_get_int_parm(lp, LPX_K_OUTFRQ);
alpar@9 505 parm->out_dly =
alpar@9 506 (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_OUTDLY));
alpar@9 507 switch (lpx_get_int_parm(lp, LPX_K_PRESOL))
alpar@9 508 { case 0: parm->presolve = GLP_OFF; break;
alpar@9 509 case 1: parm->presolve = GLP_ON; break;
alpar@9 510 default: xassert(lp != lp);
alpar@9 511 }
alpar@9 512 return;
alpar@9 513 }
alpar@9 514
alpar@9 515 int lpx_simplex(LPX *lp)
alpar@9 516 { /* easy-to-use driver to the simplex method */
alpar@9 517 glp_smcp parm;
alpar@9 518 int ret;
alpar@9 519 fill_smcp(lp, &parm);
alpar@9 520 ret = glp_simplex(lp, &parm);
alpar@9 521 switch (ret)
alpar@9 522 { case 0: ret = LPX_E_OK; break;
alpar@9 523 case GLP_EBADB:
alpar@9 524 case GLP_ESING:
alpar@9 525 case GLP_ECOND:
alpar@9 526 case GLP_EBOUND: ret = LPX_E_FAULT; break;
alpar@9 527 case GLP_EFAIL: ret = LPX_E_SING; break;
alpar@9 528 case GLP_EOBJLL: ret = LPX_E_OBJLL; break;
alpar@9 529 case GLP_EOBJUL: ret = LPX_E_OBJUL; break;
alpar@9 530 case GLP_EITLIM: ret = LPX_E_ITLIM; break;
alpar@9 531 case GLP_ETMLIM: ret = LPX_E_TMLIM; break;
alpar@9 532 case GLP_ENOPFS: ret = LPX_E_NOPFS; break;
alpar@9 533 case GLP_ENODFS: ret = LPX_E_NODFS; break;
alpar@9 534 default: xassert(ret != ret);
alpar@9 535 }
alpar@9 536 return ret;
alpar@9 537 }
alpar@9 538
alpar@9 539 int lpx_exact(LPX *lp)
alpar@9 540 { /* easy-to-use driver to the exact simplex method */
alpar@9 541 glp_smcp parm;
alpar@9 542 int ret;
alpar@9 543 fill_smcp(lp, &parm);
alpar@9 544 ret = glp_exact(lp, &parm);
alpar@9 545 switch (ret)
alpar@9 546 { case 0: ret = LPX_E_OK; break;
alpar@9 547 case GLP_EBADB:
alpar@9 548 case GLP_ESING:
alpar@9 549 case GLP_EBOUND:
alpar@9 550 case GLP_EFAIL: ret = LPX_E_FAULT; break;
alpar@9 551 case GLP_EITLIM: ret = LPX_E_ITLIM; break;
alpar@9 552 case GLP_ETMLIM: ret = LPX_E_TMLIM; break;
alpar@9 553 default: xassert(ret != ret);
alpar@9 554 }
alpar@9 555 return ret;
alpar@9 556 }
alpar@9 557
alpar@9 558 int lpx_get_status(glp_prob *lp)
alpar@9 559 { /* retrieve generic status of basic solution */
alpar@9 560 int status;
alpar@9 561 switch (glp_get_status(lp))
alpar@9 562 { case GLP_OPT: status = LPX_OPT; break;
alpar@9 563 case GLP_FEAS: status = LPX_FEAS; break;
alpar@9 564 case GLP_INFEAS: status = LPX_INFEAS; break;
alpar@9 565 case GLP_NOFEAS: status = LPX_NOFEAS; break;
alpar@9 566 case GLP_UNBND: status = LPX_UNBND; break;
alpar@9 567 case GLP_UNDEF: status = LPX_UNDEF; break;
alpar@9 568 default: xassert(lp != lp);
alpar@9 569 }
alpar@9 570 return status;
alpar@9 571 }
alpar@9 572
alpar@9 573 int lpx_get_prim_stat(glp_prob *lp)
alpar@9 574 { /* retrieve status of primal basic solution */
alpar@9 575 return glp_get_prim_stat(lp) - GLP_UNDEF + LPX_P_UNDEF;
alpar@9 576 }
alpar@9 577
alpar@9 578 int lpx_get_dual_stat(glp_prob *lp)
alpar@9 579 { /* retrieve status of dual basic solution */
alpar@9 580 return glp_get_dual_stat(lp) - GLP_UNDEF + LPX_D_UNDEF;
alpar@9 581 }
alpar@9 582
alpar@9 583 double lpx_get_obj_val(LPX *lp)
alpar@9 584 { /* retrieve objective value (basic solution) */
alpar@9 585 return glp_get_obj_val(lp);
alpar@9 586 }
alpar@9 587
alpar@9 588 int lpx_get_row_stat(LPX *lp, int i)
alpar@9 589 { /* retrieve row status (basic solution) */
alpar@9 590 return glp_get_row_stat(lp, i) - GLP_BS + LPX_BS;
alpar@9 591 }
alpar@9 592
alpar@9 593 double lpx_get_row_prim(LPX *lp, int i)
alpar@9 594 { /* retrieve row primal value (basic solution) */
alpar@9 595 return glp_get_row_prim(lp, i);
alpar@9 596 }
alpar@9 597
alpar@9 598 double lpx_get_row_dual(LPX *lp, int i)
alpar@9 599 { /* retrieve row dual value (basic solution) */
alpar@9 600 return glp_get_row_dual(lp, i);
alpar@9 601 }
alpar@9 602
alpar@9 603 void lpx_get_row_info(glp_prob *lp, int i, int *tagx, double *vx,
alpar@9 604 double *dx)
alpar@9 605 { /* obtain row solution information */
alpar@9 606 if (tagx != NULL) *tagx = lpx_get_row_stat(lp, i);
alpar@9 607 if (vx != NULL) *vx = lpx_get_row_prim(lp, i);
alpar@9 608 if (dx != NULL) *dx = lpx_get_row_dual(lp, i);
alpar@9 609 return;
alpar@9 610 }
alpar@9 611
alpar@9 612 int lpx_get_col_stat(LPX *lp, int j)
alpar@9 613 { /* retrieve column status (basic solution) */
alpar@9 614 return glp_get_col_stat(lp, j) - GLP_BS + LPX_BS;
alpar@9 615 }
alpar@9 616
alpar@9 617 double lpx_get_col_prim(LPX *lp, int j)
alpar@9 618 { /* retrieve column primal value (basic solution) */
alpar@9 619 return glp_get_col_prim(lp, j);
alpar@9 620 }
alpar@9 621
alpar@9 622 double lpx_get_col_dual(glp_prob *lp, int j)
alpar@9 623 { /* retrieve column dual value (basic solution) */
alpar@9 624 return glp_get_col_dual(lp, j);
alpar@9 625 }
alpar@9 626
alpar@9 627 void lpx_get_col_info(glp_prob *lp, int j, int *tagx, double *vx,
alpar@9 628 double *dx)
alpar@9 629 { /* obtain column solution information */
alpar@9 630 if (tagx != NULL) *tagx = lpx_get_col_stat(lp, j);
alpar@9 631 if (vx != NULL) *vx = lpx_get_col_prim(lp, j);
alpar@9 632 if (dx != NULL) *dx = lpx_get_col_dual(lp, j);
alpar@9 633 return;
alpar@9 634 }
alpar@9 635
alpar@9 636 int lpx_get_ray_info(LPX *lp)
alpar@9 637 { /* determine what causes primal unboundness */
alpar@9 638 return glp_get_unbnd_ray(lp);
alpar@9 639 }
alpar@9 640
alpar@9 641 void lpx_check_kkt(LPX *lp, int scaled, LPXKKT *kkt)
alpar@9 642 { /* check Karush-Kuhn-Tucker conditions */
alpar@9 643 int ae_ind, re_ind;
alpar@9 644 double ae_max, re_max;
alpar@9 645 xassert(scaled == scaled);
alpar@9 646 _glp_check_kkt(lp, GLP_SOL, GLP_KKT_PE, &ae_max, &ae_ind, &re_max,
alpar@9 647 &re_ind);
alpar@9 648 kkt->pe_ae_max = ae_max;
alpar@9 649 kkt->pe_ae_row = ae_ind;
alpar@9 650 kkt->pe_re_max = re_max;
alpar@9 651 kkt->pe_re_row = re_ind;
alpar@9 652 if (re_max <= 1e-9)
alpar@9 653 kkt->pe_quality = 'H';
alpar@9 654 else if (re_max <= 1e-6)
alpar@9 655 kkt->pe_quality = 'M';
alpar@9 656 else if (re_max <= 1e-3)
alpar@9 657 kkt->pe_quality = 'L';
alpar@9 658 else
alpar@9 659 kkt->pe_quality = '?';
alpar@9 660 _glp_check_kkt(lp, GLP_SOL, GLP_KKT_PB, &ae_max, &ae_ind, &re_max,
alpar@9 661 &re_ind);
alpar@9 662 kkt->pb_ae_max = ae_max;
alpar@9 663 kkt->pb_ae_ind = ae_ind;
alpar@9 664 kkt->pb_re_max = re_max;
alpar@9 665 kkt->pb_re_ind = re_ind;
alpar@9 666 if (re_max <= 1e-9)
alpar@9 667 kkt->pb_quality = 'H';
alpar@9 668 else if (re_max <= 1e-6)
alpar@9 669 kkt->pb_quality = 'M';
alpar@9 670 else if (re_max <= 1e-3)
alpar@9 671 kkt->pb_quality = 'L';
alpar@9 672 else
alpar@9 673 kkt->pb_quality = '?';
alpar@9 674 _glp_check_kkt(lp, GLP_SOL, GLP_KKT_DE, &ae_max, &ae_ind, &re_max,
alpar@9 675 &re_ind);
alpar@9 676 kkt->de_ae_max = ae_max;
alpar@9 677 if (ae_ind == 0)
alpar@9 678 kkt->de_ae_col = 0;
alpar@9 679 else
alpar@9 680 kkt->de_ae_col = ae_ind - lp->m;
alpar@9 681 kkt->de_re_max = re_max;
alpar@9 682 if (re_ind == 0)
alpar@9 683 kkt->de_re_col = 0;
alpar@9 684 else
alpar@9 685 kkt->de_re_col = ae_ind - lp->m;
alpar@9 686 if (re_max <= 1e-9)
alpar@9 687 kkt->de_quality = 'H';
alpar@9 688 else if (re_max <= 1e-6)
alpar@9 689 kkt->de_quality = 'M';
alpar@9 690 else if (re_max <= 1e-3)
alpar@9 691 kkt->de_quality = 'L';
alpar@9 692 else
alpar@9 693 kkt->de_quality = '?';
alpar@9 694 _glp_check_kkt(lp, GLP_SOL, GLP_KKT_DB, &ae_max, &ae_ind, &re_max,
alpar@9 695 &re_ind);
alpar@9 696 kkt->db_ae_max = ae_max;
alpar@9 697 kkt->db_ae_ind = ae_ind;
alpar@9 698 kkt->db_re_max = re_max;
alpar@9 699 kkt->db_re_ind = re_ind;
alpar@9 700 if (re_max <= 1e-9)
alpar@9 701 kkt->db_quality = 'H';
alpar@9 702 else if (re_max <= 1e-6)
alpar@9 703 kkt->db_quality = 'M';
alpar@9 704 else if (re_max <= 1e-3)
alpar@9 705 kkt->db_quality = 'L';
alpar@9 706 else
alpar@9 707 kkt->db_quality = '?';
alpar@9 708 kkt->cs_ae_max = 0.0, kkt->cs_ae_ind = 0;
alpar@9 709 kkt->cs_re_max = 0.0, kkt->cs_re_ind = 0;
alpar@9 710 kkt->cs_quality = 'H';
alpar@9 711 return;
alpar@9 712 }
alpar@9 713
alpar@9 714 int lpx_warm_up(LPX *lp)
alpar@9 715 { /* "warm up" LP basis */
alpar@9 716 int ret;
alpar@9 717 ret = glp_warm_up(lp);
alpar@9 718 if (ret == 0)
alpar@9 719 ret = LPX_E_OK;
alpar@9 720 else if (ret == GLP_EBADB)
alpar@9 721 ret = LPX_E_BADB;
alpar@9 722 else if (ret == GLP_ESING)
alpar@9 723 ret = LPX_E_SING;
alpar@9 724 else if (ret == GLP_ECOND)
alpar@9 725 ret = LPX_E_SING;
alpar@9 726 else
alpar@9 727 xassert(ret != ret);
alpar@9 728 return ret;
alpar@9 729 }
alpar@9 730
alpar@9 731 int lpx_eval_tab_row(LPX *lp, int k, int ind[], double val[])
alpar@9 732 { /* compute row of the simplex tableau */
alpar@9 733 return glp_eval_tab_row(lp, k, ind, val);
alpar@9 734 }
alpar@9 735
alpar@9 736 int lpx_eval_tab_col(LPX *lp, int k, int ind[], double val[])
alpar@9 737 { /* compute column of the simplex tableau */
alpar@9 738 return glp_eval_tab_col(lp, k, ind, val);
alpar@9 739 }
alpar@9 740
alpar@9 741 int lpx_transform_row(LPX *lp, int len, int ind[], double val[])
alpar@9 742 { /* transform explicitly specified row */
alpar@9 743 return glp_transform_row(lp, len, ind, val);
alpar@9 744 }
alpar@9 745
alpar@9 746 int lpx_transform_col(LPX *lp, int len, int ind[], double val[])
alpar@9 747 { /* transform explicitly specified column */
alpar@9 748 return glp_transform_col(lp, len, ind, val);
alpar@9 749 }
alpar@9 750
alpar@9 751 int lpx_prim_ratio_test(LPX *lp, int len, const int ind[],
alpar@9 752 const double val[], int how, double tol)
alpar@9 753 { /* perform primal ratio test */
alpar@9 754 int piv;
alpar@9 755 piv = glp_prim_rtest(lp, len, ind, val, how, tol);
alpar@9 756 xassert(0 <= piv && piv <= len);
alpar@9 757 return piv == 0 ? 0 : ind[piv];
alpar@9 758 }
alpar@9 759
alpar@9 760 int lpx_dual_ratio_test(LPX *lp, int len, const int ind[],
alpar@9 761 const double val[], int how, double tol)
alpar@9 762 { /* perform dual ratio test */
alpar@9 763 int piv;
alpar@9 764 piv = glp_dual_rtest(lp, len, ind, val, how, tol);
alpar@9 765 xassert(0 <= piv && piv <= len);
alpar@9 766 return piv == 0 ? 0 : ind[piv];
alpar@9 767 }
alpar@9 768
alpar@9 769 int lpx_interior(LPX *lp)
alpar@9 770 { /* easy-to-use driver to the interior-point method */
alpar@9 771 int ret;
alpar@9 772 ret = glp_interior(lp, NULL);
alpar@9 773 switch (ret)
alpar@9 774 { case 0: ret = LPX_E_OK; break;
alpar@9 775 case GLP_EFAIL: ret = LPX_E_FAULT; break;
alpar@9 776 case GLP_ENOFEAS: ret = LPX_E_NOFEAS; break;
alpar@9 777 case GLP_ENOCVG: ret = LPX_E_NOCONV; break;
alpar@9 778 case GLP_EITLIM: ret = LPX_E_ITLIM; break;
alpar@9 779 case GLP_EINSTAB: ret = LPX_E_INSTAB; break;
alpar@9 780 default: xassert(ret != ret);
alpar@9 781 }
alpar@9 782 return ret;
alpar@9 783 }
alpar@9 784
alpar@9 785 int lpx_ipt_status(glp_prob *lp)
alpar@9 786 { /* retrieve status of interior-point solution */
alpar@9 787 int status;
alpar@9 788 switch (glp_ipt_status(lp))
alpar@9 789 { case GLP_UNDEF: status = LPX_T_UNDEF; break;
alpar@9 790 case GLP_OPT: status = LPX_T_OPT; break;
alpar@9 791 default: xassert(lp != lp);
alpar@9 792 }
alpar@9 793 return status;
alpar@9 794 }
alpar@9 795
alpar@9 796 double lpx_ipt_obj_val(LPX *lp)
alpar@9 797 { /* retrieve objective value (interior point) */
alpar@9 798 return glp_ipt_obj_val(lp);
alpar@9 799 }
alpar@9 800
alpar@9 801 double lpx_ipt_row_prim(LPX *lp, int i)
alpar@9 802 { /* retrieve row primal value (interior point) */
alpar@9 803 return glp_ipt_row_prim(lp, i);
alpar@9 804 }
alpar@9 805
alpar@9 806 double lpx_ipt_row_dual(LPX *lp, int i)
alpar@9 807 { /* retrieve row dual value (interior point) */
alpar@9 808 return glp_ipt_row_dual(lp, i);
alpar@9 809 }
alpar@9 810
alpar@9 811 double lpx_ipt_col_prim(LPX *lp, int j)
alpar@9 812 { /* retrieve column primal value (interior point) */
alpar@9 813 return glp_ipt_col_prim(lp, j);
alpar@9 814 }
alpar@9 815
alpar@9 816 double lpx_ipt_col_dual(LPX *lp, int j)
alpar@9 817 { /* retrieve column dual value (interior point) */
alpar@9 818 return glp_ipt_col_dual(lp, j);
alpar@9 819 }
alpar@9 820
alpar@9 821 void lpx_set_class(LPX *lp, int klass)
alpar@9 822 { /* set problem class */
alpar@9 823 xassert(lp == lp);
alpar@9 824 if (!(klass == LPX_LP || klass == LPX_MIP))
alpar@9 825 xerror("lpx_set_class: invalid problem class\n");
alpar@9 826 return;
alpar@9 827 }
alpar@9 828
alpar@9 829 int lpx_get_class(LPX *lp)
alpar@9 830 { /* determine problem klass */
alpar@9 831 return glp_get_num_int(lp) == 0 ? LPX_LP : LPX_MIP;
alpar@9 832 }
alpar@9 833
alpar@9 834 void lpx_set_col_kind(LPX *lp, int j, int kind)
alpar@9 835 { /* set (change) column kind */
alpar@9 836 glp_set_col_kind(lp, j, kind - LPX_CV + GLP_CV);
alpar@9 837 return;
alpar@9 838 }
alpar@9 839
alpar@9 840 int lpx_get_col_kind(LPX *lp, int j)
alpar@9 841 { /* retrieve column kind */
alpar@9 842 return glp_get_col_kind(lp, j) == GLP_CV ? LPX_CV : LPX_IV;
alpar@9 843 }
alpar@9 844
alpar@9 845 int lpx_get_num_int(LPX *lp)
alpar@9 846 { /* retrieve number of integer columns */
alpar@9 847 return glp_get_num_int(lp);
alpar@9 848 }
alpar@9 849
alpar@9 850 int lpx_get_num_bin(LPX *lp)
alpar@9 851 { /* retrieve number of binary columns */
alpar@9 852 return glp_get_num_bin(lp);
alpar@9 853 }
alpar@9 854
alpar@9 855 static int solve_mip(LPX *lp, int presolve)
alpar@9 856 { glp_iocp parm;
alpar@9 857 int ret;
alpar@9 858 glp_init_iocp(&parm);
alpar@9 859 switch (lpx_get_int_parm(lp, LPX_K_MSGLEV))
alpar@9 860 { case 0: parm.msg_lev = GLP_MSG_OFF; break;
alpar@9 861 case 1: parm.msg_lev = GLP_MSG_ERR; break;
alpar@9 862 case 2: parm.msg_lev = GLP_MSG_ON; break;
alpar@9 863 case 3: parm.msg_lev = GLP_MSG_ALL; break;
alpar@9 864 default: xassert(lp != lp);
alpar@9 865 }
alpar@9 866 switch (lpx_get_int_parm(lp, LPX_K_BRANCH))
alpar@9 867 { case 0: parm.br_tech = GLP_BR_FFV; break;
alpar@9 868 case 1: parm.br_tech = GLP_BR_LFV; break;
alpar@9 869 case 2: parm.br_tech = GLP_BR_DTH; break;
alpar@9 870 case 3: parm.br_tech = GLP_BR_MFV; break;
alpar@9 871 default: xassert(lp != lp);
alpar@9 872 }
alpar@9 873 switch (lpx_get_int_parm(lp, LPX_K_BTRACK))
alpar@9 874 { case 0: parm.bt_tech = GLP_BT_DFS; break;
alpar@9 875 case 1: parm.bt_tech = GLP_BT_BFS; break;
alpar@9 876 case 2: parm.bt_tech = GLP_BT_BPH; break;
alpar@9 877 case 3: parm.bt_tech = GLP_BT_BLB; break;
alpar@9 878 default: xassert(lp != lp);
alpar@9 879 }
alpar@9 880 parm.tol_int = lpx_get_real_parm(lp, LPX_K_TOLINT);
alpar@9 881 parm.tol_obj = lpx_get_real_parm(lp, LPX_K_TOLOBJ);
alpar@9 882 if (lpx_get_real_parm(lp, LPX_K_TMLIM) < 0.0 ||
alpar@9 883 lpx_get_real_parm(lp, LPX_K_TMLIM) > 1e6)
alpar@9 884 parm.tm_lim = INT_MAX;
alpar@9 885 else
alpar@9 886 parm.tm_lim =
alpar@9 887 (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_TMLIM));
alpar@9 888 parm.mip_gap = lpx_get_real_parm(lp, LPX_K_MIPGAP);
alpar@9 889 if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_GOMORY)
alpar@9 890 parm.gmi_cuts = GLP_ON;
alpar@9 891 else
alpar@9 892 parm.gmi_cuts = GLP_OFF;
alpar@9 893 if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_MIR)
alpar@9 894 parm.mir_cuts = GLP_ON;
alpar@9 895 else
alpar@9 896 parm.mir_cuts = GLP_OFF;
alpar@9 897 if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_COVER)
alpar@9 898 parm.cov_cuts = GLP_ON;
alpar@9 899 else
alpar@9 900 parm.cov_cuts = GLP_OFF;
alpar@9 901 if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_CLIQUE)
alpar@9 902 parm.clq_cuts = GLP_ON;
alpar@9 903 else
alpar@9 904 parm.clq_cuts = GLP_OFF;
alpar@9 905 parm.presolve = presolve;
alpar@9 906 if (lpx_get_int_parm(lp, LPX_K_BINARIZE))
alpar@9 907 parm.binarize = GLP_ON;
alpar@9 908 ret = glp_intopt(lp, &parm);
alpar@9 909 switch (ret)
alpar@9 910 { case 0: ret = LPX_E_OK; break;
alpar@9 911 case GLP_ENOPFS: ret = LPX_E_NOPFS; break;
alpar@9 912 case GLP_ENODFS: ret = LPX_E_NODFS; break;
alpar@9 913 case GLP_EBOUND:
alpar@9 914 case GLP_EROOT: ret = LPX_E_FAULT; break;
alpar@9 915 case GLP_EFAIL: ret = LPX_E_SING; break;
alpar@9 916 case GLP_EMIPGAP: ret = LPX_E_MIPGAP; break;
alpar@9 917 case GLP_ETMLIM: ret = LPX_E_TMLIM; break;
alpar@9 918 default: xassert(ret != ret);
alpar@9 919 }
alpar@9 920 return ret;
alpar@9 921 }
alpar@9 922
alpar@9 923 int lpx_integer(LPX *lp)
alpar@9 924 { /* easy-to-use driver to the branch-and-bound method */
alpar@9 925 return solve_mip(lp, GLP_OFF);
alpar@9 926 }
alpar@9 927
alpar@9 928 int lpx_intopt(LPX *lp)
alpar@9 929 { /* easy-to-use driver to the branch-and-bound method */
alpar@9 930 return solve_mip(lp, GLP_ON);
alpar@9 931 }
alpar@9 932
alpar@9 933 int lpx_mip_status(glp_prob *lp)
alpar@9 934 { /* retrieve status of MIP solution */
alpar@9 935 int status;
alpar@9 936 switch (glp_mip_status(lp))
alpar@9 937 { case GLP_UNDEF: status = LPX_I_UNDEF; break;
alpar@9 938 case GLP_OPT: status = LPX_I_OPT; break;
alpar@9 939 case GLP_FEAS: status = LPX_I_FEAS; break;
alpar@9 940 case GLP_NOFEAS: status = LPX_I_NOFEAS; break;
alpar@9 941 default: xassert(lp != lp);
alpar@9 942 }
alpar@9 943 return status;
alpar@9 944 }
alpar@9 945
alpar@9 946 double lpx_mip_obj_val(LPX *lp)
alpar@9 947 { /* retrieve objective value (MIP solution) */
alpar@9 948 return glp_mip_obj_val(lp);
alpar@9 949 }
alpar@9 950
alpar@9 951 double lpx_mip_row_val(LPX *lp, int i)
alpar@9 952 { /* retrieve row value (MIP solution) */
alpar@9 953 return glp_mip_row_val(lp, i);
alpar@9 954 }
alpar@9 955
alpar@9 956 double lpx_mip_col_val(LPX *lp, int j)
alpar@9 957 { /* retrieve column value (MIP solution) */
alpar@9 958 return glp_mip_col_val(lp, j);
alpar@9 959 }
alpar@9 960
alpar@9 961 void lpx_check_int(LPX *lp, LPXKKT *kkt)
alpar@9 962 { /* check integer feasibility conditions */
alpar@9 963 int ae_ind, re_ind;
alpar@9 964 double ae_max, re_max;
alpar@9 965 _glp_check_kkt(lp, GLP_MIP, GLP_KKT_PE, &ae_max, &ae_ind, &re_max,
alpar@9 966 &re_ind);
alpar@9 967 kkt->pe_ae_max = ae_max;
alpar@9 968 kkt->pe_ae_row = ae_ind;
alpar@9 969 kkt->pe_re_max = re_max;
alpar@9 970 kkt->pe_re_row = re_ind;
alpar@9 971 if (re_max <= 1e-9)
alpar@9 972 kkt->pe_quality = 'H';
alpar@9 973 else if (re_max <= 1e-6)
alpar@9 974 kkt->pe_quality = 'M';
alpar@9 975 else if (re_max <= 1e-3)
alpar@9 976 kkt->pe_quality = 'L';
alpar@9 977 else
alpar@9 978 kkt->pe_quality = '?';
alpar@9 979 _glp_check_kkt(lp, GLP_MIP, GLP_KKT_PB, &ae_max, &ae_ind, &re_max,
alpar@9 980 &re_ind);
alpar@9 981 kkt->pb_ae_max = ae_max;
alpar@9 982 kkt->pb_ae_ind = ae_ind;
alpar@9 983 kkt->pb_re_max = re_max;
alpar@9 984 kkt->pb_re_ind = re_ind;
alpar@9 985 if (re_max <= 1e-9)
alpar@9 986 kkt->pb_quality = 'H';
alpar@9 987 else if (re_max <= 1e-6)
alpar@9 988 kkt->pb_quality = 'M';
alpar@9 989 else if (re_max <= 1e-3)
alpar@9 990 kkt->pb_quality = 'L';
alpar@9 991 else
alpar@9 992 kkt->pb_quality = '?';
alpar@9 993 return;
alpar@9 994 }
alpar@9 995
alpar@9 996 #if 1 /* 17/XI-2009 */
alpar@9 997 static void reset_parms(LPX *lp)
alpar@9 998 { /* reset control parameters to default values */
alpar@9 999 struct LPXCPS *cps = lp->parms;
alpar@9 1000 xassert(cps != NULL);
alpar@9 1001 cps->msg_lev = 3;
alpar@9 1002 cps->scale = 1;
alpar@9 1003 cps->dual = 0;
alpar@9 1004 cps->price = 1;
alpar@9 1005 cps->relax = 0.07;
alpar@9 1006 cps->tol_bnd = 1e-7;
alpar@9 1007 cps->tol_dj = 1e-7;
alpar@9 1008 cps->tol_piv = 1e-9;
alpar@9 1009 cps->round = 0;
alpar@9 1010 cps->obj_ll = -DBL_MAX;
alpar@9 1011 cps->obj_ul = +DBL_MAX;
alpar@9 1012 cps->it_lim = -1;
alpar@9 1013 #if 0 /* 02/XII-2010 */
alpar@9 1014 lp->it_cnt = 0;
alpar@9 1015 #endif
alpar@9 1016 cps->tm_lim = -1.0;
alpar@9 1017 cps->out_frq = 200;
alpar@9 1018 cps->out_dly = 0.0;
alpar@9 1019 cps->branch = 2;
alpar@9 1020 cps->btrack = 3;
alpar@9 1021 cps->tol_int = 1e-5;
alpar@9 1022 cps->tol_obj = 1e-7;
alpar@9 1023 cps->mps_info = 1;
alpar@9 1024 cps->mps_obj = 2;
alpar@9 1025 cps->mps_orig = 0;
alpar@9 1026 cps->mps_wide = 1;
alpar@9 1027 cps->mps_free = 0;
alpar@9 1028 cps->mps_skip = 0;
alpar@9 1029 cps->lpt_orig = 0;
alpar@9 1030 cps->presol = 0;
alpar@9 1031 cps->binarize = 0;
alpar@9 1032 cps->use_cuts = 0;
alpar@9 1033 cps->mip_gap = 0.0;
alpar@9 1034 return;
alpar@9 1035 }
alpar@9 1036 #endif
alpar@9 1037
alpar@9 1038 #if 1 /* 17/XI-2009 */
alpar@9 1039 static struct LPXCPS *access_parms(LPX *lp)
alpar@9 1040 { /* allocate and initialize control parameters, if necessary */
alpar@9 1041 if (lp->parms == NULL)
alpar@9 1042 { lp->parms = xmalloc(sizeof(struct LPXCPS));
alpar@9 1043 reset_parms(lp);
alpar@9 1044 }
alpar@9 1045 return lp->parms;
alpar@9 1046 }
alpar@9 1047 #endif
alpar@9 1048
alpar@9 1049 #if 1 /* 17/XI-2009 */
alpar@9 1050 void lpx_reset_parms(LPX *lp)
alpar@9 1051 { /* reset control parameters to default values */
alpar@9 1052 access_parms(lp);
alpar@9 1053 reset_parms(lp);
alpar@9 1054 return;
alpar@9 1055 }
alpar@9 1056 #endif
alpar@9 1057
alpar@9 1058 void lpx_set_int_parm(LPX *lp, int parm, int val)
alpar@9 1059 { /* set (change) integer control parameter */
alpar@9 1060 #if 0 /* 17/XI-2009 */
alpar@9 1061 struct LPXCPS *cps = lp->cps;
alpar@9 1062 #else
alpar@9 1063 struct LPXCPS *cps = access_parms(lp);
alpar@9 1064 #endif
alpar@9 1065 switch (parm)
alpar@9 1066 { case LPX_K_MSGLEV:
alpar@9 1067 if (!(0 <= val && val <= 3))
alpar@9 1068 xerror("lpx_set_int_parm: MSGLEV = %d; invalid value\n",
alpar@9 1069 val);
alpar@9 1070 cps->msg_lev = val;
alpar@9 1071 break;
alpar@9 1072 case LPX_K_SCALE:
alpar@9 1073 if (!(0 <= val && val <= 3))
alpar@9 1074 xerror("lpx_set_int_parm: SCALE = %d; invalid value\n",
alpar@9 1075 val);
alpar@9 1076 cps->scale = val;
alpar@9 1077 break;
alpar@9 1078 case LPX_K_DUAL:
alpar@9 1079 if (!(val == 0 || val == 1))
alpar@9 1080 xerror("lpx_set_int_parm: DUAL = %d; invalid value\n",
alpar@9 1081 val);
alpar@9 1082 cps->dual = val;
alpar@9 1083 break;
alpar@9 1084 case LPX_K_PRICE:
alpar@9 1085 if (!(val == 0 || val == 1))
alpar@9 1086 xerror("lpx_set_int_parm: PRICE = %d; invalid value\n",
alpar@9 1087 val);
alpar@9 1088 cps->price = val;
alpar@9 1089 break;
alpar@9 1090 case LPX_K_ROUND:
alpar@9 1091 if (!(val == 0 || val == 1))
alpar@9 1092 xerror("lpx_set_int_parm: ROUND = %d; invalid value\n",
alpar@9 1093 val);
alpar@9 1094 cps->round = val;
alpar@9 1095 break;
alpar@9 1096 case LPX_K_ITLIM:
alpar@9 1097 cps->it_lim = val;
alpar@9 1098 break;
alpar@9 1099 case LPX_K_ITCNT:
alpar@9 1100 lp->it_cnt = val;
alpar@9 1101 break;
alpar@9 1102 case LPX_K_OUTFRQ:
alpar@9 1103 if (!(val > 0))
alpar@9 1104 xerror("lpx_set_int_parm: OUTFRQ = %d; invalid value\n",
alpar@9 1105 val);
alpar@9 1106 cps->out_frq = val;
alpar@9 1107 break;
alpar@9 1108 case LPX_K_BRANCH:
alpar@9 1109 if (!(val == 0 || val == 1 || val == 2 || val == 3))
alpar@9 1110 xerror("lpx_set_int_parm: BRANCH = %d; invalid value\n",
alpar@9 1111 val);
alpar@9 1112 cps->branch = val;
alpar@9 1113 break;
alpar@9 1114 case LPX_K_BTRACK:
alpar@9 1115 if (!(val == 0 || val == 1 || val == 2 || val == 3))
alpar@9 1116 xerror("lpx_set_int_parm: BTRACK = %d; invalid value\n",
alpar@9 1117 val);
alpar@9 1118 cps->btrack = val;
alpar@9 1119 break;
alpar@9 1120 case LPX_K_MPSINFO:
alpar@9 1121 if (!(val == 0 || val == 1))
alpar@9 1122 xerror("lpx_set_int_parm: MPSINFO = %d; invalid value\n",
alpar@9 1123 val);
alpar@9 1124 cps->mps_info = val;
alpar@9 1125 break;
alpar@9 1126 case LPX_K_MPSOBJ:
alpar@9 1127 if (!(val == 0 || val == 1 || val == 2))
alpar@9 1128 xerror("lpx_set_int_parm: MPSOBJ = %d; invalid value\n",
alpar@9 1129 val);
alpar@9 1130 cps->mps_obj = val;
alpar@9 1131 break;
alpar@9 1132 case LPX_K_MPSORIG:
alpar@9 1133 if (!(val == 0 || val == 1))
alpar@9 1134 xerror("lpx_set_int_parm: MPSORIG = %d; invalid value\n",
alpar@9 1135 val);
alpar@9 1136 cps->mps_orig = val;
alpar@9 1137 break;
alpar@9 1138 case LPX_K_MPSWIDE:
alpar@9 1139 if (!(val == 0 || val == 1))
alpar@9 1140 xerror("lpx_set_int_parm: MPSWIDE = %d; invalid value\n",
alpar@9 1141 val);
alpar@9 1142 cps->mps_wide = val;
alpar@9 1143 break;
alpar@9 1144 case LPX_K_MPSFREE:
alpar@9 1145 if (!(val == 0 || val == 1))
alpar@9 1146 xerror("lpx_set_int_parm: MPSFREE = %d; invalid value\n",
alpar@9 1147 val);
alpar@9 1148 cps->mps_free = val;
alpar@9 1149 break;
alpar@9 1150 case LPX_K_MPSSKIP:
alpar@9 1151 if (!(val == 0 || val == 1))
alpar@9 1152 xerror("lpx_set_int_parm: MPSSKIP = %d; invalid value\n",
alpar@9 1153 val);
alpar@9 1154 cps->mps_skip = val;
alpar@9 1155 break;
alpar@9 1156 case LPX_K_LPTORIG:
alpar@9 1157 if (!(val == 0 || val == 1))
alpar@9 1158 xerror("lpx_set_int_parm: LPTORIG = %d; invalid value\n",
alpar@9 1159 val);
alpar@9 1160 cps->lpt_orig = val;
alpar@9 1161 break;
alpar@9 1162 case LPX_K_PRESOL:
alpar@9 1163 if (!(val == 0 || val == 1))
alpar@9 1164 xerror("lpx_set_int_parm: PRESOL = %d; invalid value\n",
alpar@9 1165 val);
alpar@9 1166 cps->presol = val;
alpar@9 1167 break;
alpar@9 1168 case LPX_K_BINARIZE:
alpar@9 1169 if (!(val == 0 || val == 1))
alpar@9 1170 xerror("lpx_set_int_parm: BINARIZE = %d; invalid value\n"
alpar@9 1171 , val);
alpar@9 1172 cps->binarize = val;
alpar@9 1173 break;
alpar@9 1174 case LPX_K_USECUTS:
alpar@9 1175 if (val & ~LPX_C_ALL)
alpar@9 1176 xerror("lpx_set_int_parm: USECUTS = 0x%X; invalid value\n",
alpar@9 1177 val);
alpar@9 1178 cps->use_cuts = val;
alpar@9 1179 break;
alpar@9 1180 case LPX_K_BFTYPE:
alpar@9 1181 #if 0
alpar@9 1182 if (!(1 <= val && val <= 3))
alpar@9 1183 xerror("lpx_set_int_parm: BFTYPE = %d; invalid value\n",
alpar@9 1184 val);
alpar@9 1185 cps->bf_type = val;
alpar@9 1186 #else
alpar@9 1187 { glp_bfcp parm;
alpar@9 1188 glp_get_bfcp(lp, &parm);
alpar@9 1189 switch (val)
alpar@9 1190 { case 1:
alpar@9 1191 parm.type = GLP_BF_FT; break;
alpar@9 1192 case 2:
alpar@9 1193 parm.type = GLP_BF_BG; break;
alpar@9 1194 case 3:
alpar@9 1195 parm.type = GLP_BF_GR; break;
alpar@9 1196 default:
alpar@9 1197 xerror("lpx_set_int_parm: BFTYPE = %d; invalid val"
alpar@9 1198 "ue\n", val);
alpar@9 1199 }
alpar@9 1200 glp_set_bfcp(lp, &parm);
alpar@9 1201 }
alpar@9 1202 #endif
alpar@9 1203 break;
alpar@9 1204 default:
alpar@9 1205 xerror("lpx_set_int_parm: parm = %d; invalid parameter\n",
alpar@9 1206 parm);
alpar@9 1207 }
alpar@9 1208 return;
alpar@9 1209 }
alpar@9 1210
alpar@9 1211 int lpx_get_int_parm(LPX *lp, int parm)
alpar@9 1212 { /* query integer control parameter */
alpar@9 1213 #if 0 /* 17/XI-2009 */
alpar@9 1214 struct LPXCPS *cps = lp->cps;
alpar@9 1215 #else
alpar@9 1216 struct LPXCPS *cps = access_parms(lp);
alpar@9 1217 #endif
alpar@9 1218 int val = 0;
alpar@9 1219 switch (parm)
alpar@9 1220 { case LPX_K_MSGLEV:
alpar@9 1221 val = cps->msg_lev; break;
alpar@9 1222 case LPX_K_SCALE:
alpar@9 1223 val = cps->scale; break;
alpar@9 1224 case LPX_K_DUAL:
alpar@9 1225 val = cps->dual; break;
alpar@9 1226 case LPX_K_PRICE:
alpar@9 1227 val = cps->price; break;
alpar@9 1228 case LPX_K_ROUND:
alpar@9 1229 val = cps->round; break;
alpar@9 1230 case LPX_K_ITLIM:
alpar@9 1231 val = cps->it_lim; break;
alpar@9 1232 case LPX_K_ITCNT:
alpar@9 1233 val = lp->it_cnt; break;
alpar@9 1234 case LPX_K_OUTFRQ:
alpar@9 1235 val = cps->out_frq; break;
alpar@9 1236 case LPX_K_BRANCH:
alpar@9 1237 val = cps->branch; break;
alpar@9 1238 case LPX_K_BTRACK:
alpar@9 1239 val = cps->btrack; break;
alpar@9 1240 case LPX_K_MPSINFO:
alpar@9 1241 val = cps->mps_info; break;
alpar@9 1242 case LPX_K_MPSOBJ:
alpar@9 1243 val = cps->mps_obj; break;
alpar@9 1244 case LPX_K_MPSORIG:
alpar@9 1245 val = cps->mps_orig; break;
alpar@9 1246 case LPX_K_MPSWIDE:
alpar@9 1247 val = cps->mps_wide; break;
alpar@9 1248 case LPX_K_MPSFREE:
alpar@9 1249 val = cps->mps_free; break;
alpar@9 1250 case LPX_K_MPSSKIP:
alpar@9 1251 val = cps->mps_skip; break;
alpar@9 1252 case LPX_K_LPTORIG:
alpar@9 1253 val = cps->lpt_orig; break;
alpar@9 1254 case LPX_K_PRESOL:
alpar@9 1255 val = cps->presol; break;
alpar@9 1256 case LPX_K_BINARIZE:
alpar@9 1257 val = cps->binarize; break;
alpar@9 1258 case LPX_K_USECUTS:
alpar@9 1259 val = cps->use_cuts; break;
alpar@9 1260 case LPX_K_BFTYPE:
alpar@9 1261 #if 0
alpar@9 1262 val = cps->bf_type; break;
alpar@9 1263 #else
alpar@9 1264 { glp_bfcp parm;
alpar@9 1265 glp_get_bfcp(lp, &parm);
alpar@9 1266 switch (parm.type)
alpar@9 1267 { case GLP_BF_FT:
alpar@9 1268 val = 1; break;
alpar@9 1269 case GLP_BF_BG:
alpar@9 1270 val = 2; break;
alpar@9 1271 case GLP_BF_GR:
alpar@9 1272 val = 3; break;
alpar@9 1273 default:
alpar@9 1274 xassert(lp != lp);
alpar@9 1275 }
alpar@9 1276 }
alpar@9 1277 break;
alpar@9 1278 #endif
alpar@9 1279 default:
alpar@9 1280 xerror("lpx_get_int_parm: parm = %d; invalid parameter\n",
alpar@9 1281 parm);
alpar@9 1282 }
alpar@9 1283 return val;
alpar@9 1284 }
alpar@9 1285
alpar@9 1286 void lpx_set_real_parm(LPX *lp, int parm, double val)
alpar@9 1287 { /* set (change) real control parameter */
alpar@9 1288 #if 0 /* 17/XI-2009 */
alpar@9 1289 struct LPXCPS *cps = lp->cps;
alpar@9 1290 #else
alpar@9 1291 struct LPXCPS *cps = access_parms(lp);
alpar@9 1292 #endif
alpar@9 1293 switch (parm)
alpar@9 1294 { case LPX_K_RELAX:
alpar@9 1295 if (!(0.0 <= val && val <= 1.0))
alpar@9 1296 xerror("lpx_set_real_parm: RELAX = %g; invalid value\n",
alpar@9 1297 val);
alpar@9 1298 cps->relax = val;
alpar@9 1299 break;
alpar@9 1300 case LPX_K_TOLBND:
alpar@9 1301 if (!(DBL_EPSILON <= val && val <= 0.001))
alpar@9 1302 xerror("lpx_set_real_parm: TOLBND = %g; invalid value\n",
alpar@9 1303 val);
alpar@9 1304 #if 0
alpar@9 1305 if (cps->tol_bnd > val)
alpar@9 1306 { /* invalidate the basic solution */
alpar@9 1307 lp->p_stat = LPX_P_UNDEF;
alpar@9 1308 lp->d_stat = LPX_D_UNDEF;
alpar@9 1309 }
alpar@9 1310 #endif
alpar@9 1311 cps->tol_bnd = val;
alpar@9 1312 break;
alpar@9 1313 case LPX_K_TOLDJ:
alpar@9 1314 if (!(DBL_EPSILON <= val && val <= 0.001))
alpar@9 1315 xerror("lpx_set_real_parm: TOLDJ = %g; invalid value\n",
alpar@9 1316 val);
alpar@9 1317 #if 0
alpar@9 1318 if (cps->tol_dj > val)
alpar@9 1319 { /* invalidate the basic solution */
alpar@9 1320 lp->p_stat = LPX_P_UNDEF;
alpar@9 1321 lp->d_stat = LPX_D_UNDEF;
alpar@9 1322 }
alpar@9 1323 #endif
alpar@9 1324 cps->tol_dj = val;
alpar@9 1325 break;
alpar@9 1326 case LPX_K_TOLPIV:
alpar@9 1327 if (!(DBL_EPSILON <= val && val <= 0.001))
alpar@9 1328 xerror("lpx_set_real_parm: TOLPIV = %g; invalid value\n",
alpar@9 1329 val);
alpar@9 1330 cps->tol_piv = val;
alpar@9 1331 break;
alpar@9 1332 case LPX_K_OBJLL:
alpar@9 1333 cps->obj_ll = val;
alpar@9 1334 break;
alpar@9 1335 case LPX_K_OBJUL:
alpar@9 1336 cps->obj_ul = val;
alpar@9 1337 break;
alpar@9 1338 case LPX_K_TMLIM:
alpar@9 1339 cps->tm_lim = val;
alpar@9 1340 break;
alpar@9 1341 case LPX_K_OUTDLY:
alpar@9 1342 cps->out_dly = val;
alpar@9 1343 break;
alpar@9 1344 case LPX_K_TOLINT:
alpar@9 1345 if (!(DBL_EPSILON <= val && val <= 0.001))
alpar@9 1346 xerror("lpx_set_real_parm: TOLINT = %g; invalid value\n",
alpar@9 1347 val);
alpar@9 1348 cps->tol_int = val;
alpar@9 1349 break;
alpar@9 1350 case LPX_K_TOLOBJ:
alpar@9 1351 if (!(DBL_EPSILON <= val && val <= 0.001))
alpar@9 1352 xerror("lpx_set_real_parm: TOLOBJ = %g; invalid value\n",
alpar@9 1353 val);
alpar@9 1354 cps->tol_obj = val;
alpar@9 1355 break;
alpar@9 1356 case LPX_K_MIPGAP:
alpar@9 1357 if (val < 0.0)
alpar@9 1358 xerror("lpx_set_real_parm: MIPGAP = %g; invalid value\n",
alpar@9 1359 val);
alpar@9 1360 cps->mip_gap = val;
alpar@9 1361 break;
alpar@9 1362 default:
alpar@9 1363 xerror("lpx_set_real_parm: parm = %d; invalid parameter\n",
alpar@9 1364 parm);
alpar@9 1365 }
alpar@9 1366 return;
alpar@9 1367 }
alpar@9 1368
alpar@9 1369 double lpx_get_real_parm(LPX *lp, int parm)
alpar@9 1370 { /* query real control parameter */
alpar@9 1371 #if 0 /* 17/XI-2009 */
alpar@9 1372 struct LPXCPS *cps = lp->cps;
alpar@9 1373 #else
alpar@9 1374 struct LPXCPS *cps = access_parms(lp);
alpar@9 1375 #endif
alpar@9 1376 double val = 0.0;
alpar@9 1377 switch (parm)
alpar@9 1378 { case LPX_K_RELAX:
alpar@9 1379 val = cps->relax;
alpar@9 1380 break;
alpar@9 1381 case LPX_K_TOLBND:
alpar@9 1382 val = cps->tol_bnd;
alpar@9 1383 break;
alpar@9 1384 case LPX_K_TOLDJ:
alpar@9 1385 val = cps->tol_dj;
alpar@9 1386 break;
alpar@9 1387 case LPX_K_TOLPIV:
alpar@9 1388 val = cps->tol_piv;
alpar@9 1389 break;
alpar@9 1390 case LPX_K_OBJLL:
alpar@9 1391 val = cps->obj_ll;
alpar@9 1392 break;
alpar@9 1393 case LPX_K_OBJUL:
alpar@9 1394 val = cps->obj_ul;
alpar@9 1395 break;
alpar@9 1396 case LPX_K_TMLIM:
alpar@9 1397 val = cps->tm_lim;
alpar@9 1398 break;
alpar@9 1399 case LPX_K_OUTDLY:
alpar@9 1400 val = cps->out_dly;
alpar@9 1401 break;
alpar@9 1402 case LPX_K_TOLINT:
alpar@9 1403 val = cps->tol_int;
alpar@9 1404 break;
alpar@9 1405 case LPX_K_TOLOBJ:
alpar@9 1406 val = cps->tol_obj;
alpar@9 1407 break;
alpar@9 1408 case LPX_K_MIPGAP:
alpar@9 1409 val = cps->mip_gap;
alpar@9 1410 break;
alpar@9 1411 default:
alpar@9 1412 xerror("lpx_get_real_parm: parm = %d; invalid parameter\n",
alpar@9 1413 parm);
alpar@9 1414 }
alpar@9 1415 return val;
alpar@9 1416 }
alpar@9 1417
alpar@9 1418 LPX *lpx_read_mps(const char *fname)
alpar@9 1419 { /* read problem data in fixed MPS format */
alpar@9 1420 LPX *lp = lpx_create_prob();
alpar@9 1421 if (glp_read_mps(lp, GLP_MPS_DECK, NULL, fname))
alpar@9 1422 lpx_delete_prob(lp), lp = NULL;
alpar@9 1423 return lp;
alpar@9 1424 }
alpar@9 1425
alpar@9 1426 int lpx_write_mps(LPX *lp, const char *fname)
alpar@9 1427 { /* write problem data in fixed MPS format */
alpar@9 1428 return glp_write_mps(lp, GLP_MPS_DECK, NULL, fname);
alpar@9 1429 }
alpar@9 1430
alpar@9 1431 int lpx_read_bas(LPX *lp, const char *fname)
alpar@9 1432 { /* read LP basis in fixed MPS format */
alpar@9 1433 #if 0 /* 13/IV-2009 */
alpar@9 1434 return read_bas(lp, fname);
alpar@9 1435 #else
alpar@9 1436 xassert(lp == lp);
alpar@9 1437 xassert(fname == fname);
alpar@9 1438 xerror("lpx_read_bas: operation not supported\n");
alpar@9 1439 return 0;
alpar@9 1440 #endif
alpar@9 1441 }
alpar@9 1442
alpar@9 1443 int lpx_write_bas(LPX *lp, const char *fname)
alpar@9 1444 { /* write LP basis in fixed MPS format */
alpar@9 1445 #if 0 /* 13/IV-2009 */
alpar@9 1446 return write_bas(lp, fname);
alpar@9 1447 #else
alpar@9 1448 xassert(lp == lp);
alpar@9 1449 xassert(fname == fname);
alpar@9 1450 xerror("lpx_write_bas: operation not supported\n");
alpar@9 1451 return 0;
alpar@9 1452 #endif
alpar@9 1453 }
alpar@9 1454
alpar@9 1455 LPX *lpx_read_freemps(const char *fname)
alpar@9 1456 { /* read problem data in free MPS format */
alpar@9 1457 LPX *lp = lpx_create_prob();
alpar@9 1458 if (glp_read_mps(lp, GLP_MPS_FILE, NULL, fname))
alpar@9 1459 lpx_delete_prob(lp), lp = NULL;
alpar@9 1460 return lp;
alpar@9 1461 }
alpar@9 1462
alpar@9 1463 int lpx_write_freemps(LPX *lp, const char *fname)
alpar@9 1464 { /* write problem data in free MPS format */
alpar@9 1465 return glp_write_mps(lp, GLP_MPS_FILE, NULL, fname);
alpar@9 1466 }
alpar@9 1467
alpar@9 1468 LPX *lpx_read_cpxlp(const char *fname)
alpar@9 1469 { /* read problem data in CPLEX LP format */
alpar@9 1470 LPX *lp;
alpar@9 1471 lp = lpx_create_prob();
alpar@9 1472 if (glp_read_lp(lp, NULL, fname))
alpar@9 1473 lpx_delete_prob(lp), lp = NULL;
alpar@9 1474 return lp;
alpar@9 1475 }
alpar@9 1476
alpar@9 1477 int lpx_write_cpxlp(LPX *lp, const char *fname)
alpar@9 1478 { /* write problem data in CPLEX LP format */
alpar@9 1479 return glp_write_lp(lp, NULL, fname);
alpar@9 1480 }
alpar@9 1481
alpar@9 1482 LPX *lpx_read_model(const char *model, const char *data, const char
alpar@9 1483 *output)
alpar@9 1484 { /* read LP/MIP model written in GNU MathProg language */
alpar@9 1485 LPX *lp = NULL;
alpar@9 1486 glp_tran *tran;
alpar@9 1487 /* allocate the translator workspace */
alpar@9 1488 tran = glp_mpl_alloc_wksp();
alpar@9 1489 /* read model section and optional data section */
alpar@9 1490 if (glp_mpl_read_model(tran, model, data != NULL)) goto done;
alpar@9 1491 /* read separate data section, if required */
alpar@9 1492 if (data != NULL)
alpar@9 1493 if (glp_mpl_read_data(tran, data)) goto done;
alpar@9 1494 /* generate the model */
alpar@9 1495 if (glp_mpl_generate(tran, output)) goto done;
alpar@9 1496 /* build the problem instance from the model */
alpar@9 1497 lp = glp_create_prob();
alpar@9 1498 glp_mpl_build_prob(tran, lp);
alpar@9 1499 done: /* free the translator workspace */
alpar@9 1500 glp_mpl_free_wksp(tran);
alpar@9 1501 /* bring the problem object to the calling program */
alpar@9 1502 return lp;
alpar@9 1503 }
alpar@9 1504
alpar@9 1505 int lpx_print_prob(LPX *lp, const char *fname)
alpar@9 1506 { /* write problem data in plain text format */
alpar@9 1507 return glp_write_lp(lp, NULL, fname);
alpar@9 1508 }
alpar@9 1509
alpar@9 1510 int lpx_print_sol(LPX *lp, const char *fname)
alpar@9 1511 { /* write LP problem solution in printable format */
alpar@9 1512 return glp_print_sol(lp, fname);
alpar@9 1513 }
alpar@9 1514
alpar@9 1515 int lpx_print_sens_bnds(LPX *lp, const char *fname)
alpar@9 1516 { /* write bounds sensitivity information */
alpar@9 1517 if (glp_get_status(lp) == GLP_OPT && !glp_bf_exists(lp))
alpar@9 1518 glp_factorize(lp);
alpar@9 1519 return glp_print_ranges(lp, 0, NULL, 0, fname);
alpar@9 1520 }
alpar@9 1521
alpar@9 1522 int lpx_print_ips(LPX *lp, const char *fname)
alpar@9 1523 { /* write interior point solution in printable format */
alpar@9 1524 return glp_print_ipt(lp, fname);
alpar@9 1525 }
alpar@9 1526
alpar@9 1527 int lpx_print_mip(LPX *lp, const char *fname)
alpar@9 1528 { /* write MIP problem solution in printable format */
alpar@9 1529 return glp_print_mip(lp, fname);
alpar@9 1530 }
alpar@9 1531
alpar@9 1532 int lpx_is_b_avail(glp_prob *lp)
alpar@9 1533 { /* check if LP basis is available */
alpar@9 1534 return glp_bf_exists(lp);
alpar@9 1535 }
alpar@9 1536
alpar@9 1537 int lpx_main(int argc, const char *argv[])
alpar@9 1538 { /* stand-alone LP/MIP solver */
alpar@9 1539 return glp_main(argc, argv);
alpar@9 1540 }
alpar@9 1541
alpar@9 1542 /* eof */