Changeset 496


Ignore:
Timestamp:
Apr 24, 2007 7:28:25 PM (12 years ago)
Author:
pbonami
Message:

A few fixes in initialization for specific applications

Location:
trunk/Bonmin
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/examples/CppExample/MyBonmin.cpp

    r481 r496  
    3333  using namespace Ipopt;
    3434  using namespace Bonmin;
    35   SmartPtr<TMINLP> tminlp = new MyTMINLP;
     35  SmartPtr<MyTMINLP> tminlp = new MyTMINLP;
     36 
     37  BasicSetup b;
     38 
     39  //Register an additional option
     40  b.roptions()->AddStringOption2("print_solution","Do we print the solution or not?",
     41                                 "yes",
     42                                 "no", "No, we don't.",
     43                                 "yes", "Yes, we do.",
     44                                 "A longer comment can be put here");
     45 
     46 
     47  // Register all the bonmin options.
     48  BonminSetup::registerAllOptions(b.roptions());
     49 
     50  // Here we can change the default value of some Bonmin or Ipopt option
     51  b.options()->SetNumericValue("bonmin.time_limit", 5); //changes bonmin's time limit
     52  b.options()->SetStringValue("mu_oracle","loqo");
     53 
     54  //Here we can read one or several option files
     55  b.Initialize("Mybonmin.opt");
     56  b.Initialize("bonmin.opt");
     57
     58 
     59  // Now we can obtain the value of the new option
     60  int printSolution;
     61  b.options()->GetEnumValue("print_solution", printSolution,"");
     62  if(printSolution == 1){
     63    tminlp->printSolutionAtEndOfAlgorithm();
     64  }
     65 
    3666  BonminSetup bonmin;
    37   bonmin.initializeBonmin(tminlp);
     67  bonmin.setBasicOptions(b);
     68  bonmin.initializeBonmin(GetRawPtr(tminlp));
    3869
    39   bonmin.options()->SetNumericValue("bonmin.time_limit", 1); //changes bonmin's time limit
    40   bonmin.options()->SetStringValue("mu_oracle","loqo");
    4170
    42   // we can also try and read an option file (this can eventually change options set before, option file always have priority)
    43 //  bonmin.initialize("My_bonmin.opt");
    4471
    4572  //Set up done, now let's branch and bound
     
    4976    bb(bonmin);//process parameter file using Ipopt and do branch and bound
    5077
    51     std::cout.precision(10);
    5278
    5379  }
  • trunk/Bonmin/examples/CppExample/MyTMINLP.cpp

    r481 r496  
    196196  std::cout<<"Problem status: "<<status<<std::endl;
    197197  std::cout<<"Objective value: "<<obj_value<<std::endl;
    198   if(x != NULL){
     198  if(printSol_ && x != NULL){
    199199    std::cout<<"Solution:"<<std::endl;
    200200    for(int i = 0 ; i < n ; i++){
  • trunk/Bonmin/examples/CppExample/MyTMINLP.hpp

    r481 r496  
    3030public:
    3131  /// Default constructor.
    32   MyTMINLP(){}
     32  MyTMINLP():
     33printSol_(false){}
    3334 
    3435  /// virtual destructor.
     
    3637
    3738 
    38         /** Copy constructor. (no data = nothing to copy).*/   
    39   MyTMINLP(const MyTMINLP &){}
     39        /** Copy constructor.*/   
     40  MyTMINLP(const MyTMINLP &other):
     41printSol_(other.printSol_){}
    4042  /** Assignment operator. no data = nothing to assign*/
    4143  //MyTMINLP& operator=(const MyTMINLP&) {}
     
    164166  virtual const SosInfo * sosConstraints() const{return NULL;}
    165167  virtual const BranchingInfo* branchingInfo() const{return NULL;}
     168 
     169 
     170  void printSolutionAtEndOfAlgorithm(){
     171    printSol_ = true;}
     172 
     173private:
     174   bool printSol_;
    166175};
    167176
  • trunk/Bonmin/src/Algorithms/BonBonminSetup.hpp

    r489 r496  
    4141    /** Get the basic options if don't already have them.*/
    4242    virtual void defaultBasicOptions();
     43    /** Set the basic options.*/
     44    void setBasicOptions(BasicSetup &b){
     45      options_ = b.options();
     46      roptions_ = b.roptions();
     47      journalist_ = b.journalist();
     48    }
    4349protected:
    4450      /** Register standard MILP cut generators. */
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.cpp

    r485 r496  
    361361
    362362void
    363 OsiTMINLPInterface::readOptionFile(const char * fileName)
    364 {
     363OsiTMINLPInterface::readOptionFile(const std::string & fileName)
     364{
     365  if(IsValid(app_)){
     366  std::ifstream is;
     367  if (fileName != "") {
     368    try {
     369      is.open(fileName.c_str());
     370    }
     371    catch(std::bad_alloc) {
     372      std::cerr<<"Not enough memory to open option file.\n";
     373      throw -1;
     374    }
     375  }
     376  options()->ReadFromStream(*app_->Jnlst(), is);
    365377  extractInterfaceParams();
     378  }
    366379}
    367380
     
    22112224            }     
    22122225        }
    2213       if(numcols - numberFixed > numberEqualities)
    2214         {
    2215           std::string probName;
    2216           getStrParam(OsiProbName, probName);
    2217           throw newUnsolvedError(app_->errorCode(), problem_, probName);
    2218         }
     2226      if(numcols - numberFixed > numberEqualities || numcols < numberEqualities)
     2227      {
     2228        std::string probName;
     2229        getStrParam(OsiProbName, probName);
     2230        throw newUnsolvedError(app_->errorCode(), problem_, probName);
     2231      }
    22192232      double * saveColLow = CoinCopyOfArray(getColLower(), getNumCols());
    22202233      double * saveColUp = CoinCopyOfArray(getColUpper(), getNumCols());
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.hpp

    r481 r496  
    147147
    148148  /// Read parameter file
    149   void readOptionFile(const char * fileName);
     149  void readOptionFile(const std::string & fileName);
    150150
    151151  /// Retrieve OsiTMINLPApplication option list
Note: See TracChangeset for help on using the changeset viewer.