Bonmin  1.8.8
BonColReader.hpp
Go to the documentation of this file.
1 // (C) Copyright Carnegie Mellon University 2005
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, Carnegie Mellon University,
7 //
8 // Date : 26/05/2005
9 
10 #ifndef NameReader_HPP
11 #define NameReader_HPP
12 #include <string>
13 #include <vector>
14 #include <list>
15 #include <fstream>
16 #include <iostream>
17 #include <CoinHelperFunctions.hpp>
18 #include "OsiSolverInterface.hpp"
19 //#include <tr1/unordered_map>
20 #include <map>
21 
22 namespace Bonmin{
26 {
27 public:
29  NamesReader(const char * fileName, const char * suffix);
31  NamesReader(const std::string & fileName="", const std::string& suffix=".col");
33  bool readFile();
35  bool readFile(const std::string &file)
36  {
37  file_=file;
38  return readFile();
39  }
40 
43 
45  const std::string& name(int i){
46  return names_[i];
47  }
48 
50  int index(const char * str){
51  return indices_[str];
52  }
53 private:
55  std::string file_;
56 
58  std::string suffix_;
59 
61  struct ltstr
62  {
63  bool operator()(const char* s1, const char* s2) const
64  {
65  return strcmp(s1, s2) < 0;
66  }
67  };
68 
70  typedef std::map<const char *, int, ltstr> namesHash;
72  namesHash indices_;
74  std::vector<std::string> names_;
75 };
76 }
77 #endif
A class for reading a .col or .row file containing name for variables and constraints (usually ampl g...
NamesReader(const std::string &fileName="", const std::string &suffix=".col")
Constructor with a file name given by a string and also default (empty string)
int index(const char *str)
Access index of variable str.
void copyNames(OsiSolverInterface::OsiNameVec &Names)
Copy the names to Names.
bool readFile(const std::string &file)
Reads the .col file fileName.
const std::string & name(int i)
Access Names of indexed by i.
bool readFile()
Reads the .col file.
NamesReader(const char *fileName, const char *suffix)
Constructor with a file name given by a const char *.
std::vector< std::string > OsiNameVec
(C) Copyright International Business Machines Corporation 2007