/home/coin/SVN-release/OS-2.1.1/Bonmin/src/Interfaces/Ampl/BonAmplInterface.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and
00002 // Carnegie Mellon University 2004, 2007
00003 //
00004 // All Rights Reserved.
00005 // This code is published under the Common Public License.
00006 //
00007 // Authors :
00008 // Pierre Bonami, Carnegie Mellon University,
00009 // Andreas Waechter, International Business Machines Corporation
00010 //
00011 // Date : 12/01/2004
00012 
00013 #include "BonminConfig.h"
00014 
00015 #include "BonAmplInterface.hpp"
00016 #include "BonIpoptSolver.hpp"
00017 #include "BonColReader.hpp"
00018 #ifdef COIN_HAS_FILTERSQP
00019 # include "BonFilterSolver.hpp"
00020 #endif
00021 #include <string>
00022 #include <sstream>
00023 
00024 #include "BonTNLP2FPNLP.hpp"
00025 
00026 namespace Bonmin
00027 {
00029   AmplInterface::AmplInterface():
00030       OsiTMINLPInterface(), amplTminlp_(NULL)
00031   {}
00032 
00034   AmplInterface::AmplInterface(const AmplInterface &other):
00035       OsiTMINLPInterface(other), amplTminlp_(NULL)
00036   {
00037     amplTminlp_ = dynamic_cast<Bonmin::AmplTMINLP *> (GetRawPtr(tminlp_));
00038   }
00040   OsiSolverInterface *
00041   AmplInterface::clone(bool CopyData )
00042   {
00043     return new AmplInterface(*this);
00044   }
00045 
00047   AmplInterface::~AmplInterface()
00048   {
00049     amplTminlp_ = NULL;
00050   }
00051 
00052 
00053   void AmplInterface::readAmplNlFile(char **& argv, Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00054       Ipopt::SmartPtr<Ipopt::OptionsList> options,
00055       Ipopt::SmartPtr<Ipopt::Journalist> journalist,
00056       std::string* nl_file_content /* = NULL*/
00057                                     )
00058   {
00059     if (!IsValid(app_)) {
00060       createApplication(roptions, options, journalist, "bonmin.");
00061     }
00062     // set the default options... expect_infeasible, etc...
00063     if (!IsValid(tminlp_)) {
00064       amplTminlp_ = new AmplTMINLP(Ipopt::ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00065           NULL, appName() , nl_file_content);
00066       tminlp_ = GetRawPtr(amplTminlp_);
00067     }
00068     else {
00069       AmplTMINLP * amplTMINLP = dynamic_cast<AmplTMINLP *> (GetRawPtr(tminlp_));
00070       if (amplTMINLP) {
00071         AmplTMINLP * newAmpl = amplTMINLP->createEmpty();
00072         newAmpl->Initialize(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00073             NULL, appName() , nl_file_content);
00074         amplTminlp_ = newAmpl;
00075         tminlp_ = GetRawPtr(amplTminlp_);
00076       }
00077       else {
00078         amplTminlp_ = new AmplTMINLP(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00079             NULL, appName() , nl_file_content);
00080         tminlp_ = GetRawPtr(amplTminlp_);
00081       }
00082     }
00083     problem_ = new TMINLP2TNLP(tminlp_);
00084     feasibilityProblem_ = new TNLP2FPNLP
00085         (Ipopt::SmartPtr<TNLP>(Ipopt::GetRawPtr(problem_)));
00086   if(feasibility_mode_){
00087     problem_to_optimize_ = GetRawPtr(feasibilityProblem_);
00088   }
00089   else {
00090     problem_to_optimize_ = GetRawPtr(problem_);
00091   }
00092 
00093     int numcols = getNumCols();
00094     if (obj_)
00095       delete [] obj_;
00096     obj_ = new double[numcols];
00097     CoinFillN(obj_,numcols,1.);
00098     setStrParam(OsiProbName, std::string(argv[1]));
00099     extractInterfaceParams();
00100     hasBeenOptimized_ = false;
00101     //Read columns and row names if they exists
00102     readNames();
00103   }
00104 
00105   void
00106   AmplInterface::setAppDefaultOptions(Ipopt::SmartPtr<Ipopt::OptionsList> Options)
00107 {}
00108 
00109 
00110   void
00111   AmplInterface::readNames()
00112   {
00113     std::string probName;
00114     getStrParam(OsiProbName, probName);
00115     NamesReader colRead(probName, ".col");
00116     if (colRead.readFile()) {
00117       OsiNameVec colNames;
00118       colRead.copyNames(colNames);
00119       setColNames(colNames, 0, colNames.size(), 0);
00120     }
00121 
00122     NamesReader rowRead(probName, ".row");
00123     if (rowRead.readFile()) {
00124       OsiNameVec rowNames;
00125       rowRead.copyNames(rowNames);
00126       setRowNames(rowNames, 0, rowNames.size(), 0);
00127     }
00128 
00129 
00130   }
00131 
00132 } /* end namespace Bonmin. */

Generated on Mon May 3 03:05:16 2010 by  doxygen 1.4.7