alpar@1: /* glplpx01.c (obsolete API routines) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #include "glpapi.h" alpar@1: alpar@1: struct LPXCPS alpar@1: { /* control parameters and statistics */ alpar@1: int msg_lev; alpar@1: /* level of messages output by the solver: alpar@1: 0 - no output alpar@1: 1 - error messages only alpar@1: 2 - normal output alpar@1: 3 - full output (includes informational messages) */ alpar@1: int scale; alpar@1: /* scaling option: alpar@1: 0 - no scaling alpar@1: 1 - equilibration scaling alpar@1: 2 - geometric mean scaling alpar@1: 3 - geometric mean scaling, then equilibration scaling */ alpar@1: int dual; alpar@1: /* dual simplex option: alpar@1: 0 - use primal simplex alpar@1: 1 - use dual simplex */ alpar@1: int price; alpar@1: /* pricing option (for both primal and dual simplex): alpar@1: 0 - textbook pricing alpar@1: 1 - steepest edge pricing */ alpar@1: double relax; alpar@1: /* relaxation parameter used in the ratio test; if it is zero, alpar@1: the textbook ratio test is used; if it is non-zero (should be alpar@1: positive), Harris' two-pass ratio test is used; in the latter alpar@1: case on the first pass basic variables (in the case of primal alpar@1: simplex) or reduced costs of non-basic variables (in the case alpar@1: of dual simplex) are allowed to slightly violate their bounds, alpar@1: but not more than (relax * tol_bnd) or (relax * tol_dj) (thus, alpar@1: relax is a percentage of tol_bnd or tol_dj) */ alpar@1: double tol_bnd; alpar@1: /* relative tolerance used to check if the current basic solution alpar@1: is primal feasible */ alpar@1: double tol_dj; alpar@1: /* absolute tolerance used to check if the current basic solution alpar@1: is dual feasible */ alpar@1: double tol_piv; alpar@1: /* relative tolerance used to choose eligible pivotal elements of alpar@1: the simplex table in the ratio test */ alpar@1: int round; alpar@1: /* solution rounding option: alpar@1: 0 - report all computed values and reduced costs "as is" alpar@1: 1 - if possible (allowed by the tolerances), replace computed alpar@1: values and reduced costs which are close to zero by exact alpar@1: zeros */ alpar@1: double obj_ll; alpar@1: /* lower limit of the objective function; if on the phase II the alpar@1: objective function reaches this limit and continues decreasing, alpar@1: the solver stops the search */ alpar@1: double obj_ul; alpar@1: /* upper limit of the objective function; if on the phase II the alpar@1: objective function reaches this limit and continues increasing, alpar@1: the solver stops the search */ alpar@1: int it_lim; alpar@1: /* simplex iterations limit; if this value is positive, it is alpar@1: decreased by one each time when one simplex iteration has been alpar@1: performed, and reaching zero value signals the solver to stop alpar@1: the search; negative value means no iterations limit */ alpar@1: double tm_lim; alpar@1: /* searching time limit, in seconds; if this value is positive, alpar@1: it is decreased each time when one simplex iteration has been alpar@1: performed by the amount of time spent for the iteration, and alpar@1: reaching zero value signals the solver to stop the search; alpar@1: negative value means no time limit */ alpar@1: int out_frq; alpar@1: /* output frequency, in iterations; this parameter specifies how alpar@1: frequently the solver sends information about the solution to alpar@1: the standard output */ alpar@1: double out_dly; alpar@1: /* output delay, in seconds; this parameter specifies how long alpar@1: the solver should delay sending information about the solution alpar@1: to the standard output; zero value means no delay */ alpar@1: int branch; /* MIP */ alpar@1: /* branching heuristic: alpar@1: 0 - branch on first variable alpar@1: 1 - branch on last variable alpar@1: 2 - branch using heuristic by Driebeck and Tomlin alpar@1: 3 - branch on most fractional variable */ alpar@1: int btrack; /* MIP */ alpar@1: /* backtracking heuristic: alpar@1: 0 - select most recent node (depth first search) alpar@1: 1 - select earliest node (breadth first search) alpar@1: 2 - select node using the best projection heuristic alpar@1: 3 - select node with best local bound */ alpar@1: double tol_int; /* MIP */ alpar@1: /* absolute tolerance used to check if the current basic solution alpar@1: is integer feasible */ alpar@1: double tol_obj; /* MIP */ alpar@1: /* relative tolerance used to check if the value of the objective alpar@1: function is not better than in the best known integer feasible alpar@1: solution */ alpar@1: int mps_info; /* lpx_write_mps */ alpar@1: /* if this flag is set, the routine lpx_write_mps outputs several alpar@1: comment cards that contains some information about the problem; alpar@1: otherwise the routine outputs no comment cards */ alpar@1: int mps_obj; /* lpx_write_mps */ alpar@1: /* this parameter tells the routine lpx_write_mps how to output alpar@1: the objective function row: alpar@1: 0 - never output objective function row alpar@1: 1 - always output objective function row alpar@1: 2 - output objective function row if and only if the problem alpar@1: has no free rows */ alpar@1: int mps_orig; /* lpx_write_mps */ alpar@1: /* if this flag is set, the routine lpx_write_mps uses original alpar@1: row and column symbolic names; otherwise the routine generates alpar@1: plain names using ordinal numbers of rows and columns */ alpar@1: int mps_wide; /* lpx_write_mps */ alpar@1: /* if this flag is set, the routine lpx_write_mps uses all data alpar@1: fields; otherwise the routine keeps fields 5 and 6 empty */ alpar@1: int mps_free; /* lpx_write_mps */ alpar@1: /* if this flag is set, the routine lpx_write_mps omits column alpar@1: and vector names everytime if possible (free style); otherwise alpar@1: the routine never omits these names (pedantic style) */ alpar@1: int mps_skip; /* lpx_write_mps */ alpar@1: /* if this flag is set, the routine lpx_write_mps skips empty alpar@1: columns (i.e. which has no constraint coefficients); otherwise alpar@1: the routine outputs all columns */ alpar@1: int lpt_orig; /* lpx_write_lpt */ alpar@1: /* if this flag is set, the routine lpx_write_lpt uses original alpar@1: row and column symbolic names; otherwise the routine generates alpar@1: plain names using ordinal numbers of rows and columns */ alpar@1: int presol; /* lpx_simplex */ alpar@1: /* LP presolver option: alpar@1: 0 - do not use LP presolver alpar@1: 1 - use LP presolver */ alpar@1: int binarize; /* lpx_intopt */ alpar@1: /* if this flag is set, the routine lpx_intopt replaces integer alpar@1: columns by binary ones */ alpar@1: int use_cuts; /* lpx_intopt */ alpar@1: /* if this flag is set, the routine lpx_intopt tries generating alpar@1: cutting planes: alpar@1: LPX_C_COVER - mixed cover cuts alpar@1: LPX_C_CLIQUE - clique cuts alpar@1: LPX_C_GOMORY - Gomory's mixed integer cuts alpar@1: LPX_C_ALL - all cuts */ alpar@1: double mip_gap; /* MIP */ alpar@1: /* relative MIP gap tolerance */ alpar@1: }; alpar@1: alpar@1: LPX *lpx_create_prob(void) alpar@1: { /* create problem object */ alpar@1: return glp_create_prob(); alpar@1: } alpar@1: alpar@1: void lpx_set_prob_name(LPX *lp, const char *name) alpar@1: { /* assign (change) problem name */ alpar@1: glp_set_prob_name(lp, name); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_obj_name(LPX *lp, const char *name) alpar@1: { /* assign (change) objective function name */ alpar@1: glp_set_obj_name(lp, name); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_obj_dir(LPX *lp, int dir) alpar@1: { /* set (change) optimization direction flag */ alpar@1: glp_set_obj_dir(lp, dir - LPX_MIN + GLP_MIN); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_add_rows(LPX *lp, int nrs) alpar@1: { /* add new rows to problem object */ alpar@1: return glp_add_rows(lp, nrs); alpar@1: } alpar@1: alpar@1: int lpx_add_cols(LPX *lp, int ncs) alpar@1: { /* add new columns to problem object */ alpar@1: return glp_add_cols(lp, ncs); alpar@1: } alpar@1: alpar@1: void lpx_set_row_name(LPX *lp, int i, const char *name) alpar@1: { /* assign (change) row name */ alpar@1: glp_set_row_name(lp, i, name); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_col_name(LPX *lp, int j, const char *name) alpar@1: { /* assign (change) column name */ alpar@1: glp_set_col_name(lp, j, name); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_row_bnds(LPX *lp, int i, int type, double lb, double ub) alpar@1: { /* set (change) row bounds */ alpar@1: glp_set_row_bnds(lp, i, type - LPX_FR + GLP_FR, lb, ub); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_col_bnds(LPX *lp, int j, int type, double lb, double ub) alpar@1: { /* set (change) column bounds */ alpar@1: glp_set_col_bnds(lp, j, type - LPX_FR + GLP_FR, lb, ub); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_obj_coef(glp_prob *lp, int j, double coef) alpar@1: { /* set (change) obj. coefficient or constant term */ alpar@1: glp_set_obj_coef(lp, j, coef); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_mat_row(LPX *lp, int i, int len, const int ind[], alpar@1: const double val[]) alpar@1: { /* set (replace) row of the constraint matrix */ alpar@1: glp_set_mat_row(lp, i, len, ind, val); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_mat_col(LPX *lp, int j, int len, const int ind[], alpar@1: const double val[]) alpar@1: { /* set (replace) column of the constraint matrix */ alpar@1: glp_set_mat_col(lp, j, len, ind, val); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_load_matrix(LPX *lp, int ne, const int ia[], const int ja[], alpar@1: const double ar[]) alpar@1: { /* load (replace) the whole constraint matrix */ alpar@1: glp_load_matrix(lp, ne, ia, ja, ar); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_del_rows(LPX *lp, int nrs, const int num[]) alpar@1: { /* delete specified rows from problem object */ alpar@1: glp_del_rows(lp, nrs, num); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_del_cols(LPX *lp, int ncs, const int num[]) alpar@1: { /* delete specified columns from problem object */ alpar@1: glp_del_cols(lp, ncs, num); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_delete_prob(LPX *lp) alpar@1: { /* delete problem object */ alpar@1: glp_delete_prob(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: const char *lpx_get_prob_name(LPX *lp) alpar@1: { /* retrieve problem name */ alpar@1: return glp_get_prob_name(lp); alpar@1: } alpar@1: alpar@1: const char *lpx_get_obj_name(LPX *lp) alpar@1: { /* retrieve objective function name */ alpar@1: return glp_get_obj_name(lp); alpar@1: } alpar@1: alpar@1: int lpx_get_obj_dir(LPX *lp) alpar@1: { /* retrieve optimization direction flag */ alpar@1: return glp_get_obj_dir(lp) - GLP_MIN + LPX_MIN; alpar@1: } alpar@1: alpar@1: int lpx_get_num_rows(LPX *lp) alpar@1: { /* retrieve number of rows */ alpar@1: return glp_get_num_rows(lp); alpar@1: } alpar@1: alpar@1: int lpx_get_num_cols(LPX *lp) alpar@1: { /* retrieve number of columns */ alpar@1: return glp_get_num_cols(lp); alpar@1: } alpar@1: alpar@1: const char *lpx_get_row_name(LPX *lp, int i) alpar@1: { /* retrieve row name */ alpar@1: return glp_get_row_name(lp, i); alpar@1: } alpar@1: alpar@1: const char *lpx_get_col_name(LPX *lp, int j) alpar@1: { /* retrieve column name */ alpar@1: return glp_get_col_name(lp, j); alpar@1: } alpar@1: alpar@1: int lpx_get_row_type(LPX *lp, int i) alpar@1: { /* retrieve row type */ alpar@1: return glp_get_row_type(lp, i) - GLP_FR + LPX_FR; alpar@1: } alpar@1: alpar@1: double lpx_get_row_lb(glp_prob *lp, int i) alpar@1: { /* retrieve row lower bound */ alpar@1: double lb; alpar@1: lb = glp_get_row_lb(lp, i); alpar@1: if (lb == -DBL_MAX) lb = 0.0; alpar@1: return lb; alpar@1: } alpar@1: alpar@1: double lpx_get_row_ub(glp_prob *lp, int i) alpar@1: { /* retrieve row upper bound */ alpar@1: double ub; alpar@1: ub = glp_get_row_ub(lp, i); alpar@1: if (ub == +DBL_MAX) ub = 0.0; alpar@1: return ub; alpar@1: } alpar@1: alpar@1: void lpx_get_row_bnds(glp_prob *lp, int i, int *typx, double *lb, alpar@1: double *ub) alpar@1: { /* retrieve row bounds */ alpar@1: if (typx != NULL) *typx = lpx_get_row_type(lp, i); alpar@1: if (lb != NULL) *lb = lpx_get_row_lb(lp, i); alpar@1: if (ub != NULL) *ub = lpx_get_row_ub(lp, i); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_col_type(LPX *lp, int j) alpar@1: { /* retrieve column type */ alpar@1: return glp_get_col_type(lp, j) - GLP_FR + LPX_FR; alpar@1: } alpar@1: alpar@1: double lpx_get_col_lb(glp_prob *lp, int j) alpar@1: { /* retrieve column lower bound */ alpar@1: double lb; alpar@1: lb = glp_get_col_lb(lp, j); alpar@1: if (lb == -DBL_MAX) lb = 0.0; alpar@1: return lb; alpar@1: } alpar@1: alpar@1: double lpx_get_col_ub(glp_prob *lp, int j) alpar@1: { /* retrieve column upper bound */ alpar@1: double ub; alpar@1: ub = glp_get_col_ub(lp, j); alpar@1: if (ub == +DBL_MAX) ub = 0.0; alpar@1: return ub; alpar@1: } alpar@1: alpar@1: void lpx_get_col_bnds(glp_prob *lp, int j, int *typx, double *lb, alpar@1: double *ub) alpar@1: { /* retrieve column bounds */ alpar@1: if (typx != NULL) *typx = lpx_get_col_type(lp, j); alpar@1: if (lb != NULL) *lb = lpx_get_col_lb(lp, j); alpar@1: if (ub != NULL) *ub = lpx_get_col_ub(lp, j); alpar@1: return; alpar@1: } alpar@1: alpar@1: double lpx_get_obj_coef(LPX *lp, int j) alpar@1: { /* retrieve obj. coefficient or constant term */ alpar@1: return glp_get_obj_coef(lp, j); alpar@1: } alpar@1: alpar@1: int lpx_get_num_nz(LPX *lp) alpar@1: { /* retrieve number of constraint coefficients */ alpar@1: return glp_get_num_nz(lp); alpar@1: } alpar@1: alpar@1: int lpx_get_mat_row(LPX *lp, int i, int ind[], double val[]) alpar@1: { /* retrieve row of the constraint matrix */ alpar@1: return glp_get_mat_row(lp, i, ind, val); alpar@1: } alpar@1: alpar@1: int lpx_get_mat_col(LPX *lp, int j, int ind[], double val[]) alpar@1: { /* retrieve column of the constraint matrix */ alpar@1: return glp_get_mat_col(lp, j, ind, val); alpar@1: } alpar@1: alpar@1: void lpx_create_index(LPX *lp) alpar@1: { /* create the name index */ alpar@1: glp_create_index(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_find_row(LPX *lp, const char *name) alpar@1: { /* find row by its name */ alpar@1: return glp_find_row(lp, name); alpar@1: } alpar@1: alpar@1: int lpx_find_col(LPX *lp, const char *name) alpar@1: { /* find column by its name */ alpar@1: return glp_find_col(lp, name); alpar@1: } alpar@1: alpar@1: void lpx_delete_index(LPX *lp) alpar@1: { /* delete the name index */ alpar@1: glp_delete_index(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_scale_prob(LPX *lp) alpar@1: { /* scale problem data */ alpar@1: switch (lpx_get_int_parm(lp, LPX_K_SCALE)) alpar@1: { case 0: alpar@1: /* no scaling */ alpar@1: glp_unscale_prob(lp); alpar@1: break; alpar@1: case 1: alpar@1: /* equilibration scaling */ alpar@1: glp_scale_prob(lp, GLP_SF_EQ); alpar@1: break; alpar@1: case 2: alpar@1: /* geometric mean scaling */ alpar@1: glp_scale_prob(lp, GLP_SF_GM); alpar@1: break; alpar@1: case 3: alpar@1: /* geometric mean scaling, then equilibration scaling */ alpar@1: glp_scale_prob(lp, GLP_SF_GM | GLP_SF_EQ); alpar@1: break; alpar@1: default: alpar@1: xassert(lp != lp); alpar@1: } alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_unscale_prob(LPX *lp) alpar@1: { /* unscale problem data */ alpar@1: glp_unscale_prob(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_row_stat(LPX *lp, int i, int stat) alpar@1: { /* set (change) row status */ alpar@1: glp_set_row_stat(lp, i, stat - LPX_BS + GLP_BS); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_set_col_stat(LPX *lp, int j, int stat) alpar@1: { /* set (change) column status */ alpar@1: glp_set_col_stat(lp, j, stat - LPX_BS + GLP_BS); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_std_basis(LPX *lp) alpar@1: { /* construct standard initial LP basis */ alpar@1: glp_std_basis(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_adv_basis(LPX *lp) alpar@1: { /* construct advanced initial LP basis */ alpar@1: glp_adv_basis(lp, 0); alpar@1: return; alpar@1: } alpar@1: alpar@1: void lpx_cpx_basis(LPX *lp) alpar@1: { /* construct Bixby's initial LP basis */ alpar@1: glp_cpx_basis(lp); alpar@1: return; alpar@1: } alpar@1: alpar@1: static void fill_smcp(LPX *lp, glp_smcp *parm) alpar@1: { glp_init_smcp(parm); alpar@1: switch (lpx_get_int_parm(lp, LPX_K_MSGLEV)) alpar@1: { case 0: parm->msg_lev = GLP_MSG_OFF; break; alpar@1: case 1: parm->msg_lev = GLP_MSG_ERR; break; alpar@1: case 2: parm->msg_lev = GLP_MSG_ON; break; alpar@1: case 3: parm->msg_lev = GLP_MSG_ALL; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: switch (lpx_get_int_parm(lp, LPX_K_DUAL)) alpar@1: { case 0: parm->meth = GLP_PRIMAL; break; alpar@1: case 1: parm->meth = GLP_DUAL; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: switch (lpx_get_int_parm(lp, LPX_K_PRICE)) alpar@1: { case 0: parm->pricing = GLP_PT_STD; break; alpar@1: case 1: parm->pricing = GLP_PT_PSE; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: if (lpx_get_real_parm(lp, LPX_K_RELAX) == 0.0) alpar@1: parm->r_test = GLP_RT_STD; alpar@1: else alpar@1: parm->r_test = GLP_RT_HAR; alpar@1: parm->tol_bnd = lpx_get_real_parm(lp, LPX_K_TOLBND); alpar@1: parm->tol_dj = lpx_get_real_parm(lp, LPX_K_TOLDJ); alpar@1: parm->tol_piv = lpx_get_real_parm(lp, LPX_K_TOLPIV); alpar@1: parm->obj_ll = lpx_get_real_parm(lp, LPX_K_OBJLL); alpar@1: parm->obj_ul = lpx_get_real_parm(lp, LPX_K_OBJUL); alpar@1: if (lpx_get_int_parm(lp, LPX_K_ITLIM) < 0) alpar@1: parm->it_lim = INT_MAX; alpar@1: else alpar@1: parm->it_lim = lpx_get_int_parm(lp, LPX_K_ITLIM); alpar@1: if (lpx_get_real_parm(lp, LPX_K_TMLIM) < 0.0) alpar@1: parm->tm_lim = INT_MAX; alpar@1: else alpar@1: parm->tm_lim = alpar@1: (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_TMLIM)); alpar@1: parm->out_frq = lpx_get_int_parm(lp, LPX_K_OUTFRQ); alpar@1: parm->out_dly = alpar@1: (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_OUTDLY)); alpar@1: switch (lpx_get_int_parm(lp, LPX_K_PRESOL)) alpar@1: { case 0: parm->presolve = GLP_OFF; break; alpar@1: case 1: parm->presolve = GLP_ON; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_simplex(LPX *lp) alpar@1: { /* easy-to-use driver to the simplex method */ alpar@1: glp_smcp parm; alpar@1: int ret; alpar@1: fill_smcp(lp, &parm); alpar@1: ret = glp_simplex(lp, &parm); alpar@1: switch (ret) alpar@1: { case 0: ret = LPX_E_OK; break; alpar@1: case GLP_EBADB: alpar@1: case GLP_ESING: alpar@1: case GLP_ECOND: alpar@1: case GLP_EBOUND: ret = LPX_E_FAULT; break; alpar@1: case GLP_EFAIL: ret = LPX_E_SING; break; alpar@1: case GLP_EOBJLL: ret = LPX_E_OBJLL; break; alpar@1: case GLP_EOBJUL: ret = LPX_E_OBJUL; break; alpar@1: case GLP_EITLIM: ret = LPX_E_ITLIM; break; alpar@1: case GLP_ETMLIM: ret = LPX_E_TMLIM; break; alpar@1: case GLP_ENOPFS: ret = LPX_E_NOPFS; break; alpar@1: case GLP_ENODFS: ret = LPX_E_NODFS; break; alpar@1: default: xassert(ret != ret); alpar@1: } alpar@1: return ret; alpar@1: } alpar@1: alpar@1: int lpx_exact(LPX *lp) alpar@1: { /* easy-to-use driver to the exact simplex method */ alpar@1: glp_smcp parm; alpar@1: int ret; alpar@1: fill_smcp(lp, &parm); alpar@1: ret = glp_exact(lp, &parm); alpar@1: switch (ret) alpar@1: { case 0: ret = LPX_E_OK; break; alpar@1: case GLP_EBADB: alpar@1: case GLP_ESING: alpar@1: case GLP_EBOUND: alpar@1: case GLP_EFAIL: ret = LPX_E_FAULT; break; alpar@1: case GLP_EITLIM: ret = LPX_E_ITLIM; break; alpar@1: case GLP_ETMLIM: ret = LPX_E_TMLIM; break; alpar@1: default: xassert(ret != ret); alpar@1: } alpar@1: return ret; alpar@1: } alpar@1: alpar@1: int lpx_get_status(glp_prob *lp) alpar@1: { /* retrieve generic status of basic solution */ alpar@1: int status; alpar@1: switch (glp_get_status(lp)) alpar@1: { case GLP_OPT: status = LPX_OPT; break; alpar@1: case GLP_FEAS: status = LPX_FEAS; break; alpar@1: case GLP_INFEAS: status = LPX_INFEAS; break; alpar@1: case GLP_NOFEAS: status = LPX_NOFEAS; break; alpar@1: case GLP_UNBND: status = LPX_UNBND; break; alpar@1: case GLP_UNDEF: status = LPX_UNDEF; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: return status; alpar@1: } alpar@1: alpar@1: int lpx_get_prim_stat(glp_prob *lp) alpar@1: { /* retrieve status of primal basic solution */ alpar@1: return glp_get_prim_stat(lp) - GLP_UNDEF + LPX_P_UNDEF; alpar@1: } alpar@1: alpar@1: int lpx_get_dual_stat(glp_prob *lp) alpar@1: { /* retrieve status of dual basic solution */ alpar@1: return glp_get_dual_stat(lp) - GLP_UNDEF + LPX_D_UNDEF; alpar@1: } alpar@1: alpar@1: double lpx_get_obj_val(LPX *lp) alpar@1: { /* retrieve objective value (basic solution) */ alpar@1: return glp_get_obj_val(lp); alpar@1: } alpar@1: alpar@1: int lpx_get_row_stat(LPX *lp, int i) alpar@1: { /* retrieve row status (basic solution) */ alpar@1: return glp_get_row_stat(lp, i) - GLP_BS + LPX_BS; alpar@1: } alpar@1: alpar@1: double lpx_get_row_prim(LPX *lp, int i) alpar@1: { /* retrieve row primal value (basic solution) */ alpar@1: return glp_get_row_prim(lp, i); alpar@1: } alpar@1: alpar@1: double lpx_get_row_dual(LPX *lp, int i) alpar@1: { /* retrieve row dual value (basic solution) */ alpar@1: return glp_get_row_dual(lp, i); alpar@1: } alpar@1: alpar@1: void lpx_get_row_info(glp_prob *lp, int i, int *tagx, double *vx, alpar@1: double *dx) alpar@1: { /* obtain row solution information */ alpar@1: if (tagx != NULL) *tagx = lpx_get_row_stat(lp, i); alpar@1: if (vx != NULL) *vx = lpx_get_row_prim(lp, i); alpar@1: if (dx != NULL) *dx = lpx_get_row_dual(lp, i); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_col_stat(LPX *lp, int j) alpar@1: { /* retrieve column status (basic solution) */ alpar@1: return glp_get_col_stat(lp, j) - GLP_BS + LPX_BS; alpar@1: } alpar@1: alpar@1: double lpx_get_col_prim(LPX *lp, int j) alpar@1: { /* retrieve column primal value (basic solution) */ alpar@1: return glp_get_col_prim(lp, j); alpar@1: } alpar@1: alpar@1: double lpx_get_col_dual(glp_prob *lp, int j) alpar@1: { /* retrieve column dual value (basic solution) */ alpar@1: return glp_get_col_dual(lp, j); alpar@1: } alpar@1: alpar@1: void lpx_get_col_info(glp_prob *lp, int j, int *tagx, double *vx, alpar@1: double *dx) alpar@1: { /* obtain column solution information */ alpar@1: if (tagx != NULL) *tagx = lpx_get_col_stat(lp, j); alpar@1: if (vx != NULL) *vx = lpx_get_col_prim(lp, j); alpar@1: if (dx != NULL) *dx = lpx_get_col_dual(lp, j); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_ray_info(LPX *lp) alpar@1: { /* determine what causes primal unboundness */ alpar@1: return glp_get_unbnd_ray(lp); alpar@1: } alpar@1: alpar@1: void lpx_check_kkt(LPX *lp, int scaled, LPXKKT *kkt) alpar@1: { /* check Karush-Kuhn-Tucker conditions */ alpar@1: int ae_ind, re_ind; alpar@1: double ae_max, re_max; alpar@1: xassert(scaled == scaled); alpar@1: _glp_check_kkt(lp, GLP_SOL, GLP_KKT_PE, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->pe_ae_max = ae_max; alpar@1: kkt->pe_ae_row = ae_ind; alpar@1: kkt->pe_re_max = re_max; alpar@1: kkt->pe_re_row = re_ind; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->pe_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->pe_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->pe_quality = 'L'; alpar@1: else alpar@1: kkt->pe_quality = '?'; alpar@1: _glp_check_kkt(lp, GLP_SOL, GLP_KKT_PB, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->pb_ae_max = ae_max; alpar@1: kkt->pb_ae_ind = ae_ind; alpar@1: kkt->pb_re_max = re_max; alpar@1: kkt->pb_re_ind = re_ind; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->pb_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->pb_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->pb_quality = 'L'; alpar@1: else alpar@1: kkt->pb_quality = '?'; alpar@1: _glp_check_kkt(lp, GLP_SOL, GLP_KKT_DE, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->de_ae_max = ae_max; alpar@1: if (ae_ind == 0) alpar@1: kkt->de_ae_col = 0; alpar@1: else alpar@1: kkt->de_ae_col = ae_ind - lp->m; alpar@1: kkt->de_re_max = re_max; alpar@1: if (re_ind == 0) alpar@1: kkt->de_re_col = 0; alpar@1: else alpar@1: kkt->de_re_col = ae_ind - lp->m; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->de_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->de_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->de_quality = 'L'; alpar@1: else alpar@1: kkt->de_quality = '?'; alpar@1: _glp_check_kkt(lp, GLP_SOL, GLP_KKT_DB, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->db_ae_max = ae_max; alpar@1: kkt->db_ae_ind = ae_ind; alpar@1: kkt->db_re_max = re_max; alpar@1: kkt->db_re_ind = re_ind; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->db_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->db_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->db_quality = 'L'; alpar@1: else alpar@1: kkt->db_quality = '?'; alpar@1: kkt->cs_ae_max = 0.0, kkt->cs_ae_ind = 0; alpar@1: kkt->cs_re_max = 0.0, kkt->cs_re_ind = 0; alpar@1: kkt->cs_quality = 'H'; alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_warm_up(LPX *lp) alpar@1: { /* "warm up" LP basis */ alpar@1: int ret; alpar@1: ret = glp_warm_up(lp); alpar@1: if (ret == 0) alpar@1: ret = LPX_E_OK; alpar@1: else if (ret == GLP_EBADB) alpar@1: ret = LPX_E_BADB; alpar@1: else if (ret == GLP_ESING) alpar@1: ret = LPX_E_SING; alpar@1: else if (ret == GLP_ECOND) alpar@1: ret = LPX_E_SING; alpar@1: else alpar@1: xassert(ret != ret); alpar@1: return ret; alpar@1: } alpar@1: alpar@1: int lpx_eval_tab_row(LPX *lp, int k, int ind[], double val[]) alpar@1: { /* compute row of the simplex tableau */ alpar@1: return glp_eval_tab_row(lp, k, ind, val); alpar@1: } alpar@1: alpar@1: int lpx_eval_tab_col(LPX *lp, int k, int ind[], double val[]) alpar@1: { /* compute column of the simplex tableau */ alpar@1: return glp_eval_tab_col(lp, k, ind, val); alpar@1: } alpar@1: alpar@1: int lpx_transform_row(LPX *lp, int len, int ind[], double val[]) alpar@1: { /* transform explicitly specified row */ alpar@1: return glp_transform_row(lp, len, ind, val); alpar@1: } alpar@1: alpar@1: int lpx_transform_col(LPX *lp, int len, int ind[], double val[]) alpar@1: { /* transform explicitly specified column */ alpar@1: return glp_transform_col(lp, len, ind, val); alpar@1: } alpar@1: alpar@1: int lpx_prim_ratio_test(LPX *lp, int len, const int ind[], alpar@1: const double val[], int how, double tol) alpar@1: { /* perform primal ratio test */ alpar@1: int piv; alpar@1: piv = glp_prim_rtest(lp, len, ind, val, how, tol); alpar@1: xassert(0 <= piv && piv <= len); alpar@1: return piv == 0 ? 0 : ind[piv]; alpar@1: } alpar@1: alpar@1: int lpx_dual_ratio_test(LPX *lp, int len, const int ind[], alpar@1: const double val[], int how, double tol) alpar@1: { /* perform dual ratio test */ alpar@1: int piv; alpar@1: piv = glp_dual_rtest(lp, len, ind, val, how, tol); alpar@1: xassert(0 <= piv && piv <= len); alpar@1: return piv == 0 ? 0 : ind[piv]; alpar@1: } alpar@1: alpar@1: int lpx_interior(LPX *lp) alpar@1: { /* easy-to-use driver to the interior-point method */ alpar@1: int ret; alpar@1: ret = glp_interior(lp, NULL); alpar@1: switch (ret) alpar@1: { case 0: ret = LPX_E_OK; break; alpar@1: case GLP_EFAIL: ret = LPX_E_FAULT; break; alpar@1: case GLP_ENOFEAS: ret = LPX_E_NOFEAS; break; alpar@1: case GLP_ENOCVG: ret = LPX_E_NOCONV; break; alpar@1: case GLP_EITLIM: ret = LPX_E_ITLIM; break; alpar@1: case GLP_EINSTAB: ret = LPX_E_INSTAB; break; alpar@1: default: xassert(ret != ret); alpar@1: } alpar@1: return ret; alpar@1: } alpar@1: alpar@1: int lpx_ipt_status(glp_prob *lp) alpar@1: { /* retrieve status of interior-point solution */ alpar@1: int status; alpar@1: switch (glp_ipt_status(lp)) alpar@1: { case GLP_UNDEF: status = LPX_T_UNDEF; break; alpar@1: case GLP_OPT: status = LPX_T_OPT; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: return status; alpar@1: } alpar@1: alpar@1: double lpx_ipt_obj_val(LPX *lp) alpar@1: { /* retrieve objective value (interior point) */ alpar@1: return glp_ipt_obj_val(lp); alpar@1: } alpar@1: alpar@1: double lpx_ipt_row_prim(LPX *lp, int i) alpar@1: { /* retrieve row primal value (interior point) */ alpar@1: return glp_ipt_row_prim(lp, i); alpar@1: } alpar@1: alpar@1: double lpx_ipt_row_dual(LPX *lp, int i) alpar@1: { /* retrieve row dual value (interior point) */ alpar@1: return glp_ipt_row_dual(lp, i); alpar@1: } alpar@1: alpar@1: double lpx_ipt_col_prim(LPX *lp, int j) alpar@1: { /* retrieve column primal value (interior point) */ alpar@1: return glp_ipt_col_prim(lp, j); alpar@1: } alpar@1: alpar@1: double lpx_ipt_col_dual(LPX *lp, int j) alpar@1: { /* retrieve column dual value (interior point) */ alpar@1: return glp_ipt_col_dual(lp, j); alpar@1: } alpar@1: alpar@1: void lpx_set_class(LPX *lp, int klass) alpar@1: { /* set problem class */ alpar@1: xassert(lp == lp); alpar@1: if (!(klass == LPX_LP || klass == LPX_MIP)) alpar@1: xerror("lpx_set_class: invalid problem class\n"); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_class(LPX *lp) alpar@1: { /* determine problem klass */ alpar@1: return glp_get_num_int(lp) == 0 ? LPX_LP : LPX_MIP; alpar@1: } alpar@1: alpar@1: void lpx_set_col_kind(LPX *lp, int j, int kind) alpar@1: { /* set (change) column kind */ alpar@1: glp_set_col_kind(lp, j, kind - LPX_CV + GLP_CV); alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_col_kind(LPX *lp, int j) alpar@1: { /* retrieve column kind */ alpar@1: return glp_get_col_kind(lp, j) == GLP_CV ? LPX_CV : LPX_IV; alpar@1: } alpar@1: alpar@1: int lpx_get_num_int(LPX *lp) alpar@1: { /* retrieve number of integer columns */ alpar@1: return glp_get_num_int(lp); alpar@1: } alpar@1: alpar@1: int lpx_get_num_bin(LPX *lp) alpar@1: { /* retrieve number of binary columns */ alpar@1: return glp_get_num_bin(lp); alpar@1: } alpar@1: alpar@1: static int solve_mip(LPX *lp, int presolve) alpar@1: { glp_iocp parm; alpar@1: int ret; alpar@1: glp_init_iocp(&parm); alpar@1: switch (lpx_get_int_parm(lp, LPX_K_MSGLEV)) alpar@1: { case 0: parm.msg_lev = GLP_MSG_OFF; break; alpar@1: case 1: parm.msg_lev = GLP_MSG_ERR; break; alpar@1: case 2: parm.msg_lev = GLP_MSG_ON; break; alpar@1: case 3: parm.msg_lev = GLP_MSG_ALL; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: switch (lpx_get_int_parm(lp, LPX_K_BRANCH)) alpar@1: { case 0: parm.br_tech = GLP_BR_FFV; break; alpar@1: case 1: parm.br_tech = GLP_BR_LFV; break; alpar@1: case 2: parm.br_tech = GLP_BR_DTH; break; alpar@1: case 3: parm.br_tech = GLP_BR_MFV; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: switch (lpx_get_int_parm(lp, LPX_K_BTRACK)) alpar@1: { case 0: parm.bt_tech = GLP_BT_DFS; break; alpar@1: case 1: parm.bt_tech = GLP_BT_BFS; break; alpar@1: case 2: parm.bt_tech = GLP_BT_BPH; break; alpar@1: case 3: parm.bt_tech = GLP_BT_BLB; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: parm.tol_int = lpx_get_real_parm(lp, LPX_K_TOLINT); alpar@1: parm.tol_obj = lpx_get_real_parm(lp, LPX_K_TOLOBJ); alpar@1: if (lpx_get_real_parm(lp, LPX_K_TMLIM) < 0.0 || alpar@1: lpx_get_real_parm(lp, LPX_K_TMLIM) > 1e6) alpar@1: parm.tm_lim = INT_MAX; alpar@1: else alpar@1: parm.tm_lim = alpar@1: (int)(1000.0 * lpx_get_real_parm(lp, LPX_K_TMLIM)); alpar@1: parm.mip_gap = lpx_get_real_parm(lp, LPX_K_MIPGAP); alpar@1: if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_GOMORY) alpar@1: parm.gmi_cuts = GLP_ON; alpar@1: else alpar@1: parm.gmi_cuts = GLP_OFF; alpar@1: if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_MIR) alpar@1: parm.mir_cuts = GLP_ON; alpar@1: else alpar@1: parm.mir_cuts = GLP_OFF; alpar@1: if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_COVER) alpar@1: parm.cov_cuts = GLP_ON; alpar@1: else alpar@1: parm.cov_cuts = GLP_OFF; alpar@1: if (lpx_get_int_parm(lp, LPX_K_USECUTS) & LPX_C_CLIQUE) alpar@1: parm.clq_cuts = GLP_ON; alpar@1: else alpar@1: parm.clq_cuts = GLP_OFF; alpar@1: parm.presolve = presolve; alpar@1: if (lpx_get_int_parm(lp, LPX_K_BINARIZE)) alpar@1: parm.binarize = GLP_ON; alpar@1: ret = glp_intopt(lp, &parm); alpar@1: switch (ret) alpar@1: { case 0: ret = LPX_E_OK; break; alpar@1: case GLP_ENOPFS: ret = LPX_E_NOPFS; break; alpar@1: case GLP_ENODFS: ret = LPX_E_NODFS; break; alpar@1: case GLP_EBOUND: alpar@1: case GLP_EROOT: ret = LPX_E_FAULT; break; alpar@1: case GLP_EFAIL: ret = LPX_E_SING; break; alpar@1: case GLP_EMIPGAP: ret = LPX_E_MIPGAP; break; alpar@1: case GLP_ETMLIM: ret = LPX_E_TMLIM; break; alpar@1: default: xassert(ret != ret); alpar@1: } alpar@1: return ret; alpar@1: } alpar@1: alpar@1: int lpx_integer(LPX *lp) alpar@1: { /* easy-to-use driver to the branch-and-bound method */ alpar@1: return solve_mip(lp, GLP_OFF); alpar@1: } alpar@1: alpar@1: int lpx_intopt(LPX *lp) alpar@1: { /* easy-to-use driver to the branch-and-bound method */ alpar@1: return solve_mip(lp, GLP_ON); alpar@1: } alpar@1: alpar@1: int lpx_mip_status(glp_prob *lp) alpar@1: { /* retrieve status of MIP solution */ alpar@1: int status; alpar@1: switch (glp_mip_status(lp)) alpar@1: { case GLP_UNDEF: status = LPX_I_UNDEF; break; alpar@1: case GLP_OPT: status = LPX_I_OPT; break; alpar@1: case GLP_FEAS: status = LPX_I_FEAS; break; alpar@1: case GLP_NOFEAS: status = LPX_I_NOFEAS; break; alpar@1: default: xassert(lp != lp); alpar@1: } alpar@1: return status; alpar@1: } alpar@1: alpar@1: double lpx_mip_obj_val(LPX *lp) alpar@1: { /* retrieve objective value (MIP solution) */ alpar@1: return glp_mip_obj_val(lp); alpar@1: } alpar@1: alpar@1: double lpx_mip_row_val(LPX *lp, int i) alpar@1: { /* retrieve row value (MIP solution) */ alpar@1: return glp_mip_row_val(lp, i); alpar@1: } alpar@1: alpar@1: double lpx_mip_col_val(LPX *lp, int j) alpar@1: { /* retrieve column value (MIP solution) */ alpar@1: return glp_mip_col_val(lp, j); alpar@1: } alpar@1: alpar@1: void lpx_check_int(LPX *lp, LPXKKT *kkt) alpar@1: { /* check integer feasibility conditions */ alpar@1: int ae_ind, re_ind; alpar@1: double ae_max, re_max; alpar@1: _glp_check_kkt(lp, GLP_MIP, GLP_KKT_PE, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->pe_ae_max = ae_max; alpar@1: kkt->pe_ae_row = ae_ind; alpar@1: kkt->pe_re_max = re_max; alpar@1: kkt->pe_re_row = re_ind; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->pe_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->pe_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->pe_quality = 'L'; alpar@1: else alpar@1: kkt->pe_quality = '?'; alpar@1: _glp_check_kkt(lp, GLP_MIP, GLP_KKT_PB, &ae_max, &ae_ind, &re_max, alpar@1: &re_ind); alpar@1: kkt->pb_ae_max = ae_max; alpar@1: kkt->pb_ae_ind = ae_ind; alpar@1: kkt->pb_re_max = re_max; alpar@1: kkt->pb_re_ind = re_ind; alpar@1: if (re_max <= 1e-9) alpar@1: kkt->pb_quality = 'H'; alpar@1: else if (re_max <= 1e-6) alpar@1: kkt->pb_quality = 'M'; alpar@1: else if (re_max <= 1e-3) alpar@1: kkt->pb_quality = 'L'; alpar@1: else alpar@1: kkt->pb_quality = '?'; alpar@1: return; alpar@1: } alpar@1: alpar@1: #if 1 /* 17/XI-2009 */ alpar@1: static void reset_parms(LPX *lp) alpar@1: { /* reset control parameters to default values */ alpar@1: struct LPXCPS *cps = lp->parms; alpar@1: xassert(cps != NULL); alpar@1: cps->msg_lev = 3; alpar@1: cps->scale = 1; alpar@1: cps->dual = 0; alpar@1: cps->price = 1; alpar@1: cps->relax = 0.07; alpar@1: cps->tol_bnd = 1e-7; alpar@1: cps->tol_dj = 1e-7; alpar@1: cps->tol_piv = 1e-9; alpar@1: cps->round = 0; alpar@1: cps->obj_ll = -DBL_MAX; alpar@1: cps->obj_ul = +DBL_MAX; alpar@1: cps->it_lim = -1; alpar@1: #if 0 /* 02/XII-2010 */ alpar@1: lp->it_cnt = 0; alpar@1: #endif alpar@1: cps->tm_lim = -1.0; alpar@1: cps->out_frq = 200; alpar@1: cps->out_dly = 0.0; alpar@1: cps->branch = 2; alpar@1: cps->btrack = 3; alpar@1: cps->tol_int = 1e-5; alpar@1: cps->tol_obj = 1e-7; alpar@1: cps->mps_info = 1; alpar@1: cps->mps_obj = 2; alpar@1: cps->mps_orig = 0; alpar@1: cps->mps_wide = 1; alpar@1: cps->mps_free = 0; alpar@1: cps->mps_skip = 0; alpar@1: cps->lpt_orig = 0; alpar@1: cps->presol = 0; alpar@1: cps->binarize = 0; alpar@1: cps->use_cuts = 0; alpar@1: cps->mip_gap = 0.0; alpar@1: return; alpar@1: } alpar@1: #endif alpar@1: alpar@1: #if 1 /* 17/XI-2009 */ alpar@1: static struct LPXCPS *access_parms(LPX *lp) alpar@1: { /* allocate and initialize control parameters, if necessary */ alpar@1: if (lp->parms == NULL) alpar@1: { lp->parms = xmalloc(sizeof(struct LPXCPS)); alpar@1: reset_parms(lp); alpar@1: } alpar@1: return lp->parms; alpar@1: } alpar@1: #endif alpar@1: alpar@1: #if 1 /* 17/XI-2009 */ alpar@1: void lpx_reset_parms(LPX *lp) alpar@1: { /* reset control parameters to default values */ alpar@1: access_parms(lp); alpar@1: reset_parms(lp); alpar@1: return; alpar@1: } alpar@1: #endif alpar@1: alpar@1: void lpx_set_int_parm(LPX *lp, int parm, int val) alpar@1: { /* set (change) integer control parameter */ alpar@1: #if 0 /* 17/XI-2009 */ alpar@1: struct LPXCPS *cps = lp->cps; alpar@1: #else alpar@1: struct LPXCPS *cps = access_parms(lp); alpar@1: #endif alpar@1: switch (parm) alpar@1: { case LPX_K_MSGLEV: alpar@1: if (!(0 <= val && val <= 3)) alpar@1: xerror("lpx_set_int_parm: MSGLEV = %d; invalid value\n", alpar@1: val); alpar@1: cps->msg_lev = val; alpar@1: break; alpar@1: case LPX_K_SCALE: alpar@1: if (!(0 <= val && val <= 3)) alpar@1: xerror("lpx_set_int_parm: SCALE = %d; invalid value\n", alpar@1: val); alpar@1: cps->scale = val; alpar@1: break; alpar@1: case LPX_K_DUAL: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: DUAL = %d; invalid value\n", alpar@1: val); alpar@1: cps->dual = val; alpar@1: break; alpar@1: case LPX_K_PRICE: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: PRICE = %d; invalid value\n", alpar@1: val); alpar@1: cps->price = val; alpar@1: break; alpar@1: case LPX_K_ROUND: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: ROUND = %d; invalid value\n", alpar@1: val); alpar@1: cps->round = val; alpar@1: break; alpar@1: case LPX_K_ITLIM: alpar@1: cps->it_lim = val; alpar@1: break; alpar@1: case LPX_K_ITCNT: alpar@1: lp->it_cnt = val; alpar@1: break; alpar@1: case LPX_K_OUTFRQ: alpar@1: if (!(val > 0)) alpar@1: xerror("lpx_set_int_parm: OUTFRQ = %d; invalid value\n", alpar@1: val); alpar@1: cps->out_frq = val; alpar@1: break; alpar@1: case LPX_K_BRANCH: alpar@1: if (!(val == 0 || val == 1 || val == 2 || val == 3)) alpar@1: xerror("lpx_set_int_parm: BRANCH = %d; invalid value\n", alpar@1: val); alpar@1: cps->branch = val; alpar@1: break; alpar@1: case LPX_K_BTRACK: alpar@1: if (!(val == 0 || val == 1 || val == 2 || val == 3)) alpar@1: xerror("lpx_set_int_parm: BTRACK = %d; invalid value\n", alpar@1: val); alpar@1: cps->btrack = val; alpar@1: break; alpar@1: case LPX_K_MPSINFO: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: MPSINFO = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_info = val; alpar@1: break; alpar@1: case LPX_K_MPSOBJ: alpar@1: if (!(val == 0 || val == 1 || val == 2)) alpar@1: xerror("lpx_set_int_parm: MPSOBJ = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_obj = val; alpar@1: break; alpar@1: case LPX_K_MPSORIG: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: MPSORIG = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_orig = val; alpar@1: break; alpar@1: case LPX_K_MPSWIDE: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: MPSWIDE = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_wide = val; alpar@1: break; alpar@1: case LPX_K_MPSFREE: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: MPSFREE = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_free = val; alpar@1: break; alpar@1: case LPX_K_MPSSKIP: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: MPSSKIP = %d; invalid value\n", alpar@1: val); alpar@1: cps->mps_skip = val; alpar@1: break; alpar@1: case LPX_K_LPTORIG: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: LPTORIG = %d; invalid value\n", alpar@1: val); alpar@1: cps->lpt_orig = val; alpar@1: break; alpar@1: case LPX_K_PRESOL: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: PRESOL = %d; invalid value\n", alpar@1: val); alpar@1: cps->presol = val; alpar@1: break; alpar@1: case LPX_K_BINARIZE: alpar@1: if (!(val == 0 || val == 1)) alpar@1: xerror("lpx_set_int_parm: BINARIZE = %d; invalid value\n" alpar@1: , val); alpar@1: cps->binarize = val; alpar@1: break; alpar@1: case LPX_K_USECUTS: alpar@1: if (val & ~LPX_C_ALL) alpar@1: xerror("lpx_set_int_parm: USECUTS = 0x%X; invalid value\n", alpar@1: val); alpar@1: cps->use_cuts = val; alpar@1: break; alpar@1: case LPX_K_BFTYPE: alpar@1: #if 0 alpar@1: if (!(1 <= val && val <= 3)) alpar@1: xerror("lpx_set_int_parm: BFTYPE = %d; invalid value\n", alpar@1: val); alpar@1: cps->bf_type = val; alpar@1: #else alpar@1: { glp_bfcp parm; alpar@1: glp_get_bfcp(lp, &parm); alpar@1: switch (val) alpar@1: { case 1: alpar@1: parm.type = GLP_BF_FT; break; alpar@1: case 2: alpar@1: parm.type = GLP_BF_BG; break; alpar@1: case 3: alpar@1: parm.type = GLP_BF_GR; break; alpar@1: default: alpar@1: xerror("lpx_set_int_parm: BFTYPE = %d; invalid val" alpar@1: "ue\n", val); alpar@1: } alpar@1: glp_set_bfcp(lp, &parm); alpar@1: } alpar@1: #endif alpar@1: break; alpar@1: default: alpar@1: xerror("lpx_set_int_parm: parm = %d; invalid parameter\n", alpar@1: parm); alpar@1: } alpar@1: return; alpar@1: } alpar@1: alpar@1: int lpx_get_int_parm(LPX *lp, int parm) alpar@1: { /* query integer control parameter */ alpar@1: #if 0 /* 17/XI-2009 */ alpar@1: struct LPXCPS *cps = lp->cps; alpar@1: #else alpar@1: struct LPXCPS *cps = access_parms(lp); alpar@1: #endif alpar@1: int val = 0; alpar@1: switch (parm) alpar@1: { case LPX_K_MSGLEV: alpar@1: val = cps->msg_lev; break; alpar@1: case LPX_K_SCALE: alpar@1: val = cps->scale; break; alpar@1: case LPX_K_DUAL: alpar@1: val = cps->dual; break; alpar@1: case LPX_K_PRICE: alpar@1: val = cps->price; break; alpar@1: case LPX_K_ROUND: alpar@1: val = cps->round; break; alpar@1: case LPX_K_ITLIM: alpar@1: val = cps->it_lim; break; alpar@1: case LPX_K_ITCNT: alpar@1: val = lp->it_cnt; break; alpar@1: case LPX_K_OUTFRQ: alpar@1: val = cps->out_frq; break; alpar@1: case LPX_K_BRANCH: alpar@1: val = cps->branch; break; alpar@1: case LPX_K_BTRACK: alpar@1: val = cps->btrack; break; alpar@1: case LPX_K_MPSINFO: alpar@1: val = cps->mps_info; break; alpar@1: case LPX_K_MPSOBJ: alpar@1: val = cps->mps_obj; break; alpar@1: case LPX_K_MPSORIG: alpar@1: val = cps->mps_orig; break; alpar@1: case LPX_K_MPSWIDE: alpar@1: val = cps->mps_wide; break; alpar@1: case LPX_K_MPSFREE: alpar@1: val = cps->mps_free; break; alpar@1: case LPX_K_MPSSKIP: alpar@1: val = cps->mps_skip; break; alpar@1: case LPX_K_LPTORIG: alpar@1: val = cps->lpt_orig; break; alpar@1: case LPX_K_PRESOL: alpar@1: val = cps->presol; break; alpar@1: case LPX_K_BINARIZE: alpar@1: val = cps->binarize; break; alpar@1: case LPX_K_USECUTS: alpar@1: val = cps->use_cuts; break; alpar@1: case LPX_K_BFTYPE: alpar@1: #if 0 alpar@1: val = cps->bf_type; break; alpar@1: #else alpar@1: { glp_bfcp parm; alpar@1: glp_get_bfcp(lp, &parm); alpar@1: switch (parm.type) alpar@1: { case GLP_BF_FT: alpar@1: val = 1; break; alpar@1: case GLP_BF_BG: alpar@1: val = 2; break; alpar@1: case GLP_BF_GR: alpar@1: val = 3; break; alpar@1: default: alpar@1: xassert(lp != lp); alpar@1: } alpar@1: } alpar@1: break; alpar@1: #endif alpar@1: default: alpar@1: xerror("lpx_get_int_parm: parm = %d; invalid parameter\n", alpar@1: parm); alpar@1: } alpar@1: return val; alpar@1: } alpar@1: alpar@1: void lpx_set_real_parm(LPX *lp, int parm, double val) alpar@1: { /* set (change) real control parameter */ alpar@1: #if 0 /* 17/XI-2009 */ alpar@1: struct LPXCPS *cps = lp->cps; alpar@1: #else alpar@1: struct LPXCPS *cps = access_parms(lp); alpar@1: #endif alpar@1: switch (parm) alpar@1: { case LPX_K_RELAX: alpar@1: if (!(0.0 <= val && val <= 1.0)) alpar@1: xerror("lpx_set_real_parm: RELAX = %g; invalid value\n", alpar@1: val); alpar@1: cps->relax = val; alpar@1: break; alpar@1: case LPX_K_TOLBND: alpar@1: if (!(DBL_EPSILON <= val && val <= 0.001)) alpar@1: xerror("lpx_set_real_parm: TOLBND = %g; invalid value\n", alpar@1: val); alpar@1: #if 0 alpar@1: if (cps->tol_bnd > val) alpar@1: { /* invalidate the basic solution */ alpar@1: lp->p_stat = LPX_P_UNDEF; alpar@1: lp->d_stat = LPX_D_UNDEF; alpar@1: } alpar@1: #endif alpar@1: cps->tol_bnd = val; alpar@1: break; alpar@1: case LPX_K_TOLDJ: alpar@1: if (!(DBL_EPSILON <= val && val <= 0.001)) alpar@1: xerror("lpx_set_real_parm: TOLDJ = %g; invalid value\n", alpar@1: val); alpar@1: #if 0 alpar@1: if (cps->tol_dj > val) alpar@1: { /* invalidate the basic solution */ alpar@1: lp->p_stat = LPX_P_UNDEF; alpar@1: lp->d_stat = LPX_D_UNDEF; alpar@1: } alpar@1: #endif alpar@1: cps->tol_dj = val; alpar@1: break; alpar@1: case LPX_K_TOLPIV: alpar@1: if (!(DBL_EPSILON <= val && val <= 0.001)) alpar@1: xerror("lpx_set_real_parm: TOLPIV = %g; invalid value\n", alpar@1: val); alpar@1: cps->tol_piv = val; alpar@1: break; alpar@1: case LPX_K_OBJLL: alpar@1: cps->obj_ll = val; alpar@1: break; alpar@1: case LPX_K_OBJUL: alpar@1: cps->obj_ul = val; alpar@1: break; alpar@1: case LPX_K_TMLIM: alpar@1: cps->tm_lim = val; alpar@1: break; alpar@1: case LPX_K_OUTDLY: alpar@1: cps->out_dly = val; alpar@1: break; alpar@1: case LPX_K_TOLINT: alpar@1: if (!(DBL_EPSILON <= val && val <= 0.001)) alpar@1: xerror("lpx_set_real_parm: TOLINT = %g; invalid value\n", alpar@1: val); alpar@1: cps->tol_int = val; alpar@1: break; alpar@1: case LPX_K_TOLOBJ: alpar@1: if (!(DBL_EPSILON <= val && val <= 0.001)) alpar@1: xerror("lpx_set_real_parm: TOLOBJ = %g; invalid value\n", alpar@1: val); alpar@1: cps->tol_obj = val; alpar@1: break; alpar@1: case LPX_K_MIPGAP: alpar@1: if (val < 0.0) alpar@1: xerror("lpx_set_real_parm: MIPGAP = %g; invalid value\n", alpar@1: val); alpar@1: cps->mip_gap = val; alpar@1: break; alpar@1: default: alpar@1: xerror("lpx_set_real_parm: parm = %d; invalid parameter\n", alpar@1: parm); alpar@1: } alpar@1: return; alpar@1: } alpar@1: alpar@1: double lpx_get_real_parm(LPX *lp, int parm) alpar@1: { /* query real control parameter */ alpar@1: #if 0 /* 17/XI-2009 */ alpar@1: struct LPXCPS *cps = lp->cps; alpar@1: #else alpar@1: struct LPXCPS *cps = access_parms(lp); alpar@1: #endif alpar@1: double val = 0.0; alpar@1: switch (parm) alpar@1: { case LPX_K_RELAX: alpar@1: val = cps->relax; alpar@1: break; alpar@1: case LPX_K_TOLBND: alpar@1: val = cps->tol_bnd; alpar@1: break; alpar@1: case LPX_K_TOLDJ: alpar@1: val = cps->tol_dj; alpar@1: break; alpar@1: case LPX_K_TOLPIV: alpar@1: val = cps->tol_piv; alpar@1: break; alpar@1: case LPX_K_OBJLL: alpar@1: val = cps->obj_ll; alpar@1: break; alpar@1: case LPX_K_OBJUL: alpar@1: val = cps->obj_ul; alpar@1: break; alpar@1: case LPX_K_TMLIM: alpar@1: val = cps->tm_lim; alpar@1: break; alpar@1: case LPX_K_OUTDLY: alpar@1: val = cps->out_dly; alpar@1: break; alpar@1: case LPX_K_TOLINT: alpar@1: val = cps->tol_int; alpar@1: break; alpar@1: case LPX_K_TOLOBJ: alpar@1: val = cps->tol_obj; alpar@1: break; alpar@1: case LPX_K_MIPGAP: alpar@1: val = cps->mip_gap; alpar@1: break; alpar@1: default: alpar@1: xerror("lpx_get_real_parm: parm = %d; invalid parameter\n", alpar@1: parm); alpar@1: } alpar@1: return val; alpar@1: } alpar@1: alpar@1: LPX *lpx_read_mps(const char *fname) alpar@1: { /* read problem data in fixed MPS format */ alpar@1: LPX *lp = lpx_create_prob(); alpar@1: if (glp_read_mps(lp, GLP_MPS_DECK, NULL, fname)) alpar@1: lpx_delete_prob(lp), lp = NULL; alpar@1: return lp; alpar@1: } alpar@1: alpar@1: int lpx_write_mps(LPX *lp, const char *fname) alpar@1: { /* write problem data in fixed MPS format */ alpar@1: return glp_write_mps(lp, GLP_MPS_DECK, NULL, fname); alpar@1: } alpar@1: alpar@1: int lpx_read_bas(LPX *lp, const char *fname) alpar@1: { /* read LP basis in fixed MPS format */ alpar@1: #if 0 /* 13/IV-2009 */ alpar@1: return read_bas(lp, fname); alpar@1: #else alpar@1: xassert(lp == lp); alpar@1: xassert(fname == fname); alpar@1: xerror("lpx_read_bas: operation not supported\n"); alpar@1: return 0; alpar@1: #endif alpar@1: } alpar@1: alpar@1: int lpx_write_bas(LPX *lp, const char *fname) alpar@1: { /* write LP basis in fixed MPS format */ alpar@1: #if 0 /* 13/IV-2009 */ alpar@1: return write_bas(lp, fname); alpar@1: #else alpar@1: xassert(lp == lp); alpar@1: xassert(fname == fname); alpar@1: xerror("lpx_write_bas: operation not supported\n"); alpar@1: return 0; alpar@1: #endif alpar@1: } alpar@1: alpar@1: LPX *lpx_read_freemps(const char *fname) alpar@1: { /* read problem data in free MPS format */ alpar@1: LPX *lp = lpx_create_prob(); alpar@1: if (glp_read_mps(lp, GLP_MPS_FILE, NULL, fname)) alpar@1: lpx_delete_prob(lp), lp = NULL; alpar@1: return lp; alpar@1: } alpar@1: alpar@1: int lpx_write_freemps(LPX *lp, const char *fname) alpar@1: { /* write problem data in free MPS format */ alpar@1: return glp_write_mps(lp, GLP_MPS_FILE, NULL, fname); alpar@1: } alpar@1: alpar@1: LPX *lpx_read_cpxlp(const char *fname) alpar@1: { /* read problem data in CPLEX LP format */ alpar@1: LPX *lp; alpar@1: lp = lpx_create_prob(); alpar@1: if (glp_read_lp(lp, NULL, fname)) alpar@1: lpx_delete_prob(lp), lp = NULL; alpar@1: return lp; alpar@1: } alpar@1: alpar@1: int lpx_write_cpxlp(LPX *lp, const char *fname) alpar@1: { /* write problem data in CPLEX LP format */ alpar@1: return glp_write_lp(lp, NULL, fname); alpar@1: } alpar@1: alpar@1: LPX *lpx_read_model(const char *model, const char *data, const char alpar@1: *output) alpar@1: { /* read LP/MIP model written in GNU MathProg language */ alpar@1: LPX *lp = NULL; alpar@1: glp_tran *tran; alpar@1: /* allocate the translator workspace */ alpar@1: tran = glp_mpl_alloc_wksp(); alpar@1: /* read model section and optional data section */ alpar@1: if (glp_mpl_read_model(tran, model, data != NULL)) goto done; alpar@1: /* read separate data section, if required */ alpar@1: if (data != NULL) alpar@1: if (glp_mpl_read_data(tran, data)) goto done; alpar@1: /* generate the model */ alpar@1: if (glp_mpl_generate(tran, output)) goto done; alpar@1: /* build the problem instance from the model */ alpar@1: lp = glp_create_prob(); alpar@1: glp_mpl_build_prob(tran, lp); alpar@1: done: /* free the translator workspace */ alpar@1: glp_mpl_free_wksp(tran); alpar@1: /* bring the problem object to the calling program */ alpar@1: return lp; alpar@1: } alpar@1: alpar@1: int lpx_print_prob(LPX *lp, const char *fname) alpar@1: { /* write problem data in plain text format */ alpar@1: return glp_write_lp(lp, NULL, fname); alpar@1: } alpar@1: alpar@1: int lpx_print_sol(LPX *lp, const char *fname) alpar@1: { /* write LP problem solution in printable format */ alpar@1: return glp_print_sol(lp, fname); alpar@1: } alpar@1: alpar@1: int lpx_print_sens_bnds(LPX *lp, const char *fname) alpar@1: { /* write bounds sensitivity information */ alpar@1: if (glp_get_status(lp) == GLP_OPT && !glp_bf_exists(lp)) alpar@1: glp_factorize(lp); alpar@1: return glp_print_ranges(lp, 0, NULL, 0, fname); alpar@1: } alpar@1: alpar@1: int lpx_print_ips(LPX *lp, const char *fname) alpar@1: { /* write interior point solution in printable format */ alpar@1: return glp_print_ipt(lp, fname); alpar@1: } alpar@1: alpar@1: int lpx_print_mip(LPX *lp, const char *fname) alpar@1: { /* write MIP problem solution in printable format */ alpar@1: return glp_print_mip(lp, fname); alpar@1: } alpar@1: alpar@1: int lpx_is_b_avail(glp_prob *lp) alpar@1: { /* check if LP basis is available */ alpar@1: return glp_bf_exists(lp); alpar@1: } alpar@1: alpar@1: int lpx_main(int argc, const char *argv[]) alpar@1: { /* stand-alone LP/MIP solver */ alpar@1: return glp_main(argc, argv); alpar@1: } alpar@1: alpar@1: /* eof */