| 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 _BONSTARTPOINTREADER_H_ |
| 11 |
#define _BONSTARTPOINTREADER_H_ |
| 12 |
#include <string> |
| 13 |
#include <list> |
| 14 |
#include <fstream> |
| 15 |
#include <iostream> |
| 16 |
#include "BonOsiTMINLPInterface.hpp" |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace Bonmin { |
| 21 |
/** This class reads a file with a starting point for Ipopt initalization. File format is number of primals number of duals then values one after another |
| 22 |
* Numbering of variables is first variables, then duals on lower bounds duals on upper bounds and to finish duals on constraints */ |
| 23 |
class StartPointReader |
| 24 |
{ |
| 25 |
public: |
| 26 |
/** Constructor with fileName_ given by a string (and default) */ |
| 27 |
StartPointReader(std::string fileName = ""): |
| 28 |
fileName_(fileName), |
| 29 |
primals_(NULL), |
| 30 |
duals_(NULL) |
| 31 |
{} |
| 32 |
/** Constructor with fileName_ given by a const char * */ |
| 33 |
StartPointReader(const char * fileName): |
| 34 |
fileName_(fileName), |
| 35 |
primals_(NULL), |
| 36 |
duals_(NULL) |
| 37 |
{} |
| 38 |
|
| 39 |
/** Reads the .initP file*/ |
| 40 |
bool readFile(); |
| 41 |
/** Reads the .initP file fileName*/ |
| 42 |
bool readFile(const std::string &fileName) |
| 43 |
{ |
| 44 |
fileName_=fileName; |
| 45 |
return readFile(); |
| 46 |
} |
| 47 |
/** Read warmstart info and apply to an IpoptInterface */ |
| 48 |
bool readAndApply(OsiTMINLPInterface * solver); |
| 49 |
~StartPointReader() |
| 50 |
{ |
| 51 |
gutsOfDestructor(); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
/// Dealocate arrays |
| 56 |
void gutsOfDestructor() |
| 57 |
{ |
| 58 |
if(primals_!=NULL) |
| 59 |
delete[] primals_; |
| 60 |
if(duals_!=NULL) |
| 61 |
delete[] duals_; |
| 62 |
} |
| 63 |
|
| 64 |
/// Access primal variables values. |
| 65 |
const double * getPrimals() |
| 66 |
{ |
| 67 |
return primals_; |
| 68 |
} |
| 69 |
/// Access dual variables values. |
| 70 |
const double * getDuals() |
| 71 |
{ |
| 72 |
return duals_; |
| 73 |
} |
| 74 |
private: |
| 75 |
/** Name of the file with initial point */ |
| 76 |
std::string fileName_; |
| 77 |
|
| 78 |
/// Primal variables values. |
| 79 |
double * primals_; |
| 80 |
/// Dual variables values. |
| 81 |
double * duals_; |
| 82 |
}; |
| 83 |
|
| 84 |
} |
| 85 |
#endif /*_IPCBCINITPOINTREADER_H_*/ |