Skip to content

Commit

Permalink
remove best polylines from model
Browse files Browse the repository at this point in the history
  • Loading branch information
afourmy committed Feb 23, 2018
1 parent c73c01d commit a3e2836
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ i.e the city <b>k</b> which minimizes <b>d(i, k) + d(k, j) - d(i, j)</b> with <

<pre>
- Start from a random city.
- Find the city <b>k</b> farthest from any node in the tour (i.e the city <b>k</b> which maximizes <b>d(c, k)</b> with <b>c</b> a city in the partial tour), and insert <b>k</b> where it causes the smallest increase
in length (by minimizing <b>d(i, k) + d(k, j) - d(i, j)</b>, with <b>(i, j)</b> an edge in the partial tour).
- Find the city <b>k</b> farthest from any node in the tour (i.e the city <b>k</b> which maximizes
<b>d(c, k)</b> with <b>c</b> a city in the partial tour), and insert <b>k</b> where it causes the smallest increase in length (by minimizing <b>d(i, k) + d(k, j) - d(i, j)</b>, with <b>(i, j)</b> an edge
in the partial tour).
- Repeat until every city has been visited.
</pre>

Expand Down
40 changes: 19 additions & 21 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
var currentAlgorithm = undefined;

function tourConstruction(algorithm){
clearLines(polylines);
clearLines();
if (window.optimizationTimer) {
clearTimeout(window.optimizationTimer);
window.optimizationTimer = 0;
Expand All @@ -174,7 +174,7 @@

var generationNumber = 0;
function geneticAlgorithm() {
clearLines(polylines);
clearLines();
// we cannot use setInterval as the timer depends on the slider
// we have to use setTimeout for the speed to vary through time
function timeout() {
Expand Down Expand Up @@ -202,8 +202,6 @@

// lines of the path displayed
var polylines = [];
// lines of the best path ever found (for genetic algorithm)
var bestPolylines = [];

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down Expand Up @@ -315,15 +313,15 @@
{% endif %}
}

// Function that clears an array made of lines
// Function that clears all lines

function clearLines(lines){
for (i = 0; i < lines.length; i++) {
function clearLines(){
for (i = 0; i < polylines.length; i++) {
{% if view == '2D' %}
map.removeLayer(lines[i]);
map.removeLayer(polylines[i]);
{% else %}
try {
lines[i].destroy();
polylines[i].destroy();
}
catch(err) {};
{% endif %}
Expand All @@ -341,14 +339,14 @@
$("#score").text(Math.round(Number(lengths[j])));
}
var color = '#0000ff';
clearLines(polylines);
clearLines();
for (i = 0; i < paths[j].length - 1; i++) {

var source_lat = paths[j][i][0];
source_lon = paths[j][i][1];
destination_lat = paths[j][i+1][0];
destination_lon = paths[j][i+1][1];

{% if view == '2D' %}
var pointA = new L.LatLng(source_lat, source_lon);
var pointB = new L.LatLng(destination_lat, destination_lon);
Expand All @@ -363,15 +361,15 @@

polyline.addTo(map);
polylines.push(polyline);
{% else %}
var polygonSD = WE.polygon(
[[source_lat, source_lon], [destination_lat, destination_lon],
[source_lat, source_lon]], {color: color,opacity: 20}).addTo(earth);
var polygonDS = WE.polygon(
[[destination_lat, destination_lon], [source_lat, source_lon],
[destination_lat, destination_lon]], {color: color,opacity: 20}).addTo(earth);
polylines.push(polygonSD, polygonDS)
{% endif %}
{% else %}
var polygonSD = WE.polygon(
[[source_lat, source_lon], [destination_lat, destination_lon],
[source_lat, source_lon]], {color: color,opacity: 20}).addTo(earth);
var polygonDS = WE.polygon(
[[destination_lat, destination_lon], [source_lat, source_lon],
[destination_lat, destination_lon]], {color: color,opacity: 20}).addTo(earth);
polylines.push(polygonSD, polygonDS)
{% endif %}
}
var speed = $('#base_slider').val();
await sleep(50000/speed);
Expand Down

0 comments on commit a3e2836

Please sign in to comment.