|
6 | 6 | "name": "Genetic Algorithm Assignment.ipynb", |
7 | 7 | "version": "0.3.2", |
8 | 8 | "provenance": [], |
9 | | - "collapsed_sections": [], |
| 9 | + "collapsed_sections": [ |
| 10 | + "o45jFGcl_Rq_" |
| 11 | + ], |
10 | 12 | "include_colab_link": true |
11 | 13 | }, |
12 | 14 | "kernelspec": { |
|
395 | 397 | "source": [ |
396 | 398 | "#Rank Selection Function\n", |
397 | 399 | "def rankSelection(chromosome,fitness,popSize):\n", |
398 | | - " \n", |
| 400 | + " #Total integer value from 0 to population size \n", |
399 | 401 | " rankTotal = sum(x for x in range(0,popSize))\n", |
400 | | - " #totRandom = random.uniform(0,rankTotal) #CREEPY Something is here\n", |
| 402 | + " \n", |
| 403 | + " #A random value inbetween 0 and above value\n", |
401 | 404 | " totRandom = random.uniform(0,1)*rankTotal\n", |
| 405 | + " \n", |
| 406 | + " #variable to store the accumilation of fitness values\n", |
402 | 407 | " tot=0\n", |
| 408 | + " #sorting the fitness dataframe having the lowest on the top and the highest in the bottom\n", |
403 | 409 | " fitness_sorted = fitness.sort_values(by=['fitness'])\n", |
| 410 | + " \n", |
404 | 411 | " for i in fitness_sorted.index:\n", |
| 412 | + " #accumilation of the fitness values till the accumilation is equal to the random total generated\n", |
405 | 413 | " tot += fitness_sorted.loc[i,'fitness']\n", |
406 | 414 | " if(tot>=totRandom):\n", |
407 | 415 | " global fifo_index\n", |
408 | 416 | " fifo_index = i\n", |
409 | | - " return chromosome.loc[i,:],i\n", |
410 | | - " " |
411 | | - ], |
412 | | - "execution_count": 0, |
413 | | - "outputs": [] |
414 | | - }, |
415 | | - { |
416 | | - "cell_type": "code", |
417 | | - "metadata": { |
418 | | - "id": "wzHJF4CIoRMQ", |
419 | | - "colab_type": "code", |
420 | | - "colab": {} |
421 | | - }, |
422 | | - "source": [ |
423 | | - "" |
| 417 | + " \n", |
| 418 | + " #returning the chromosome(as a parent selected) and the respective value i where the accumilation stopped. \n", |
| 419 | + " selected_parent = chromosome.loc[i,:]\n", |
| 420 | + " selected_parent_id = i\n", |
| 421 | + " \n", |
| 422 | + " return selected_parent,selected_parent_id" |
424 | 423 | ], |
425 | 424 | "execution_count": 0, |
426 | 425 | "outputs": [] |
|
0 commit comments