MOOCHO  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleNLPBandedMain.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <iostream>
43 
44 #include "NLPInterfacePack_ExampleNLPBanded.hpp"
45 #include "MoochoPack_MoochoSolver.hpp"
46 #include "Teuchos_CommandLineProcessor.hpp"
47 #include "Teuchos_StandardCatchMacros.hpp"
48 #include "Teuchos_GlobalMPISession.hpp"
49 
50 int main( int argc, char* argv[] )
51 {
52  namespace mp = MoochoPack;
53  namespace nlpip = NLPInterfacePack;
54  using mp::MoochoSolver;
55  using nlpip::NLP;
56  using nlpip::ExampleNLPBanded;
58  typedef nlpip::value_type value_type;
60  bool success = true;
61 
62  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 
64  try {
65 
66  MoochoSolver solver;
67 
68  //
69  // Get options from the command line
70  //
71 
72  bool show_options = false;
73  int nD = 1;
74  int nI = 1;
75  int bw = 1;
76  int mI = 0;
77  double xo = 1;
78  bool nlp_selects_basis = true;
79  double xDl = -NLP::infinite_bound();
80  double xDu = +NLP::infinite_bound();
81  double xIl = -NLP::infinite_bound();
82  double xIu = +NLP::infinite_bound();
83  /*double xDl = -1000.;
84  double xDu = +1000.;
85  double xIl = -1000.;
86  double xIu = +1000.;*/
87 
88  int mU = 0;
89  double hl = -NLP::infinite_bound();
90  double hu = +NLP::infinite_bound();
91  double diag_scal = 1.0;
92  double diag_vary = 1.0;
93  bool sym_basis = false;
94  double f_offset = 0.0;
95  double co = 0.0;
96  bool ignore_constraints = false;
97 
98  CommandLineProcessor clp(false); // don't throw exceptions
99 
100  solver.setup_commandline_processor(&clp);
101 
102  clp.setOption( "show-options", "no-show-options", &show_options, "Show the commandline options or not." );
103  clp.setOption( "nD", &nD, "Number of dependent variables" );
104  clp.setOption( "nI", &nI, "Number of independent variables" );
105  clp.setOption( "bw", &bw, "Band width of the basis matrix" );
106  clp.setOption( "mI", &mI, "Number of general inequality constriants" );
107  clp.setOption( "xo", &xo, "Initial guess for x" );
108  clp.setOption( "xDl", &xDl, "Lower bounds on xD" );
109  clp.setOption( "xDu", &xDu, "Upper bounds on xD" );
110  clp.setOption( "xIl", &xIl, "Lower bounds on xI" );
111  clp.setOption( "xIu", &xIu, "Upper bounds on xI" );
112 // clp.setOption( "mU", &mU, "Number of dependent equality constriants" );
113  clp.setOption( "hl", &hl, "Lower bounds on general inequalities" );
114  clp.setOption( "hu", &hu, "Upper bounds on general inequalities" );
115  clp.setOption( "diag-scal", &diag_scal, "Scaling of the basis diagonal" );
116  clp.setOption( "diag-vary", &diag_vary, "Variation of the basis diagonal scaling" );
117  clp.setOption(
118  "nlp-selects-basis", "no-nlp-selects-basis", &nlp_selects_basis
119  ,"Determine if the NLP will select basis" );
120  clp.setOption(
121  "sym-basis", "unsym-basis", &sym_basis
122  ,"Determine if the basis is symmetric" );
123  clp.setOption( "f_offset", &f_offset, "Constant offset for objective function" );
124  clp.setOption( "co", &co, "Constant term in general equalities" );
125  clp.setOption(
126  "ignore-constraints", "no-ignore-constraints", &ignore_constraints
127  ,"Determine if constraints are ignored or not" );
128 
129  CommandLineProcessor::EParseCommandLineReturn
130  parse_return = clp.parse(argc,argv,&std::cerr);
131 
132  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
133  return parse_return;
134 
135  if(show_options) {
136  std::cout << "\nPrinting commandline options used (options used shown as (default: \?\?\?) ...\n\n";
137  clp.printHelpMessage(argv[0],std::cout);
138  }
139 
140  //
141  // Create and solve the NLP
142  //
143 
144  ExampleNLPBanded
145  nlp(nD,nI,bw,mU,mI,xo,xDl,xDu,xIl,xIu,hl,hu
146  ,nlp_selects_basis,diag_scal,diag_vary
147  ,sym_basis,f_offset,co,ignore_constraints
148  );
149 
150  solver.set_nlp( Teuchos::rcp(&nlp,false) );
151 
152  const MoochoSolver::ESolutionStatus
153  solution_status = solver.solve_nlp();
154 
155  return solution_status;
156 
157  }
158  TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cout,success)
159 
160  return MoochoSolver::SOLVE_RETURN_EXCEPTION;
161 }
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
size_t size_type
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)