Need help with writing the objective function for a genetic algorithm

3 views (last 30 days)
I usually use AMPL to write mixed integer programs, but now I need to implement a Genetic Algorithm so I'm trying to write my objective function on Matlab. I cannot handle the summation over specific ranges like I used to do in AMPL. It'll be great if someone can help me figuring out how to write the attached objective function in Matlab. Thanks.
  2 Comments
Ameera
Ameera on 24 Jul 2014
Edited: Ameera on 24 Jul 2014
I have written the fitness function copied below, it is a simplified function of what I'm trying to do. My issue now is with the GA optimization tool:
1-My only variable is "x" (2x3 matrix in the given example below), what should be the number of variables in this case? Is it 1 or 6?
2-How to specify that x is binary?
3-I have the following constraint in my problem: sum(t in 1..T) x(i,t) <=1, for every i. How can I enter that constraint in the linear inequalities boxes.
Here is my fitness function:
function [x,fval] = APP(alpha,k,r,v,vz,x0)
[x,fval] = fminunc(@APPnest,x0);
function obj = APPnest(x)
obj = 0;
for t = 1:3
for i = 1:2
z = 0;
for u = 1:t
z = z + k(i,t-u+1) * x(i,u);
end
nem = v(i)*z;
w = 0;
for j = 1:2
for u = 1:t
w = w + v(j) * k(j,t-u+1) * x(j,u);
end
den = vz + w;
end
obj = obj + alpha(t)*r(i)*(nem/den);
end
end
obj = -obj;
end
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!