/home/coin/SVN-release/OS-2.0.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 
00025 namespace Bonmin
00026 {
00028   AmplInterface::AmplInterface():
00029       OsiTMINLPInterface(), amplTminlp_(NULL)
00030   {}
00031 
00033   AmplInterface::AmplInterface(const AmplInterface &other):
00034       OsiTMINLPInterface(other), amplTminlp_(NULL)
00035   {
00036     amplTminlp_ = dynamic_cast<Bonmin::AmplTMINLP *> (GetRawPtr(tminlp_));
00037   }
00039   OsiSolverInterface *
00040   AmplInterface::clone(bool CopyData )
00041   {
00042     return new AmplInterface(*this);
00043   }
00044 
00046   AmplInterface::~AmplInterface()
00047   {
00048     amplTminlp_ = NULL;
00049   }
00050 
00051 
00052   void AmplInterface::readAmplNlFile(char **& argv, Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00053       Ipopt::SmartPtr<Ipopt::OptionsList> options,
00054       Ipopt::SmartPtr<Ipopt::Journalist> journalist,
00055       std::string* nl_file_content /* = NULL*/
00056                                     )
00057   {
00058     if (!IsValid(app_)) {
00059       createApplication(roptions, options, journalist);
00060     }
00061     // set the default options... expect_infeasible, etc...
00062     if (!IsValid(tminlp_)) {
00063       amplTminlp_ = new AmplTMINLP(Ipopt::ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00064           NULL, appName() , nl_file_content);
00065       tminlp_ = GetRawPtr(amplTminlp_);
00066     }
00067     else {
00068       AmplTMINLP * amplTMINLP = dynamic_cast<AmplTMINLP *> (GetRawPtr(tminlp_));
00069       if (amplTMINLP) {
00070         AmplTMINLP * newAmpl = amplTMINLP->createEmpty();
00071         newAmpl->Initialize(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00072             NULL, appName() , nl_file_content);
00073         amplTminlp_ = newAmpl;
00074         tminlp_ = GetRawPtr(amplTminlp_);
00075       }
00076       else {
00077         amplTminlp_ = new AmplTMINLP(ConstPtr(app_->journalist()), app_->roptions(), app_->options(), argv,
00078             NULL, appName() , nl_file_content);
00079         tminlp_ = GetRawPtr(amplTminlp_);
00080       }
00081     }
00082     problem_ = new TMINLP2TNLP(tminlp_);
00083     feasibilityProblem_ = new TNLP2FPNLP
00084         (Ipopt::SmartPtr<TNLP>(Ipopt::GetRawPtr(problem_)));
00085   if(feasibility_mode_){
00086     problem_to_optimize_ = GetRawPtr(feasibilityProblem_);
00087   }
00088   else {
00089     problem_to_optimize_ = GetRawPtr(problem_);
00090   }
00091 
00092     int numcols = getNumCols();
00093     if (obj_)
00094       delete [] obj_;
00095     obj_ = new double[numcols];
00096     CoinFillN(obj_,numcols,1.);
00097     setStrParam(OsiProbName, std::string(argv[1]));
00098     extractInterfaceParams();
00099     hasBeenOptimized_ = false;
00100     //Read columns and row names if they exists
00101     readNames();
00102   }
00103 
00104   void
00105   AmplInterface::setAppDefaultOptions(Ipopt::SmartPtr<Ipopt::OptionsList> Options)
00106 {}
00107 
00108 
00109   void
00110   AmplInterface::readNames()
00111   {
00112     std::string probName;
00113     getStrParam(OsiProbName, probName);
00114     NamesReader colRead(probName, ".col");
00115     if (colRead.readFile()) {
00116       OsiNameVec colNames;
00117       colRead.copyNames(colNames);
00118       setColNames(colNames, 0, colNames.size(), 0);
00119     }
00120 
00121     NamesReader rowRead(probName, ".row");
00122     if (rowRead.readFile()) {
00123       OsiNameVec rowNames;
00124       rowRead.copyNames(rowNames);
00125       setRowNames(rowNames, 0, rowNames.size(), 0);
00126     }
00127 
00128 
00129   }
00130 
00131 } /* end namespace Bonmin. */

Generated on Thu Oct 8 03:02:54 2009 by  doxygen 1.4.7