-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
83 lines (68 loc) · 1.89 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include <memory>
#include <exception>
#include "Matrix.h"
#include "MatrixCalc.h"
#include "SquareMatrix.h"
#include "SymmetricMatrix.h"
#include "Diagonal.h"
#include "AlgorithmADP.h"
#include "AlgorithmRLS.h"
#include "AlgorithmVI.h"
#include "AlgorithmPI.h"
#include "Dynamical.h"
#include "ControllerADP.h"
#include "Step.h"
#include "RK.h"
#include "EU.h"
int main()
{
using namespace ADP;
using VI = AlgorithmVI;
using PI = AlgorithmPI;
std::cout<< "This is the test of ADPlib v1.0"<<std::endl;
SquareMatrix sysA({-1,0.1,0,2,-1,0.1,1, 2, 1});
Matrix sysB({0,0,1},1);
SymmetricMatrix Q({1,0,0,1,0,1});
SymmetricMatrix P(Q*0+0.01);
SymmetricMatrix R(1,1.0);
Step mystep(1,10,1);
std::vector<double> x0({2,0,0});
// simulate ADP + dynamical system
unsigned int n = sysA.size()[0];
unsigned int m = sysB.size()[0];
double t = 0;
double dt = 0.0001;
Matrix K0({0,0.0,0},n);
ControllerADP<VI> myADP(Q,R,0.1, P, &mystep);
//ControllerADP<PI> myADP(Q,R,0.1, K0);
Controllers* myCtrl = &myADP;
//Dynamical myADPsys(sysA, sysB, dt);
Dynamical myADPsys(sysA, sysB, myCtrl, dt);
//disp(myADPsys.x(50,x0,&Dynamical::RK));
//disp(myADPsys.x(50,x0));
//disp(myADPsys.x(1,x0));
//disp(myADPsys.x(20,x0));
//disp(myADPsys.x(30,x0));
//disp(myADPsys.x(40,x0));
disp(myADPsys.x(50,x0));
myCtrl->dispAll();
//myCtrl = &myADP2;
//Dynamical myADPsys2(sysA, sysB, myCtrl, dt);
//disp(myADPsys2.x<RK>(50,x0));
//// when model is known
////offline VI
std::shared_ptr<AlgorithmADP> myalg(new AlgorithmVI(Q,R,P,&mystep));
std::vector<Matrix> result = myalg->offline(sysA,sysB);
result[0].disp();
result[1].disp();
result[2].disp();
////offline PI
//std::shared_ptr<AlgorithmADP> myalg2(new AlgorithmPI(Q,R,K0));
//std::vector<Matrix> result2 = myalg2->offline(sysA,sysB);
//result2[0].disp();
//result2[1].disp();
//result2[2].disp();
return 0;
}