aboutsummaryrefslogtreecommitdiff
path: root/mode_match.m
blob: f3f7408c73037fd2805aba47f2cab31c0071e0a6 (plain)
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
function [ final_possible_lens_placement, initial_possible_lens_placement, possible_lens_set, possible_sample_energy] = mode_match( q0, qf, Ltot, lambda, lens_permutations, lens_width, self_flag )
%Shuffles lenses into random positions and stores possible solutions
%   Shuffles over entire lens permutation array for n_shuffles times.
%   Afterwards, solutions are sorted by Energy and truncated to n_truncate
%   decimal places. Similar solutions are then removed from the array.

n_perms = size(lens_permutations,1);
n_shuffles=20; %number of random placements of lenses

initial_MaxFunEvals = 1e8;
initial_MaxIter = 10;
final_MaxFunEvals = 1e8;
final_MaxIter = 100;

%Initialize sample arrays
N = n_perms * n_shuffles;
possible_lens_placement = zeros(N,3);
possible_lens_set = zeros(N,3);
possible_sample_energy = zeros(N,1);
initial_rand_lens_placement=zeros(N,3);

for ip = 1:n_perms
    f3=lens_permutations(ip,3);
    x3=Ltot-f3; % last lense transfer collimated region to focused spot
    for is = 1:n_shuffles
        possible_lens_set((ip-1)*n_shuffles + is,:) = lens_permutations(ip,:);

        initial_rand_lens_placement_tmp = sort(lens_width+(x3-2*lens_width)*rand(1,2));
        initial_rand_lens_placement((ip-1)*n_shuffles + is,:) = [initial_rand_lens_placement_tmp, x3];
    end
end




parfor i = 1:N
        fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda, self_flag );
        [ x_sol, energy ] = find_min(i, initial_rand_lens_placement, fitness_simplified, initial_MaxFunEvals, initial_MaxIter )
                
        initial_possible_lens_placement(i,:) =x_sol;
        
end

parfor i = 1:N
        fitness_simplified=@(x) fitness(q0, qf, Ltot, x, possible_lens_set(i,:), lambda, self_flag );
        [ x_sol, energy ] = find_min(i, initial_possible_lens_placement, fitness_simplified, final_MaxFunEvals, final_MaxIter )
                
        final_possible_lens_placement(i,:) =x_sol;
        possible_sample_energy(i) = energy;

end

end