Jump to content

Alguém pode me ajuda a executar essa função (matlab)

Recommended Posts


function [filho_cross]= crossover(pai_1, pai_2, prob_cross)
 pontos_crossover = floor(prob_cross*9);

 X = [1*ones(1,pontos_crossover) 2*ones(1,9 - pontos_crossover)];
 x = x(randperm(9));

 indices_1 = X-ones(1,9);
 indices_2 = abs(x-2*ones(1,9));

genes_pai_1 =Pai_1.*indices_1;
genes_pai_2 =Pai_2.*indices_2;
filhos_cross_1 = genes_pai_1 +genes_pai_2;
genes_pai_1 =Pai_1.*indices_2;
genes_pai_2 =Pai_2.*indices_1;
filhos_cross_1 = genes_pai_1 +genes_pai_2;

Edited by Rui Carlos

Share this post

Link to post
Share on other sites
Rui Carlos

pai_1 e pai_2 parecem ser arrays, em princípio de 9 posições. prob_cross deve ser um valor numérico (uma probabilidade, por isso deverá ser um valor entre 0 e 1).

A chamada pode ser algo como crossover([1,2,3,4,5,6,7,8,9], [9,8,7,6,5,4,3,2,1], 0.5).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.