Lessons taught; Lessons learnt

Maths, teaching and beyond.

Clustering and seating plans

with 2 comments

For the last few days, I've been diving into Processing -- basically an integrated Java wrapper which makes it easy to create simple graphical visualisations (see here for some beautiful examples). Coming from Python, I particularly like not being forced not to write the 500 pages of OO wrapping that turned me off Java in the first place a few years ago.

My first Processing visualisation demonstrates how seating plans degrade over time!

From mixed to clumped

Imagine you have a square array of seats, and a group of boys and girls sit in them, alternately boy then girl. If we highlight one of the sexes we will get a checkerboard pattern.

Now imagine that boys like to have more boys than girls around them (and vice versa for girls). To try and make everyone happy, we implement the following scheme:

  • Identify at random two people who aren't happy with their seat.
  • Swap them.
  • Repeat until everyone's happy.

If we repeat this procedure thousands of times, what will happen to the layout? Click below to find out:

Sorry, the visualisation could not be started.

Clicking again will restart the procedure.

You've probably noticed that I've wrapped left-right and top-bottom... which does move it away a little from the classroom context! This was basically to make the calculations easier.

Here are some examples of what happens if you let this run for a while:

Each frame of these animations represents 2000 swaps, and each animation covers 50000. You can see that there are similar phases in each one: a quick 'clumping', and then a much slower phase where the boundaries settle down into long straight/diagonal lines.

Notes and Extensions

There are many ways to push this visualisation further -- we could change the number of types (English, Welsh, Scottish?); change the 'happiness threshold' (which is currently 5 out of the 8 neighbours); perhaps even have different thresholds for each group. You find really interesting behaviour as you change the threshold -- too high, for example, and the pattern doesn't settle down because there are too many unhappy people.

If you'd like to use my visualisation as a starting point to explore these extensions, then the source is here: clump2.pde. Have fun!

Related Posts (automatically generated)

  1. Clumping and clustering
  2. Geogebra 3.2 beta: Now with animation
  3. Visualisation: Rotating polygons

Written by Jon Ingram

April 10th, 2009 at 6:07 pm

2 Responses to 'Clustering and seating plans'

Subscribe to comments with RSS or TrackBack to 'Clustering and seating plans'.

  1. [...] Clustering and seating plans [...]

  2. Oh NO! Just sent you a mail asking if you knew a way how to embed processing sketches in WP. I guess the above post is the answer… Your site is really outstanding, I hope you will tell me more about the technique behind the WP stuff. Go on with your work. I still dont have an approach to math, but this might change now.

    peterkaosa

    6 May 09 at 9:19 am

Leave a Reply