News for hackers. Stuff that matters.
Re:Show HN: Boids Simulation by 14113 on Tuesday March 31, 2015 @06:47PM (#9300422)
Ah, Boids! One of my favorite examples of systems that can be "embarassingly parallel". I managed to write (with very little optimisation - not even using quadtrees to optimise neighbour lookup) a GPU accelerated version about a year ago that managed to stay above 30fps even up to about 5000 individual agents.

It also hammered home the problem of device/host memory reigions which you've got to deal with when doing GPU programming. I found that other, simpler, systems didn't manage to get as much speedup as Boids did, as transferring data, not computation, was where they bottlenecked. With Boids, by contrast, I could keep everything (computation, and rendering) on the GPU, and never even have to touch the CPU, aside from calling various CUDA and OpenCL functions.

Re:Show HN: Boids Simulation by M8 on Wednesday April 01, 2015 @07:02AM (#9302767)
Can you really call them agents if they are calculated on GPU? I always assumed that using GPU would reduce them to particles (colour + position). They were probably stored in a huge array as values rather than a linked list of objects?
Re:Show HN: Boids Simulation by 14113 on Wednesday April 01, 2015 @10:19AM (#9303725)
They were stored as values in a huge array. I fail, however, to see how that causes them to be distinguished from "agents"? Surely they still fulfil the properties required to be "agents" in an abstract sense? They gather information about their environment (the positions of other agents), deliberate (work out where to move to next), and then act (change their position). That process is entirely abstracted from the storage method of the agent data itself!
Re:Show HN: Boids Simulation by M8 on Wednesday April 01, 2015 @12:25PM (#9304768)
What would happen if you need to add more properties/state to agents?
Re:Show HN: Boids Simulation by 14113 on Thursday April 02, 2015 @08:04AM (#9310095)
You'd have to change the program? Each agent was stored as a C structure - so adding further information to that would be trivial.
Re:Show HN: Boids Simulation by postnihilism on Tuesday March 31, 2015 @04:09PM (#9299521)
I was inspired by this to create my own a few months ago. It uses a quadtree to optimize nearest neighbor lookup to ideally reduce complexity from n^2 to nlogn on each tick. http://jrhdoty.github.io/SwarmJS/
Re:Show HN: Boids Simulation by anoop-elias on Tuesday March 31, 2015 @04:18PM (#9299588)
Yes, looks beautiful. Quite similar, I guess.

I had run in to some performance issues, the initial few ticks are quiet slow even now, esp. on a phone.

This one uses a kdtree instead. I'll have to try quadtree and benchmark. Thanks.

Re:Show HN: Boids Simulation by repsilat on Tuesday March 31, 2015 @06:29PM (#9300350)
The best data structure to use depends a lot on what you're actually doing with your neighbours.

If what you actually want to do is to have each boid be affected by each boid in a fixed-size neighbourhood, the best acceleration structure is actually just fixed-size bins.

Re:Show HN: Boids Simulation by anoopelias on Tuesday March 31, 2015 @09:52PM (#9301084)
Where can I read more about fixed-size bins?
Re:Show HN: Boids Simulation by repsilat on Wednesday April 01, 2015 @09:02AM (#9303179)
I mean if your world is 1024 by 768, and a boid is affected by all other boids within 64 pixels of it, you should just break the world up into 16 by 12 bins, each representing a 64 by 64 pixel block. Each of these blocks is just a growable array.

All of a boid's "close enough" neighbours will be found in the 8-neighbourhood of its block.

Re:Show HN: Boids Simulation by anoopelias on Wednesday April 01, 2015 @10:07AM (#9303615)
Yep got it. Thanks.

Feels a good idea. Have to try it to know for sure.

Re:Show HN: Boids Simulation by repsilat on Wednesday April 01, 2015 @11:42AM (#9304453)
One important thing to note while implementing it is that you have to be a little smart about how you move boids from one bin to another. You don't want to get quadratic behaviour because you're removing individual boids from the middle of lists again and again, you don't want to accidentally move a boid twice in an iteration and so on. The best way to do this is to make a list of "boids to add" and "boids to delete" for each bin, which you build as you call "move", and which you apply after you've done your movement calculations on all of your boids.
Re:Show HN: Boids Simulation by anoopelias on Thursday April 02, 2015 @02:52AM (#9309016)
There are a few ways to be clever on going about it. One as you mentioned is to do a two phase scan one to move and one to correct the bins.

Also instead of a square shaped range you can get a hexagonal range by dividing corner boxes diagonally to two and then checking which half of square the boid is. :)

Re:Show HN: Boids Simulation by maaaats on Tuesday March 31, 2015 @05:51PM (#9300142)
I think almost every AI-guy have tried making a boids simulation. They are such a good way to show emergent behavior from very simple rules.

I'm a TA for an AI-course at my uni, and this semester my students had to program a boids simulation for the first project. In addition to what's shown here, the boids also had to avoid obstacles and flee from predators. I think the students liked it, it's very rewarding to code and actually see the result.

The students also had to implement sliders, for how much cohesion, separation and alignment is weighted. It's pretty fun to change them and watch the behavior of the boids change.

Re:Show HN: Boids Simulation by avyfain on Tuesday March 31, 2015 @07:16PM (#9300533)
Is the course content available online?
Re:Show HN: Boids Simulation by cporios on Tuesday March 31, 2015 @03:12PM (#9299124)
Nice! I've done something similar in the past: http://static.mysti.co.in/boids/

Source: https://github.com/tech-no-crat/boids

Re:Show HN: Boids Simulation by nacs on Tuesday March 31, 2015 @04:19PM (#9299595)
If you use 'requestAnimationFrame()' instead of a 'setInterval()' for triggering your update method, your animation will perform a lot smoother:

https://developer.mozilla.org/en-US/docs/Web/API/window/requ...

Re:Show HN: Boids Simulation by anoop-elias on Tuesday March 31, 2015 @04:33PM (#9299686)
Have a look at this one, highly recommended, https://github.com/hughsk/ticker
Re:Show HN: Boids Simulation by akilism on Tuesday March 31, 2015 @05:08PM (#9299905)
Khan Academy has a good Natural Simulations in JS tract. https://www.khanacademy.org/computing/computer-programming/p...

It uses processing.js when I worked through it I just ended up implementing everything with canvas and making my own versions of the processing specific classes and functions needed.

Re:Show HN: Boids Simulation by stared on Tuesday March 31, 2015 @03:33PM (#9299259)
For ones want to dive deeper into collective motion and self-propelled particles: http://arxiv.org/abs/1010.5017
Re:Show HN: Boids Simulation by timdaub on Tuesday March 31, 2015 @03:14PM (#9299141)
If you're into this kind of artificial life simulation, I can recommend you watching this talk: http://developertalks.tumblr.com/post/109998034809/simon-swa...
Re:Show HN: Boids Simulation by anoop-elias on Tuesday March 31, 2015 @03:28PM (#9299219)
Excellent link. Thank you.

I haven't looked deep in to these kind of simulations in general. Inspiration came from the Princeton Algortihms course in coursera.org. There is this sample problem, http://www.cs.princeton.edu/courses/archive/spr10/cos226/ass...

Re:Show HN: Boids Simulation by fersaysrelax on Tuesday March 31, 2015 @04:15PM (#9299567)
If you enjoy this kind of simulations, this is a good intro book. http://natureofcode.com/
Re:Show HN: Boids Simulation by bhouston on Tuesday March 31, 2015 @03:43PM (#9299336)
Somewhat related:

ThreeJS GPU boids simulation http://threejs.org/examples/#webgl_gpgpu_birds

Re:Show HN: Boids Simulation by fudged71 on Tuesday March 31, 2015 @09:42PM (#9301061)
Okay now attach this code to drones
Re:Show HN: Boids Simulation by efkv on Tuesday March 31, 2015 @09:20PM (#9300988)
Like everyone else it seems, I also wrote a 3D flocking simulation a while back: http://edkelleyv.com/Flocking/

Source: https://github.com/ekelleyv/Flocking

Re:Show HN: Boids Simulation by luddypants on Tuesday March 31, 2015 @07:07PM (#9300498)
I don't think the fps calculation is quite accurate, I was getting close to 60 fps and seeing lots of jerks.
Re:Show HN: Boids Simulation by anoopelias on Thursday April 02, 2015 @02:55AM (#9309024)
I will have a look.

The value initializes as 60, so it will show as 60 until it gets updated for the first time. Would that be what you are talking about?

The initial few seconds performance is not at optimum so that is a problem. Are you on a laptop or a mobile/tablet device?