snopt_solver.cc
Go to the documentation of this file.
00001 /******************************************************************************
00002 Copyright (c) 2017, Alexander W. Winkler, ETH Zurich. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without modification,
00005 are permitted provided that the following conditions are met:
00006     * Redistributions of source code must retain the above copyright notice,
00007       this list of conditions and the following disclaimer.
00008     * Redistributions in binary form must reproduce the above copyright notice,
00009       this list of conditions and the following disclaimer in the documentation
00010       and/or other materials provided with the distribution.
00011     * Neither the name of ETH ZURICH nor the names of its contributors may be
00012       used to endorse or promote products derived from this software without
00013       specific prior written permission.
00014 
00015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00016 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00017 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00018 DISCLAIMED. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT,
00019 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00020 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 ******************************************************************************/
00026 
00027 #include <ifopt/snopt_solver.h>
00028 #include <ifopt/snopt_adapter.h>
00029 
00030 namespace ifopt {
00031 
00032 void
00033 SnoptSolver::Solve (Problem& ref)
00034 {
00035   SnoptAdapter snopt(ref);
00036   snopt.Init();
00037 
00038   // A complete list of options can be found in the snopt user guide:
00039   // https://web.stanford.edu/group/SOL/guides/sndoc7.pdf
00040   snopt.setProbName( "snopt" );
00041   snopt.setIntParameter( "Major Print level", 1 );
00042   snopt.setIntParameter( "Minor Print level", 1 );
00043   snopt.setIntParameter( "Derivative option", 1 ); // 1 = snopt will not calculate missing derivatives
00044   snopt.setIntParameter( "Verify level ", 3 ); // full check on gradients, will throw error
00045   snopt.setIntParameter("Iterations limit", 200000);
00046   snopt.setRealParameter( "Major feasibility tolerance",  1.0e-4); // target nonlinear constraint violation
00047   snopt.setRealParameter( "Minor feasibility tolerance",  1.0e-4); // for satisfying the QP bounds
00048   snopt.setRealParameter( "Major optimality tolerance",   1.0e-2); // target complementarity gap
00049 
00050 
00051   // error codes as given in the manual.
00052   int Cold = 0; // Basis = 1, Warm = 2;
00053 
00054 
00055   // interface changed with snopt version 7.6
00056 #ifdef SNOPT76
00057   int nS = 0; // number of super-basic variables (not relevant for cold start)
00058   int nInf;   // nInf : number of constraints outside of the bounds
00059   double sInf;// sInf : sum of infeasibilities
00060 
00061   int INFO  = snopt.solve(Cold, snopt.neF, snopt.n, snopt.ObjAdd,
00062                      snopt.ObjRow, &SnoptAdapter::ObjectiveAndConstraintFct,
00063                      snopt.iAfun, snopt.jAvar, snopt.A, snopt.neA,
00064                      snopt.iGfun, snopt.jGvar, snopt.neG,
00065                      snopt.xlow, snopt.xupp, snopt.Flow, snopt.Fupp,
00066                      snopt.x, snopt.xstate, snopt.xmul,
00067                      snopt.F, snopt.Fstate, snopt.Fmul,
00068                      nS, nInf, sInf);
00069 #else
00070   int INFO = snopt.solve(Cold);
00071 #endif
00072 
00073   int EXIT = INFO - INFO%10; // change least significant digit to zero
00074 
00075   if (EXIT != 0) {
00076     std::string msg = "ERROR: Snopt failed to find a solution. EXIT:" + std::to_string(EXIT) + ", INFO:" + std::to_string(INFO) + "\n";
00077     throw std::runtime_error(msg);
00078   }
00079 
00080   snopt.SetVariables();
00081 }
00082 
00083 } /* namespace ifopt */


ifopt
Author(s): Alexander W. Winkler
autogenerated on Sat May 18 2019 02:43:08