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-2017 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 "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 { return m_section; }
141  ///
142  int lineno() const { return m_lineno; }
143  ///
144  const char* field0() const { return m_f0; }
145  ///
146  const char* field1() const { return m_f1; }
147  ///
148  const char* field2() const { return m_f2; }
149  ///
150  const char* field3() const { return m_f3; }
151  ///
152  const char* field4() const { return m_f4; }
153  ///
154  const char* field5() const { return m_f5; }
155  ///
156  const char* probName() const { return m_probname; }
157  ///
158  const char* objName() const { return m_objname; }
159  ///
160  Sense objSense() const { return m_objsense; }
161  ///
162  bool hasError() const { return m_has_error; }
163  ///
164  bool isInteger() const { return m_is_integer; }
165  //@}
166 
167  //-----------------------------------
168  /**@name Modification */
169  //@{
170  ///
171  void setSection(Section p_section)
172  {
173  m_section = p_section;
174  }
175  ///
176  void setProbName(const char* p_probname)
177  {
178  assert(strlen(p_probname) < MAX_LINE_LEN);
179  strncpy(m_probname, p_probname, MAX_LINE_LEN);
180  }
181  ///
182  void setObjName(const char* p_objname)
183  {
184  assert(strlen(p_objname) < MAX_LINE_LEN);
185  strncpy(m_objname, p_objname, MAX_LINE_LEN);
186  }
187  ///
188  void setObjSense(Sense sense)
189  {
190  m_objsense = sense;
191  }
192  //@}
193 
194  //-----------------------------------
195  /**@name Warnings and Errors */
196  //@{
197  ///
198  void syntaxError()
199  {
200  MSG_ERROR( std::cerr << "Syntax error in line " << m_lineno << std::endl; )
201  m_section = ENDATA;
202  m_has_error = true;
203  }
204  ///
206  const char* what, const char* what_name,
207  const char* entity, const char* entity_name)
208  {
209  if ( m_ignored < m_max_ignore )
210  {
211  MSG_ERROR( std::cerr << "Warning: line " << m_lineno << ": "
212  << what << " \"" << what_name << "\""
213  << " for " << entity << " \""
214  << entity_name << "\" ignored" << std::endl; )
215  ++m_ignored;
216 
217  if ( m_ignored == m_max_ignore )
218  MSG_ERROR( std::cerr << "Warning: This was the " << m_max_ignore
219  << " ignored entry. No further warnings on "
220  << "ignored entries will be given." << std::endl; )
221  }
222  }
223  //@}
224 
225  //-----------------------------------
226  /**@name Helpers */
227  //@{
228  /// reads an MPS format data line and parse the fields.
229  bool readLine();
230  /// Inserts \p name as field 1 and shifts all other fields up.
231  void insertName( const char* name,
232  bool second = false );
233  //@}
234 };
235 } // namespace soplex
236 #endif // _MPSINPUT_H_
char m_probname[MAX_LINE_LEN]
problem name
Definition: mpsinput.h:90
const char * field4() const
Definition: mpsinput.h:152
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:205
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:160
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:198
bool hasError() const
Definition: mpsinput.h:162
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:57
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:142
const char * probName() const
Definition: mpsinput.h:156
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
const char * field3() const
Definition: mpsinput.h:150
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:144
const char * m_f3
fourth field in a line
Definition: mpsinput.h:84
void setObjSense(Sense sense)
Definition: mpsinput.h:188
const char * objName() const
Definition: mpsinput.h:158
void setSection(Section p_section)
Definition: mpsinput.h:171
void setObjName(const char *p_objname)
Definition: mpsinput.h:182
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:164
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:176
const char * m_f2
third field in a line
Definition: mpsinput.h:82
const char * field5() const
Definition: mpsinput.h:154
int m_lineno
line number
Definition: mpsinput.h:70
const char * field1() const
Definition: mpsinput.h:146
void insertName(const char *name, bool second=false)
Inserts name as field 1 and shifts all other fields up.
Definition: mpsinput.cpp:250
const char * m_f1
second field in a line
Definition: mpsinput.h:80
const char * field2() const
Definition: mpsinput.h:148