Ignore:
Timestamp:
Sep 29, 2006 4:48:36 PM (13 years ago)
Author:
pbonami
Message:

astyled the devel branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Bonmin/src/BonminAmplInterface/BonAmplInterface.cpp

    r57 r62  
    44
    55
    6 namespace Bonmin {
    7 /** Default constructor */
    8 AmplInterface::AmplInterface(): IpoptInterface(), amplTminlp_(NULL)
    9 {}
    10  
    11 /** Constructor with inputed ampl command line (reads model from nl file)*/
    12 AmplInterface::AmplInterface(char **& amplArgs)
    13 :
    14 IpoptInterface(),
    15 amplTminlp_(NULL)
     6namespace Bonmin
    167{
    17   readAmplNlFile(amplArgs, NULL, NULL);
    18 }
     8  /** Default constructor */
     9  AmplInterface::AmplInterface(): IpoptInterface(), amplTminlp_(NULL)
     10  {}
    1911
    20 /** Copy constructor */
    21 AmplInterface::AmplInterface(const AmplInterface &other):
    22           IpoptInterface(other), amplTminlp_(NULL)
    23 {
    24   amplTminlp_ = dynamic_cast<Bonmin::AmplTMINLP *> (GetRawPtr(tminlp_));
    25 }
     12  /** Constructor with inputed ampl command line (reads model from nl file)*/
     13  AmplInterface::AmplInterface(char **& amplArgs)
     14      :
     15      IpoptInterface(),
     16      amplTminlp_(NULL)
     17  {
     18    readAmplNlFile(amplArgs, NULL, NULL);
     19  }
     20
     21  /** Copy constructor */
     22  AmplInterface::AmplInterface(const AmplInterface &other):
     23      IpoptInterface(other), amplTminlp_(NULL)
     24  {
     25    amplTminlp_ = dynamic_cast<Bonmin::AmplTMINLP *> (GetRawPtr(tminlp_));
     26  }
    2627/// Clone
    27 AmplInterface *
    28 AmplInterface::clone(bool CopyData )
    29 {
    30   return new AmplInterface(*this);
    31 }
     28  AmplInterface *
     29  AmplInterface::clone(bool CopyData )
     30  {
     31    return new AmplInterface(*this);
     32  }
    3233
    3334///Destructor
    34 AmplInterface::~AmplInterface()
    35 {amplTminlp_ = NULL;}
     35  AmplInterface::~AmplInterface()
     36  {
     37    amplTminlp_ = NULL;
     38  }
    3639
    37 /** Read an ampl . nl file from the given filename */
    38 void
    39 AmplInterface::readAmplNlFile(char**& filename,
    40     std::string* ipopt_file_content,
    41     std::string* nl_file_content)
    42 {
     40  /** Read an ampl . nl file from the given filename */
     41  void
     42  AmplInterface::readAmplNlFile(char**& filename,
     43      std::string* ipopt_file_content,
     44      std::string* nl_file_content)
     45  {
    4346
    4447
    4548
    46   app_ = new IpoptSolver;
     49    app_ = new IpoptSolver;
    4750
    48   SmartPtr<RegisteredOptions> roptions = app_->RegOptions();
    49   register_ALL_options(roptions);
     51    SmartPtr<RegisteredOptions> roptions = app_->RegOptions();
     52    register_ALL_options(roptions);
    5053
    51   // Call initalize to open output
    52   app_->Initialize("");
    53   // Read the bonmin.opt input file
    54   if (ipopt_file_content == NULL) {
    55     app_->Initialize("bonmin.opt");
    56   }
    57   else {
    58     std::stringstream ss(ipopt_file_content->c_str());
    59     app_->Initialize(ss);
    60   }
     54    // Call initalize to open output
     55    app_->Initialize("");
     56    // Read the bonmin.opt input file
     57    if (ipopt_file_content == NULL) {
     58      app_->Initialize("bonmin.opt");
     59    }
     60    else {
     61      std::stringstream ss(ipopt_file_content->c_str());
     62      app_->Initialize(ss);
     63    }
    6164
    6265
    63   // set the default options... expect_infeasible, etc...
    64   IpoptSolver * ipopt = dynamic_cast<IpoptSolver *> (GetRawPtr(app_));
    65   if(!IsValid(tminlp_)) {
    66         amplTminlp_ = new AmplTMINLP(ConstPtr(ipopt->getIpoptApp().Jnlst()), app_->Options(), filename,
    67         NULL, appName() , nl_file_content);
    68         tminlp_ = GetRawPtr(amplTminlp_);
    69   }
    70   else {
    71     AmplTMINLP * amplTMINLP = dynamic_cast<AmplTMINLP *> (GetRawPtr(tminlp_));
    72     if(amplTMINLP) {
    73       AmplTMINLP * newAmpl = amplTMINLP->createEmpty();
    74       newAmpl->Initialize(ConstPtr(ipopt->getIpoptApp().Jnlst()), app_->Options(), filename,
    75           NULL, appName() , nl_file_content);
    76       amplTminlp_ = newAmpl;
    77       tminlp_ = GetRawPtr(amplTminlp_);
    78     }
    79     else {
     66    // set the default options... expect_infeasible, etc...
     67    IpoptSolver * ipopt = dynamic_cast<IpoptSolver *> (GetRawPtr(app_));
     68    if (!IsValid(tminlp_)) {
    8069      amplTminlp_ = new AmplTMINLP(ConstPtr(ipopt->getIpoptApp().Jnlst()), app_->Options(), filename,
    8170          NULL, appName() , nl_file_content);
    8271      tminlp_ = GetRawPtr(amplTminlp_);
    8372    }
    84   }
    85   problem_ = new TMINLP2TNLP(tminlp_);//, *app_->Options());
     73    else {
     74      AmplTMINLP * amplTMINLP = dynamic_cast<AmplTMINLP *> (GetRawPtr(tminlp_));
     75      if (amplTMINLP) {
     76        AmplTMINLP * newAmpl = amplTMINLP->createEmpty();
     77        newAmpl->Initialize(ConstPtr(ipopt->getIpoptApp().Jnlst()), app_->Options(), filename,
     78            NULL, appName() , nl_file_content);
     79        amplTminlp_ = newAmpl;
     80        tminlp_ = GetRawPtr(amplTminlp_);
     81      }
     82      else {
     83        amplTminlp_ = new AmplTMINLP(ConstPtr(ipopt->getIpoptApp().Jnlst()), app_->Options(), filename,
     84            NULL, appName() , nl_file_content);
     85        tminlp_ = GetRawPtr(amplTminlp_);
     86      }
     87    }
     88    problem_ = new TMINLP2TNLP(tminlp_);//, *app_->Options());
    8689
    87   bool print_options_documentation;
    88   app_->Options()->GetBoolValue("print_options_documentation",
    89       print_options_documentation, "");
    90   if (print_options_documentation) {
    91     std::list<std::string> categories;
    92     categories.push_back("bonmin branch-and-bound options");
    93     categories.push_back("bonmin options for robustness");
    94     categories.push_back("bonmin options for non-convex problems");
    95     categories.push_back("bonmin options : B-Hyb specific options");
     90    bool print_options_documentation;
     91    app_->Options()->GetBoolValue("print_options_documentation",
     92        print_options_documentation, "");
     93    if (print_options_documentation) {
     94      std::list<std::string> categories;
     95      categories.push_back("bonmin branch-and-bound options");
     96      categories.push_back("bonmin options for robustness");
     97      categories.push_back("bonmin options for non-convex problems");
     98      categories.push_back("bonmin options : B-Hyb specific options");
    9699//    roptions->OutputLatexOptionDocumentation2(*app_->Jnlst(),categories);
    97     roptions->OutputOptionDocumentation(*(ipopt->getIpoptApp().Jnlst()),categories);
     100      roptions->OutputOptionDocumentation(*(ipopt->getIpoptApp().Jnlst()),categories);
     101    }
     102
     103    int numcols = getNumCols();
     104    if (obj_)
     105      delete [] obj_;
     106    obj_ = new double[numcols];
     107    CoinFillN(obj_,numcols,1.);
     108    setStrParam(OsiProbName, std::string(filename[1]));
     109    extractInterfaceParams();
     110    hasBeenOptimized_ = false;
     111    feasibilityProblem_ = new TNLP2FPNLP
     112        (Ipopt::SmartPtr<TNLP>(Ipopt::GetRawPtr(problem_)));
    98113  }
    99114
    100   int numcols = getNumCols();
    101   if(obj_)
    102     delete [] obj_;
    103   obj_ = new double[numcols];
    104   CoinFillN(obj_,numcols,1.);
    105   setStrParam(OsiProbName, std::string(filename[1]));
    106   extractInterfaceParams();
    107   hasBeenOptimized_ = false;
    108   feasibilityProblem_ = new TNLP2FPNLP
    109       (Ipopt::SmartPtr<TNLP>(Ipopt::GetRawPtr(problem_)));
    110 }
    111 
    112 /** write ampl solution file */
    113 void
    114 AmplInterface::writeAmplSolFile(std::string message,const double * primalSol,const double * dualSol)
    115 {
    116   TMINLP * tminlp = GetRawPtr(tminlp_);
    117   AmplTMINLP * ampl_tminlp = dynamic_cast<AmplTMINLP *> (tminlp);
    118   if(ampl_tminlp)
    119     ampl_tminlp->write_solution(message,primalSol,dualSol);
    120   else
    121     std::cerr<<"Errot can not write .sol file for non ampl problem"<<std::endl;
    122 }
     115  /** write ampl solution file */
     116  void
     117  AmplInterface::writeAmplSolFile(std::string message,const double * primalSol,const double * dualSol)
     118  {
     119    TMINLP * tminlp = GetRawPtr(tminlp_);
     120    AmplTMINLP * ampl_tminlp = dynamic_cast<AmplTMINLP *> (tminlp);
     121    if (ampl_tminlp)
     122      ampl_tminlp->write_solution(message,primalSol,dualSol);
     123    else
     124      std::cerr<<"Errot can not write .sol file for non ampl problem"<<std::endl;
     125  }
    123126
    124127}
Note: See TracChangeset for help on using the changeset viewer.