Algorithm na Neman Juyin Halitta hanya ce mai ƙarfi a cikin shirye-shiryen PHP, wanda aka yi wahayi ta hanyar tsarin halitta na juyin halitta. Hanya ce ta ingantawa dangane da hanyoyin haifuwa da zaɓin yanayi don nemo mafi kyawun mafita a cikin sararin bincike.
Yadda Algorithm na Neman Juyin Halitta ke Aiki
Algorithm na Neman Juyin Halitta yana farawa ta hanyar samar da saitin “mutane” na farko, wanda ke wakiltar yuwuwar mafita. Sannan yana amfani da masu aiki kamar crossover da maye gurbi don ƙirƙirar sabbin tsararrun mutane. Ana kimanta dacewa da daidaitattun mutane a cikin kowane tsara ta amfani da aikin tantancewa don sanin ingancin maganin.
Fa'idodi da rashin Amfanin Algorithm na Neman Juyin Halitta
Amfani:
- Hanyar Haɓaka Halitta: Wannan algorithm yana jawo wahayi daga juyin halitta don neman mafi kyawun mafita.
- Haɗin Bincike da Haɓakawa: Algorithm na Neman Juyin Halitta yana haɗa ikon bincika sabbin mafita da haɓaka waɗanda ke akwai.
Rashin hasara:
- Ana Bukatar La'akarin Siga: Don ingantaccen aiki, algorithm yana buƙatar daidaitawa a hankali da zaɓin sigogi kamar giciye da ƙimar maye gurbi.
Misali da Bayani
Yi la'akari da misali na amfani da Algorithm na Neman Juyin Halitta don nemo matsakaicin jimlar jimlar juzu'i a cikin tsararrun lamba ta amfani da PHP.
function evolutionarySearch($array, $numGenerations) {
$populationSize = count($array);
$population = $array;
for($generation = 0; $generation < $numGenerations; $generation++) {
$population = evolvePopulation($population);
}
return max($population);
}
function evolvePopulation($population) {
// Crossover and mutation operations here
// Return a new population
}
$array = array(1, -2, 3, 4, -5, 6);
$numGenerations = 50;
$maxSum = evolutionarySearch($array, $numGenerations);
echo "Maximum contiguous sum found: $maxSum";
A cikin wannan misalin, muna amfani da Algorithm na Neman Juyin Halitta don nemo matsakaicin jimlar jimlar juzu'i a cikin tsararrun lamba. Kowane mutum a farkon yawan jama'a yana wakiltar yanki na tsararru. Ta hanyar tsararraki na juyin halitta, muna amfani da ayyuka kamar crossover da maye gurbi don ƙirƙirar sabbin tsararraki na yawan jama'a. Sakamakon shine matsakaicin jimlar jimlar da aka samu ta hanyar ingantawa.
Duk da yake wannan misalin yana nuna yadda za'a iya amfani da Algorithm na Neman Juyin Halitta don inganta yanki a cikin tsararru, ana iya amfani da shi ga wasu matsalolin ingantawa a cikin PHP.