1 /* glplpx03.c (OPB format) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Author: Oscar Gustafsson <oscarg@isy.liu.se>.
8 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
9 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
10 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
11 * E-mail: <mao@gnu.org>.
13 * GLPK is free software: you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * GLPK is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
21 * License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
25 ***********************************************************************/
30 #if 0 /* 24/XII-2009; by mao */
34 /*----------------------------------------------------------------------
35 -- lpx_write_pb - write problem data in (normalized) OPB format.
39 -- #include "glplpx.h"
40 -- int lpx_write_pb(LPX *lp, const char *fname, int normalized,
45 -- The routine lpx_write_pb writes problem data in OPB format
46 -- to an output text file whose name is the character string fname.
47 -- If normalized is non-zero the output will be generated in a
48 -- normalized form with sequentially numbered variables, x1, x2 etc.
49 -- If binarize, any integer variable will be repalzec by binary ones,
54 -- If the operation was successful, the routine returns zero. Otherwise
55 -- the routine prints an error message and returns non-zero. */
57 #if 1 /* 24/XII-2009; by mao (disabled, because IPP was removed) */
58 int lpx_write_pb(LPX *lp, const char *fname, int normalized,
61 xassert(fname == fname);
62 xassert(normalized == normalized);
63 xassert(binarize == binarize);
64 xprintf("lpx_write_pb: sorry, currently this operation is not ava"
69 int lpx_write_pb(LPX *lp, const char *fname, int normalized,
73 int m,n,i,j,k,o,nonfree=0, obj_dir, dbl, *ndx, row_type, emptylhs=0;
74 double coeff, *val, bound, constant/*=0.0*/;
75 char* objconstname = "dummy_one";
76 char* emptylhsname = "dummy_zero";
78 /* Variables needed for possible binarization */
83 if(binarize) /* Transform integer variables to binary ones */
85 ipp = ipp_create_wksp();
86 ipp_load_orig(ipp, lp);
88 lp = ipp_build_prob(ipp);
90 fp = fopen(fname, "w");
95 "lpx_write_pb: writing problem in %sOPB format to `%s'...\n",
96 (normalized?"normalized ":""), fname);
98 m = glp_get_num_rows(lp);
99 n = glp_get_num_cols(lp);
102 switch(glp_get_row_type(lp,i))
118 constant=glp_get_obj_coef(lp,0);
119 fprintf(fp,"* #variables = %d #constraints = %d\n",
120 n + (constant == 0?1:0), nonfree + (constant == 0?1:0));
121 /* Objective function */
122 obj_dir = glp_get_obj_dir(lp);
126 coeff = glp_get_obj_coef(lp,i);
129 if(obj_dir == GLP_MAX)
132 fprintf(fp, " %d x%d", (int)coeff, i);
134 fprintf(fp, " %d*%s", (int)coeff,
135 glp_get_col_name(lp,i));
142 fprintf(fp, " %d x%d", (int)constant, n+1);
144 fprintf(fp, " %d*%s", (int)constant, objconstname);
148 if(normalized && !binarize) /* Name substitution */
150 fprintf(fp,"* Variable name substitution:\n");
153 fprintf(fp, "* x%d = %s\n", j, glp_get_col_name(lp,j));
156 fprintf(fp, "* x%d = %s\n", n+1, objconstname);
159 ndx = xcalloc(1+n, sizeof(int));
160 val = xcalloc(1+n, sizeof(double));
165 row_type=glp_get_row_type(lp,j);
168 if(row_type == GLP_DB)
177 k=glp_get_mat_row(lp, j, ndx, val);
184 if(k==0) /* Empty LHS */
189 fprintf(fp, "0 x%d ", n+2);
193 fprintf(fp, "0*%s ", emptylhsname);
204 fprintf(fp, "%d x%d ",
205 (row_type==GLP_UP)?(-(int)val[i]):((int)val[i]), ndx[i]);
209 fprintf(fp, "%d*%s ", (int)val[i],
210 glp_get_col_name(lp,ndx[i]));
219 bound = glp_get_row_lb(lp,j);
227 bound = -glp_get_row_ub(lp,j);
232 bound = glp_get_row_ub(lp,j);
240 bound = glp_get_row_lb(lp,j);
244 fprintf(fp," %d;\n",(int)bound);
254 "lpx_write_pb: adding constant objective function variable\n");
257 fprintf(fp, "1 x%d = 1;\n", n+1);
259 fprintf(fp, "1*%s = 1;\n", objconstname);
264 "lpx_write_pb: adding dummy variable for empty left-hand si"
268 fprintf(fp, "1 x%d = 0;\n", n+2);
270 fprintf(fp, "1*%s = 0;\n", emptylhsname);
276 xprintf("Problems opening file for writing: %s\n", fname);
281 { xprintf("lpx_write_pb: can't write to `%s' - %s\n", fname,
290 /* delete the resultant problem object */
291 if (lp != NULL) lpx_delete_prob(lp);
292 /* delete MIP presolver workspace */
293 if (ipp != NULL) ipp_delete_wksp(ipp);
297 fail: if (fp != NULL) fclose(fp);