Friday, January 1, 2010

Snowbirding with Prolog

This time of year, when it's so cold in Wyoming I'm tempted to snowbird and wait out the chilly months somewhere toasty. Of course, many places have warm weather, so how do I choose one and how do I get there? I could drive to Tucson but that means spending two days on the road (losing billable hours), buying meals, getting a hotel, etc. I could fly to Tucson, but then I have to rent a car. Vegas has cheap flights and rental cars, maybe that's more economical. There are so many variations and each possible choice can affect other choices.

I've been learning Prolog and this seemed like a great chance to use it. I've coded up a simple snowbirding model and am pretty pleased with the results. It's really easy to add new cities and new possibilities. For instance I initially had rental cars as the only local transportation option after flying to a city. With a few lines I added options for Zip Car and public transit. Running the program instantly accounted for those two new possibilities in cities where they applied.

Here's a sample of the first 10 snowbirding options produced by the program:

1361.28 st_george [drive, drive]
1853.84 vegas [drive, drive]
2218.51 mesquite [drive, drive]
3441.47 vegas [taxi, fly, buses, fly]
3836.91 amarillo [drive, drive]
3861.47 vegas [park(long), fly, buses, fly]
4341.47 vegas [park(airport), fly, buses, fly]
5000.83 tucson [drive, drive]
5177.63 tucson [taxi, fly, buses, fly]
5597.63 tucson [park(long), fly, buses, fly]

The first line tells us that driving to St. George, UT is the least expensive option at $1,361.28 per year (housing and food costs are not included yet). The 10th most expensive option is using long-term parking at the Denver airport, flying to Tucson, using public transit while I'm there and flying home. That option runs about $5,600 per year. All these calculations are for a 3 month stay for a family of 6.

It seems like there are lots of economic decisions which could be modeled this way and for which Prolog is a natural fit. The full Prolog code is available and included below. I'm new to the language, so I gladly welcome any suggestions for improvement.

1 comments:

JJ Hendricks said...

I am interested to see the results with the housing added in. Over 3 months housing would be a significant part of a snowbirding trip.

I imagine St. George would be cheap but would it be free like Tucson? Would renting a house for 3 months be the cheapest or staying in an extended stay hotel?

Your final results will be very interesting.