example1.py
Go to the documentation of this file.
1 
22 
23 ## Example adapted from examples/example1.cpp.
24 ## author of this file: Sebastian F. Walter
25 
26 import numpy as np
27 from qpoases import PyQProblem as QProblem
28 from qpoases import PyOptions as Options
29 from qpoases import PyPrintLevel as PrintLevel
30 
31 #Setup data of first QP.
32 
33 H = np.array([1.0, 0.0, 0.0, 0.5 ]).reshape((2,2))
34 A = np.array([1.0, 1.0 ]).reshape((2,1))
35 g = np.array([1.5, 1.0 ])
36 lb = np.array([0.5, -2.0])
37 ub = np.array([5.0, 2.0 ])
38 lbA = np.array([-1.0 ])
39 ubA = np.array([2.0])
40 
41 
42 # Setup data of second QP.
43 
44 g_new = np.array([1.0, 1.5])
45 lb_new = np.array([0.0, -1.0])
46 ub_new = np.array([5.0, -0.5])
47 lbA_new = np.array([-2.0])
48 ubA_new = np.array([1.0])
49 
50 
51 # Setting up QProblem object.
52 
53 example = QProblem(2, 1)
54 options = Options()
55 options.printLevel = PrintLevel.NONE
56 example.setOptions(options)
57 
58 # Solve first QP.
59 nWSR = np.array([10])
60 example.init(H, g, A, lb, ub, lbA, ubA, nWSR)
61 
62 
63 # Solve second QP.
64 nWSR = np.array([10])
65 
66 for i in range(100000):
67  for j in range(1, 100):
68  g_new[0] = i%j
69  example.hotstart( g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR)
70 
71 # Get and print solution of second QP.
72 
73 xOpt = np.zeros(2)
74 example.getPrimalSolution(xOpt)
75 print("\nxOpt = [ %e, %e ]; objVal = %e\n\n"%(xOpt[0],xOpt[1],example.getObjVal()))
76 example.printOptions()
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)
Implements the online active set strategy for QPs with general constraints.


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