How Can I Customize Simulated Annealing Algorithm?
Afficher commentaires plus anciens
I have an optimization problem with discrete design variables, all of which are picked from a set {-45, 0, 45, 90}, to solve with built-in simulannealbnd function of Optimization Toolbox. In other words, optimal (x*) will be a combination of those values from the set. I read up on it from respective documentation and found out that it is by default for continuous variables. Again in the documentation there are ways to customize it so I decided to tweak with 'AnnealingFcn' option. This way I will randomly generate next iteration point as I wanted. I wrote my code as follows:
rng(7, 'twister')
ply_nums = 64;
E_11 = 127600 * 1e6;
E_22 = 13000 * 1e6;
G_12 = 6400 * 1e6;
v_12 = 0.3;
q = Q([E_11, E_22, G_12], v_12);
a = 0.508;
b = 0.254;
t = 0.127 * 1e-3;
z0 = 0;
N_xx = 1;
N_yy = 1;
N_xy = 0;
ply_qs = uniform_ply_qs(q, ply_nums);
ply_ts = uniform_ts(ply_nums, t);
ply_locations = PLY_ZS(ply_ts, z0);
lb = -90 * ones(1, ply_nums);
ub = 90 * ones(1, ply_nums);
values = [-45, 0, 45, 90];
x0 = values(randi(length(values), 1, ply_nums));
F = @(x) -lambda_critical(ply_qs, x, ply_locations, a, b, N_xx, N_yy, N_xy);
function newx = mynewx(optimValues, ~)
newx = values(randi(length(optimValues.x)), 1, length(optimValues.x));
end
options = optimoptions(@simulannealbnd, ...
'Display', ...
'iter', ...
'AnnealingFcn', @mynewx, ...
'MaxIterations', 2000);
[x, F, exitflag, output] = simulannealbnd(F, x0, lb, ub, options);
disp('x : ')
disp(x)
disp('F(x) : ')
disp(F)
However, this code throws the following error when I run it:
Incorrect number or types of inputs or outputs for function values.
Error in sa_run>mynewx (line 40)
newx = values(randi(length(optimValues.x)), 1, length(optimValues.x));
Error in globaloptim.simulannealbnd.sanewpoint (line 17)
newx(:) = options.AnnealingFcn(optimvalues,problem);
Error in globaloptim.simulannealbnd.saengine (line 29)
solverData = globaloptim.simulannealbnd.sanewpoint(solverData,problem,options);
Error in globaloptim.simulannealbnd.driver (line 28)
solverData = globaloptim.simulannealbnd.saengine(solverData,problem,options);
Error in simulannealbnd (line 197)
globaloptim.simulannealbnd.driver(FUN, x0, [], [], [], [], lb, ub, options, defaultopt);
Error in sa_run (line 50)
[x, F, exitflag, output] = simulannealbnd(F, x0, lb, ub, options);
How can I solve the error here? What do I miss here?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulated Annealing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!