Genetic Algorithm forming a Fitness Function

Hi.. i am new to Optimization Problems and specifically Genetic Algorithm.. I have read through all the given literature and have tried some simple practice functions which now seem too simple and straight forward..
My current task is to model a optimization problem with a Fitness Function which has a couple of summations within it. Is there an alternative to write the function without using long for loops? I have attached an example within.
Or where else can i look on guides to write such Fitness Functions?
This is still practice for me to get started on my work ahead.. your help will be much appreciated.

1 Comment

could u tell me the procedure of writing , say five equations of five variables but each equation has its own value(means it can't be taken as any variable) for GA toolbox... will be waiting for ur kind rplyy...thanking u

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 5 Jan 2014
Edited: Matt J on 5 Jan 2014
I'm assuming the unknowns are X(k,i,t).
Weighted summations are just matrix-vector multiplications or dot products, which MATLAB is good at, once you've built the relevant matrices. For example, the first summation term you've shown is dot(Q(:), X(:)) where
[D,I,T]=size(X);
Q=kron(P(1,1:D), tril(ones(I,T),-1));
I wonder, though, whether GA is the appropriate tool here. Since the whole objective function is linear in X, you should probably be using LINPROG, unless you have weird constraints that you haven't mentioned.

9 Comments

Hi Matt.. Thank you for your reply.. This is very different and efficient from what I've been trying recently and yes i have my data matrices set-up.
Now.. Just looking at the 1st summation.. i understand how you are modelling the answer into a dot product.. but could you provide more clarity on the 1st line and why it has been done so please..
Why are modelling a 3 dimensional matrix by factoring in the 'I' when only 'D' & 'T' are of a certain fixed value and 'I' only counts the summation loop? Then why is the 'K' count omitted?
Also, I am using GA as this example has non-linear components tagged to it. This equation along with 2 others will tackle them..
Matt J
Matt J on 6 Jan 2014
Edited: Matt J on 6 Jan 2014
You seem to be missing a summation over t in the first term. Or is t supposed to be some known fixed index?
't' and 'D' are known indexes, where t = 24 & D = 14.
If t is fixed then the first term is just
P(1,1:D)*sum( X(1:D,1:t-1,t),2)
I am still a little puzzled with the above mentioned solution. Could you kindly clarify please.
Xkit and P1k are a set of values which i'll load from a pre-defined matrix. If i represent the issue as the following equation will your solution above still apply?
Please advise and thank you very much!
Matt J
Matt J on 26 Jan 2014
Edited: Matt J on 26 Jan 2014
The only difference I can see is that you've now assigned specific values to D and t.
If you're still puzzled, it might help to point out that "k" is the only index of summation that X and P have in common. That's true in both of the summation expressions. If you rearrange so that the summation over k is the outer summation, everything simplifies greatly. In particular, after you apply the inner summations, you're left with a simple dot product expression between 2 vectors indexed by k. The inner summation over i will be applied along dimension 2 of X only (easily implemented with the SUM command) and similarly the summation over l will be applied along dimension 1 of P only.
thanks matt! was very helpful indeed... :)
Pls can you assist in writing the function code so as to use it in GA optimization Toolbox. Tnx.
Joseph
I am having similar problem. That is sum*sum from i=1 to 24. but I need assistance on how to write the function code. That is,
function y=objective_function(x) Y=........; end
Pls, can anyone assist in writing this code. So I can apply it in solving my problem which is similar to above.
Tnx. Joseph

Sign in to comment.

More Answers (0)

Asked:

Sam
on 5 Jan 2014

Community Treasure Hunt

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

Start Hunting!