-
Notifications
You must be signed in to change notification settings - Fork 357
/
blocksqp_test.cpp
66 lines (57 loc) · 2.53 KB
/
blocksqp_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* This file is part of CasADi.
*
* CasADi -- A symbolic framework for dynamic optimization.
* Copyright (C) 2010-2014 Joel Andersson, Joris Gillis, Moritz Diehl,
* K.U. Leuven. All rights reserved.
* Copyright (C) 2011-2014 Greg Horn
*
* CasADi is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* CasADi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with CasADi; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/** \brief Writing a multiple shooting code from scratch
This example demonstrates how to write a simple, yet powerful multiple shooting code from
scratch using CasADi. For clarity, the code below uses a simple formulation with only states
and controls, and no path constrants. It relies on CasADi machinery to keep track of sparsity,
formulate ODE sensitivity equations and build up the Jacobian of the NLP constraint function.
By extending the code below, it should be possible for a user to solve ever more complex
problems. For example, one can easily make a multi-stage formulation by simply allocating
another integrator instance and use the two integrators instances for different shooting nodes.
By replacing the explicit CVodes integrator with the fully-implicit IDAS integrator, one can
solve optimal control problems in differential-algebraic equations.
\author Joel Andersson
\date 2011-2012
*/
// CasADi core
#include <casadi/casadi.hpp>
using namespace casadi;
using namespace std;
int main(){
auto x=SX::sym("x");
auto y=SX::sym("y");
SXDict nlp = {{"x", SX::vertcat({x,y})},
{"f", sq(1-x)+100*sq(y-sq(x))},
{"g", x+y}};
Dict solver_options;
auto solver = nlpsol("mysolver", "blocksqp", nlp, solver_options);
DMDict solver_in;
solver_in["x0"]=vector<double>{0,1};
solver_in["lbx"]=vector<double>{-10,1.2};
solver_in["ubx"]=vector<double>{10,2};
solver_in["lbg"]=-10;
solver_in["ubg"]=10;
auto solver_out = solver(solver_in);
return 0;
}