Skip to content

Instantly share code, notes, and snippets.

@Vchekryzhov
Created September 19, 2018 18:36
Show Gist options
  • Save Vchekryzhov/a015da964b4ad587cf83311b71409570 to your computer and use it in GitHub Desktop.
Save Vchekryzhov/a015da964b4ad587cf83311b71409570 to your computer and use it in GitHub Desktop.
laba sokolov
<script>
var points = [];
function generatePoints(){
for(var i =0; i< 100; i++)
points.push({
'x': parseInt(Math.random() * 100),
'y': parseInt(Math.random() * 100),
});
}
generatePoints()
console.log(points)
var potentials = [];
points.forEach((p)=>{
console.log(p);
var potential = 0;
var sum =0
points.forEach((p2)=>{
if (p2 != p){
sum += Math.exp(-0.1*Math.sqrt((Math.abs(Math.pow((p['x']-p2['x']),2) + Math.pow((p['y']-p2['y']),2) ) )))
}
})
potential = sum;
potentials.push(potential)
})
console.log(potentials)
var max = potentials[0];
var index = 0;
potentials.forEach((pot,i)=>{
if (max < pot){
max = pot;
index = i;
}
})
console.log(index,points[index])
var potentials2 = [];
potentials.forEach((p,i)=>{
potentials2.push(p - max * Math.exp(-0.1*Math.sqrt((Math.abs(Math.pow((points[i]['x']-points[index]['x']),2) + Math.pow((points[i]['y']-points[index]['y']),2) )))))
})
console.log(potentials2)
var max2 = potentials[0];
var index2 = 0;
potentials2.forEach((pot,i)=>{
if (max2 < pot){
max2 = pot;
index2 = i;
}
})
console.log(index2,points[index2])
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment