title: How to implement a clustering process, using a genetic algorithm in python?
body: <p>I'm a novice in python coding.
  I have a question regarding clustering using genetic algorithm in python.</p>
  
  <p>I would like to cluster the station based on not only distance but also the other index of the cluster. I want to maximize the total index of all clusters.<br>
  I have 900 bike stations GPS coordinate data. </p>
  
  <p><a href="https://i.stack.imgur.com/83SIp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/83SIp.png" alt="900 number of bike stations in Seoul"></a></p>
  
  <p>I have already created a distance matrix of [all stations] x [all stations]. Units are in [km].</p>
  
  <h2>Basic idea - draw random circles of clusters.</h2>
  
  <p>If I want to cluster in 50 clusters, then the code should generate 50 different circles of clusters. The station inside the circle<sub><strong><em>n</em></strong></sub>, it will be labeled in cluster<sub><strong><em>n</em></strong></sub>. The example is shown in the image below</p>
  
  <p><a href="https://i.stack.imgur.com/xqDUG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xqDUG.png" alt="basic idea to generate circle"></a></p>
  
  <p>There are some restrictions to generate circles,</p>
  
  <ol>
  <li>the cluster circles should not be overlapping.<br> - to satisfy this condition, distance between two center of the circles should be larger than the sum of radii. ( but I don't know how to code with python )</li>
  <li>the radius of circle limits in size. ( It should be found in hyperparameter, but minimum of 1 km and maximum of 4 km is the first candidate )</li>
  <li>While clustering, stations that cannot go into the circle cluster will occur. For this case we should allocate these stations to the nearest circle based on the distance. </li>
  </ol>
  
  <p>After we successfully generate the random not overlapping 50 cluster circles, I want to find the best combination of the circles which can maximize my own index. </p>
  
  <h2>Genetic algorithm</h2>
  
  <p><strong><code>gene</code></strong> : <code>{ x1, y1, r1, x2, y2, r2, x3, y3, r3, ... x50, y50, r50 }</code><br>
  <strong><code>[ xn, yn ]</code></strong> is the center of the circle and <strong><code>rn</code></strong> is the radius of the circle.</p>
  
  <p>The center of the cluster should be a station rather than a point within the map. Meaning that each 50 clusters center point should be a station.</p>
  
  <p><strong><code>rn</code></strong> generate randomly within the boundary.</p>
  
  <p>For example, if I want to make a cluster <code>1km &lt; rn &lt; 4km</code>, than <strong><code>r</code></strong> can be generated randomly in a 100 [m] interval.</p>
  
  <p>So, <strong><code>r</code></strong> can get a values like in <code>{ 1.1km, 1.2km, ... 3.9km, 4km }</code></p>
  
  <p>Division point will be:  </p>
  
  <pre><code>{ x1, y1, r1,/ x2, y2, r2,/ x3, y3, r3,/ ... / x50, y50, r50 } 
  </code></pre>
  
  <p>Fitness function is my own index of the cluster that I mentioned.</p>
  
  <p>I already have a code to calculate the index. If stations are labeled by the cluster number, then I can calculate it with a pre-built code.</p>
  
  <p>Labeling form should be like csv file below:  </p>
  
  <p><a href="https://i.stack.imgur.com/sBT1o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sBT1o.png" alt="cluster labeling form"></a></p>
  
  <p>Sorry for the long explanation, and thank you!!!! </p>