/home/coin/SVN-release/OS-2.4.0/Bonmin/src/Interfaces/Ampl/BonSolReader.cpp

Go to the documentation of this file.
00001 // (C) Copyright CNRS 2011
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, LIF, CNRS,
00007 //
00008 // Date : 03/01/2011
00009 #include "BonSolReader.hpp"
00010 #include <fstream>
00011 #include <iostream>
00012 
00013 namespace Bonmin{
00014 
00015 SolReader::SolReader(const char * file, const char * suffix)
00016     :
00017     file_(), suffix_(suffix), x_()
00018 {
00019   assert(file!= NULL);
00020   file_=file;
00021   if (suffix!=NULL)
00022     suffix_ = suffix;
00023 }
00024 SolReader::SolReader(const std::string & file, const std::string & suffix)
00025     :
00026     file_(file), suffix_(suffix), x_()
00027 {}
00028 
00029 bool SolReader::readFile()
00030 {
00031   std::string fileName = file_;
00032   size_t size = fileName.size();
00033   bool hasNlExtension =  (fileName.size()>4) && (fileName[size - 1] =='l') && (fileName[size - 2] =='n') && (fileName[size - 3] =='.');
00034   if(hasNlExtension)
00035     fileName.erase(size-3,3);
00036   fileName+=suffix_;
00037   std::ifstream inFile(fileName.c_str());
00038   if(!inFile.is_open()) {
00039     return false;
00040   }
00041   std::string token;
00042   inFile>>token;
00043   assert(token == "bonmin:");
00044 
00045   std::string status;
00046   inFile>>status;
00047   inFile>>token;
00048   if(token == "Options"){
00049     for(int i = 0 ; i < 6 ; i++){
00050       inFile>>token;
00051     }
00052     int n_cols, n_cols_2;
00053     inFile>>n_cols_2>>n_cols;
00054     if(n_cols != x_.size()){
00055        fprintf(stderr, "Number of columns different %d\n", n_cols);
00056        x_.resize(n_cols);
00057     }
00058   }
00059 for(int i = 0 ; i < x_.size() ; i++){
00060      inFile>>x_[i];
00061   }
00062   return true;
00063 }
00064 
00065 void
00066 SolReader::copySol(double * x)
00067 {
00068   std::copy(x_.begin(), x_.end(), x);
00069 }
00070 }

Generated on Thu Sep 22 03:05:54 2011 by  doxygen 1.4.7