Scippy

SoPlex

Sequential object-oriented simPlex

mpsinput.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file mpsinput.h
17  * @brief Read MPS format files.
18  */
19 #ifndef _MPSINPUT_H_
20 #define _MPSINPUT_H_
21 
22 #include <iostream>
23 
24 #include "soplex/spxout.h"
25 
26 namespace soplex
27 {
28 
29 /**@class MPSInput
30 
31  Reads MPS input files. A right-hand side for the objective function is
32  allowed but ignored.
33  */
34 class MPSInput
35 {
36 public:
37 
38  //-----------------------------------
39  /**@name Types */
40  //@{
41  ///
42 
43  enum Section
44  {
46  };
47  ///
48 
49  /// optimization sense.
50  enum Sense
51  {
52  MAXIMIZE = 1,
53  MINIMIZE = -1
54  };
55 
56  enum { MAX_LINE_LEN = 256 };
57 
58  //@}
59 
60 private:
61 
62  //-----------------------------------
63  /**@name Private data */
64  //@{
65  ///
67  /// the input stream from which the file is read
68  std::istream& m_input;
69  /// line number
70  int m_lineno;
71  /// objctive sense (maximization or minimization)
73  /// is set to \c true upon a syntax error
75  /// the line buffer
77  /// first field in a line
78  const char* m_f0;
79  /// second field in a line
80  const char* m_f1;
81  /// third field in a line
82  const char* m_f2;
83  /// fourth field in a line
84  const char* m_f3;
85  /// fifth field in a line
86  const char* m_f4;
87  /// sixth field in a line
88  const char* m_f5;
89  /// problem name
91  /// objective name
93  ///
95  /// new MPS format?
97  /// Number of already ignored entries.
98  int m_ignored;
99  /// Maximal number of ignored entries for which a warning will be issued.
100  static const int m_max_ignore = 1000;
101  //@}
102 
103 public:
104 
105  //-----------------------------------
106  /**@name Construction / destruction */
107  //@{
108  ///
109  explicit
110  MPSInput(std::istream& p_input)
111  : m_section(NAME)
112  , m_input(p_input)
113  , m_lineno(0)
114  , m_objsense(MPSInput::MINIMIZE)
115  , m_has_error(false)
116  , m_is_integer(false)
117  , m_is_new_format(false)
118  , m_ignored(0)
119  {
120  m_f0 = m_f1 = m_f2 = m_f3 = m_f4 = m_f5 = 0;
121 
122  m_buf [0] = '\0';
123  m_probname[0] = '\0';
124  m_objname [0] = '\0';
125  }
126  ///
127  virtual
129  {
130  // only to signal to flexelint that the pointers do
131  // not point to anything that has to be freed.
132  m_f0 = m_f1 = m_f2 = m_f3 = m_f4 = m_f5 = 0;
133  }
134  //@}
135 
136  //-----------------------------------
137  /**@name Access */
138  //@{
139  ///
140  Section section() const
141  {
142  return m_section;
143  }
144  ///
145  int lineno() const
146  {
147  return m_lineno;
148  }
149  ///
150  const char* field0() const
151  {
152  return m_f0;
153  }
154  ///
155  const char* field1() const
156  {
157  return m_f1;
158  }
159  ///
160  const char* field2() const
161  {
162  return m_f2;
163  }
164  ///
165  const char* field3() const
166  {
167  return m_f3;
168  }
169  ///
170  const char* field4() const
171  {
172  return m_f4;
173  }
174  ///
175  const char* field5() const
176  {
177  return m_f5;
178  }
179  ///
180  const char* probName() const
181  {
182  return m_probname;
183  }
184  ///
185  const char* objName() const
186  {
187  return m_objname;
188  }
189  ///
190  Sense objSense() const
191  {
192  return m_objsense;
193  }
194  ///
195  bool hasError() const
196  {
197  return m_has_error;
198  }
199  ///
200  bool isInteger() const
201  {
202  return m_is_integer;
203  }
204  //@}
205 
206  //-----------------------------------
207  /**@name Modification */
208  //@{
209  ///
210  void setSection(Section p_section)
211  {
212  m_section = p_section;
213  }
214  ///
215  void setProbName(const char* p_probname)
216  {
217  assert(strlen(p_probname) < MAX_LINE_LEN);
218  spxSnprintf(m_probname, MAX_LINE_LEN, "%s", p_probname);
219  }
220  ///
221  void setObjName(const char* p_objname)
222  {
223  assert(strlen(p_objname) < MAX_LINE_LEN);
224  spxSnprintf(m_objname, MAX_LINE_LEN, "%s", p_objname);
225  }
226  ///
227  void setObjSense(Sense sense)
228  {
229  m_objsense = sense;
230  }
231  //@}
232 
233  //-----------------------------------
234  /**@name Warnings and Errors */
235  //@{
236  ///
237  void syntaxError()
238  {
239  MSG_ERROR(std::cerr << "Syntax error in line " << m_lineno << std::endl;)
240  m_section = ENDATA;
241  m_has_error = true;
242  }
243  ///
245  const char* what, const char* what_name,
246  const char* entity, const char* entity_name)
247  {
248  if(m_ignored < m_max_ignore)
249  {
250  MSG_ERROR(std::cerr << "Warning: line " << m_lineno << ": "
251  << what << " \"" << what_name << "\""
252  << " for " << entity << " \""
253  << entity_name << "\" ignored" << std::endl;)
254  ++m_ignored;
255 
256  if(m_ignored == m_max_ignore)
257  MSG_ERROR(std::cerr << "Warning: This was the " << m_max_ignore
258  << " ignored entry. No further warnings on "
259  << "ignored entries will be given." << std::endl;)
260  }
261  }
262  //@}
263 
264  //-----------------------------------
265  /**@name Helpers */
266  //@{
267  /// reads an MPS format data line and parse the fields.
268  bool readLine();
269  /// Inserts \p name as field 1 and shifts all other fields up.
270  void insertName(const char* name,
271  bool second = false);
272  //@}
273 };
274 } // namespace soplex
275 #endif // _MPSINPUT_H_
char m_probname[MAX_LINE_LEN]
problem name
Definition: mpsinput.h:90
const char * field4() const
Definition: mpsinput.h:170
Section m_section
Definition: mpsinput.h:66
void entryIgnored(const char *what, const char *what_name, const char *entity, const char *entity_name)
Definition: mpsinput.h:244
const char * m_f0
first field in a line
Definition: mpsinput.h:78
const char * m_f5
sixth field in a line
Definition: mpsinput.h:88
bool m_is_new_format
new MPS format?
Definition: mpsinput.h:96
Sense objSense() const
Definition: mpsinput.h:190
MPSInput(std::istream &p_input)
Definition: mpsinput.h:110
char m_buf[MAX_LINE_LEN]
the line buffer
Definition: mpsinput.h:76
const char * m_f4
fifth field in a line
Definition: mpsinput.h:86
void syntaxError()
Definition: mpsinput.h:237
bool hasError() const
Definition: mpsinput.h:195
char m_objname[MAX_LINE_LEN]
objective name
Definition: mpsinput.h:92
Wrapper for different output streams and verbosity levels.
bool readLine()
reads an MPS format data line and parse the fields.
Definition: mpsinput.cpp:58
Sense m_objsense
objctive sense (maximization or minimization)
Definition: mpsinput.h:72
int m_ignored
Number of already ignored entries.
Definition: mpsinput.h:98
int lineno() const
Definition: mpsinput.h:145
const char * probName() const
Definition: mpsinput.h:180
Section section() const
Definition: mpsinput.h:140
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:114
int spxSnprintf(char *t, size_t len, const char *s,...)
safe version of snprintf
Definition: spxdefines.h:460
const char * field3() const
Definition: mpsinput.h:165
static const int m_max_ignore
Maximal number of ignored entries for which a warning will be issued.
Definition: mpsinput.h:100
const char * field0() const
Definition: mpsinput.h:150
const char * m_f3
fourth field in a line
Definition: mpsinput.h:84
void setObjSense(Sense sense)
Definition: mpsinput.h:227
const char * objName() const
Definition: mpsinput.h:185
void setSection(Section p_section)
Definition: mpsinput.h:210
void setObjName(const char *p_objname)
Definition: mpsinput.h:221
bool m_is_integer
Definition: mpsinput.h:94
virtual ~MPSInput()
Definition: mpsinput.h:128
Everything should be within this namespace.
bool isInteger() const
Definition: mpsinput.h:200
bool m_has_error
is set to true upon a syntax error
Definition: mpsinput.h:74
Sense
optimization sense.
Definition: mpsinput.h:50
std::istream & m_input
the input stream from which the file is read
Definition: mpsinput.h:68
void setProbName(const char *p_probname)
Definition: mpsinput.h:215
const char * m_f2
third field in a line
Definition: mpsinput.h:82
const char * field5() const
Definition: mpsinput.h:175
int m_lineno
line number
Definition: mpsinput.h:70
const char * field1() const
Definition: mpsinput.h:155
void insertName(const char *name, bool second=false)
Inserts name as field 1 and shifts all other fields up.
Definition: mpsinput.cpp:259
const char * m_f1
second field in a line
Definition: mpsinput.h:80
const char * field2() const
Definition: mpsinput.h:160