Skip to content

Commit aa131f5

Browse files
committed
Created using Colaboratory
1 parent a75c043 commit aa131f5

1 file changed

Lines changed: 103 additions & 46 deletions

File tree

Genetic_Algorithm_Assignment.ipynb

Lines changed: 103 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,6 +3525,33 @@
35253525
"execution_count": 0,
35263526
"outputs": []
35273527
},
3528+
{
3529+
"cell_type": "code",
3530+
"metadata": {
3531+
"id": "yuYxCX6CK8Yw",
3532+
"colab_type": "code",
3533+
"colab": {}
3534+
},
3535+
"source": [
3536+
"def details2(row):\n",
3537+
" duration = 0\n",
3538+
" size = 0\n",
3539+
" fitness = 0\n",
3540+
" for i in range(len(row)):\n",
3541+
" if(row[i] == 1):\n",
3542+
" size += df.loc[i,'size']\n",
3543+
" duration += df.loc[i,'duration']\n",
3544+
" \n",
3545+
" if(size<=4500):\n",
3546+
" fitness += duration\n",
3547+
" else:\n",
3548+
" fitness += duration*0.5\n",
3549+
" \n",
3550+
" return duration,size,fitness"
3551+
],
3552+
"execution_count": 0,
3553+
"outputs": []
3554+
},
35283555
{
35293556
"cell_type": "code",
35303557
"metadata": {
@@ -3552,6 +3579,19 @@
35523579
"execution_count": 0,
35533580
"outputs": []
35543581
},
3582+
{
3583+
"cell_type": "code",
3584+
"metadata": {
3585+
"id": "nRcRCeWvKawF",
3586+
"colab_type": "code",
3587+
"colab": {}
3588+
},
3589+
"source": [
3590+
""
3591+
],
3592+
"execution_count": 0,
3593+
"outputs": []
3594+
},
35553595
{
35563596
"cell_type": "code",
35573597
"metadata": {
@@ -3560,11 +3600,13 @@
35603600
"colab": {}
35613601
},
35623602
"source": [
3603+
"finalDuration = []\n",
35633604
"finalFitness = []\n",
35643605
"finalSize = []\n",
35653606
"#Get Fitness and Size information for the Last Population\n",
35663607
"for i in range(popSize):\n",
3567-
" fitness,size = getFitness(population.iloc[i,1:].values)\n",
3608+
" duration,size,fitness = details2(population.iloc[i,1:].values)\n",
3609+
" finalDuration.append(duration)\n",
35683610
" finalFitness.append(fitness)\n",
35693611
" finalSize.append(size)"
35703612
],
@@ -3576,91 +3618,106 @@
35763618
"metadata": {
35773619
"id": "yBBu8t91DGnF",
35783620
"colab_type": "code",
3621+
"colab": {}
3622+
},
3623+
"source": [
3624+
"nearst = 0\n",
3625+
"index = -1\n",
3626+
"for i in range(popSize):\n",
3627+
" if(finalFitness[i] > nearst and finalSize[i] <=4500):\n",
3628+
" nearst = final_size[i]\n",
3629+
" index = i"
3630+
],
3631+
"execution_count": 0,
3632+
"outputs": []
3633+
},
3634+
{
3635+
"cell_type": "code",
3636+
"metadata": {
3637+
"id": "McmqkVFHJaOQ",
3638+
"colab_type": "code",
35793639
"colab": {
35803640
"base_uri": "https://localhost:8080/",
35813641
"height": 34
35823642
},
3583-
"outputId": "356b1b56-ac91-4007-bc10-8981b7f96039"
3643+
"outputId": "2b721bb0-3042-4898-d4ca-65ab127cc012"
35843644
},
35853645
"source": [
3586-
"max(finalFitness)"
3646+
"finalFitness[index]"
35873647
],
3588-
"execution_count": 499,
3648+
"execution_count": 521,
35893649
"outputs": [
35903650
{
35913651
"output_type": "execute_result",
35923652
"data": {
35933653
"text/plain": [
3594-
"573"
3654+
"2795"
35953655
]
35963656
},
35973657
"metadata": {
35983658
"tags": []
35993659
},
3600-
"execution_count": 499
3660+
"execution_count": 521
36013661
}
36023662
]
36033663
},
36043664
{
36053665
"cell_type": "code",
36063666
"metadata": {
3607-
"id": "qtqbDM4eDUIV",
3667+
"id": "JHDsez3zJjc0",
36083668
"colab_type": "code",
3609-
"colab": {}
3669+
"colab": {
3670+
"base_uri": "https://localhost:8080/",
3671+
"height": 34
3672+
},
3673+
"outputId": "85a83391-b233-4711-fb36-13080406d1bf"
36103674
},
36113675
"source": [
3612-
"#Getting the Optimum solution Information to Variables\n",
3613-
"Best_Solution_id = finalFitness.index(max(finalFitness))\n",
3614-
"Best_Solution_Size = finalSize[Best_Solution_id] \n",
3615-
"Best_Solution_Duration = finalDuration[Best_Solution_id]\n",
3616-
"Best_Solution = chromosome.iloc[Best_Solution_id]\n"
3676+
"finalSize[index]"
36173677
],
3618-
"execution_count": 0,
3619-
"outputs": []
3678+
"execution_count": 522,
3679+
"outputs": [
3680+
{
3681+
"output_type": "execute_result",
3682+
"data": {
3683+
"text/plain": [
3684+
"4300"
3685+
]
3686+
},
3687+
"metadata": {
3688+
"tags": []
3689+
},
3690+
"execution_count": 522
3691+
}
3692+
]
36203693
},
36213694
{
36223695
"cell_type": "code",
36233696
"metadata": {
3624-
"id": "MBlGAsC6FGFb",
3697+
"id": "51BpFkk_KtV_",
36253698
"colab_type": "code",
36263699
"colab": {
36273700
"base_uri": "https://localhost:8080/",
3628-
"height": 289
3701+
"height": 34
36293702
},
3630-
"outputId": "d80b3e48-b3ff-4879-ae71-ece12612a4ec"
3703+
"outputId": "f3fdbc62-b780-42f8-c7fe-f66901af1c20"
36313704
},
36323705
"source": [
3633-
"#Printing the Optimum Solution Information\n",
3634-
"print(\"Optimum Solution ID : \" + str(Best_Solution_id))\n",
3635-
"print(\"Optimum Fitness : \" + str(finalFitness[Best_Solution_id]))\n",
3636-
"print(\"Optimum Solution File Size : \" + str(Best_Solution_Size) + \"MB\")\n",
3637-
"print(\"Optimum Solution Duration : \" + str(Best_Solution_Duration) + \" Minutes\")\n",
3638-
"print(\"Optimum Solution : \")\n",
3639-
"print(str(Best_Solution[1:]))"
3706+
"finalDuration[index]"
36403707
],
3641-
"execution_count": 501,
3708+
"execution_count": 523,
36423709
"outputs": [
36433710
{
3644-
"output_type": "stream",
3645-
"text": [
3646-
"Optimum Solution ID : 4\n",
3647-
"Optimum Fitness : 573\n",
3648-
"Optimum Solution File Size : 4225MB\n",
3649-
"Optimum Solution Duration : 444 Minutes\n",
3650-
"Optimum Solution : \n",
3651-
"file 1 1\n",
3652-
"file 2 0\n",
3653-
"file 3 1\n",
3654-
"file 4 1\n",
3655-
"file 5 0\n",
3656-
"file 6 0\n",
3657-
"file 7 0\n",
3658-
"file 8 0\n",
3659-
"file 9 0\n",
3660-
"file 10 1\n",
3661-
"Name: 4, dtype: int64\n"
3662-
],
3663-
"name": "stdout"
3711+
"output_type": "execute_result",
3712+
"data": {
3713+
"text/plain": [
3714+
"575"
3715+
]
3716+
},
3717+
"metadata": {
3718+
"tags": []
3719+
},
3720+
"execution_count": 523
36643721
}
36653722
]
36663723
},

0 commit comments

Comments
 (0)