source: branches/devel/Bonmin/src/IpoptInterface/IpCbcColReader.cpp @ 44

Last change on this file since 44 was 44, checked in by pbonami, 13 years ago

Can add linear cut to nonlinear formulation in Ipopt

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 1.7 KB
Line 
1// (C) Copyright Carnegie Mellon University 2005
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Pierre Bonami, Carnegie Mellon University,
7//
8// Date : 26/05/2005
9#include "IpCbcColReader.hpp"
10#include <fstream>
11#include <iostream>
12/** Keywords of the .int file */
13static std::string keywords[]= { "priorities", "PRIORITIES",
14    "special_ordered_set_1",
15    "SPECIAL_ORDERED_SET_1"};
16IpCbcColReader::IpCbcColReader(const char * fileName)
17    :
18    fileName_(), varIndices_(), varNames_()
19{
20  assert(fileName != NULL);
21  fileName_=fileName;
22}
23IpCbcColReader::IpCbcColReader(const std::string & fileName)
24    :
25    fileName_(fileName), varIndices_(), varNames_()
26{}
27
28bool IpCbcColReader::readFile()
29{
30  std::string colFileName = fileName_;
31  int size = colFileName.size();
32  bool hasNlExtension =  (colFileName.size()>4) && (colFileName[size - 1] =='l') && (colFileName[size - 2] =='n') && (colFileName[size - 3] =='.');
33  if(hasNlExtension)
34    colFileName.erase(size-3,3);
35  colFileName+=".col";
36  std::ifstream inFile(colFileName.c_str());
37  if(!inFile.is_open()) {
38    return false;
39  }
40  std::string name;
41  int nVar = 0;
42  do {
43    name="";
44    inFile>>name;
45    if(name.size()==0)
46      continue;
47    varNames_.push_back(name);
48    varIndices_[varNames_[nVar].c_str()] = nVar;
49    nVar++;
50  }
51  while(!inFile.eof());
52
53  //  varNames_ = new std::string[nVar];
54  for(int i = 0 ; i < nVar ; i++) {
55    assert(i==varIndices_ [ varNames_ [i].c_str()]);
56  }
57  return true;
58}
59
60void
61IpCbcColReader::copyNames(std::string *varNames, int n_var)
62{
63  assert(n_var >= 0 && (unsigned int) n_var==varNames_.size());
64  for(int i = 0 ; i < n_var ; i++) {
65    varNames[i] = varNames_[i];
66  }
67}
Note: See TracBrowser for help on using the repository browser.