snopt_solver.cc
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2017, Alexander W. Winkler, ETH Zurich. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be
12  used to endorse or promote products derived from this software without
13  specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT,
19 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ******************************************************************************/
26 
27 #include <ifopt/snopt_solver.h>
28 #include <ifopt/snopt_adapter.h>
29 
30 namespace ifopt {
31 
32 void
34 {
35  SnoptAdapter snopt(ref);
36  snopt.Init();
37 
38  // A complete list of options can be found in the snopt user guide:
39  // https://web.stanford.edu/group/SOL/guides/sndoc7.pdf
40  snopt.setProbName( "snopt" );
41  snopt.setIntParameter( "Major Print level", 1 );
42  snopt.setIntParameter( "Minor Print level", 1 );
43  snopt.setIntParameter( "Derivative option", 1 ); // 1 = snopt will not calculate missing derivatives
44  snopt.setIntParameter( "Verify level ", 3 ); // full check on gradients, will throw error
45  snopt.setIntParameter("Iterations limit", 200000);
46  snopt.setRealParameter( "Major feasibility tolerance", 1.0e-4); // target nonlinear constraint violation
47  snopt.setRealParameter( "Minor feasibility tolerance", 1.0e-4); // for satisfying the QP bounds
48  snopt.setRealParameter( "Major optimality tolerance", 1.0e-2); // target complementarity gap
49 
50 
51  // error codes as given in the manual.
52  int Cold = 0; // Basis = 1, Warm = 2;
53 
54 
55  // interface changed with snopt version 7.6
56 #ifdef SNOPT76
57  int nS = 0; // number of super-basic variables (not relevant for cold start)
58  int nInf; // nInf : number of constraints outside of the bounds
59  double sInf;// sInf : sum of infeasibilities
60 
61  int INFO = snopt.solve(Cold, snopt.neF, snopt.n, snopt.ObjAdd,
63  snopt.iAfun, snopt.jAvar, snopt.A, snopt.neA,
64  snopt.iGfun, snopt.jGvar, snopt.neG,
65  snopt.xlow, snopt.xupp, snopt.Flow, snopt.Fupp,
66  snopt.x, snopt.xstate, snopt.xmul,
67  snopt.F, snopt.Fstate, snopt.Fmul,
68  nS, nInf, sInf);
69 #else
70  int INFO = snopt.solve(Cold);
71 #endif
72 
73  int EXIT = INFO - INFO%10; // change least significant digit to zero
74 
75  if (EXIT != 0) {
76  std::string msg = "ERROR: Snopt failed to find a solution. EXIT:" + std::to_string(EXIT) + ", INFO:" + std::to_string(INFO) + "\n";
77  throw std::runtime_error(msg);
78  }
79 
80  snopt.SetVariables();
81 }
82 
83 } /* namespace ifopt */
A generic optimization problem with variables, costs and constraints.
Definition: problem.h:97
static void ObjectiveAndConstraintFct(int *Status, int *n, double x[], int *needF, int *neF, double F[], int *needG, int *neG, double G[], char *cu, int *lencu, int iu[], int *leniu, double ru[], int *lenru)
common namespace for all elements in this library.
Definition: bounds.h:33
void Solve(Problem &nlp) override
Creates a snoptProblemA from nlp and solves it.
Definition: snopt_solver.cc:33
Solves the optimization problem with SNOPT version 7.5 and below.
Definition: snopt_adapter.h:48


ifopt
Author(s): Alexander W. Winkler
autogenerated on Fri May 17 2019 02:29:49