Debian Codegraph @

Bonmin/src/Interfaces/Ampl/BonSolReader.hpp

raw
1 // (C) Copyright CNRS 2011
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, LIF, CNRS,
7 //
8 // Date : 03/01/2011
9
10 #ifndef SolReader_HPP
11 #define SolReader_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 "BonTypes.hpp"
20
21 namespace Bonmin{
22 /** A class for reading a .col or .row file containing name for variables and constraints (usually ampl generated file).
23 */
24 class SolReader
25 {
26 public:
27 /** Constructor with a file name given by a const char * */
28 SolReader(const char * fileName, const char * suffix);
29 /** Constructor with a file name given by a string and also default (empty string) */
30 SolReader(const std::string & fileName="", const std::string& suffix=".col");
31 /** Reads the .sol file*/
32 bool readFile();
33 /** Reads the .sol file fileName*/
34 bool readFile(const std::string &file)
35 {
36 file_=file;
37 return readFile();
38 }
39
40 /** Copy the names to Names. */
41 void copySol(double * x);
42
43 const double * x(){
44 return x_();
45 }
46
47 /** Set the number of variables in the problem.*/
48 void set_n_cols(int n){
49 x_.resize(n);
50 }
51 private:
52 /// Name of the file to read.
53 std::string file_;
54
55 /// Suffix of the file (".col", ".row")
56 std::string suffix_;
57
58 /// Sol values
59 vector<double> x_;
60 };
61 }
62 #endif