ub = np.array([ 5.0, 2.0 ]) lbA = np.array([ -1.0 ]) ubA = np.array([ 2.0 ]) # Setup data of second QP. H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2)) A_new = np.array([ 1.0, 5.0 ]).reshape((2,1)) g_new = np.array([ 1.0, 1.5 ]) lb_new = np.array([ 0.0, -1.0 ]) ub_new = np.array([ 5.0, -0.5 ]) lbA_new = np.array([ -2.0 ]) ubA_new = np.array([ 1.0 ]) # Setting up SQProblem object and solution analyser. example = SQProblem(2, 1) analyser = SolutionAnalysis() # Solve first QP ... nWSR = 10 example.init(H, g, A, lb, ub, lbA, ubA, nWSR) # ... and analyse it. maxKKTviolation = np.zeros(1) analyser.getMaxKKTviolation(example, maxKKTviolation) print("maxKKTviolation: %e\n"%maxKKTviolation) # Solve second QP ... nWSR = 10; example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR)
ub = np.array([ 5.0, 2.0 ]) lbA = np.array([ -1.0 ]) ubA = np.array([ 2.0 ]) # Setup data of second QP. H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2)) A_new = np.array([ 1.0, 5.0 ]).reshape((2,1)) g_new = np.array([ 1.0, 1.5 ]) lb_new = np.array([ 0.0, -1.0 ]) ub_new = np.array([ 5.0, -0.5 ]) lbA_new = np.array([ -2.0 ]) ubA_new = np.array([ 1.0 ]) # Setting up SQProblem object and solution analyser. example = SQProblem(2, 1) analyser = SolutionAnalysis() # Solve first QP ... nWSR = np.array([10]) example.init(H, g, A, lb, ub, lbA, ubA, nWSR) # ... and analyse it. maxStat = np.zeros(1) maxFeas = np.zeros(1) maxCmpl = np.zeros(1) analyser.getKktViolation(example, maxStat, maxFeas, maxCmpl) print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl)) # Solve second QP ... nWSR = np.array([10])
def test_example2(self): # Example for qpOASES main function using the SQProblem class. # Setup data of first QP. H = np.array([ 1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) A = np.array([ 1.0, 1.0 ]).reshape((2,1)) g = np.array([ 1.5, 1.0 ]) lb = np.array([ 0.5, -2.0 ]) ub = np.array([ 5.0, 2.0 ]) lbA = np.array([ -1.0 ]) ubA = np.array([ 2.0 ]) # Setup data of second QP. H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2)) A_new = np.array([ 1.0, 5.0 ]).reshape((2,1)) g_new = np.array([ 1.0, 1.5 ]) lb_new = np.array([ 0.0, -1.0 ]) ub_new = np.array([ 5.0, -0.5 ]) lbA_new = np.array([ -2.0 ]) ubA_new = np.array([ 1.0 ]) # Setting up SQProblem object and solution analyser. qp = SQProblem(2, 1) options = Options() options.printLevel = PrintLevel.NONE qp.setOptions(options) analyser = SolutionAnalysis() # get c++ solution from std cmd = os.path.join(bin_path, "example2") p = Popen(cmd, shell=True, stdout=PIPE) stdout, stderr = p.communicate() stdout = str(stdout).replace('\\n', '\n') stdout = stdout.replace("'", '') print(stdout) # Solve first QP ... nWSR = 10 qp.init(H, g, A, lb, ub, lbA, ubA, nWSR) # ... and analyse it. maxKKTviolation = np.zeros(1) analyser.getMaxKKTviolation(qp, maxKKTviolation) print("maxKKTviolation: %e\n"%maxKKTviolation) actual = np.asarray(maxKKTviolation) pattern = re.compile(r'maxKKTviolation: (?P<maxKKTviolation>[0-9+-e.]*)') match = pattern.findall(stdout) expected = np.asarray(match[0], dtype=float) assert_almost_equal(actual, expected, decimal=7) # Solve second QP ... nWSR = 10 qp.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR) # ... and analyse it. analyser.getMaxKKTviolation(qp, maxKKTviolation) print("maxKKTviolation: %e\n"%maxKKTviolation) actual = np.asarray(maxKKTviolation) expected = np.asarray(match[1], dtype=float) assert_almost_equal(actual, expected, decimal=7) # ------------ VARIANCE-COVARIANCE EVALUATION -------------------- Var = np.zeros(5*5) Primal_Dual_Var = np.zeros(5*5) Var.reshape((5,5))[0,0] = 1. Var.reshape((5,5))[1,1] = 1. # ( 1 0 0 0 0 ) # ( 0 1 0 0 0 ) # Var = ( 0 0 0 0 0 ) # ( 0 0 0 0 0 ) # ( 0 0 0 0 0 ) analyser.getVarianceCovariance(qp, Var, Primal_Dual_Var) print('Primal_Dual_Var=\n', Primal_Dual_Var.reshape((5,5))) actual = Primal_Dual_Var.reshape((5,5)) pattern = re.compile(r'Primal_Dual_VAR = (?P<VAR>.*)', re.DOTALL) print(stdout) match = pattern.search(stdout) expected = match.group('VAR').strip().split("\n") expected = [x.strip().split() for x in expected] print(expected) expected = np.asarray(expected, dtype=float) assert_almost_equal(actual, expected, decimal=7)
ub = np.array([5.0, 2.0]) lbA = np.array([-1.0]) ubA = np.array([2.0]) # Setup data of second QP. H_new = np.array([1.0, 0.5, 0.5, 0.5]).reshape((2, 2)) A_new = np.array([1.0, 5.0]).reshape((2, 1)) g_new = np.array([1.0, 1.5]) lb_new = np.array([0.0, -1.0]) ub_new = np.array([5.0, -0.5]) lbA_new = np.array([-2.0]) ubA_new = np.array([1.0]) # Setting up SQProblem object and solution analyser. example = SQProblem(2, 1) analyser = SolutionAnalysis() # Solve first QP ... nWSR = 10 example.init(H, g, A, lb, ub, lbA, ubA, nWSR) # ... and analyse it. maxKKTviolation = np.zeros(1) analyser.getMaxKKTviolation(example, maxKKTviolation) print("maxKKTviolation: %e\n" % maxKKTviolation) # Solve second QP ... nWSR = 10 example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR) # ... and analyse it.