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
|
function [Energy, Waist] = fitness( q_0, q_final, x_final, optics_positions, optics_focal_length, lambda )
%FITNESS Summary of this function goes here
% Detailed explanation goes here
x0 = 0;
q_f_trial = gbeam_propagation(x_final,q_0,x0,optics_placer(optics_positions, optics_focal_length));
[Waist, Radius] = q2wr(q_f_trial, lambda);
Energy = abs(q_final-q_f_trial);
% penalty calculation
% do not put lenses too close to each other and end positions
lens_size=0.03;
x1=optics_positions(1);
x2=optics_positions(2);
x3=optics_positions(3);
d(1)=abs(x1-x2);
d(2)=abs(x2-x3);
d(3)=abs(x1-x3);
d_from_start=abs(x0-optics_positions);
d_from_end=abs(x_final-optics_positions);
d=cat(2, d, d_from_start, d_from_end);
coef = 1;
penalty=coef*sum( exp(-(d/(lens_size)).^12) );
Energy = Energy + penalty;
% make sure that lenses are between ends
d_from_start=(x0-optics_positions);
d_from_end=(optics_positions-x_final);
d = cat(2, d_from_start, d_from_end);
coef = 1e-2;
penalty = coef * sum(1 + tanh(10*d));
Energy = Energy + penalty;
% make collimated region between 2nd and 3rd lens
%intialize intermediate points between lenses
intermediate_positions = linspace(optics_positions(2), optics_positions(3),10);
f_q_x = @(x) gbeam_propagation(x,q_0,x0,optics_placer(optics_positions, optics_focal_length));
q_intermediate = arrayfun(f_q_x,intermediate_positions);
lambda_over_waist_sq = (-imag(1./q_intermediate)); %with numerical factor
coef = 1e-2;
penalty = coef * sum(exp((std(lambda_over_waist_sq)/mean(lambda_over_waist_sq))));
Energy = Energy + penalty;
end
|