| 1 |
// (C) Copyright International Business Machines Corporation and |
| 2 |
// Carnegie Mellon University 2004, 2007 |
| 3 |
// |
| 4 |
// All Rights Reserved. |
| 5 |
// This code is published under the Eclipse Public License. |
| 6 |
// |
| 7 |
// Authors : |
| 8 |
// Pierre Bonami, Carnegie Mellon University, |
| 9 |
// Andreas Waechter, International Business Machines Corporation |
| 10 |
// |
| 11 |
// Date : 12/01/2004 |
| 12 |
|
| 13 |
#include "BonminConfig.h" |
| 14 |
|
| 15 |
#include "BonAmplInterface.hpp" |
| 16 |
#include "BonIpoptSolver.hpp" |
| 17 |
#include "BonColReader.hpp" |
| 18 |
#ifdef COIN_HAS_FILTERSQP |
| 19 |
# include "BonFilterSolver.hpp" |
| 20 |
#endif |
| 21 |
#include <string> |
| 22 |
#include <sstream> |
| 23 |
|
| 24 |
#include "BonTNLP2FPNLP.hpp" |
| 25 |
|
| 26 |
namespace Bonmin |
| 27 |
{ |
| 28 |
/** Default constructor no initialization*/ |
| 29 |
AmplInterface::AmplInterface(): |
| 30 |
OsiTMINLPInterface(), amplTminlp_(NULL) |
| 31 |
{} |
| 32 |
|
| 33 |
/** Copy constructor */ |
| 34 |
AmplInterface::AmplInterface(const AmplInterface &other): |
| 35 |
OsiTMINLPInterface(other), amplTminlp_(NULL) |
| 36 |
{ |
| 37 |
amplTminlp_ = dynamic_cast<Bonmin::AmplTMINLP *> (GetRawPtr(tminlp_)); |
| 38 |
} |
| 39 |
/// Clone |
| 40 |
OsiSolverInterface * |
| 41 |
AmplInterface::clone(bool CopyData ) |
| 42 |
{ |
| 43 |
return new AmplInterface(*this); |
| 44 |
} |
| 45 |
|
| 46 |
///Destructor |
| 47 |
AmplInterface::~AmplInterface() |
| 48 |
{ |
| 49 |
amplTminlp_ = NULL; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
void AmplInterface::readAmplNlFile(char **& argv, Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions, |
| 54 |
Ipopt::SmartPtr<Ipopt::OptionsList> options, |
| 55 |
Ipopt::SmartPtr<Ipopt::Journalist> journalist, |
| 56 |
std::string* nl_file_content /* = NULL*/ |
| 57 |
) |
| 58 |
{ |
| 59 |
if (!IsValid(app_)) { |
| 60 |
createApplication(roptions, options, journalist, "bonmin."); |
| 61 |
} |
| 62 |
// set the default options... expect_infeasible, etc... |
| 63 |
if (!IsValid(tminlp_)) { |
| 64 |
amplTminlp_ = new AmplTMINLP(Ipopt::ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv, |
| 65 |
NULL, appName() , nl_file_content); |
| 66 |
tminlp_ = GetRawPtr(amplTminlp_); |
| 67 |
} |
| 68 |
else { |
| 69 |
AmplTMINLP * amplTMINLP = dynamic_cast<AmplTMINLP *> (GetRawPtr(tminlp_)); |
| 70 |
if (amplTMINLP) { |
| 71 |
AmplTMINLP * newAmpl = amplTMINLP->createEmpty(); |
| 72 |
newAmpl->Initialize(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv, |
| 73 |
NULL, appName() , nl_file_content); |
| 74 |
amplTminlp_ = newAmpl; |
| 75 |
tminlp_ = GetRawPtr(amplTminlp_); |
| 76 |
} |
| 77 |
else { |
| 78 |
amplTminlp_ = new AmplTMINLP(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv, |
| 79 |
NULL, appName() , nl_file_content); |
| 80 |
tminlp_ = GetRawPtr(amplTminlp_); |
| 81 |
} |
| 82 |
} |
| 83 |
problem_ = new TMINLP2TNLP(tminlp_); |
| 84 |
feasibilityProblem_ = new TNLP2FPNLP |
| 85 |
(Ipopt::SmartPtr<Ipopt::TNLP>(Ipopt::GetRawPtr(problem_))); |
| 86 |
if(feasibility_mode_){ |
| 87 |
problem_to_optimize_ = GetRawPtr(feasibilityProblem_); |
| 88 |
} |
| 89 |
else { |
| 90 |
problem_to_optimize_ = GetRawPtr(problem_); |
| 91 |
} |
| 92 |
|
| 93 |
int numcols = getNumCols(); |
| 94 |
if (obj_) |
| 95 |
delete [] obj_; |
| 96 |
obj_ = new double[numcols]; |
| 97 |
CoinFillN(obj_,numcols,1.); |
| 98 |
setStrParam(OsiProbName, std::string(argv[1])); |
| 99 |
extractInterfaceParams(); |
| 100 |
hasBeenOptimized_ = false; |
| 101 |
//Read columns and row names if they exists |
| 102 |
readNames(); |
| 103 |
} |
| 104 |
|
| 105 |
void |
| 106 |
AmplInterface::setAppDefaultOptions(Ipopt::SmartPtr<Ipopt::OptionsList> Options) |
| 107 |
{} |
| 108 |
|
| 109 |
|
| 110 |
void |
| 111 |
AmplInterface::readNames() |
| 112 |
{ |
| 113 |
std::string probName; |
| 114 |
getStrParam(OsiProbName, probName); |
| 115 |
NamesReader colRead(probName, ".col"); |
| 116 |
if (colRead.readFile()) { |
| 117 |
OsiNameVec colNames; |
| 118 |
colRead.copyNames(colNames); |
| 119 |
setColNames(colNames, 0, static_cast<int>(colNames.size()), 0); |
| 120 |
} |
| 121 |
|
| 122 |
NamesReader rowRead(probName, ".row"); |
| 123 |
if (rowRead.readFile()) { |
| 124 |
OsiNameVec rowNames; |
| 125 |
rowRead.copyNames(rowNames); |
| 126 |
setRowNames(rowNames, 0, static_cast<int>(rowNames.size()), 0); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
} /* end namespace Bonmin. */ |