1 | function Matrices = mpt_collect_equalities(Matrices,equalities) |
---|
2 | |
---|
3 | % These were just found |
---|
4 | Aeq_fixed = Matrices.G(equalities,:); |
---|
5 | Beq_fixed = -Matrices.E(equalities,:); |
---|
6 | beq_fixed = Matrices.W(equalities,:); |
---|
7 | |
---|
8 | % For numerical reasons, remove fixed variables in old constraints |
---|
9 | % (This will remove big numbers from big-M) |
---|
10 | if ~isempty(Matrices.Aeq) |
---|
11 | fixed = find(Matrices.lb(1:Matrices.nu) == Matrices.ub(1:Matrices.nu)); |
---|
12 | if ~isempty(fixed) |
---|
13 | Matrices.beq = Matrices.beq - Matrices.Aeq(:,fixed)*Matrices.lb(fixed); |
---|
14 | Matrices.Aeq(:,fixed) = 0; |
---|
15 | end |
---|
16 | |
---|
17 | skip = find(~any(full([Matrices.Aeq Matrices.beq Matrices.Beq]),2)); |
---|
18 | if ~isempty(skip) |
---|
19 | Matrices.Aeq(skip,:) = []; |
---|
20 | Matrices.Beq(skip,:) = []; |
---|
21 | Matrices.beq(skip,:) = []; |
---|
22 | end |
---|
23 | end |
---|
24 | |
---|
25 | % These variables are fixed |
---|
26 | fixed = find(Matrices.lb == Matrices.ub); |
---|
27 | if ~isempty(fixed) |
---|
28 | fixed = fixed(find(fixed <= Matrices.nu)); |
---|
29 | end |
---|
30 | |
---|
31 | Aeq = sparse(1:length(fixed),fixed,ones(length(fixed),1),length(fixed),size(Matrices.G,2)); |
---|
32 | |
---|
33 | Beq = zeros(length(fixed),size(Matrices.E,2)); |
---|
34 | beq = Matrices.lb(fixed); |
---|
35 | |
---|
36 | % Merge everything with original equalities |
---|
37 | Matrices.Aeq = [Aeq;Matrices.Aeq;Aeq_fixed]; |
---|
38 | Matrices.Beq = [Beq;Matrices.Beq;Beq_fixed]; |
---|
39 | Matrices.beq = [beq;Matrices.beq;beq_fixed]; |
---|