examples/basic_data_structures/variables_grid/getting_started.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
34 #include <acado_integrators.hpp>
35 
36 using namespace std;
37 
39 
40 /* >>> start tutorial code >>> */
41 int main( )
42 {
43  // Setup an equidistant VariablesGrid with 5 grid points
44  // and vectors of dimension 2 at each grid point and assign values
45  double tStart = 0.0;
46  double tEnd = 2.0;
47 
48  VariablesGrid equidistantGrid(2, tStart, tEnd, 5);
49 
50  equidistantGrid.setZero();
51 
52  DVector v(2);
53  v(0) = 1.0;
54  v(1) = 2.0;
55  equidistantGrid.setVector(1, v);
56  equidistantGrid.setVector(2, v);
57 
58  v.setAll(5.0);
59  equidistantGrid.setVector(3, v);
60  equidistantGrid.setVector(4, v);
61 
62  cout << "The grid consists of the following grid points:\n"
63  << equidistantGrid
64  << "Its number of grid points is: " << equidistantGrid.getNumPoints() << endl
65  << "Each vector has dimension: " << equidistantGrid.getNumValues() << endl;
66 
67  // Construct another VariablesGrid from file
68  VariablesGrid gridFromFile;
69  gridFromFile.read( "./data.txt" );
70 
71  cout << "\nThe second grid consists of the following grid points:\n"
72  << gridFromFile;
73 
74  // Append (in time) grid points of second VariablesGrid to first one
75  equidistantGrid.appendTimes(gridFromFile);
76 
77  cout << "\nNow, the grid consists of the following grid points:\n"
78  << equidistantGrid
79  << "Its number of grid points is: " << equidistantGrid.getNumPoints() << endl
80  << "Each vector has dimension: " << equidistantGrid.getNumValues() << endl;
81 
82  // Setup a third grid with identical grid points as modified first one,
83  // and comprising Vectors of dimension 1...
84  VariablesGrid thirdGrid(1, equidistantGrid);
85 
86  // ... and initialise these vectors
87  for (unsigned int i = 0; i < thirdGrid.getNumPoints(); ++i)
88  thirdGrid(i, 0) = (double) i;
89 
90  cout << "\nThe third grid consists of the following grid points:\n" << thirdGrid;
91 
92  // Append values of all grid points of third VariablesGrid to ones of first VariablesGrid
93  equidistantGrid.appendValues(thirdGrid);
94 
95  cout << "\nNow, the grid consists of the following grid points:\n";
96  equidistantGrid.print();
97  cout << "Its number of grid points is: " << equidistantGrid.getNumPoints() << endl;
98  cout << "Each vector has dimension: " << equidistantGrid.getNumValues() << endl;
99 
100  return 0;
101 }
102 /* <<< end tutorial code <<< */
103 
104 
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue appendValues(const VariablesGrid &arg)
returnValue setVector(uint pointIdx, const DVector &_values)
returnValue appendTimes(const VariablesGrid &arg, MergeMethod _mergeMethod=MM_DUPLICATE)
#define v
returnValue read(std::istream &stream)
uint getNumPoints() const
void setAll(const T &_value)
Definition: vector.hpp:160


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:39