File: mps.h

package info (click to toggle)
gnumeric 1.4.3-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 71,576 kB
  • ctags: 28,555
  • sloc: ansic: 282,333; xml: 45,788; sh: 8,479; makefile: 3,119; yacc: 1,129; lisp: 200; perl: 173; python: 86
file content (169 lines) | stat: -rw-r--r-- 3,883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * mps.h: The main header file for the MPS file importer.
 *
 * Authors:
 *   Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
 *   File handling code copied from Dif module.
 *
 *      MPS importer module.  MPS format is a de facto standard ASCII format
 *      among most of the commercial LP solvers.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef GNUMERIC_PLUGINS_MPS_H
#define GNUMERIC_PLUGINS_MPS_H 1

#include <gsf/gsf-input-textline.h>

#define N_INPUT_LINES_BETWEEN_UPDATES   50
#define MAX_COL                         160


/*************************************************************************
 *
 * Data structures.
 */

/*
 * MPS Row type (E, L, G, or N).
 */
typedef enum {
        EqualityRow, LessOrEqualRow, GreaterOrEqualRow, ObjectiveRow
} MpsRowType;

/*
 * MPS Row.
 */
typedef struct {
        MpsRowType type;
        gchar      *name;
        gint       index;
} MpsRow;

/*
 * MPS Column.
 */
typedef struct {
        gchar      *name;
        MpsRow     *row;
        gnm_float value;
} MpsCol;

/*
 * MPS Range.
 */
typedef struct {
        gchar      *name;
        MpsRow     *row;
        gnm_float value;
} MpsRange;

/*
 * MPS Bound type (LO, UP, FX, FR, MI, BV, LI, or UI).
 */
typedef enum {
        LowerBound, UpperBound, FixedVariable, FreeVariable, LowerBoundInf,
	BinaryVariable, LowerBoundInt, UpperBoundInt
} MpsBoundType;

/*
 * MPS Bound.
 */
typedef struct {
        char         *name;
        gint         col_index;
        gnm_float   value;
        MpsBoundType type;
} MpsBound;


/*
 * MPS RHS.
 */
typedef struct {
        gchar      *name;
        MpsRow     *row;
        gnm_float value;
} MpsRhs;

/*
 * Column mapping.
 */
typedef struct {
        gchar *name;
        gint  index;
} MpsColInfo;


/*
 * Input context.
 */
typedef struct {
        IOContext *io_context;

	GsfInputTextline *input;
        gint   line_no;
        gchar *line;

        Sheet  *sheet;

        gchar      *name;
        GSList     *rows;
        GSList     *cols;
        GSList     *rhs;
        GSList     *bounds;
        gint       n_rows, n_cols, n_bounds;
        GHashTable *row_hash;
        GHashTable *col_hash;
        gchar      **col_name_tbl;
        MpsRow     *objective_row;
        gnm_float **matrix;
} MpsInputContext;



/*************************************************************************
 *
 * Constants.
 */

static const int MAIN_INFO_ROW       = 1;
static const int MAIN_INFO_COL       = 0;
static const int OBJECTIVE_VALUE_COL = 1;

static const int VARIABLE_COL        = 1;
static const int VARIABLE_ROW        = 5;

static const int CONSTRAINT_COL      = 1;
static const int CONSTRAINT_ROW      = 10;


/*************************************************************************
 *
 * The Public Interface of the module
 */

/* Reads the MPS file in and creates a spreadsheet model of it. */
void     mps_file_open  (GnmFileOpener const *fo, IOContext *io_context,
			 WorkbookView *wbv, GsfInput *input);

void     mps_parse_file (MpsInputContext *ctxt);
gboolean mps_add_row    (MpsInputContext *ctxt, MpsRowType type, gchar *txt);


#endif