Skip to content

Commit 5ffcb55

Browse files
committed
Created using Colaboratory
1 parent 20b4b06 commit 5ffcb55

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

Genetic_Algorithm_Assignment.ipynb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"name": "Genetic Algorithm Assignment.ipynb",
77
"version": "0.3.2",
88
"provenance": [],
9-
"collapsed_sections": [],
9+
"collapsed_sections": [
10+
"o45jFGcl_Rq_"
11+
],
1012
"include_colab_link": true
1113
},
1214
"kernelspec": {
@@ -395,32 +397,29 @@
395397
"source": [
396398
"#Rank Selection Function\n",
397399
"def rankSelection(chromosome,fitness,popSize):\n",
398-
" \n",
400+
" #Total integer value from 0 to population size \n",
399401
" 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",
401404
" totRandom = random.uniform(0,1)*rankTotal\n",
405+
" \n",
406+
" #variable to store the accumilation of fitness values\n",
402407
" tot=0\n",
408+
" #sorting the fitness dataframe having the lowest on the top and the highest in the bottom\n",
403409
" fitness_sorted = fitness.sort_values(by=['fitness'])\n",
410+
" \n",
404411
" for i in fitness_sorted.index:\n",
412+
" #accumilation of the fitness values till the accumilation is equal to the random total generated\n",
405413
" tot += fitness_sorted.loc[i,'fitness']\n",
406414
" if(tot>=totRandom):\n",
407415
" global fifo_index\n",
408416
" 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"
424423
],
425424
"execution_count": 0,
426425
"outputs": []

0 commit comments

Comments
 (0)