Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>About SourceCode</strong></p> <p>At first, I might advise you to change the definition of a cities coordinates to class City, and, as you're cities are pre-defined, you might want to 'export' it in external file and load it at file beggining. For example,</p> <pre><code>public class City{ public double North; public double West; public String Name; public double getDistanceToCity(City target){ double R = 6371; double dLat = Math.toRadians((target.North-this.North)); double dLon = Math.toRadians((target.West-this.West)); double a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(Math.toRadians(this.North)) * Math.cos(Math.toRadians(this.West)) * Math.sin(dLon/2) * Math.sin(dLon/2); double d = R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); return d;}} </code></pre> <p>Then, for example, after reading your file into "ArrayList Cities" you'll bild your matrix by:</p> <pre><code>double[][] distances = new double[Cities.size()][Cities.size()]; int i=0; int j=0; for(City start:Cities){ for(City end:Cities){ distances[i][j]=start.getDistanceToCity(end); j++;} i++;} </code></pre> <p>And get the same matrix. In this case, you'll can change input data size, for example testing Correctness of your algo with 10 cities, and after all works fine run with 80. Besides, in this case you'll see by yourself hardness of this problem - simply run it on 40 and 41 city...</p> <p><strong>Next, about algo...</strong></p> <p>This is NP-hard problem, so your permutations will work VERY long time. I'll suggest Held–Karp algorithm, which is much faster but pretty hard for realization and needs a lot of memory. ( For example, suggested method if (n*n*2^n), which is 10^27 for n=80, and permutations are n!, which 10^121 for n=80 - i mean operations required for solving task).</p> <p>In any way, afaic the best exact solution for now is linear programming (can't remember exact method, but...). May you'll find some algo considering to use graph methods.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload