ex_test_ipopt.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 <iostream>
00028 
00029 #include <ifopt/problem.h>
00030 #include <ifopt/ipopt_solver.h>
00031 #include <ifopt/test_vars_constr_cost.h>
00032 
00033 using namespace ifopt;
00034 
00035 int main()
00036 {
00037   // 1. define the problem
00038   Problem nlp;
00039   nlp.AddVariableSet  (std::make_shared<ExVariables>());
00040   nlp.AddConstraintSet(std::make_shared<ExConstraint>());
00041   nlp.AddCostSet      (std::make_shared<ExCost>());
00042   nlp.PrintCurrent();
00043 
00044   // 2. choose solver and options
00045   IpoptSolver ipopt;
00046   ipopt.SetOption("linear_solver", "mumps");
00047   ipopt.SetOption("jacobian_approximation", "exact");
00048 
00049   // 3 . solve
00050   ipopt.Solve(nlp);
00051   Eigen::VectorXd x = nlp.GetOptVariables()->GetValues();
00052   std::cout << x.transpose() << std::endl;
00053 
00054   // 4. test if solution correct
00055   double eps = 1e-5; //double precision
00056   assert(1.0-eps < x(0) && x(0) < 1.0+eps);
00057   assert(0.0-eps < x(1) && x(1) < 0.0+eps);
00058 }


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