function range(low, high) {
var ret = [];
for(var i=low; i e) {
return arr.slice(s, arr.length).concat(arr.slice(0, e));
} else {
return arr.slice(s, e);
}
}
function swap(arr, p1, p2) {
var tmp = arr[p1];
arr[p1] = arr[p2];
arr[p2] = tmp;
}
function randint(l, u) {
return Math.floor((Math.random()*(u-l))+l);
}
function angle(pt1, pt2, pt3) {
// pt2 is vertex
// c^2 = a^2 + b^2 - 2ab cos(t)
// acos((c^2 - a^2 - b^2)/(-2ab)) = t
var a = distance(pt2, pt1);
var b = distance(pt2, pt3);
var c = distance(pt1, pt3);
var a2 = Math.pow(a, 2);
var b2 = Math.pow(b, 2);
var c2 = Math.pow(c, 2);
var ratio = (c2-a2-b2)/(-2*a*b);
var bounded = Math.max(-1, Math.min(1, ratio));
return Math.acos(bounded);
}
function distance(pt1, pt2) {
return Math.sqrt(Math.pow(pt1[0]-pt2[0], 2)+Math.pow(pt1[1]-pt2[1], 2))
}
function cumulate(arr, ignore, numer) {
ignore = typeof ignore !== 'undefined' || ignore == null ? ignore : -1;
var totLen = 0;
for(var j=0; j 0 ? arr[j] : 1
if(typeof numer !== 'undefined') {
cumulate.push(tot+((numer/amt)/totLen));
} else {
cumulate.push(tot+((amt)/totLen));
}
} else {
cumulate.push(tot);
}
tot = cumulate[cumulate.length-1];
}
cumulate.push(0);
return cumulate;
}
function pdistr(cumulate) {
var rp = Math.random();
for(var i=0; i xmax) xmax = nodes[i][0];
if(nodes[i][0] < xmax) xmin = nodes[i][0];
if(nodes[i][1] > ymax) ymax = nodes[i][1];
if(nodes[i][1] < ymax) ymin = nodes[i][1];
}
for(var i=0; i\u25CF ' + this.series.name + ': ' + formatNum(this.y) + '
';
}
},
legend: {
enabled: false
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Best',
yAxis: 0,
xAxis: 0,
data: [],
color: '#ff3300',
marker: {
enabled: false
}
}]
};
if(selections[suffix]['ymax'] > 0) {
chartOpts.yAxis[0].max = selections[suffix]['ymax'];
}
$('#tsp-progress-container-' + suffix).highcharts(chartOpts);
$('#tsp-convergence-container-' + suffix).highcharts({
chart: {
backgroundColor: null
},
title: {
text: '',
},
xAxis: [{
lineWidth: 0,
lineColor: 'transparent',
gridLineColor: 'transparent',
minorGridLineWidth: 0,
minorGridLineColor: 'transparent',
minorTickLength: 0,
tickLength: 0,
labels: {
enabled: false
},
min: 0,
max: nodes.length,
visible: false,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
}],
yAxis: [{
reversed: true,
gridLineColor: 'transparent',
min: 0,
max: 10,
visible: false,
title: {
text: null
},
labels: {
enabled: false
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
}],
plotOptions: {
series: {
stickyTracking: false
}
},
tooltip: {
pointFormatter: function() {
return '\u25CF ' + this.series.name + ': ' + formatNum(this.y) + '
';
}
},
legend: {
enabled: false
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Convergence',
type: 'column',
groupPadding: 0,
pointPadding: 0,
borderWidth: 0,
data: [],
color: 'rgba(196, 196, 196, 0.5)',
}]
});
TSP[suffix].ga = new GA({
id: suffix,
init: $('#inittype-' + suffix).val(),
size: $('#popsize-' + suffix).val(),
nodes: nodes,
muttype: $('#muttype-' + suffix).val(),
mutrate: $('#mutrate-' + suffix).val(),
crosstype: $('#crosstype-' + suffix).val(),
crossrate: $('#crossrate-' + suffix).val(),
genDelay: ($('#graph-on-' + suffix).bootstrapSwitch('state') && $('#draw-edges-on-' + suffix).bootstrapSwitch('state') ? 0 : 1000),
showGraph: $('#graph-on-' + suffix).bootstrapSwitch('state'),
showProgress: $('#progress-on-' + suffix).bootstrapSwitch('state'),
showConvergence: $('#convergence-on-' + suffix).bootstrapSwitch('state'),
sigma: s[suffix]
});
TSP[suffix].ga.progress = $('#tsp-progress-container-' + suffix).highcharts();
TSP[suffix].ga.convergence = $('#tsp-convergence-container-' + suffix).highcharts();
$('.tsp-progress-graph .tsp-progress').each(function() {
$(this.parentNode).css('height', $(this).height());
});
$('.cgp').hover(function() {
$('.tsp-pause-container', this).animate({'opacity': 1}, 100);
}, function() {
$('.tsp-pause-container', this).animate({'opacity': 0}, 100);
});
$('#tsp-pause-' + suffix).click(function() {
var suf = this.id.replace('tsp-pause-', '');
if(!TSP[suf].ga.done) {
if(TSP[suf].ga.pause) {
TSP[suf].ga.pause = false;
$('.fa', this.parentNode).removeClass('fa-play').addClass('fa-pause').css('transform', 'translate(-50%, -50%)');
} else {
TSP[suf].ga.pause = true;
$('.fa', this.parentNode).removeClass('fa-pause').addClass('fa-play').css('transform', 'translate(-40%, -50%)');
}
} else {
if($('.fa-repeat', this.parentNode).length) {
var that = TSP[suf].ga;
that.repeats++;
that.run(that.runOptions);
$('.fa', this.parentNode).removeClass('fa-repeat').addClass('fa-pause').css('transform', 'translate(-50%, -50%)');
}
}
});
}
function start(suffix, pause) {
var pause = typeof pause !== 'undefined' ? pause : false;
TSP[suffix].ga.run({'maxtimes': $('#maxgen-' + suffix).val(),
'delay': ($('#draw-edges-on-' + suffix).bootstrapSwitch('state') ? 50 : 0),
'pause': pause});
}