Skip to content

Commit 359f1d9

Browse files
committed
Version with working ga
Still broken but I found the elegant way of handling the variable. So the path is here
1 parent bdbd2f1 commit 359f1d9

File tree

9 files changed

+150
-369
lines changed

9 files changed

+150
-369
lines changed

get_data.m

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function param = get_data(solver_name)
22

33
%% options
4-
n_split = 1000;
4+
n_split = 500;
55

66
switch solver_name
77
case 'bruteforce'
@@ -29,7 +29,8 @@
2929
'n_split', n_split,...
3030
'fct_solve', @get_solve,...
3131
'fct_obj', @get_obj_scalar,...
32-
'fct_con', @get_con,...
32+
'fct_con_cnq', @get_con_cnq,...
33+
'fct_con_ceq', @get_con_ceq,...
3334
'options', options...
3435
);
3536
case 'gamultiobj'
@@ -59,41 +60,67 @@
5960

6061
end
6162

62-
function [cnq, ceq] = get_con(sol, n_sweep)
63+
function cnq = get_con_cnq(input, n_sol)
64+
65+
assert(n_sol>=1, 'invalid data')
66+
67+
% assign
68+
x_1 = input.x_1;
69+
x_2 = input.x_2;
70+
x_3 = input.x_3;
71+
x_4 = input.x_4;
72+
73+
% compute
74+
y_1 = x_1.^2+x_2.^2+x_3;
75+
y_2 = 0.5*((x_1-2).^2+(x_2+1).^2)+2+x_4;
76+
77+
% assign
78+
cnq = [y_1-10 ; y_2-10];
79+
80+
end
81+
82+
function ceq = get_con_ceq(input, n_sol)
6383

64-
cnq = [sol.y_1-10 ; sol.y_2-10];
6584
ceq = [];
6685

6786
end
6887

69-
function val = get_obj_scalar(sol, n_sol)
7088

71-
keyboard
89+
function val = get_obj_scalar(input, n_sol)
7290

73-
val = sol.y_1+sol.y_2;
91+
assert(n_sol>=1, 'invalid data')
7492

75-
end
93+
% assign
94+
x_1 = input.x_1;
95+
x_2 = input.x_2;
96+
x_3 = input.x_3;
97+
x_4 = input.x_4;
7698

77-
function val = get_obj_vector(sol, n_sol)
99+
% compute
100+
y_1 = x_1.^2+x_2.^2+x_3;
101+
y_2 = 0.5*((x_1-2).^2+(x_2+1).^2)+2+x_4;
78102

79-
val = [sol.y_1 ; sol.y_2];
103+
% assign
104+
val = y_1+y_2;
80105

81106
end
82107

83-
function var_param = get_var_param(integer)
108+
function val = get_obj_vector(input, n_sol)
84109

85-
var = {};
86-
var{end+1} = struct('type', 'float', 'name', 'x_1', 'scale', 'lin', 'v', 1.5, 'vec', linspace(0, 3, 25), 'lb', 0.0, 'ub', 3.0);
87-
var{end+1} = struct('type', 'float', 'name', 'x_2', 'scale', 'log', 'v', 2.0, 'vec', logspace(log10(1), log10(3), 25), 'lb', 1.0, 'ub', 3.0);
88-
if integer==true
89-
var{end+1} = struct('type', 'integer', 'name', 'x_3', 'v', 7 ,'vec', [5 7 9], 'set', [5 7 9]);
90-
var{end+1} = struct('type', 'scalar', 'name', 'x_4', 'v', 2);
91-
else
92-
var{end+1} = struct('type', 'scalar', 'name', 'x_3', 'v', 5);
93-
var{end+1} = struct('type', 'scalar', 'name', 'x_4', 'v', 2);
94-
end
110+
assert(n_sol>=1, 'invalid data')
95111

96-
var_param = struct('var', {var}, 'n_max', 100e3, 'fct_select', @(input, n_sol) true(1, n_sol));
112+
% assign
113+
x_1 = input.x_1;
114+
x_2 = input.x_2;
115+
x_3 = input.x_3;
116+
x_4 = input.x_4;
117+
118+
% compute
119+
y_1 = x_1.^2+x_2.^2+x_3;
120+
y_2 = 0.5*((x_1-2).^2+(x_2+1).^2)+2+x_4;
121+
122+
% assign
123+
val = [y_1 ; y_2];
97124

98125
end
99126

@@ -120,3 +147,21 @@
120147
sol.x_4 = x_4;
121148

122149
end
150+
151+
function var_param = get_var_param(integer)
152+
153+
var = {};
154+
var{end+1} = struct('type', 'float', 'name', 'x_1', 'scale', 'lin', 'v', 1.5, 'vec', linspace(0, 3, 25), 'lb', 0.0, 'ub', 3.0);
155+
var{end+1} = struct('type', 'float', 'name', 'x_2', 'scale', 'log', 'v', 2.0, 'vec', logspace(log10(1), log10(3), 25), 'lb', 1.0, 'ub', 3.0);
156+
if integer==true
157+
var{end+1} = struct('type', 'integer', 'name', 'x_3', 'v', 7 ,'vec', [5 7 9], 'set', [5 7 9]);
158+
var{end+1} = struct('type', 'scalar', 'name', 'x_4', 'v', 2);
159+
else
160+
var{end+1} = struct('type', 'scalar', 'name', 'x_3', 'v', 5);
161+
var{end+1} = struct('type', 'scalar', 'name', 'x_4', 'v', 2);
162+
end
163+
164+
var_param = struct('var', {var}, 'n_max', 100e3, 'fct_select', @(input, n_sol) true(1, n_sol));
165+
166+
end
167+

src/optim/get_pre_proc.asv

Lines changed: 0 additions & 214 deletions
This file was deleted.

0 commit comments

Comments
 (0)