Main Content

For Lua Programmers AND for Town Planners

Archive - Originally posted on "The Horse's Mouth" - 2009-08-02 15:49:37 - Graham Ellis

I'm always happy to be able to make multiple use of the same piece of work, and so it is with an example written last week.



READ THIS SIDE ...
if you are a Lua or game programmer

I was asked to provide an exercise during the Lua course that related to game playing - where a series of elements (of different types) move forward at a given time interval, depending of their characteristics, other elements around them, and user entered changes.

Well - there was no way we could write a complete game in just an hour and a half, but we could put something together that would show the structure. The data file that I put together had different towns as its varying data elements, and as new inhabitants moved into the area, and moved away, they were distributed around the towns according to different algorithms for different types of town.

At the start of the application, we set up tables to contain the various operations for each type of town, being careful to ensure that they had the same API so could be used polymorphic ally. We also set up a table for operations common to all towns.

At the start of the game / simulation, the town data was read in and interpreted (taking care to eliminate comment and blank lines and to validate the remaining data) and a table was set up for each town, making use of a metatable for each type, and storing a reference to the specific or general town methods in a table member of a standard name.

To run the simulation, all we then had to do was to call the appropriate methods in a loop (v being the code for each town in turn, 6000 being the number of extra inhabitants per annum (that should REALLY have been a variable!:

-- Get the town's growth proportion
fftt = v:getfact()
-- Save the people at the start of the year
incoming = v.pop
-- Add in the newcomers
v:addpeeps(6000 * fftt / totfact)
-- Take away leavers
v:wastage()
-- Adjust house prices for next year
-- based on supply and demand
outgoing = v.pop
v:change_house_prices(incoming, outgoing)


Full source code and data links:
An answer to the town simulation exercise
Town Specification data
Main Simulation Program
Data (object) type definition

We run Lua Programming Courses at our Melksham, Wiltshire training centre - or on your site at almost any location in the world. I am typing this entry at the Airport at Mexico City, while awaiting my ongoing flight ... and it will be posted when I get back home.



READ THIS SIDE ...
if you are a local politician or transport planner

Lisa has often commented to me that I shoulds run something like Sim-City on North and West Wiltshire to see how the populations would changed in the future with and without a decent rail service, and with and without road improvements. Alas, there are too many things I don't know and a complex setup to doing that, but it did set a seed of thought in my mind when I was looking for data for a simulation exercise last week. Now I will be the first to admit that my model is rudimentary, many factors are missing, and that my data is suspect but never the less, this simulation (run a number of times with changed data) gives a very interesting insight into the rise and fall of towns and cities.

You'll see in tables below that I have printed out some of the initial data for each town, including whether it is scheduled for growth (so there is unlikely to be as much upward pressure on house prices there); the data also includes "trains per hour" - not listed but available in th e associated data file. Newcomers go to where the house prices are good, and where there is excellent access - they don't actually follow government dictat, but you'll see how the government dictat pushes prices up in places like Devizes and Malmesbury, which indirectly limits the growth.

Looking forward 20 years, what do we see?

Amongst the growth towns, Chippenham and Westbury have grown 80%. Trowbridge has grown nearly 60%, and Warminster just over 60%. Melksham's growth is lower - a shade under 50%, and Corsham's is even lower at just over 40%

Looking at the towns where substantial growth was not encouraged in my model, you'll see 8% growth at Bradford-on-Avon and 3% growth at Calne. There's actually a slight shrinkage in Devizes and Malmesbury. That wouldn't mean a lower housing stock - the trend of reducing inhabitants per dwelling is set to carry on into the future, I understand.

In the growth towns, house prices have all risen - nearly 50% at both Westbury and Trowbridge (where they started very low) and nearly 30% at Chippeham. At Melksham, they're up just 22% and at Corsham it's very low 15%

Looking at the stable towns, Malmesbury house prices have risen by nearly 30%, Devizes by nearly 40%, Calne by 58% and Bradford-on-Avon by an astonishing 70%+

In order to test the behaviour of my model, I also ran it with various different parameters - changing the specification of towns, adding in and taking out rail services, changing the net inflow and annual move-away factors, and running for a longer period. The results were fascinating ... but I have chosen to stop at the 20 years of the RSS for what I comment on / publish here

More conclusions below the data ...



Here is the original data and simulation results from this program / test

          Chippenham -  34000 -   FAST -  150000
Melksham - 22000 - FAST - 120000
Trowbridge - 28000 - FAST - 120000
Westbury - 11000 - FAST - 130000
Dilton Marsh - 2000 - FAST - 140000
Warminster - 17000 - FAST - 130000
Devizes - 11000 - STABLE - 150000
Calne - 12000 - STABLE - 120000
Corsham - 12000 - FAST - 130000
Bradford-o-A - 9000 - STABLE - 160000
Malmesbury - 4000 - STABLE - 180000

Progression of population every 4 years
2007 2011 2015 2019 2023 2027
Devizes 11000 11009 10975 10902 10793 10653
Warminster 17000 19184 21338 23445 25499 27496
Chippenham 34000 38017 42023 45976 49852 53635
Westbury 11000 12982 14841 16601 18279 19883
Trowbridge 28000 33032 37753 42225 46487 50563
Calne 12000 12263 12411 12466 12446 12366
Dilton Marsh 2000 2169 2346 2527 2708 2888
Bradford-o-A 9000 9355 9570 9683 9718 9693
Malmesbury 4000 3955 3905 3849 3786 3717
Melksham 22000 24154 26357 28572 30772 32942
Corsham 12000 12897 13849 14831 15826 16822

Progression of house prices every 4 years
Devizes 150000 162628 174987 186935 198395 209329
Warminster 130000 141094 150908 159429 166704 172805
Chippenham 150000 161292 171437 180334 187982 194423
Westbury 130000 147625 162328 174624 184870 193332
Trowbridge 120000 136211 149742 161061 170494 178286
Calne 120000 135544 150205 164004 176977 189164
Dilton Marsh 140000 146017 151823 157163 161897 165961
Bradford-o-A 160000 186873 211494 234238 255348 274997
Malmesbury 180000 190626 201256 211715 221894 231720
Melksham 120000 126676 132903 138502 143396 147559
Corsham 130000 134318 138646 142721 146390 149567


Conclusions. Once again, I need to stress that this is just a very simple mathematic model with unverified 'best guess' inputs so you should not read anything into the specific results. But it certainly does provide food for thought.

Did you notice how the two growth towns which have no (or no effective) rail service - that's Corsham and Melksham - fail to grow in spite of the encouragement offered. And that Bradford-on-Avon, not marked for major growth, does grow in spite of the lack of official encouragement, with the highest price rises in the chart.

Looking carefully, you'll see that Bradford-on-Avon has actually hit a ceiling and has started to loose population, and that growth at Corsham and Melksham has accelerated towards the end of the period, whereas at Chippenham and Trowbridge it is tailing off a bit. People are being encouraged to move to Melksham and Corsham due to the share low prices of housing there, and I suspect this would in turn be leading to a population that is actually less affluent / more deprived in what are basically sink towns.

When you think about it ... many of these factors are natural, and I can't say for sure whether the results seem high or low ... which probably means that, for all the guesswork involved, my model may be remarkably close to the mark.