-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialization.m
More file actions
50 lines (43 loc) · 1.08 KB
/
initialization.m
File metadata and controls
50 lines (43 loc) · 1.08 KB
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
function [basic,non_basic,b,a,c,z,result_ok] = initialization(basic,non_basic,b,a,c,z)
result_ok = 0;
b1 = ones(size(c)(2),1);
a1 = -a';
c1 = -b';
z1 = 0;
basic1 = non_basic;
non_basic1 = basic;
[basic1,non_basic1,b1,a1,c1,z1,result_ok] = simplex_phase2(basic1,non_basic1,b1,a1,c1,z1);
%if the dual is unbounded, the primal will be infeasible
if (result_ok == 1)
return;
end
b = -c1';
a = -a1';
%recalculate z and c
tmp_c = zeros(1,size(basic1)(2));
tmp_z = 0;
size_non_basic = size(non_basic)(2);
size_non_basic1 = size(non_basic1)(2);
size_basic1 = size(basic1)(2);
for i = 1:size_non_basic
%if this variable is in basic, update entire c
for j = 1:size_non_basic1
if non_basic1(j) == non_basic(i)
tmp_c = tmp_c .+ a(j,:) * c(i);
tmp_z += b(j) * c(i);
break;
end
end
%if this variable is already in non_basic, just update the corresponding coefficient
for j = 1:size_basic1
if basic1(j) == non_basic(i)
tmp_c(j) = tmp_c(j) + c(i);
break;
end
end
end
c = tmp_c;
z = tmp_z;
basic = non_basic1;
non_basic = basic1;
end