example2.py
Go to the documentation of this file.
1 
22 
23 ## Example adapted from examples/example2.cpp.
24 ## author of this file: Sebastian F. Walter
25 
26 import numpy as np
27 from qpoases import PySQProblem as SQProblem
28 from qpoases import PySolutionAnalysis as SolutionAnalysis
29 
30 
31 # Setup data of first QP.
32 H = np.array([ 1.0, 0.0, 0.0, 0.5 ]).reshape((2,2))
33 A = np.array([ 1.0, 1.0 ]).reshape((2,1))
34 g = np.array([ 1.5, 1.0 ])
35 lb = np.array([ 0.5, -2.0 ])
36 ub = np.array([ 5.0, 2.0 ])
37 lbA = np.array([ -1.0 ])
38 ubA = np.array([ 2.0 ])
39 
40 # Setup data of second QP.
41 H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2))
42 A_new = np.array([ 1.0, 5.0 ]).reshape((2,1))
43 g_new = np.array([ 1.0, 1.5 ])
44 lb_new = np.array([ 0.0, -1.0 ])
45 ub_new = np.array([ 5.0, -0.5 ])
46 lbA_new = np.array([ -2.0 ])
47 ubA_new = np.array([ 1.0 ])
48 
49 # Setting up SQProblem object and solution analyser.
50 example = SQProblem(2, 1)
51 analyser = SolutionAnalysis()
52 
53 # Solve first QP ...
54 nWSR = np.array([10])
55 example.init(H, g, A, lb, ub, lbA, ubA, nWSR)
56 
57 # ... and analyse it.
58 maxStat = np.zeros(1)
59 maxFeas = np.zeros(1)
60 maxCmpl = np.zeros(1)
61 
62 analyser.getKktViolation(example, maxStat, maxFeas, maxCmpl)
63 print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl))
64 
65 # Solve second QP ...
66 nWSR = np.array([10])
67 example.hotstart(H_new, g_new, A_new, lb_new, ub_new,
68  lbA_new, ubA_new, nWSR)
69 
70 # ... and analyse it.
71 analyser.getKktViolation(example, maxStat, maxFeas, maxCmpl)
72 print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl))
73 
74 
75 # ------------ VARIANCE-COVARIANCE EVALUATION --------------------
76 
77 Var = np.zeros(5*5)
78 Primal_Dual_Var = np.zeros(5*5)
79 
80 Var.reshape((5,5))[0,0] = 1.
81 Var.reshape((5,5))[1,1] = 1.
82 
83 # ( 1 0 0 0 0 )
84 # ( 0 1 0 0 0 )
85 # Var = ( 0 0 0 0 0 )
86 # ( 0 0 0 0 0 )
87 # ( 0 0 0 0 0 )
88 
89 
90 analyser.getVarianceCovariance(example, Var, Primal_Dual_Var)
91 print('Primal_Dual_Var=\n', Primal_Dual_Var.reshape((5,5)))
92 print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl))
Implements the online active set strategy for QPs with varying matrices.
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)


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