-
Notifications
You must be signed in to change notification settings - Fork 0
/
n_D_simplex_generalized_step.m
executable file
·137 lines (106 loc) · 3.01 KB
/
n_D_simplex_generalized_step.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
clear; set(0,'defaultfigurecolor',[1 1 1]);
% 19-03-2021 N. Riel
% generalized simplex discretization in n-Dimensions with lower and upper bounds
%% Define the parameters %%
D = 4; % number of dimensions
ABS = 100; % max number of point
step = 1/ABS; % compositional step
istep(1:D) = 20;
% istep(1:D) = [8,4,8,16]; % lower bound
MAXB(1:D) = [60,60,20,60]; % upper bound
MINB(1:D) = [0,0,0,10]; % lower bound
% MINB(1:D) = [0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0];
% MAXB(1:D) = [3, 1, 1, 1, 1, 5, 1, 1, 1, 7, 1, 3];
% MAXB(1:D) = ABS; % upper bound
% MINB(1:D) = 0; % lower bound
IP(1:D) = 0; % indexes
ID(1:D) = 0; % point coordinates
LB(1:D) = 0; % active lower bound
UB(1:D) = 0; % active upper bound
v = []; % vector of compositions
w = []; % vector of coordinates
%% Run the generalized simplex algorithm
UB = update_ub(D,ABS,MAXB,UB,IP);
LB = update_lb(D,MINB,LB);
IP = get_ip(D,MINB,LB);
p = D;
while IP(1) == 0
ID(D) = ABS;
for k=1:D-1
ID(k) = IP(k+1);
ID(D) = ID(D) - IP(k+1);
end
% save the coordinates and composition vectors
if (ID(D) >= MINB(D) && ID(D) <= MAXB(D) && mod(ID(D),istep(1)) == 0)
w = [w; ID];
v = [v; step*ID];
end
IP(p) = IP(p) + istep(p);
while IP(p) > UB(p)
IP(p) = LB(p);
p = p - 1;
IP(p) = IP(p) + istep(p);
UB = update_ub(D,ABS,MAXB,UB,IP);
if IP(p) <= UB(p)
p = D;
end
end
end
% check results here %
info = check_sum(v);
disp(info)
if info == 1
disp('Calculation is successful');
end
%% Plot results
figure(1)
subplot(1,3,1)
scatter3(v(:,1),v(:,2),v(:,3),'MarkerFaceColor','b')
daspect([1 1 1])
xlabel('1')
ylabel('2')
zlabel('3')
subplot(1,3,2)
scatter3(v(:,2),v(:,3),v(:,4),'MarkerFaceColor','b')
daspect([1 1 1])
xlabel('2')
ylabel('3')
zlabel('4')
subplot(1,3,3)
scatter3(v(:,3),v(:,4),v(:,1),'MarkerFaceColor','b')
daspect([1 1 1])
xlabel('3')
ylabel('4')
zlabel('1')
%% Function list
function info = check_sum(v)
R = sum(v,2);
minSum = min(R);
maxSum = min(R);
if abs(maxSum - minSum) < 1e-8
info = 1;
else
info = 0;
end
end
function UB = update_ub(D,ABS,MAXB,UB,IP)
UB(1) = 1e10;
UB(2) = MAXB(1);
for k=3:D
UB(k) = ABS;
for l=2:(k-1)
UB(k) = UB(k) - IP(l);
end
UB(k) = min(UB(k),MAXB(k-1));
end
end
function LB = update_lb(D,MINB,LB)
for k=2:D
LB(k) = MINB(k-1);
end
end
function IP = get_ip(D,MINB,IP)
for k=2:D
IP(k) = MINB(k-1);
end
end