1 /*
2 * Name: writelp.c
3 * Author: Pietro Belotti
4 * Purpose: write feasible subsystem into a .lp file
5 *
6 * This code is published under the Eclipse Public License (EPL).
7 * See http://www.eclipse.org/legal/epl-v10.html
8 *
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <math.h>
15 #include <bzlib.h>
16
17 #include "sparse.h"
18 #include "lpio.h"
19 #include "rtr.h"
20 #include "misc.h"
21
22 #include "config_creme.h"
23
24 /*
25 * Write feasible subsystem into a .lp file
26 */
27
write_lp(sparseLP * lp,char * mfs,char * filename)28 int write_lp (sparseLP *lp, /* LP data */
29 char *mfs, /* feasible subsystem */
30 char *filename /* file name */
31 ) {
32
33 FILE *f;
34
35 register int i;
36
37 if (strcmp (filename, "-")) f = fopen (filename, "w");
38 else f = stdout;
39
40 if ((f == NULL) || ferror (f)) {
41 printf ("Unable to open file %s\n", filename);
42 return -1;
43 }
44
45 fprintf (f, "\\ Feasible subsystem created by Crème %d.%d\n\n"
46 "minimize x0\n\n"
47 "subject to\n\n",
48 CREME_VERSION_MAJOR, CREME_VERSION_MINOR);
49
50 for (i=0; i<lp -> rk; ++i)
51 if (mfs [i]) {
52 int j;
53 fprintf (f, "c%04d: ", i);
54 for (j=0; j < lp -> il [i]; ++j)
55 fprintf (f, "%+g x_%d ", lp -> ic [i][j], lp -> ip [i][j]);
56 fprintf (f, ">= %e\n", lp -> rhs [i]);
57 }
58
59 fprintf (f, "\nbounds\n");
60
61 for (i=0; i < lp -> c0; ++i)
62 if (lp -> lb [i] != 0. ||
63 lp -> ub [i] < .5e30)
64 fprintf (f, "%g <= x_%d <= %g\n",
65 lp -> lb [i],
66 i,
67 lp -> ub [i]);
68
69 fprintf (f, "\nend\n");
70
71 fclose (f);
72
73 return 0;
74 }
75