开发者

fitness function in PHP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜