Commit 0f250376 by Yolanda

first commit

parent 5bffc7ae
......@@ -46,15 +46,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
]
}
],
"outputs": [],
"source": [
"# Library \n",
"import pandas as pd\n",
......@@ -67,15 +59,7 @@
"import time\n",
"import sys\n",
"import datetime\n",
"import timeit\n",
"from sklearn.neighbors import DistanceMetric\n",
"from math import radians,cos,sin\n",
"from haversine import haversine, Unit\n",
"from scipy.spatial import distance\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from keras.models import Sequential\n",
"from keras.layers import Bidirectional, GlobalMaxPool1D\n",
"from keras.layers import LSTM"
"import timeit"
]
},
{
......@@ -94,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"outputs": [
{
......@@ -118,1132 +102,236 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Pantai BUL BUL</th>\n",
" <th>BUKIT travel Gibeon</th>\n",
" <th>Pakkodian</th>\n",
" <th>Taman Eden 100 Tobasa</th>\n",
" <th>Water Park Tambunan</th>\n",
" <th>Bukit Pahoda</th>\n",
" <th>Bukit Senyum</th>\n",
" <th>Air Terjun Pandumaan</th>\n",
" <th>Long Beach</th>\n",
" <th>PANTAI AGADON</th>\n",
" <th>...</th>\n",
" <th>Dolok Surungan</th>\n",
" <th>Air Terjun Sampuran</th>\n",
" <th>Air Terjun Morena</th>\n",
" <th>Tornagodang</th>\n",
" <th>Hatulian Beach</th>\n",
" <th>Monumen Raja Sonakmalela</th>\n",
" <th>Lumban Binanga Beach</th>\n",
" <th>Pantai Pasifik Porsea</th>\n",
" <th>Desa Adat Ragi Hotang</th>\n",
" <th>Makam Raja Sisingamangaraja XII</th>\n",
" <th>ID_City</th>\n",
" <th>City</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>50.9</td>\n",
" <td>12.8</td>\n",
" <td>44.7</td>\n",
" <td>5.9</td>\n",
" <td>71.0</td>\n",
" <td>60.6</td>\n",
" <td>12.4</td>\n",
" <td>63.5</td>\n",
" <td>50.5</td>\n",
" <td>...</td>\n",
" <td>74.2</td>\n",
" <td>37.1</td>\n",
" <td>64.5</td>\n",
" <td>36.1</td>\n",
" <td>11.6</td>\n",
" <td>3.30</td>\n",
" <td>10.7</td>\n",
" <td>22.5</td>\n",
" <td>14.4</td>\n",
" <td>5.70</td>\n",
" <td>0</td>\n",
" <td>Pantai BUL BUL</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>50.9</td>\n",
" <td>0.0</td>\n",
" <td>59.2</td>\n",
" <td>6.2</td>\n",
" <td>47.3</td>\n",
" <td>53.5</td>\n",
" <td>12.0</td>\n",
" <td>51.4</td>\n",
" <td>17.6</td>\n",
" <td>18.6</td>\n",
" <td>...</td>\n",
" <td>102.0</td>\n",
" <td>83.5</td>\n",
" <td>71.7</td>\n",
" <td>63.9</td>\n",
" <td>46.1</td>\n",
" <td>49.70</td>\n",
" <td>45.2</td>\n",
" <td>32.9</td>\n",
" <td>60.8</td>\n",
" <td>52.10</td>\n",
" <td>1</td>\n",
" <td>BUKIT travel Gibeon</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>12.8</td>\n",
" <td>59.2</td>\n",
" <td>0.0</td>\n",
" <td>53.0</td>\n",
" <td>14.2</td>\n",
" <td>11.9</td>\n",
" <td>68.9</td>\n",
" <td>20.7</td>\n",
" <td>71.8</td>\n",
" <td>58.8</td>\n",
" <td>...</td>\n",
" <td>82.5</td>\n",
" <td>30.4</td>\n",
" <td>72.8</td>\n",
" <td>44.4</td>\n",
" <td>19.9</td>\n",
" <td>9.50</td>\n",
" <td>18.9</td>\n",
" <td>31.8</td>\n",
" <td>4.5</td>\n",
" <td>7.70</td>\n",
" <td>2</td>\n",
" <td>Pakkodian</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>44.7</td>\n",
" <td>6.2</td>\n",
" <td>53.0</td>\n",
" <td>0.0</td>\n",
" <td>41.1</td>\n",
" <td>47.2</td>\n",
" <td>15.9</td>\n",
" <td>45.5</td>\n",
" <td>18.8</td>\n",
" <td>12.3</td>\n",
" <td>...</td>\n",
" <td>95.8</td>\n",
" <td>77.2</td>\n",
" <td>65.5</td>\n",
" <td>57.7</td>\n",
" <td>39.9</td>\n",
" <td>43.50</td>\n",
" <td>39.0</td>\n",
" <td>26.7</td>\n",
" <td>54.5</td>\n",
" <td>45.90</td>\n",
" <td>3</td>\n",
" <td>Taman Eden 100 Tobasa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5.9</td>\n",
" <td>47.3</td>\n",
" <td>14.2</td>\n",
" <td>41.1</td>\n",
" <td>0.0</td>\n",
" <td>8.4</td>\n",
" <td>57.0</td>\n",
" <td>13.8</td>\n",
" <td>59.8</td>\n",
" <td>46.9</td>\n",
" <td>...</td>\n",
" <td>70.5</td>\n",
" <td>38.4</td>\n",
" <td>60.9</td>\n",
" <td>32.4</td>\n",
" <td>7.9</td>\n",
" <td>4.70</td>\n",
" <td>7.0</td>\n",
" <td>19.9</td>\n",
" <td>15.7</td>\n",
" <td>7.10</td>\n",
" <td>4</td>\n",
" <td>Water Park Tambunan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>7.1</td>\n",
" <td>53.5</td>\n",
" <td>11.1</td>\n",
" <td>47.2</td>\n",
" <td>8.4</td>\n",
" <td>0.0</td>\n",
" <td>63.2</td>\n",
" <td>14.9</td>\n",
" <td>66.0</td>\n",
" <td>53.1</td>\n",
" <td>...</td>\n",
" <td>76.7</td>\n",
" <td>36.2</td>\n",
" <td>67.1</td>\n",
" <td>38.6</td>\n",
" <td>14.1</td>\n",
" <td>3.80</td>\n",
" <td>13.2</td>\n",
" <td>26.1</td>\n",
" <td>13.5</td>\n",
" <td>4.00</td>\n",
" <td>5</td>\n",
" <td>Bukit Pahoda</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>60.6</td>\n",
" <td>12.0</td>\n",
" <td>68.9</td>\n",
" <td>15.9</td>\n",
" <td>57.0</td>\n",
" <td>63.1</td>\n",
" <td>0.0</td>\n",
" <td>61.4</td>\n",
" <td>5.5</td>\n",
" <td>28.2</td>\n",
" <td>...</td>\n",
" <td>112.0</td>\n",
" <td>93.1</td>\n",
" <td>81.4</td>\n",
" <td>73.6</td>\n",
" <td>55.8</td>\n",
" <td>59.40</td>\n",
" <td>54.9</td>\n",
" <td>42.6</td>\n",
" <td>70.4</td>\n",
" <td>61.80</td>\n",
" <td>6</td>\n",
" <td>Bukit Senyum</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>12.4</td>\n",
" <td>51.7</td>\n",
" <td>20.7</td>\n",
" <td>45.5</td>\n",
" <td>11.3</td>\n",
" <td>14.9</td>\n",
" <td>61.4</td>\n",
" <td>0.0</td>\n",
" <td>64.2</td>\n",
" <td>51.3</td>\n",
" <td>...</td>\n",
" <td>74.9</td>\n",
" <td>44.9</td>\n",
" <td>65.3</td>\n",
" <td>36.8</td>\n",
" <td>12.8</td>\n",
" <td>11.20</td>\n",
" <td>11.9</td>\n",
" <td>24.3</td>\n",
" <td>22.2</td>\n",
" <td>13.60</td>\n",
" <td>7</td>\n",
" <td>Air Terjun Pandumaan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>62.5</td>\n",
" <td>16.6</td>\n",
" <td>71.8</td>\n",
" <td>17.8</td>\n",
" <td>58.8</td>\n",
" <td>66.0</td>\n",
" <td>5.5</td>\n",
" <td>63.3</td>\n",
" <td>0.0</td>\n",
" <td>31.1</td>\n",
" <td>...</td>\n",
" <td>114.0</td>\n",
" <td>95.0</td>\n",
" <td>83.3</td>\n",
" <td>75.5</td>\n",
" <td>57.7</td>\n",
" <td>61.30</td>\n",
" <td>56.8</td>\n",
" <td>44.5</td>\n",
" <td>72.3</td>\n",
" <td>64.60</td>\n",
" <td>8</td>\n",
" <td>Long Beach</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>50.5</td>\n",
" <td>18.6</td>\n",
" <td>58.8</td>\n",
" <td>12.3</td>\n",
" <td>46.9</td>\n",
" <td>53.1</td>\n",
" <td>28.2</td>\n",
" <td>51.3</td>\n",
" <td>31.1</td>\n",
" <td>0.0</td>\n",
" <td>...</td>\n",
" <td>102.0</td>\n",
" <td>83.1</td>\n",
" <td>71.3</td>\n",
" <td>63.5</td>\n",
" <td>45.7</td>\n",
" <td>49.30</td>\n",
" <td>44.8</td>\n",
" <td>19.8</td>\n",
" <td>60.4</td>\n",
" <td>51.70</td>\n",
" <td>9</td>\n",
" <td>PANTAI AGADON</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>52.7</td>\n",
" <td>20.7</td>\n",
" <td>61.0</td>\n",
" <td>14.5</td>\n",
" <td>49.0</td>\n",
" <td>55.2</td>\n",
" <td>30.4</td>\n",
" <td>53.5</td>\n",
" <td>33.2</td>\n",
" <td>5.7</td>\n",
" <td>...</td>\n",
" <td>104.0</td>\n",
" <td>85.2</td>\n",
" <td>73.5</td>\n",
" <td>65.7</td>\n",
" <td>47.9</td>\n",
" <td>51.50</td>\n",
" <td>47.0</td>\n",
" <td>34.7</td>\n",
" <td>62.5</td>\n",
" <td>53.80</td>\n",
" <td>10</td>\n",
" <td>Situmurun Waterfall</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>43.1</td>\n",
" <td>50.3</td>\n",
" <td>51.4</td>\n",
" <td>44.0</td>\n",
" <td>39.4</td>\n",
" <td>45.6</td>\n",
" <td>59.9</td>\n",
" <td>43.8</td>\n",
" <td>62.8</td>\n",
" <td>49.9</td>\n",
" <td>...</td>\n",
" <td>94.2</td>\n",
" <td>75.6</td>\n",
" <td>26.2</td>\n",
" <td>56.1</td>\n",
" <td>38.2</td>\n",
" <td>41.80</td>\n",
" <td>37.3</td>\n",
" <td>25.1</td>\n",
" <td>52.9</td>\n",
" <td>44.20</td>\n",
" <td>11</td>\n",
" <td>Simanimbo Waterfall</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>51.9</td>\n",
" <td>59.0</td>\n",
" <td>60.2</td>\n",
" <td>52.8</td>\n",
" <td>48.2</td>\n",
" <td>54.4</td>\n",
" <td>68.7</td>\n",
" <td>52.8</td>\n",
" <td>71.6</td>\n",
" <td>58.6</td>\n",
" <td>...</td>\n",
" <td>103.0</td>\n",
" <td>84.4</td>\n",
" <td>15.5</td>\n",
" <td>64.9</td>\n",
" <td>47.0</td>\n",
" <td>50.60</td>\n",
" <td>46.1</td>\n",
" <td>33.8</td>\n",
" <td>61.7</td>\n",
" <td>53.00</td>\n",
" <td>12</td>\n",
" <td>Air Terjun Sigura Gura</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>56.3</td>\n",
" <td>7.7</td>\n",
" <td>64.6</td>\n",
" <td>11.6</td>\n",
" <td>52.7</td>\n",
" <td>58.8</td>\n",
" <td>10.8</td>\n",
" <td>57.1</td>\n",
" <td>23.0</td>\n",
" <td>23.9</td>\n",
" <td>...</td>\n",
" <td>107.0</td>\n",
" <td>88.8</td>\n",
" <td>77.1</td>\n",
" <td>69.3</td>\n",
" <td>51.5</td>\n",
" <td>55.10</td>\n",
" <td>50.6</td>\n",
" <td>38.3</td>\n",
" <td>66.1</td>\n",
" <td>57.50</td>\n",
" <td>13</td>\n",
" <td>The Kaldera</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>6.0</td>\n",
" <td>52.5</td>\n",
" <td>8.0</td>\n",
" <td>46.2</td>\n",
" <td>7.4</td>\n",
" <td>3.3</td>\n",
" <td>62.1</td>\n",
" <td>13.9</td>\n",
" <td>65.0</td>\n",
" <td>52.0</td>\n",
" <td>...</td>\n",
" <td>75.7</td>\n",
" <td>32.3</td>\n",
" <td>66.0</td>\n",
" <td>37.6</td>\n",
" <td>13.1</td>\n",
" <td>2.80</td>\n",
" <td>12.2</td>\n",
" <td>25.1</td>\n",
" <td>9.6</td>\n",
" <td>0.35</td>\n",
" <td>14</td>\n",
" <td>Museum T. B. Silalahi Center</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>11.8</td>\n",
" <td>58.2</td>\n",
" <td>4.1</td>\n",
" <td>52.0</td>\n",
" <td>13.2</td>\n",
" <td>10.9</td>\n",
" <td>67.9</td>\n",
" <td>19.6</td>\n",
" <td>70.7</td>\n",
" <td>57.8</td>\n",
" <td>...</td>\n",
" <td>81.4</td>\n",
" <td>29.3</td>\n",
" <td>71.8</td>\n",
" <td>43.3</td>\n",
" <td>18.8</td>\n",
" <td>8.50</td>\n",
" <td>17.9</td>\n",
" <td>30.8</td>\n",
" <td>5.6</td>\n",
" <td>6.60</td>\n",
" <td>15</td>\n",
" <td>Bukit Tarabunga</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>14.6</td>\n",
" <td>61.0</td>\n",
" <td>4.7</td>\n",
" <td>54.8</td>\n",
" <td>16.0</td>\n",
" <td>13.7</td>\n",
" <td>70.7</td>\n",
" <td>22.5</td>\n",
" <td>73.6</td>\n",
" <td>60.6</td>\n",
" <td>...</td>\n",
" <td>84.3</td>\n",
" <td>32.1</td>\n",
" <td>74.6</td>\n",
" <td>46.2</td>\n",
" <td>21.7</td>\n",
" <td>11.40</td>\n",
" <td>20.8</td>\n",
" <td>33.7</td>\n",
" <td>0.6</td>\n",
" <td>9.50</td>\n",
" <td>16</td>\n",
" <td>Pantai Meat</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>60.7</td>\n",
" <td>67.9</td>\n",
" <td>74.2</td>\n",
" <td>61.7</td>\n",
" <td>57.0</td>\n",
" <td>68.5</td>\n",
" <td>82.8</td>\n",
" <td>61.5</td>\n",
" <td>80.4</td>\n",
" <td>72.7</td>\n",
" <td>...</td>\n",
" <td>112.0</td>\n",
" <td>93.2</td>\n",
" <td>9.7</td>\n",
" <td>73.7</td>\n",
" <td>55.9</td>\n",
" <td>59.50</td>\n",
" <td>55.0</td>\n",
" <td>42.7</td>\n",
" <td>70.5</td>\n",
" <td>67.10</td>\n",
" <td>17</td>\n",
" <td>Air Terjun Sialogo</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>9.0</td>\n",
" <td>55.5</td>\n",
" <td>15.4</td>\n",
" <td>49.2</td>\n",
" <td>10.4</td>\n",
" <td>9.6</td>\n",
" <td>65.1</td>\n",
" <td>15.0</td>\n",
" <td>68.0</td>\n",
" <td>55.1</td>\n",
" <td>...</td>\n",
" <td>78.7</td>\n",
" <td>39.6</td>\n",
" <td>69.0</td>\n",
" <td>40.6</td>\n",
" <td>16.1</td>\n",
" <td>5.90</td>\n",
" <td>15.2</td>\n",
" <td>28.1</td>\n",
" <td>16.9</td>\n",
" <td>8.30</td>\n",
" <td>18</td>\n",
" <td>Air Terjun Siboruon</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>42.4</td>\n",
" <td>8.7</td>\n",
" <td>50.7</td>\n",
" <td>2.4</td>\n",
" <td>38.8</td>\n",
" <td>44.9</td>\n",
" <td>18.3</td>\n",
" <td>43.2</td>\n",
" <td>21.2</td>\n",
" <td>10.0</td>\n",
" <td>...</td>\n",
" <td>93.5</td>\n",
" <td>74.9</td>\n",
" <td>63.2</td>\n",
" <td>55.4</td>\n",
" <td>37.6</td>\n",
" <td>41.20</td>\n",
" <td>36.7</td>\n",
" <td>24.4</td>\n",
" <td>52.2</td>\n",
" <td>43.60</td>\n",
" <td>19</td>\n",
" <td>Gunung Pangulubao</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>6.7</td>\n",
" <td>53.1</td>\n",
" <td>8.7</td>\n",
" <td>46.9</td>\n",
" <td>8.1</td>\n",
" <td>2.8</td>\n",
" <td>62.9</td>\n",
" <td>14.6</td>\n",
" <td>65.7</td>\n",
" <td>52.8</td>\n",
" <td>...</td>\n",
" <td>76.4</td>\n",
" <td>32.9</td>\n",
" <td>66.7</td>\n",
" <td>38.3</td>\n",
" <td>13.8</td>\n",
" <td>3.40</td>\n",
" <td>12.9</td>\n",
" <td>25.7</td>\n",
" <td>10.2</td>\n",
" <td>2.00</td>\n",
" <td>20</td>\n",
" <td>Lumban Silintong</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>36.3</td>\n",
" <td>45.7</td>\n",
" <td>44.6</td>\n",
" <td>39.5</td>\n",
" <td>32.7</td>\n",
" <td>38.9</td>\n",
" <td>55.4</td>\n",
" <td>37.1</td>\n",
" <td>58.2</td>\n",
" <td>23.4</td>\n",
" <td>...</td>\n",
" <td>87.4</td>\n",
" <td>68.9</td>\n",
" <td>59.3</td>\n",
" <td>49.3</td>\n",
" <td>32.5</td>\n",
" <td>35.10</td>\n",
" <td>30.6</td>\n",
" <td>14.7</td>\n",
" <td>46.2</td>\n",
" <td>37.50</td>\n",
" <td>21</td>\n",
" <td>Siregar Aek Nalas</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>4.4</td>\n",
" <td>47.9</td>\n",
" <td>12.7</td>\n",
" <td>41.7</td>\n",
" <td>2.9</td>\n",
" <td>7.0</td>\n",
" <td>57.6</td>\n",
" <td>11.9</td>\n",
" <td>60.5</td>\n",
" <td>47.5</td>\n",
" <td>...</td>\n",
" <td>71.2</td>\n",
" <td>37.0</td>\n",
" <td>61.5</td>\n",
" <td>33.1</td>\n",
" <td>8.6</td>\n",
" <td>3.20</td>\n",
" <td>7.6</td>\n",
" <td>20.5</td>\n",
" <td>14.3</td>\n",
" <td>5.60</td>\n",
" <td>22</td>\n",
" <td>Pantai Janji Maria</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>3.4</td>\n",
" <td>49.8</td>\n",
" <td>9.4</td>\n",
" <td>43.6</td>\n",
" <td>4.8</td>\n",
" <td>3.6</td>\n",
" <td>59.5</td>\n",
" <td>11.3</td>\n",
" <td>62.4</td>\n",
" <td>49.4</td>\n",
" <td>...</td>\n",
" <td>73.1</td>\n",
" <td>33.6</td>\n",
" <td>63.4</td>\n",
" <td>35.0</td>\n",
" <td>10.5</td>\n",
" <td>0.13</td>\n",
" <td>9.5</td>\n",
" <td>22.4</td>\n",
" <td>5.6</td>\n",
" <td>2.30</td>\n",
" <td>23</td>\n",
" <td>Balerong Onan Balige</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>9.8</td>\n",
" <td>56.2</td>\n",
" <td>4.1</td>\n",
" <td>50.0</td>\n",
" <td>11.2</td>\n",
" <td>8.9</td>\n",
" <td>65.9</td>\n",
" <td>17.7</td>\n",
" <td>68.8</td>\n",
" <td>55.8</td>\n",
" <td>...</td>\n",
" <td>79.5</td>\n",
" <td>27.4</td>\n",
" <td>69.8</td>\n",
" <td>41.4</td>\n",
" <td>16.9</td>\n",
" <td>6.60</td>\n",
" <td>16.0</td>\n",
" <td>28.9</td>\n",
" <td>5.6</td>\n",
" <td>4.70</td>\n",
" <td>24</td>\n",
" <td>Dolok Tolong</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>21.0</td>\n",
" <td>32.2</td>\n",
" <td>29.3</td>\n",
" <td>26.0</td>\n",
" <td>17.4</td>\n",
" <td>23.6</td>\n",
" <td>41.9</td>\n",
" <td>21.8</td>\n",
" <td>44.8</td>\n",
" <td>31.9</td>\n",
" <td>...</td>\n",
" <td>72.1</td>\n",
" <td>53.6</td>\n",
" <td>45.8</td>\n",
" <td>34.0</td>\n",
" <td>16.2</td>\n",
" <td>19.80</td>\n",
" <td>15.3</td>\n",
" <td>4.9</td>\n",
" <td>5.6</td>\n",
" <td>22.20</td>\n",
" <td>25</td>\n",
" <td>Pantai Pasir Putih Parparean</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>74.2</td>\n",
" <td>102.0</td>\n",
" <td>82.5</td>\n",
" <td>95.8</td>\n",
" <td>70.5</td>\n",
" <td>76.7</td>\n",
" <td>112.0</td>\n",
" <td>74.9</td>\n",
" <td>115.0</td>\n",
" <td>102.0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>107.0</td>\n",
" <td>118.0</td>\n",
" <td>36.5</td>\n",
" <td>69.3</td>\n",
" <td>72.90</td>\n",
" <td>68.4</td>\n",
" <td>74.6</td>\n",
" <td>84.0</td>\n",
" <td>75.30</td>\n",
" <td>26</td>\n",
" <td>Dolok Surungan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>51.5</td>\n",
" <td>83.5</td>\n",
" <td>59.8</td>\n",
" <td>78.1</td>\n",
" <td>47.8</td>\n",
" <td>36.2</td>\n",
" <td>93.1</td>\n",
" <td>52.3</td>\n",
" <td>96.8</td>\n",
" <td>83.1</td>\n",
" <td>...</td>\n",
" <td>103.0</td>\n",
" <td>0.0</td>\n",
" <td>15.1</td>\n",
" <td>69.4</td>\n",
" <td>46.7</td>\n",
" <td>34.60</td>\n",
" <td>45.7</td>\n",
" <td>56.9</td>\n",
" <td>61.3</td>\n",
" <td>31.90</td>\n",
" <td>27</td>\n",
" <td>Air Terjun Sampuran</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>64.5</td>\n",
" <td>71.7</td>\n",
" <td>72.8</td>\n",
" <td>65.5</td>\n",
" <td>60.9</td>\n",
" <td>67.1</td>\n",
" <td>81.4</td>\n",
" <td>65.3</td>\n",
" <td>84.2</td>\n",
" <td>71.3</td>\n",
" <td>...</td>\n",
" <td>116.0</td>\n",
" <td>97.1</td>\n",
" <td>0.0</td>\n",
" <td>77.5</td>\n",
" <td>59.7</td>\n",
" <td>63.30</td>\n",
" <td>58.8</td>\n",
" <td>46.5</td>\n",
" <td>74.3</td>\n",
" <td>65.70</td>\n",
" <td>28</td>\n",
" <td>Air Terjun Morena</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>36.1</td>\n",
" <td>63.9</td>\n",
" <td>44.3</td>\n",
" <td>57.7</td>\n",
" <td>32.4</td>\n",
" <td>38.6</td>\n",
" <td>73.6</td>\n",
" <td>36.8</td>\n",
" <td>76.5</td>\n",
" <td>63.5</td>\n",
" <td>...</td>\n",
" <td>36.5</td>\n",
" <td>68.6</td>\n",
" <td>77.5</td>\n",
" <td>0.0</td>\n",
" <td>31.2</td>\n",
" <td>34.80</td>\n",
" <td>30.3</td>\n",
" <td>36.5</td>\n",
" <td>45.9</td>\n",
" <td>37.20</td>\n",
" <td>29</td>\n",
" <td>Tornagodang</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>11.9</td>\n",
" <td>46.1</td>\n",
" <td>20.2</td>\n",
" <td>39.9</td>\n",
" <td>8.3</td>\n",
" <td>14.1</td>\n",
" <td>55.8</td>\n",
" <td>12.7</td>\n",
" <td>58.7</td>\n",
" <td>45.7</td>\n",
" <td>...</td>\n",
" <td>69.4</td>\n",
" <td>44.4</td>\n",
" <td>59.7</td>\n",
" <td>31.3</td>\n",
" <td>0.0</td>\n",
" <td>10.70</td>\n",
" <td>0.9</td>\n",
" <td>18.7</td>\n",
" <td>21.7</td>\n",
" <td>12.70</td>\n",
" <td>30</td>\n",
" <td>Hatulian Beach</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>3.3</td>\n",
" <td>49.7</td>\n",
" <td>9.5</td>\n",
" <td>43.5</td>\n",
" <td>4.7</td>\n",
" <td>3.8</td>\n",
" <td>59.4</td>\n",
" <td>11.2</td>\n",
" <td>62.2</td>\n",
" <td>49.3</td>\n",
" <td>...</td>\n",
" <td>72.9</td>\n",
" <td>33.8</td>\n",
" <td>63.3</td>\n",
" <td>34.8</td>\n",
" <td>10.3</td>\n",
" <td>0.00</td>\n",
" <td>9.4</td>\n",
" <td>22.3</td>\n",
" <td>11.1</td>\n",
" <td>2.40</td>\n",
" <td>31</td>\n",
" <td>Monumen Raja Sonakmalela</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>11.2</td>\n",
" <td>45.2</td>\n",
" <td>19.4</td>\n",
" <td>39.1</td>\n",
" <td>7.5</td>\n",
" <td>13.2</td>\n",
" <td>54.9</td>\n",
" <td>11.9</td>\n",
" <td>57.9</td>\n",
" <td>44.8</td>\n",
" <td>...</td>\n",
" <td>68.6</td>\n",
" <td>43.7</td>\n",
" <td>59.0</td>\n",
" <td>30.5</td>\n",
" <td>0.9</td>\n",
" <td>9.90</td>\n",
" <td>0.0</td>\n",
" <td>18.0</td>\n",
" <td>21.0</td>\n",
" <td>11.80</td>\n",
" <td>32</td>\n",
" <td>Lumban Binanga Beach</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>23.5</td>\n",
" <td>32.9</td>\n",
" <td>31.8</td>\n",
" <td>26.7</td>\n",
" <td>19.9</td>\n",
" <td>26.1</td>\n",
" <td>42.6</td>\n",
" <td>24.3</td>\n",
" <td>45.5</td>\n",
" <td>19.8</td>\n",
" <td>...</td>\n",
" <td>74.6</td>\n",
" <td>56.1</td>\n",
" <td>46.5</td>\n",
" <td>36.5</td>\n",
" <td>18.7</td>\n",
" <td>22.30</td>\n",
" <td>17.8</td>\n",
" <td>0.0</td>\n",
" <td>33.4</td>\n",
" <td>24.70</td>\n",
" <td>33</td>\n",
" <td>Pantai Pasifik Porsea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>14.4</td>\n",
" <td>60.8</td>\n",
" <td>4.5</td>\n",
" <td>54.6</td>\n",
" <td>15.7</td>\n",
" <td>13.5</td>\n",
" <td>70.4</td>\n",
" <td>22.2</td>\n",
" <td>73.3</td>\n",
" <td>60.4</td>\n",
" <td>...</td>\n",
" <td>84.0</td>\n",
" <td>31.9</td>\n",
" <td>74.4</td>\n",
" <td>45.9</td>\n",
" <td>21.4</td>\n",
" <td>11.10</td>\n",
" <td>20.5</td>\n",
" <td>33.4</td>\n",
" <td>0.0</td>\n",
" <td>9.20</td>\n",
" <td>34</td>\n",
" <td>Desa Adat Ragi Hotang</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>5.7</td>\n",
" <td>52.1</td>\n",
" <td>7.7</td>\n",
" <td>45.9</td>\n",
" <td>7.1</td>\n",
" <td>3.6</td>\n",
" <td>61.8</td>\n",
" <td>13.6</td>\n",
" <td>64.6</td>\n",
" <td>51.7</td>\n",
" <td>...</td>\n",
" <td>75.3</td>\n",
" <td>31.9</td>\n",
" <td>65.7</td>\n",
" <td>37.2</td>\n",
" <td>12.7</td>\n",
" <td>2.40</td>\n",
" <td>11.8</td>\n",
" <td>24.7</td>\n",
" <td>9.2</td>\n",
" <td>0.00</td>\n",
" <td>35</td>\n",
" <td>Makam Raja Sisingamangaraja XII</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>36 rows × 36 columns</p>\n",
"</div>"
],
"text/plain": [
" Pantai BUL BUL BUKIT travel Gibeon Pakkodian Taman Eden 100 Tobasa \\\n",
"0 0.0 50.9 12.8 44.7 \n",
"1 50.9 0.0 59.2 6.2 \n",
"2 12.8 59.2 0.0 53.0 \n",
"3 44.7 6.2 53.0 0.0 \n",
"4 5.9 47.3 14.2 41.1 \n",
"5 7.1 53.5 11.1 47.2 \n",
"6 60.6 12.0 68.9 15.9 \n",
"7 12.4 51.7 20.7 45.5 \n",
"8 62.5 16.6 71.8 17.8 \n",
"9 50.5 18.6 58.8 12.3 \n",
"10 52.7 20.7 61.0 14.5 \n",
"11 43.1 50.3 51.4 44.0 \n",
"12 51.9 59.0 60.2 52.8 \n",
"13 56.3 7.7 64.6 11.6 \n",
"14 6.0 52.5 8.0 46.2 \n",
"15 11.8 58.2 4.1 52.0 \n",
"16 14.6 61.0 4.7 54.8 \n",
"17 60.7 67.9 74.2 61.7 \n",
"18 9.0 55.5 15.4 49.2 \n",
"19 42.4 8.7 50.7 2.4 \n",
"20 6.7 53.1 8.7 46.9 \n",
"21 36.3 45.7 44.6 39.5 \n",
"22 4.4 47.9 12.7 41.7 \n",
"23 3.4 49.8 9.4 43.6 \n",
"24 9.8 56.2 4.1 50.0 \n",
"25 21.0 32.2 29.3 26.0 \n",
"26 74.2 102.0 82.5 95.8 \n",
"27 51.5 83.5 59.8 78.1 \n",
"28 64.5 71.7 72.8 65.5 \n",
"29 36.1 63.9 44.3 57.7 \n",
"30 11.9 46.1 20.2 39.9 \n",
"31 3.3 49.7 9.5 43.5 \n",
"32 11.2 45.2 19.4 39.1 \n",
"33 23.5 32.9 31.8 26.7 \n",
"34 14.4 60.8 4.5 54.6 \n",
"35 5.7 52.1 7.7 45.9 \n",
"\n",
" Water Park Tambunan Bukit Pahoda Bukit Senyum Air Terjun Pandumaan \\\n",
"0 5.9 71.0 60.6 12.4 \n",
"1 47.3 53.5 12.0 51.4 \n",
"2 14.2 11.9 68.9 20.7 \n",
"3 41.1 47.2 15.9 45.5 \n",
"4 0.0 8.4 57.0 13.8 \n",
"5 8.4 0.0 63.2 14.9 \n",
"6 57.0 63.1 0.0 61.4 \n",
"7 11.3 14.9 61.4 0.0 \n",
"8 58.8 66.0 5.5 63.3 \n",
"9 46.9 53.1 28.2 51.3 \n",
"10 49.0 55.2 30.4 53.5 \n",
"11 39.4 45.6 59.9 43.8 \n",
"12 48.2 54.4 68.7 52.8 \n",
"13 52.7 58.8 10.8 57.1 \n",
"14 7.4 3.3 62.1 13.9 \n",
"15 13.2 10.9 67.9 19.6 \n",
"16 16.0 13.7 70.7 22.5 \n",
"17 57.0 68.5 82.8 61.5 \n",
"18 10.4 9.6 65.1 15.0 \n",
"19 38.8 44.9 18.3 43.2 \n",
"20 8.1 2.8 62.9 14.6 \n",
"21 32.7 38.9 55.4 37.1 \n",
"22 2.9 7.0 57.6 11.9 \n",
"23 4.8 3.6 59.5 11.3 \n",
"24 11.2 8.9 65.9 17.7 \n",
"25 17.4 23.6 41.9 21.8 \n",
"26 70.5 76.7 112.0 74.9 \n",
"27 47.8 36.2 93.1 52.3 \n",
"28 60.9 67.1 81.4 65.3 \n",
"29 32.4 38.6 73.6 36.8 \n",
"30 8.3 14.1 55.8 12.7 \n",
"31 4.7 3.8 59.4 11.2 \n",
"32 7.5 13.2 54.9 11.9 \n",
"33 19.9 26.1 42.6 24.3 \n",
"34 15.7 13.5 70.4 22.2 \n",
"35 7.1 3.6 61.8 13.6 \n",
"\n",
" Long Beach PANTAI AGADON ... Dolok Surungan Air Terjun Sampuran \\\n",
"0 63.5 50.5 ... 74.2 37.1 \n",
"1 17.6 18.6 ... 102.0 83.5 \n",
"2 71.8 58.8 ... 82.5 30.4 \n",
"3 18.8 12.3 ... 95.8 77.2 \n",
"4 59.8 46.9 ... 70.5 38.4 \n",
"5 66.0 53.1 ... 76.7 36.2 \n",
"6 5.5 28.2 ... 112.0 93.1 \n",
"7 64.2 51.3 ... 74.9 44.9 \n",
"8 0.0 31.1 ... 114.0 95.0 \n",
"9 31.1 0.0 ... 102.0 83.1 \n",
"10 33.2 5.7 ... 104.0 85.2 \n",
"11 62.8 49.9 ... 94.2 75.6 \n",
"12 71.6 58.6 ... 103.0 84.4 \n",
"13 23.0 23.9 ... 107.0 88.8 \n",
"14 65.0 52.0 ... 75.7 32.3 \n",
"15 70.7 57.8 ... 81.4 29.3 \n",
"16 73.6 60.6 ... 84.3 32.1 \n",
"17 80.4 72.7 ... 112.0 93.2 \n",
"18 68.0 55.1 ... 78.7 39.6 \n",
"19 21.2 10.0 ... 93.5 74.9 \n",
"20 65.7 52.8 ... 76.4 32.9 \n",
"21 58.2 23.4 ... 87.4 68.9 \n",
"22 60.5 47.5 ... 71.2 37.0 \n",
"23 62.4 49.4 ... 73.1 33.6 \n",
"24 68.8 55.8 ... 79.5 27.4 \n",
"25 44.8 31.9 ... 72.1 53.6 \n",
"26 115.0 102.0 ... 0.0 107.0 \n",
"27 96.8 83.1 ... 103.0 0.0 \n",
"28 84.2 71.3 ... 116.0 97.1 \n",
"29 76.5 63.5 ... 36.5 68.6 \n",
"30 58.7 45.7 ... 69.4 44.4 \n",
"31 62.2 49.3 ... 72.9 33.8 \n",
"32 57.9 44.8 ... 68.6 43.7 \n",
"33 45.5 19.8 ... 74.6 56.1 \n",
"34 73.3 60.4 ... 84.0 31.9 \n",
"35 64.6 51.7 ... 75.3 31.9 \n",
"\n",
" Air Terjun Morena Tornagodang Hatulian Beach Monumen Raja Sonakmalela \\\n",
"0 64.5 36.1 11.6 3.30 \n",
"1 71.7 63.9 46.1 49.70 \n",
"2 72.8 44.4 19.9 9.50 \n",
"3 65.5 57.7 39.9 43.50 \n",
"4 60.9 32.4 7.9 4.70 \n",
"5 67.1 38.6 14.1 3.80 \n",
"6 81.4 73.6 55.8 59.40 \n",
"7 65.3 36.8 12.8 11.20 \n",
"8 83.3 75.5 57.7 61.30 \n",
"9 71.3 63.5 45.7 49.30 \n",
"10 73.5 65.7 47.9 51.50 \n",
"11 26.2 56.1 38.2 41.80 \n",
"12 15.5 64.9 47.0 50.60 \n",
"13 77.1 69.3 51.5 55.10 \n",
"14 66.0 37.6 13.1 2.80 \n",
"15 71.8 43.3 18.8 8.50 \n",
"16 74.6 46.2 21.7 11.40 \n",
"17 9.7 73.7 55.9 59.50 \n",
"18 69.0 40.6 16.1 5.90 \n",
"19 63.2 55.4 37.6 41.20 \n",
"20 66.7 38.3 13.8 3.40 \n",
"21 59.3 49.3 32.5 35.10 \n",
"22 61.5 33.1 8.6 3.20 \n",
"23 63.4 35.0 10.5 0.13 \n",
"24 69.8 41.4 16.9 6.60 \n",
"25 45.8 34.0 16.2 19.80 \n",
"26 118.0 36.5 69.3 72.90 \n",
"27 15.1 69.4 46.7 34.60 \n",
"28 0.0 77.5 59.7 63.30 \n",
"29 77.5 0.0 31.2 34.80 \n",
"30 59.7 31.3 0.0 10.70 \n",
"31 63.3 34.8 10.3 0.00 \n",
"32 59.0 30.5 0.9 9.90 \n",
"33 46.5 36.5 18.7 22.30 \n",
"34 74.4 45.9 21.4 11.10 \n",
"35 65.7 37.2 12.7 2.40 \n",
"\n",
" Lumban Binanga Beach Pantai Pasifik Porsea Desa Adat Ragi Hotang \\\n",
"0 10.7 22.5 14.4 \n",
"1 45.2 32.9 60.8 \n",
"2 18.9 31.8 4.5 \n",
"3 39.0 26.7 54.5 \n",
"4 7.0 19.9 15.7 \n",
"5 13.2 26.1 13.5 \n",
"6 54.9 42.6 70.4 \n",
"7 11.9 24.3 22.2 \n",
"8 56.8 44.5 72.3 \n",
"9 44.8 19.8 60.4 \n",
"10 47.0 34.7 62.5 \n",
"11 37.3 25.1 52.9 \n",
"12 46.1 33.8 61.7 \n",
"13 50.6 38.3 66.1 \n",
"14 12.2 25.1 9.6 \n",
"15 17.9 30.8 5.6 \n",
"16 20.8 33.7 0.6 \n",
"17 55.0 42.7 70.5 \n",
"18 15.2 28.1 16.9 \n",
"19 36.7 24.4 52.2 \n",
"20 12.9 25.7 10.2 \n",
"21 30.6 14.7 46.2 \n",
"22 7.6 20.5 14.3 \n",
"23 9.5 22.4 5.6 \n",
"24 16.0 28.9 5.6 \n",
"25 15.3 4.9 5.6 \n",
"26 68.4 74.6 84.0 \n",
"27 45.7 56.9 61.3 \n",
"28 58.8 46.5 74.3 \n",
"29 30.3 36.5 45.9 \n",
"30 0.9 18.7 21.7 \n",
"31 9.4 22.3 11.1 \n",
"32 0.0 18.0 21.0 \n",
"33 17.8 0.0 33.4 \n",
"34 20.5 33.4 0.0 \n",
"35 11.8 24.7 9.2 \n",
"\n",
" Makam Raja Sisingamangaraja XII \n",
"0 5.70 \n",
"1 52.10 \n",
"2 7.70 \n",
"3 45.90 \n",
"4 7.10 \n",
"5 4.00 \n",
"6 61.80 \n",
"7 13.60 \n",
"8 64.60 \n",
"9 51.70 \n",
"10 53.80 \n",
"11 44.20 \n",
"12 53.00 \n",
"13 57.50 \n",
"14 0.35 \n",
"15 6.60 \n",
"16 9.50 \n",
"17 67.10 \n",
"18 8.30 \n",
"19 43.60 \n",
"20 2.00 \n",
"21 37.50 \n",
"22 5.60 \n",
"23 2.30 \n",
"24 4.70 \n",
"25 22.20 \n",
"26 75.30 \n",
"27 31.90 \n",
"28 65.70 \n",
"29 37.20 \n",
"30 12.70 \n",
"31 2.40 \n",
"32 11.80 \n",
"33 24.70 \n",
"34 9.20 \n",
"35 0.00 \n",
"\n",
"[36 rows x 36 columns]"
" ID_City City\n",
"0 0 Pantai BUL BUL\n",
"1 1 BUKIT travel Gibeon\n",
"2 2 Pakkodian\n",
"3 3 Taman Eden 100 Tobasa\n",
"4 4 Water Park Tambunan\n",
"5 5 Bukit Pahoda\n",
"6 6 Bukit Senyum\n",
"7 7 Air Terjun Pandumaan\n",
"8 8 Long Beach\n",
"9 9 PANTAI AGADON\n",
"10 10 Situmurun Waterfall\n",
"11 11 Simanimbo Waterfall\n",
"12 12 Air Terjun Sigura Gura\n",
"13 13 The Kaldera\n",
"14 14 Museum T. B. Silalahi Center\n",
"15 15 Bukit Tarabunga\n",
"16 16 Pantai Meat\n",
"17 17 Air Terjun Sialogo\n",
"18 18 Air Terjun Siboruon\n",
"19 19 Gunung Pangulubao\n",
"20 20 Lumban Silintong\n",
"21 21 Siregar Aek Nalas\n",
"22 22 Pantai Janji Maria\n",
"23 23 Balerong Onan Balige\n",
"24 24 Dolok Tolong\n",
"25 25 Pantai Pasir Putih Parparean\n",
"26 26 Dolok Surungan\n",
"27 27 Air Terjun Sampuran\n",
"28 28 Air Terjun Morena\n",
"29 29 Tornagodang\n",
"30 30 Hatulian Beach\n",
"31 31 Monumen Raja Sonakmalela\n",
"32 32 Lumban Binanga Beach\n",
"33 33 Pantai Pasifik Porsea\n",
"34 34 Desa Adat Ragi Hotang\n",
"35 35 Makam Raja Sisingamangaraja XII"
]
},
"execution_count": 9,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1251,7 +339,7 @@
"source": [
"#Data1\n",
"#Data2\n",
"#Data3"
"Data3"
]
},
{
......@@ -1281,35 +369,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random Data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 23, 10, 22, 24, 5, 15]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"id_city = list(Data3['ID_City'])\n",
"Data4 = random.sample(range(len(id_city)), 7)\n",
"Data4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fitness Calculation"
]
},
......@@ -1339,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 267,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
......@@ -1349,16 +408,16 @@
"#Acceleration Constant\n",
"Acceleration_constant = 2; # Maximum velocity change allowed. Range: 0 >= V_MAX < CITY_COUNT\n",
"#Iterasi\n",
"MAX_EPOCHS = 200\n",
"MAX_EPOCHS = 2\n",
"map = [];\n",
"particles = []\n",
"Maximum_distance = Fitness_value.getting_max_distance()\n",
"Maximum_distance= Fitness_value.getting_max_distance()\n",
"CITY_COUNT = len(Data4)"
]
},
{
"cell_type": "code",
"execution_count": 333,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
......@@ -1384,7 +443,7 @@
},
{
"cell_type": "code",
"execution_count": 346,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
......@@ -1392,33 +451,30 @@
" def __init__(self):\n",
" self.mX = 0\n",
" self.mY = 0 \n",
"def get_distance(firstCity,secondCity):\n",
"def get_total_distance(index):\n",
" particles[index].set_pBest_distance(0)\n",
" distance_route = []\n",
" last_distance = 0\n",
" distance = 0\n",
" for i in range(0,6):\n",
" source = particles[i].get_data(i)\n",
" target = particles[i].get_data(i+1)\n",
" distance_route.append(Data2.iloc[source][target])\n",
" for i in range(0,6):\n",
" source = particles[i].get_data(i)\n",
" target = particles[i].get_data(i)\n",
" last_distance = Data1.iloc[source][target] \n",
" distance = sum(distance_route)+last_distance\n",
" return distance\n",
"def get_total_distance(index):\n",
" particles[index].set_pBest_distance(0) \n",
" for i in range(CITY_COUNT):\n",
" if i == CITY_COUNT - 1:\n",
" particles[index].set_pBest_distance(particles[index].get_pBest_distance() + get_distance(particles[index].get_data(CITY_COUNT - 1), particles[index].get_data(0))) # Complete trip.\n",
" source = particles[index].get_data(CITY_COUNT -1)\n",
" target = particles[index].get_data(0)\n",
" distance_route.append(Data2.iloc[source][target])\n",
" distance = sum(distance_route)\n",
" particles[index].set_pBest_distance(distance) # Complete trip.\n",
" else:\n",
" particles[index].set_pBest_distance(particles[index].get_pBest_distance() + get_distance(particles[index].get_data(i), particles[index].get_data(i + 1)))\n",
" source = particles[index].get_data(i)\n",
" target = particles[index].get_data(i + 1)\n",
" distance_route.append(Data2.iloc[source][target])\n",
" distance = sum(distance_route)\n",
" particles[index].set_pBest_distance(distance)\n",
" \n",
" return "
]
},
{
"cell_type": "code",
"execution_count": 347,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
......@@ -1432,7 +488,7 @@
},
{
"cell_type": "code",
"execution_count": 348,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
......@@ -1443,7 +499,7 @@
" while not done:\n",
" cityB = random.randrange(0, CITY_COUNT)\n",
" if cityB != cityA:\n",
" done = \tTrue \n",
" done = \tTrue\n",
" # swap cityA and cityB.\n",
" temp = particles[index].get_data(cityA)\n",
" particles[index].set_data(cityA, particles[index].get_data(cityB))\n",
......@@ -1453,7 +509,7 @@
},
{
"cell_type": "code",
"execution_count": 349,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
......@@ -1465,21 +521,20 @@
" particles.append(newParticle) \n",
" for j in range(10): # just any number of times to randomize them.\n",
" randomly_arrange(len(particles) - 1) \n",
" get_total_distance(len(particles) - 1)\n",
" get_total_distance(len(particles) - 1)\n",
" return"
]
},
{
"cell_type": "code",
"execution_count": 350,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def quicksort(array, left, right):\n",
" pivot = quicksort_partition(array, left, right) \n",
" if left < pivot:\n",
" quicksort(array, left, pivot - 1)\n",
" \n",
" quicksort(array, left, pivot - 1) \n",
" if right > pivot:\n",
" quicksort(array, pivot + 1, right) \n",
" return array"
......@@ -1487,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 351,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
......@@ -1514,12 +569,12 @@
" left = I_hold\n",
" right = r_hold\n",
" \n",
" return pivot"
" return pivot\n"
]
},
{
"cell_type": "code",
"execution_count": 352,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
......@@ -1541,7 +596,7 @@
},
{
"cell_type": "code",
"execution_count": 353,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
......@@ -1585,11 +640,11 @@
},
{
"cell_type": "code",
"execution_count": 325,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# updating particles city\n",
" # updating particles city\n",
"def update_particles():\n",
" # Best was previously sorted to index 0, so start from the second best.\n",
" for i in range(5):\n",
......@@ -1604,28 +659,20 @@
" \n",
" # Push it closer to it's best neighbor.\n",
" copy_from_particle(i - 1, i) \n",
" # Update pBest value.\n",
" get_total_distance(i) \n",
" # Update pBest value.\n",
" get_total_distance(i) \n",
" return"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 326,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def PSO_algorithm():\n",
" epoch = 0\n",
" done = False\n",
" \n",
" done = False \n",
" initialize_particles() \n",
" while not done:\n",
" # Two conditions can end this loop:\n",
......@@ -1644,18 +691,16 @@
" # list has to sorted in order for get_velocity() to work.\n",
" get_velocity() \n",
" update_particles() \n",
" sys.stdout.write(\"epoch number: \" + str(epoch) + \"\\n\")\n",
" \n",
" sys.stdout.write(\"epoch number: \" + str(epoch) + \"\\n\") \n",
" epoch += 1 \n",
" else:\n",
" done = True\n",
" \n",
" done = True \n",
" return"
]
},
{
"cell_type": "code",
"execution_count": 327,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
......@@ -1673,25 +718,25 @@
},
{
"cell_type": "code",
"execution_count": 328,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Route: 2, 0, 1, 4, 6, 5, 3, Distance: 392.0\n",
"Route: 2, 4, 5, 1, 6, 0, 3, Distance: 392.0\n",
"Route: 2, 4, 5, 0, 1, 6, 3, Distance: 392.0\n",
"Route: 2, 6, 1, 0, 4, 5, 3, Distance: 392.0\n",
"Route: 6, 5, 3, 1, 0, 4, 2, Distance: 392.0\n",
"Changes for particle 1: 2\n",
"Changes for particle 2: 2\n",
"Changes for particle 3: 2\n",
"Changes for particle 4: 2\n",
"Route: 6, 2, 1, 0, 3, 5, 4, Distance: 336.3\n",
"Route: 6, 2, 5, 1, 0, 4, 3, Distance: 248.10000000000002\n",
"Route: 3, 0, 1, 4, 5, 6, 2, Distance: 336.4\n",
"Route: 4, 3, 0, 6, 5, 1, 2, Distance: 336.4\n",
"Route: 6, 0, 4, 3, 2, 1, 5, Distance: 336.5\n",
"Changes for particle 1: 0\n",
"Changes for particle 2: 0\n",
"Changes for particle 3: 0\n",
"Changes for particle 4: 0\n",
"epoch number: 0\n",
"Target reached.\n",
"Best Route: 2, 0, 1, 4, 6, 5, 3, Distance: 392.0\n"
"Best Route: 5, 2, 0, 4, 1, 6, 3, Distance: 152.2\n"
]
}
],
......@@ -1704,59 +749,67 @@
},
{
"cell_type": "code",
"execution_count": 221,
"metadata": {},
"outputs": [],
"source": [
"def checking_city():\n",
" Route = []\n",
" if (particles[0].get_pBest_distance() <= Maximum_distance):\n",
" for j in range(CITY_COUNT):\n",
" Route.append(particles[0].get_data(j))\n",
" return Route"
]
},
{
"cell_type": "code",
"execution_count": 223,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
"[5, 2, 0, 4, 1, 6, 3]"
]
},
"execution_count": 223,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Decode PSO\n",
"def checking_city():\n",
" if (particles[0].get_pBest_distance() <= Maximum_distance):\n",
" Route = []\n",
" for j in range(CITY_COUNT):\n",
" Route.append(particles[0].get_data(j))\n",
" return Route\n",
"Route= checking_city()\n",
"Route"
]
},
{
"cell_type": "code",
"execution_count": 224,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"def decoding(Route):\n",
" name = 0\n",
" id_ = 0\n",
" name = []\n",
" for i in range(len(Route)):\n",
" name = Route[i]\n",
" print(Data5.iloc[name][3])\n",
" id_= Route[i]\n",
" print(Data3.iloc[id_][1])\n",
" i+=1\n",
" return "
]
},
{
"cell_type": "code",
"execution_count": 225,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bukit Pahoda\n",
"Pakkodian\n",
"Pantai BUL BUL\n",
"Water Park Tambunan\n",
"BUKIT travel Gibeon\n",
"Bukit Senyum\n",
"Taman Eden 100 Tobasa\n"
]
}
],
"source": [
"decoding(Route)"
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment