1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*   File....: ratmstwrite.c                                                 */
4 /*   Name....: MST File Write                                                */
5 /*   Author..: Thorsten Koch                                                 */
6 /*   Copyright by Author, All rights reserved                                */
7 /*                                                                           */
8 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
9 /*
10  * Copyright (C) 2001-2018 by Thorsten Koch <koch@zib.de>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 3
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <assert.h>
32 
33 #include <gmp.h>
34 
35 #include "zimpl/lint.h"
36 #include "zimpl/mshell.h"
37 #include <stdbool.h>
38 #include "zimpl/gmpmisc.h"
39 #include "zimpl/ratlptypes.h"
40 #include "zimpl/numb.h"
41 #include "zimpl/bound.h"
42 #include "zimpl/mme.h"
43 #include "zimpl/mono.h"
44 #include "zimpl/term.h"
45 #include "zimpl/ratlp.h"
46 #include "zimpl/ratlpstore.h"
47 
48 
49 /* A specification for the ORD file format can be found in the
50  * ILOG CPLEX 7.0 Reference Manual page 545.
51  */
lps_mstfile(const Lps * lp,FILE * fp,LpFormat format,const char * text)52 void lps_mstfile(
53    const Lps*  lp,
54    FILE*       fp,
55    LpFormat    format,
56    const char* text)
57 {
58    const Var*  var;
59    int         name_size;
60    char*       vtmp;
61 
62    assert(lp     != NULL);
63    assert(fp     != NULL);
64    assert(format == LP_FORM_LPF || format == LP_FORM_MPS);
65 
66    name_size = lps_getnamesize(lp, format);
67    vtmp      = malloc((size_t)name_size);
68 
69    assert(vtmp != NULL);
70 
71    if (text != NULL)
72       fprintf(fp, "* %s\n", text);
73 
74    fprintf(fp, "NAME        %8.8s\n", lp->name);
75 
76    for(var = lp->var_root; var != NULL; var = var->next)
77    {
78       if (var->vclass == VAR_CON)
79          continue;
80 
81       if (var->size == 0)
82           continue;
83 
84       lps_makename(vtmp, name_size, var->name, var->number);
85 
86       fprintf(fp, "    %-*s  %.10e",
87          name_size - 1, vtmp, mpq_get_d(var->startval));
88 
89       fputc('\n', fp);
90    }
91    fprintf(fp, "ENDATA\n");
92 
93    free(vtmp);
94 }
95 
96 
97 
98 
99 
100 
101 
102