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
84
85
86
87
88
89
90
91
92
93
|
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
// <-- CLI SHELL MODE -->
//Find x in R^6 such that:
//C1*x = b1 (3 equality constraints i.e me=3)
C1= [1,-1,1,0,3,1;
-1,0,-3,-4,5,6;
2,5,3,0,1,0];
b1=[1;2;3];
//C2*x <= b2 (2 inequality constraints)
C2=[0,1,0,1,2,-1;
-1,0,2,1,1,0];
b2=[-1;2.5];
//and minimize 0.5*x'*Q*x + p'*x with
p=[1;2;3;4;5;6]; Q=eye(6,6);
//No initial point is given;
C=[C1;C2] ; //
b=[b1;b2] ; //
me=3;
[x1, iact, iter, f]=qpsolve(Q,p,C,b,[],[],me);
if or(iact<>[1;3;2;4;0]) then bugmes();quit;end
if x1'*p+x1'*Q*x1/2>- 14.843 then bugmes();quit;end
if or(abs(C(1:4,:)*x1-b(1:4))>100*%eps) then bugmes();quit;end
if C(5,:)*x1>b(5) then bugmes();quit;end
//sparse
[x1, iact, iter, f]=qpsolve(Q,p,sparse(C),b,[],[],me);
if or(iact<>[1;3;2;4;0]) then bugmes();quit;end
if x1'*p+x1'*Q*x1/2>- 14.843 then bugmes();quit;end
if or(abs(C(1:4,:)*x1-b(1:4))>100*%eps) then bugmes();quit;end
if C(5,:)*x1>b(5) then bugmes();quit;end
//second test
Q = [0.5 -1; -1 3]; //positive-defined
p = [0; 0];
C = [1 1];
b = 1;
me = 1;
x1=qpsolve(Q,p,C,b,[],[],me);
if or(x1-[8;3]/11 >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2-1/22)>100*%eps then bugmes();quit;end
if abs(C*x1-b)>100*%eps then bugmes();quit;end
//sparse
x1=qpsolve(Q,p,sparse(C),b,[],[],me);
if or(x1-[8;3]/11 >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2-1/22)>100*%eps then bugmes();quit;end
if abs(C*x1-b)>100*%eps then bugmes();quit;end
//third test (R)
Q=eye(3,3);p=-[0;5;0];
C=-[-4 2 0;-3 1 -2;0 0 1];b=-[-8;2;0];me=0;
x1=qpsolve(Q,p,C,b,[],[],me);
if or(x1-[0;5;0] >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+12.5)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[-18;-3;0])>100*%eps) then bugmes();quit;end
//sparse
x1=qpsolve(Q,p,sparse(C),b,[],[],me);
if or(x1-[0;5;0] >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+12.5)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[-18;-3;0])>100*%eps) then bugmes();quit;end
//fourth test (Matlab)
Q= [1 -1; -1 2] ;
p = [-2; -6];
C = [1 1; -1 2; 2 1];
b = [2; 2; 3];
lb = zeros(2,1);
me=0;
x1=qpsolve(Q,p,C,b,[],[],me);
if or(x1-[2;4]/3 >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+74/9)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[0;0;-1/3])>100*%eps) then bugmes();quit;end
//sparse
x1=qpsolve(Q,p,sparse(C),b,[],[],me);
if or(x1-[2;4]/3 >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+74/9)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[0;0;-1/3])>100*%eps) then bugmes();quit;end
//avec bornes
Q= [1 -1; -1 2] ;
p = [-2; -6];
C = [1 1; -1 2; 2 1];
b = [2; 2; 3];
lb = [0.8;0]; //zeros(2,1);
me=0;
x1=qpsolve(Q,p,C,b,lb,[],me);
if or(x1-[0.8;1.2] >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+8)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[0;-0.4;-0.2])>100*%eps) then bugmes();quit;end
//sparse
x1=qpsolve(Q,p,sparse(C),b,lb,[],me);
if or(x1-[0.8;1.2] >100*%eps) then bugmes();quit;end
if abs(x1'*p+x1'*Q*x1/2+8)>100*%eps then bugmes();quit;end
if or(abs(C*x1-b-[0;-0.4;-0.2])>100*%eps) then bugmes();quit;end
|