开发者

fitness function in PHP

开发者 https://www.devze.com 2023-02-23 07:19 出处:网络
I looked a whole day after an example to implement the \'fitness function\' in a Genetic开发者_JS百科 algorithm. (I implemented already a \'begin population\', \'mutation\' and permutation). The follo

I looked a whole day after an example to implement the 'fitness function' in a Genetic开发者_JS百科 algorithm. (I implemented already a 'begin population', 'mutation' and permutation). The following step is the 'fitness function'. Does anyone have an example of calculating the 'fitness' in PHP? Java or C# is OK as well.


The fitness function will simply rank one member of your population. The item with the highest fitness function "wins" and then has intercourse with a new member of the population in the next round.

It is up to you how to define the fitness of a member. It is up to this function to determine what will win in Brains vs. Brawn, so to speak.


Create a java, C or C# software wich implement your personal fitness function. Later, you can use the exec() function to execute the software and collect the output. For example:

<?php
    $output = array();
    exec("/path/to/fitness_function_executable", $output);
    print_r($output);
?>


The fitness function is completely dependent on your application. It could be anything from how far a creature travels, to how many units you can build in Starcraft 2 at a certain time in the game, to measuring how closely an image resembles another.

Make sure it has enough granularity between good and bad though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号