Changeset 417


Ignore:
Timestamp:
Aug 1, 2005 12:00:19 PM (14 years ago)
Author:
claird
Message:

Slight cleanup of the Application code. Moved the Journalist setup and the reading of options to the constructor.

Location:
branches/dev/Apps/StdInterface
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev/Apps/StdInterface/IpIpoptApplication.cpp

    r414 r417  
    2424  DefineIpoptType(IpoptApplication);
    2525
    26   IpoptApplication::IpoptApplication()
     26  IpoptApplication::IpoptApplication(bool read_params_dat, bool create_console_out)
    2727      :
    28       read_params_dat_(true),
    29       report_solution_(true),
    30       force_report_solution_to_console_(false),
    31       report_statistics_(true),
    3228      jnlst_(new Journalist()),
    3329      options_(new OptionsList())
    3430  {
     31# ifdef IP_DEBUG
     32    DebugJournalistWrapper::SetJournalist(GetRawPtr(jnlst_));
     33    Journal* debug_jrnl = jnlst_->AddJournal("Debug", "debug.out", J_SUMMARY);
     34    debug_jrnl->SetPrintLevel(J_DBG, J_ALL);
     35# endif
     36
    3537    DBG_START_METH("IpoptApplication::IpoptApplication()",
    3638                   dbg_verbosity);
     39
     40
     41    Journal* stdout_jrnl = NULL;
     42    if (create_console_out) {
     43      stdout_jrnl =
     44        jnlst_->AddJournal("console", "stdout", J_SUMMARY);
     45      stdout_jrnl->SetPrintLevel(J_DBG, J_NONE);
     46    }
     47
     48
     49    // Register the valid options
     50    SmartPtr<RegisteredOptions> reg_options = new RegisteredOptions();
     51    IpoptTypeInfo::RegisterAllOptions(reg_options);
     52
     53    options_->SetJournalist(jnlst_);
     54    options_->SetRegisteredOptions(reg_options);
     55
     56    // Get the options
     57    if (read_params_dat) {
     58      FILE* fp_options = fopen("PARAMS.DAT", "r");
     59      if (fp_options) {
     60        // PARAMS.DAT exists, read the content
     61        options_->ReadFromFile(*jnlst_, fp_options);
     62        fclose(fp_options);
     63        fp_options=NULL;
     64      }
     65    }
     66
     67    Index ivalue;
     68    EJournalLevel print_level;
     69    if (create_console_out) {
     70      // Set printlevel for stdout
     71      options_->GetIntegerValue("print_level", ivalue, "");
     72      print_level = (EJournalLevel)ivalue;
     73      stdout_jrnl->SetAllPrintLevels(print_level);
     74      stdout_jrnl->SetPrintLevel(J_DBG, J_NONE);
     75    }
     76
     77    bool option_set;
     78
     79#ifdef IP_DEBUG
     80    // Set printlevel for debug
     81    option_set = options_->GetIntegerValue("debug_print_level",
     82                                           ivalue, "");
     83    EJournalLevel debug_print_level;
     84    if (option_set) {
     85      debug_print_level = (EJournalLevel)ivalue;
     86    }
     87    else {
     88      debug_print_level = print_level;
     89    }
     90    debug_jrnl->SetAllPrintLevels(debug_print_level);
     91    debug_jrnl->SetPrintLevel(J_DBG, J_ALL);
     92#endif
     93
     94    // Open an output file if required
     95    std::string output_filename;
     96    options_->GetValue("output_file", output_filename, "");
     97    if (output_filename != "") {
     98      EJournalLevel file_print_level;
     99      option_set = options_->GetIntegerValue("file_print_level", ivalue, "");
     100      if (option_set) {
     101        file_print_level = (EJournalLevel)ivalue;
     102      }
     103      else {
     104        file_print_level = print_level;
     105      }
     106      Journal* file_jrnl = jnlst_->AddJournal("OutputFile", output_filename.c_str(), file_print_level);
     107      file_jrnl->SetPrintLevel(J_DBG, J_NONE);
     108    }
     109
     110
     111    // output a description of all the options
     112    bool print_options_documentation;
     113    options_->GetBoolValue("print_options_documentation",
     114                           print_options_documentation, "");
     115    if (print_options_documentation) {
     116      reg_options->OutputOptionDocumentation(*jnlst_);
     117    }
    37118  }
    38119
     
    136217    try {
    137218
    138 # ifdef IP_DEBUG
    139 
    140       DebugJournalistWrapper::SetJournalist(GetRawPtr(jnlst_));
    141 # endif
    142 
    143       Journal* stdout_jrnl =
    144         jnlst_->AddJournal("ConsoleStdOut", "stdout", J_SUMMARY);
    145       stdout_jrnl->SetPrintLevel(J_DBG, J_NONE);
    146 
    147 # ifdef IP_DEBUG
    148 
    149       Journal* dbg_jrnl = jnlst_->AddJournal("Debug", "debug.out", J_SUMMARY);
    150       dbg_jrnl->SetPrintLevel(J_DBG, J_ALL);
    151 # endif
    152 
    153       // Register the valid options
    154       SmartPtr<RegisteredOptions> reg_options = new RegisteredOptions();
    155       IpoptTypeInfo::RegisterAllOptions(reg_options);
    156 
    157       options_->SetJournalist(jnlst_);
    158       options_->SetRegisteredOptions(reg_options);
    159 
    160       // Get the options
    161       if (read_params_dat_) {
    162         FILE* fp_options = fopen("PARAMS.DAT", "r");
    163         if (fp_options) {
    164           // PARAMS.DAT exists, read the content
    165           options_->ReadFromFile(*jnlst_, fp_options);
    166           fclose(fp_options);
    167           fp_options=NULL;
    168         }
    169       }
    170 
    171       // Set printlevel for stdout
    172       Index ivalue;
    173       EJournalLevel print_level;
    174       options_->GetIntegerValue("print_level", ivalue, "");
    175       print_level = (EJournalLevel)ivalue;
    176       stdout_jrnl->SetAllPrintLevels(print_level);
    177       stdout_jrnl->SetPrintLevel(J_DBG, J_NONE);
    178 
    179       bool option_set;
    180 
    181 #ifdef IP_DEBUG
    182       // Set printlevel for debug
    183       option_set = options_->GetIntegerValue("debug_print_level",
    184                                              ivalue, "");
    185       EJournalLevel debug_print_level;
    186       if (option_set) {
    187         debug_print_level = (EJournalLevel)ivalue;
    188       }
    189       else {
    190         debug_print_level = print_level;
    191       }
    192       dbg_jrnl->SetAllPrintLevels(debug_print_level);
    193       dbg_jrnl->SetPrintLevel(J_DBG, J_ALL);
    194 #endif
    195 
    196       // Open an output file if required
    197       std::string output_filename;
    198       options_->GetValue("output_file", output_filename, "");
    199       if (output_filename != "") {
    200         EJournalLevel file_print_level;
    201         option_set = options_->GetIntegerValue("file_print_level", ivalue, "");
    202         if (option_set) {
    203           file_print_level = (EJournalLevel)ivalue;
    204         }
    205         else {
    206           file_print_level = print_level;
    207         }
    208         Journal* file_jrnl = jnlst_->AddJournal("OutputFile", output_filename.c_str(), file_print_level);
    209         file_jrnl->SetPrintLevel(J_DBG, J_NONE);
    210       }
    211 
    212 
    213       // output a description of all the options
    214       bool print_options_documentation;
    215       options_->GetBoolValue("print_options_documentation",
    216                              print_options_documentation, "");
    217       if (print_options_documentation) {
    218         reg_options->OutputOptionDocumentation(*jnlst_);
    219       }
    220 
    221219      SmartPtr<NLPScalingObject> nlp_scaling;
    222220      std::string nlp_scaling_method;
     
    261259      SolverReturn status = alg->Optimize();
    262260
    263       EJournalLevel vector_report_level = J_VECTOR;
    264       if (report_solution_ || force_report_solution_to_console_) {
    265         if (force_report_solution_to_console_) {
    266           vector_report_level = J_SUMMARY;
    267         }
    268         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    269                        "\nNumber of Iterations....: %d\n",
    270                        ip_data->iter_count());
    271 
    272         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    273                        "\n                                   (scaled)                 (unscaled)\n");
    274         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    275                        "Objective...............: %24.16e  %24.16e\n", ip_cq->curr_f(), ip_cq->unscaled_curr_f());
    276         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    277                        "Dual infeasibility......: %24.16e  %24.16e\n", ip_cq->curr_dual_infeasibility(NORM_MAX), ip_cq->unscaled_curr_dual_infeasibility(NORM_MAX));
    278         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    279                        "Constraint violation....: %24.16e  %24.16e\n", ip_cq->curr_nlp_constraint_violation(NORM_MAX), ip_cq->unscaled_curr_nlp_constraint_violation(NORM_MAX));
    280         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    281                        "Complementarity.........: %24.16e  %24.16e\n", ip_cq->curr_complementarity(0., NORM_MAX), ip_cq->unscaled_curr_complementarity(0., NORM_MAX));
    282         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    283                        "Overall NLP error.......: %24.16e  %24.16e\n\n", ip_cq->curr_nlp_error(), ip_cq->unscaled_curr_nlp_error());
    284 
    285 
    286         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "x", *ip_data->curr()->x());
    287         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "y_c", *ip_data->curr()->y_c());
    288         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "y_d", *ip_data->curr()->y_d());
    289         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "z_L", *ip_data->curr()->z_L());
    290         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "z_U", *ip_data->curr()->z_U());
    291         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "v_L", *ip_data->curr()->v_L());
    292         jnlst_->PrintVector(vector_report_level, J_SOLUTION, "v_U", *ip_data->curr()->v_U());
    293       }
    294 
    295       if (report_statistics_) {
    296         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    297                        "\nNumber of objective function evaluations             = %d\n",
    298                        ip_nlp->f_evals());
    299         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    300                        "Number of equality constraint evaluations            = %d\n",
    301                        ip_nlp->c_evals());
    302         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    303                        "Number of inequality constraint evaluations          = %d\n",
    304                        ip_nlp->d_evals());
    305         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    306                        "Number of equality constraint Jacobian evaluations   = %d\n",
    307                        ip_nlp->jac_c_evals());
    308         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    309                        "Number of inequality constraint Jacobian evaluations = %d\n",
    310                        ip_nlp->jac_d_evals());
    311         jnlst_->Printf(J_SUMMARY, J_SOLUTION,
    312                        "Number of Lagrangian Hessian evaluations             = %d\n",
    313                        ip_nlp->h_evals());
    314       }
     261      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     262                     "\nNumber of Iterations....: %d\n",
     263                     ip_data->iter_count());
     264
     265      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     266                     "\n                                   (scaled)                 (unscaled)\n");
     267      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     268                     "Objective...............: %24.16e  %24.16e\n", ip_cq->curr_f(), ip_cq->unscaled_curr_f());
     269      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     270                     "Dual infeasibility......: %24.16e  %24.16e\n", ip_cq->curr_dual_infeasibility(NORM_MAX), ip_cq->unscaled_curr_dual_infeasibility(NORM_MAX));
     271      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     272                     "Constraint violation....: %24.16e  %24.16e\n", ip_cq->curr_nlp_constraint_violation(NORM_MAX), ip_cq->unscaled_curr_nlp_constraint_violation(NORM_MAX));
     273      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     274                     "Complementarity.........: %24.16e  %24.16e\n", ip_cq->curr_complementarity(0., NORM_MAX), ip_cq->unscaled_curr_complementarity(0., NORM_MAX));
     275      jnlst_->Printf(J_SUMMARY, J_SOLUTION,
     276                     "Overall NLP error.......: %24.16e  %24.16e\n\n", ip_cq->curr_nlp_error(), ip_cq->unscaled_curr_nlp_error());
     277
     278      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "x", *ip_data->curr()->x());
     279      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "y_c", *ip_data->curr()->y_c());
     280      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "y_d", *ip_data->curr()->y_d());
     281      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "z_L", *ip_data->curr()->z_L());
     282      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "z_U", *ip_data->curr()->z_U());
     283      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "v_L", *ip_data->curr()->v_L());
     284      jnlst_->PrintVector(J_VECTOR, J_SOLUTION, "v_U", *ip_data->curr()->v_U());
     285
     286
     287      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     288                     "\nNumber of objective function evaluations             = %d\n",
     289                     ip_nlp->f_evals());
     290      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     291                     "Number of equality constraint evaluations            = %d\n",
     292                     ip_nlp->c_evals());
     293      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     294                     "Number of inequality constraint evaluations          = %d\n",
     295                     ip_nlp->d_evals());
     296      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     297                     "Number of equality constraint Jacobian evaluations   = %d\n",
     298                     ip_nlp->jac_c_evals());
     299      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     300                     "Number of inequality constraint Jacobian evaluations = %d\n",
     301                     ip_nlp->jac_d_evals());
     302      jnlst_->Printf(J_SUMMARY, J_STATISTICS,
     303                     "Number of Lagrangian Hessian evaluations             = %d\n",
     304                     ip_nlp->h_evals());
    315305
    316306      // Write EXIT message
  • branches/dev/Apps/StdInterface/IpIpoptApplication.hpp

    r387 r417  
    3232  {
    3333  public:
    34     IpoptApplication();
     34    IpoptApplication(bool read_params_dat = true, bool create_console_out = true);
    3535
    3636    virtual ~IpoptApplication();
     
    104104    /**@name Variables that customize the application behavior */
    105105    //@{
    106     /** Name of the file for detailed output */
    107106    /** Decide whether or not the PARAMS.DAT file should be read */
    108107    bool read_params_dat_;
    109     /** Decide whether or not to report the solution to the journalist */
    110     bool report_solution_;
    111     /** Decide whether or not to force reporting of the solution to the console */
    112     bool force_report_solution_to_console_;
    113     /** Decide whether or not to report statistics */
    114     bool report_statistics_;
    115108    //@}
    116109
Note: See TracChangeset for help on using the changeset viewer.