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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <iostream>
00043 
00044 #include "NLPInterfacePack_ExampleNLPBanded.hpp"
00045 #include "MoochoPack_MoochoSolver.hpp"
00046 #include "Teuchos_CommandLineProcessor.hpp"
00047 #include "Teuchos_StandardCatchMacros.hpp"
00048 #include "Teuchos_GlobalMPISession.hpp"
00049 
00050 int main( int argc, char* argv[] )
00051 {
00052   namespace mp  = MoochoPack;
00053   namespace nlpip = NLPInterfacePack;
00054   using mp::MoochoSolver;
00055   using nlpip::NLP;
00056   using nlpip::ExampleNLPBanded;
00057   typedef nlpip::size_type  size_type;
00058   typedef nlpip::value_type value_type;
00059   using Teuchos::CommandLineProcessor;
00060   bool success = true;
00061 
00062   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00063 
00064   try {
00065 
00066     MoochoSolver solver;
00067   
00068     //
00069     // Get options from the command line
00070     //
00071     
00072     bool     show_options = false;
00073     int      nD = 1;
00074     int      nI = 1;
00075     int      bw = 1;
00076     int      mI = 0;
00077     double   xo = 1;
00078     bool     nlp_selects_basis = true;
00079     double   xDl = -NLP::infinite_bound();
00080     double   xDu = +NLP::infinite_bound(); 
00081     double   xIl = -NLP::infinite_bound(); 
00082     double   xIu = +NLP::infinite_bound();
00083     /*double   xDl = -1000.;
00084     double   xDu = +1000.;
00085     double   xIl = -1000.;
00086     double   xIu = +1000.;*/
00087 
00088     int      mU = 0;
00089     double   hl = -NLP::infinite_bound();
00090     double   hu = +NLP::infinite_bound();
00091     double   diag_scal = 1.0;
00092     double   diag_vary = 1.0;
00093     bool     sym_basis = false;
00094     double   f_offset  = 0.0;
00095     double   co        = 0.0;
00096     bool     ignore_constraints = false;
00097     
00098     CommandLineProcessor clp(false); // don't throw exceptions
00099 
00100     solver.setup_commandline_processor(&clp);
00101 
00102     clp.setOption( "show-options", "no-show-options", &show_options, "Show the commandline options or not." );
00103     clp.setOption( "nD",  &nD, "Number of dependent variables" );
00104     clp.setOption( "nI",  &nI, "Number of independent variables" );
00105     clp.setOption( "bw",  &bw, "Band width of the basis matrix" );
00106     clp.setOption( "mI",  &mI, "Number of general inequality constriants" );
00107     clp.setOption( "xo",  &xo, "Initial guess for x" );
00108     clp.setOption( "xDl", &xDl, "Lower bounds on xD" );
00109     clp.setOption( "xDu", &xDu, "Upper bounds on xD" );
00110     clp.setOption( "xIl", &xIl, "Lower bounds on xI" );
00111     clp.setOption( "xIu", &xIu, "Upper bounds on xI" );
00112 //    clp.setOption( "mU",  &mU,  "Number of dependent equality constriants" );
00113     clp.setOption( "hl", &hl, "Lower bounds on general inequalities" );
00114     clp.setOption( "hu", &hu, "Upper bounds on general inequalities" );
00115     clp.setOption( "diag-scal", &diag_scal, "Scaling of the basis diagonal" );
00116     clp.setOption( "diag-vary", &diag_vary, "Variation of the basis diagonal scaling" );
00117     clp.setOption(
00118       "nlp-selects-basis", "no-nlp-selects-basis", &nlp_selects_basis
00119       ,"Determine if the NLP will select basis" );
00120     clp.setOption(
00121       "sym-basis", "unsym-basis", &sym_basis
00122       ,"Determine if the basis is symmetric" );
00123     clp.setOption( "f_offset", &f_offset, "Constant offset for objective function" );
00124     clp.setOption( "co", &co, "Constant term in general equalities" );
00125     clp.setOption(
00126       "ignore-constraints", "no-ignore-constraints", &ignore_constraints
00127       ,"Determine if constraints are ignored or not" );
00128   
00129     CommandLineProcessor::EParseCommandLineReturn
00130       parse_return = clp.parse(argc,argv,&std::cerr);
00131 
00132     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00133       return parse_return;
00134     
00135     if(show_options) {
00136       std::cout << "\nPrinting commandline options used (options used shown as (default: \?\?\?) ...\n\n";
00137       clp.printHelpMessage(argv[0],std::cout);
00138     }
00139     
00140     //
00141     // Create and solve the NLP
00142     //
00143 
00144     ExampleNLPBanded
00145       nlp(nD,nI,bw,mU,mI,xo,xDl,xDu,xIl,xIu,hl,hu
00146         ,nlp_selects_basis,diag_scal,diag_vary
00147         ,sym_basis,f_offset,co,ignore_constraints
00148         );
00149 
00150     solver.set_nlp( Teuchos::rcp(&nlp,false) );
00151 
00152     const MoochoSolver::ESolutionStatus
00153       solution_status = solver.solve_nlp();
00154     
00155     return solution_status;
00156 
00157   }
00158   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cout,success)
00159 
00160   return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00161 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends