ExampleNLPBandedMain.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <iostream>
00030 
00031 #include "NLPInterfacePack_ExampleNLPBanded.hpp"
00032 #include "MoochoPack_MoochoSolver.hpp"
00033 #include "Teuchos_CommandLineProcessor.hpp"
00034 #include "Teuchos_StandardCatchMacros.hpp"
00035 
00036 int main( int argc, char* argv[] )
00037 {
00038   namespace mp  = MoochoPack;
00039   namespace nlpip = NLPInterfacePack;
00040   using mp::MoochoSolver;
00041   using nlpip::NLP;
00042   using nlpip::ExampleNLPBanded;
00043   typedef nlpip::size_type  size_type;
00044   typedef nlpip::value_type value_type;
00045   using Teuchos::CommandLineProcessor;
00046   bool success = true;
00047 
00048   try {
00049 
00050     MoochoSolver solver;
00051   
00052     //
00053     // Get options from the command line
00054     //
00055     
00056     bool     show_options = false;
00057     int      nD = 1;
00058     int      nI = 1;
00059     int      bw = 1;
00060     int      mI = 0;
00061     double   xo = 1;
00062     bool     nlp_selects_basis = true;
00063     double   xDl = -NLP::infinite_bound();
00064     double   xDu = +NLP::infinite_bound(); 
00065     double   xIl = -NLP::infinite_bound(); 
00066     double   xIu = +NLP::infinite_bound();
00067     /*double   xDl = -1000.;
00068     double   xDu = +1000.;
00069     double   xIl = -1000.;
00070     double   xIu = +1000.;*/
00071 
00072     int      mU = 0;
00073     double   hl = -NLP::infinite_bound();
00074     double   hu = +NLP::infinite_bound();
00075     double   diag_scal = 1.0;
00076     double   diag_vary = 1.0;
00077     bool     sym_basis = false;
00078     double   f_offset  = 0.0;
00079     double   co        = 0.0;
00080     bool     ignore_constraints = false;
00081     
00082     CommandLineProcessor clp(false); // don't throw exceptions
00083 
00084     solver.setup_commandline_processor(&clp);
00085 
00086     clp.setOption( "show-options", "no-show-options", &show_options, "Show the commandline options or not." );
00087     clp.setOption( "nD",  &nD, "Number of dependent variables" );
00088     clp.setOption( "nI",  &nI, "Number of independent variables" );
00089     clp.setOption( "bw",  &bw, "Band width of the basis matrix" );
00090     clp.setOption( "mI",  &mI, "Number of general inequality constriants" );
00091     clp.setOption( "xo",  &xo, "Initial guess for x" );
00092     clp.setOption( "xDl", &xDl, "Lower bounds on xD" );
00093     clp.setOption( "xDu", &xDu, "Upper bounds on xD" );
00094     clp.setOption( "xIl", &xIl, "Lower bounds on xI" );
00095     clp.setOption( "xIu", &xIu, "Upper bounds on xI" );
00096 //    clp.setOption( "mU",  &mU,  "Number of dependent equality constriants" );
00097     clp.setOption( "hl", &hl, "Lower bounds on general inequalities" );
00098     clp.setOption( "hu", &hu, "Upper bounds on general inequalities" );
00099     clp.setOption( "diag-scal", &diag_scal, "Scaling of the basis diagonal" );
00100     clp.setOption( "diag-vary", &diag_vary, "Variation of the basis diagonal scaling" );
00101     clp.setOption(
00102       "nlp-selects-basis", "no-nlp-selects-basis", &nlp_selects_basis
00103       ,"Determine if the NLP will select basis" );
00104     clp.setOption(
00105       "sym-basis", "unsym-basis", &sym_basis
00106       ,"Determine if the basis is symmetric" );
00107     clp.setOption( "f_offset", &f_offset, "Constant offset for objective function" );
00108     clp.setOption( "co", &co, "Constant term in general equalities" );
00109     clp.setOption(
00110       "ignore-constraints", "no-ignore-constraints", &ignore_constraints
00111       ,"Determine if constraints are ignored or not" );
00112   
00113     CommandLineProcessor::EParseCommandLineReturn
00114       parse_return = clp.parse(argc,argv,&std::cerr);
00115 
00116     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00117       return parse_return;
00118     
00119     if(show_options) {
00120       std::cout << "\nPrinting commandline options used (options used shown as (default: \?\?\?) ...\n\n";
00121       clp.printHelpMessage(argv[0],std::cout);
00122     }
00123     
00124     //
00125     // Create and solve the NLP
00126     //
00127 
00128     ExampleNLPBanded
00129       nlp(nD,nI,bw,mU,mI,xo,xDl,xDu,xIl,xIu,hl,hu
00130         ,nlp_selects_basis,diag_scal,diag_vary
00131         ,sym_basis,f_offset,co,ignore_constraints
00132         );
00133 
00134     solver.set_nlp( Teuchos::rcp(&nlp,false) );
00135 
00136     const MoochoSolver::ESolutionStatus
00137       solution_status = solver.solve_nlp();
00138     
00139     return solution_status;
00140 
00141   }
00142   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cout,success)
00143 
00144   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00145 }

Generated on Thu Sep 18 12:36:38 2008 for MOOCHO by doxygen 1.3.9.1