summaryrefslogtreecommitdiff
path: root/fitness.m
diff options
context:
space:
mode:
Diffstat (limited to 'fitness.m')
-rw-r--r--fitness.m21
1 files changed, 15 insertions, 6 deletions
diff --git a/fitness.m b/fitness.m
index 54060a7..00cbada 100644
--- a/fitness.m
+++ b/fitness.m
@@ -2,10 +2,19 @@ function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_posit
%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);
+ Np=20;
+ x=linspace(x0,x_final,Np);
+ q_f_trial_forward = gbeam_propagation(x,q_0,x0,optics_placer(optics_positions, optics_focal_length));
+ [Waist_trial_forward, Radius_trial_forward] = q2wr(q_f_trial_forward, lambda);
+ q_f_trial_backward = gbeam_propagation(x,q_final,x_final,optics_placer(optics_positions, optics_focal_length));
+ [Waist_trial_backward, Radius_trial_backward] = q2wr(q_f_trial_backward, lambda);
+
+ Energy = 0;
+ Penalty_waist_mismatch = sum(abs((Waist_trial_forward-Waist_trial_backward)./min(Waist_trial_forward, Waist_trial_backward)))/Np;
+ Penalty_waist_mismatch = 0*Penalty_waist_mismatch + 1e9*sum(abs((Waist_trial_forward-Waist_trial_backward)))/Np;
+ Penalty_radius_mismatch = sum(abs((Radius_trial_forward-Radius_trial_backward)./max(Radius_trial_forward, Radius_trial_backward)))/Np;
+
+ Energy = 0*Penalty_radius_mismatch + Penalty_waist_mismatch;
% penalty calculation
% do not put lenses too close to each other and end positions
@@ -39,8 +48,8 @@ function [Energy, Waist, Penalty] = fitness( q_0, q_final, x_final, optics_posit
d = cat(2, d_from_start, d_from_end);
coef = 1e-2;
-
- penalty_lenses_outside_optical_path = coef * sum(1 + tanh(10*d));
+ distance_scaling=100;
+ penalty_lenses_outside_optical_path = coef * sum(1 + tanh(distance_scaling*d));
Energy = Energy + penalty_lenses_outside_optical_path;