MOOCHO Version of the Day
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 #include "Teuchos_GlobalMPISession.hpp"
00036 
00037 int main( int argc, char* argv[] )
00038 {
00039   namespace mp  = MoochoPack;
00040   namespace nlpip = NLPInterfacePack;
00041   using mp::MoochoSolver;
00042   using nlpip::NLP;
00043   using nlpip::ExampleNLPBanded;
00044   typedef nlpip::size_type  size_type;
00045   typedef nlpip::value_type value_type;
00046   using Teuchos::CommandLineProcessor;
00047   bool success = true;
00048 
00049   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00050 
00051   try {
00052 
00053     MoochoSolver solver;
00054   
00055     //
00056     // Get options from the command line
00057     //
00058     
00059     bool     show_options = false;
00060     int      nD = 1;
00061     int      nI = 1;
00062     int      bw = 1;
00063     int      mI = 0;
00064     double   xo = 1;
00065     bool     nlp_selects_basis = true;
00066     double   xDl = -NLP::infinite_bound();
00067     double   xDu = +NLP::infinite_bound(); 
00068     double   xIl = -NLP::infinite_bound(); 
00069     double   xIu = +NLP::infinite_bound();
00070     /*double   xDl = -1000.;
00071     double   xDu = +1000.;
00072     double   xIl = -1000.;
00073     double   xIu = +1000.;*/
00074 
00075     int      mU = 0;
00076     double   hl = -NLP::infinite_bound();
00077     double   hu = +NLP::infinite_bound();
00078     double   diag_scal = 1.0;
00079     double   diag_vary = 1.0;
00080     bool     sym_basis = false;
00081     double   f_offset  = 0.0;
00082     double   co        = 0.0;
00083     bool     ignore_constraints = false;
00084     
00085     CommandLineProcessor clp(false); // don't throw exceptions
00086 
00087     solver.setup_commandline_processor(&clp);
00088 
00089     clp.setOption( "show-options", "no-show-options", &show_options, "Show the commandline options or not." );
00090     clp.setOption( "nD",  &nD, "Number of dependent variables" );
00091     clp.setOption( "nI",  &nI, "Number of independent variables" );
00092     clp.setOption( "bw",  &bw, "Band width of the basis matrix" );
00093     clp.setOption( "mI",  &mI, "Number of general inequality constriants" );
00094     clp.setOption( "xo",  &xo, "Initial guess for x" );
00095     clp.setOption( "xDl", &xDl, "Lower bounds on xD" );
00096     clp.setOption( "xDu", &xDu, "Upper bounds on xD" );
00097     clp.setOption( "xIl", &xIl, "Lower bounds on xI" );
00098     clp.setOption( "xIu", &xIu, "Upper bounds on xI" );
00099 //    clp.setOption( "mU",  &mU,  "Number of dependent equality constriants" );
00100     clp.setOption( "hl", &hl, "Lower bounds on general inequalities" );
00101     clp.setOption( "hu", &hu, "Upper bounds on general inequalities" );
00102     clp.setOption( "diag-scal", &diag_scal, "Scaling of the basis diagonal" );
00103     clp.setOption( "diag-vary", &diag_vary, "Variation of the basis diagonal scaling" );
00104     clp.setOption(
00105       "nlp-selects-basis", "no-nlp-selects-basis", &nlp_selects_basis
00106       ,"Determine if the NLP will select basis" );
00107     clp.setOption(
00108       "sym-basis", "unsym-basis", &sym_basis
00109       ,"Determine if the basis is symmetric" );
00110     clp.setOption( "f_offset", &f_offset, "Constant offset for objective function" );
00111     clp.setOption( "co", &co, "Constant term in general equalities" );
00112     clp.setOption(
00113       "ignore-constraints", "no-ignore-constraints", &ignore_constraints
00114       ,"Determine if constraints are ignored or not" );
00115   
00116     CommandLineProcessor::EParseCommandLineReturn
00117       parse_return = clp.parse(argc,argv,&std::cerr);
00118 
00119     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00120       return parse_return;
00121     
00122     if(show_options) {
00123       std::cout << "\nPrinting commandline options used (options used shown as (default: \?\?\?) ...\n\n";
00124       clp.printHelpMessage(argv[0],std::cout);
00125     }
00126     
00127     //
00128     // Create and solve the NLP
00129     //
00130 
00131     ExampleNLPBanded
00132       nlp(nD,nI,bw,mU,mI,xo,xDl,xDu,xIl,xIu,hl,hu
00133         ,nlp_selects_basis,diag_scal,diag_vary
00134         ,sym_basis,f_offset,co,ignore_constraints
00135         );
00136 
00137     solver.set_nlp( Teuchos::rcp(&nlp,false) );
00138 
00139     const MoochoSolver::ESolutionStatus
00140       solution_status = solver.solve_nlp();
00141     
00142     return solution_status;
00143 
00144   }
00145   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cout,success)
00146 
00147   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00148 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends