-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_mosek_A_fw.m
80 lines (60 loc) · 1.57 KB
/
get_mosek_A_fw.m
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
function [ A, blc, buc ] = get_mosek_A( linear_constraint, alpha,alpha_2, n, P)
caca = 0;
nXi = sum(cat(1, linear_constraint.slack));
nC = length(linear_constraint);
A_subi = [];
A_subj = [];
A_subv = [];
% adding the row sum to one constraint
for i = 1:n
A_subi = cat(1, A_subi, i*ones(P,1));
A_subj = cat(1, A_subj, n*(0:(P-1))'+i);
A_subv = cat(1, A_subv, ones(P,1));
end
blc = ones(n, 1);
buc = ones(n, 1);
ti = cell(nXi, 1);
tj = cell(nXi, 1);
tv = cell(nXi, 1);
tl = cell(nXi, 1);
tu = cell(nXi, 1);
% adding the linear constraints
for i = 1:nC
sample = linear_constraint(i).sample;
class = linear_constraint(i).class;
slack = linear_constraint(i).slack;
idx = find(kron(class, sample));
weights = linear_constraint(i).weights;
ti{i} = (n+i) * ones(length(idx),1);
tj{i} = idx;
%tv{i} = ones(length(idx), 1);
tv{i} = weights;
if slack~=0
ti{i} = [ti{i}; n+i];
tj{i} = [tj{i}; (n*P)+i];
tv{i} = [tv{i}; slack];
end
value = linear_constraint(i).val;
if strcmp(linear_constraint(i).type, 'geq')
tl{i} = value;
tu{i} = inf;
elseif strcmp(linear_constraint(i).type, 'leq')
tl{i} = -inf;
tu{i} = value;
else
tl{i} = value;
tu{i} = value;
end
end
ti = cell2mat(ti);
tj = cell2mat(tj);
tv = cell2mat(tv);
tl = cell2mat(tl);
tu = cell2mat(tu);
A_subi = cat(1, A_subi, ti);
A_subj = cat(1, A_subj, tj);
A_subv = cat(1, A_subv, tv);
blc = cat(1, blc, tl);
buc = cat(1, buc, tu);
A = sparse(A_subi, A_subj, A_subv, n+nC, n*P + nXi);
end