Genetic algorithm for discrete trajectory design

4 views (last 30 days)
fe ri
fe ri on 6 Mar 2017
Edited: fe ri on 7 Mar 2017
Hi, I have to optimize an interplanetary trajectory. I thought to follow this procedure: 1- divide the trajectory in N step 2- define the control vector u = [T1,alpha1,...,TN,alphaN] 3- define the objective function J = -mf +w1Dr+w2Dv (where Dr and Dv are the errors on position and velocity respectively) 4- integrate the motion equations (considering the thrust constant for each segment)
The control vector has an upper bound and a lower bound for T and alpha.
How can I implement this problem using the "ga" of Matlab? In particular, can I pass to "ga" a population given by discrete set of values? And how can I define the bounds on the control vector?
Thank you.

Answers (1)

Alan Weiss
Alan Weiss on 6 Mar 2017
You can set bound for your control vector u in the lb and ub arguments; see the ga function reference page.
You should probably sum the absolute values or the squares of the errors, not just sum the errors, in your objective function.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 7 Mar 2017
As the function reference page states, nvars is the number of design variables, also called control variables, which are the variables that ga passes to your fitness function. In your case nvars might be 2N, because you seem to have alpha_i and T_i for i ranging from 1 to N.
Generally your fitness function accepts a row vector x of length nvars and returns the value of the fitness function. If you need to call ode45 inside your fitness function, just do so. For example, (this just solves a simple ODE starting from y(0) = x(1) then adds the squares of the solution minus a fixed function):
function fval = myobj(x)
odefun = @(t,y)(2*y-t);
tspan = 0:0.2:5;
y0 = x(1);
[t,y] = ode45(@(t,y) 2*t, tspan, y0);
fval = sum((2*y-t).^2);
Of course, you probably would do better to pass extra parameters for some arguments.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
fe ri
fe ri on 7 Mar 2017
Edited: fe ri on 7 Mar 2017
Thank you again, Alan. Since this morning (when I saw your answer) I'm trying to implement my problem defining my objfunction in this way:
function y = objmass(x)
tof = 2;
tstep = linspace(0,tof,11);
options = odeset('RelTol', 1.0e-10, 'AbsTol', 1.0e-10);
initcond = [1;0;0;1;1];
i = 1;
for n = 1:1:10
t1 = tstep(i);
t2 = tstep(i+1);
T = x(n);
alpha = x(10+n);
[twrk, ysol] = ode45(@motioneq,[t1 t2],initcond,options,T,alpha);
initcond = ysol(length(twrk), 1:5);
i = i+1;
end
w1 = 2.5;
w2 = 2;
dr = abs(ysol(length(twrk), 1)- 1.523);
dvr = abs(ysol(length(twrk), 3));
dvth = abs(0.81 - ysol(length(twrk), 4));
y = -ysol(length(twrk),5)+w1*dr^2+w2*(dvr^2+dvth^2);
But the solution doesn't match the optimal one. I think that it could depend on the initial population. Do you think so?
Thank you.

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!