|
|
@ -260,26 +260,29 @@ function calculateDistance(lat1, lon1, lat2, lon2) {
|
|
|
|
return d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getRandomInt(min, max) {
|
|
|
|
|
|
|
|
min = Math.ceil(min);
|
|
|
|
|
|
|
|
max = Math.floor(max);
|
|
|
|
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function shuffle(array, fix_start_point = true, fix_end_point = true) {
|
|
|
|
function shuffle(array, fix_start_point = true, fix_end_point = true) {
|
|
|
|
let currentIndex = array.length;
|
|
|
|
let currentIndex = array.length - 1;
|
|
|
|
if (fix_end_point) {
|
|
|
|
if (fix_end_point) {
|
|
|
|
currentIndex = array.length - 1;
|
|
|
|
currentIndex = array.length - 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let start_index = 0;
|
|
|
|
let start_index = 0;
|
|
|
|
if (fix_start_point) {
|
|
|
|
if (fix_start_point) {
|
|
|
|
start_index = 1;
|
|
|
|
start_index = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// While there remain elements to shuffle...
|
|
|
|
while (currentIndex !== start_index) {
|
|
|
|
while (currentIndex != start_index) {
|
|
|
|
let right = currentIndex;
|
|
|
|
|
|
|
|
let left = getRandomInt(start_index, currentIndex);
|
|
|
|
// Pick a remaining element...
|
|
|
|
|
|
|
|
let randomIndex = Math.floor(Math.random() * currentIndex);
|
|
|
|
|
|
|
|
currentIndex--;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// And swap it with the current element.
|
|
|
|
// And swap it with the current element.
|
|
|
|
[array[currentIndex], array[randomIndex]] = [
|
|
|
|
[array[left], array[right]] = [
|
|
|
|
array[randomIndex], array[currentIndex]
|
|
|
|
array[right], array[left]
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
currentIndex--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -351,6 +354,7 @@ function recalculateWaypoints(waypoints) {
|
|
|
|
// Три точки, старт, стоп и промежуточная выводим без расчета
|
|
|
|
// Три точки, старт, стоп и промежуточная выводим без расчета
|
|
|
|
showTravelPoints([waypoints[0].id, waypoints[1].id, waypoints[2].id]);
|
|
|
|
showTravelPoints([waypoints[0].id, waypoints[1].id, waypoints[2].id]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// применяем лучшие поиск из 200.000 лучших вариантов (9! = 362880, берем такого порядка число чтобы не грузить браузер расчетами)
|
|
|
|
// применяем лучшие поиск из 200.000 лучших вариантов (9! = 362880, берем такого порядка число чтобы не грузить браузер расчетами)
|
|
|
|
let path_indexes = stochasticPathFind(waypoints, true, true);
|
|
|
|
let path_indexes = stochasticPathFind(waypoints, true, true);
|
|
|
|
showTravelPoints(path_indexes);
|
|
|
|
showTravelPoints(path_indexes);
|
|
|
@ -360,7 +364,6 @@ function recalculateWaypoints(waypoints) {
|
|
|
|
|
|
|
|
|
|
|
|
$(() => {
|
|
|
|
$(() => {
|
|
|
|
waypoints.loadData();
|
|
|
|
waypoints.loadData();
|
|
|
|
|
|
|
|
|
|
|
|
initMap();
|
|
|
|
initMap();
|
|
|
|
initRegionDropDown();
|
|
|
|
initRegionDropDown();
|
|
|
|
initRecalculateWaypointsButton();
|
|
|
|
initRecalculateWaypointsButton();
|
|
|
|