Iran Next?

March 29th, 2012

Tension between Israel & the US and Iran has been growing the past few months. The economic sanctions are really starting to hurt Iran, but they are also hurting the West with higher oil prices. Blocking Iran’s oil exports is a big sacrifice in today’s tight oil market.

Then, there is the arrival of the third US aircraft carrier in the Middle East in the next week. It’s highly unusual for there to be more than a single aircraft carrier in any location.

Locations of US aircraft carriers and amphibious warfare ships

Obama has been busy the last few weeks making sure allies such as the UK and France are ready to release oil from their strategic petroleum reserves. This is supposedly because he wants to suppress high gas prices to help the economic recovery. But as I noted in my previous post, this is a spectacularly bad idea. Maybe he just wants them to be ready to pour out oil from the strategic reserves on short notice for a coming actual supply shortfall.

Today, the disturbing information that Israel’s army is cancelling leaves for Passover hit the newswires. The official explanation is problems with Gaza. However, cancelling leaves during the most important Jewish religious holiday sounds like overkill for a few under-equipped armed gangs in Gaza.

Edit: Another piece of information emerged today that Israel has gotten permission to use airfields in Azerbaijan for a strike against Iran. That helps Israel overcome the range problem and avoid having to perform in-air refuelling to reach Iran and fly back again. Also a great place to base search-and-rescue missions from.

Now, there are many reasons why a strike on Iran would be devastatingly dumb, and I think the odds are still against such a strike in the immediate future. But I have been surprised in the past…

Peeing Your Pants Just to Stay Warm

March 15th, 2012

The US and Great Britain are back at it, releasing their strategic oil reserves “in an effort to prevent high fuel prices derailing economic growth in an election year”. Last year, they did the same thing while Libya’s oil production was offline. The effect on oil prices lasted for  a whopping two weeks back then. This year’s action is, if possible, even more short-sighted.

Which part of the word strategic is it they don’t understand? Last year, there was at least a war and an actual disruption to oil production to go with the release. Now, unacceptably high prices are simply the new normal. I have seen no reports that the stockpiles were replenished after last year’s drawdown. The strategic oil reserves are sized to cover a complete breakdown of oil supply lines for one to two months. A limited drawdown of the size seen last year could go on for a little more than a year. If we need to use the strategic reserves just to maintain some resemblance of economic growth, you can expect another recession within that timeframe.

And what if there is an actual supply disruption in the future? A war with Iran? Unrest in Nigeria? The stockpiles will already be withered down, making the complete societal collapse that the strategic reserves are supposed to prevent that much closer. Extreme short-term thinking from the people in charge. Selling our future to make the party last a little longer… Their party… And you’re not invited…

OptiMap version 4 is here

January 25th, 2012

New user interface

Hold down shift while pressing reload to make sure the page fully reloads if OptiMap appears broken.

The first thing you’ll notice is a complete makeover of the user interface. The functionality has grown considerably since I first posted OptiMap in 2007, and the controls were scattered randomly around. Now, they are organized into neat little drawers on the left, in the order you are likely to be using them.

There is some new functionality as well. The ‘Edit Route’ section gives you the chance to re-order the trip after it has been computed. Have to visit one client first? No problem, drag to the top. You can also delete stops from the itinerary here.

OptiMap 4 also has a more powerful TSP solver routine. The new solver kicks in when there are more than 15 stops, and produces better and more robust solutions than the old engine. It is guaranteed to perform better than before, and in some hard cases I’ve tested, it improved the solutions by as much as 6-7%. That means that if you spent 8 hours on the road before, you now get home half an hour earlier.

Support for Garmin GPS units is now added as well. Support is experimental, since I only had access to one Garmin device, which did not support routes. I’m interested to hear whether this works on your device if you have a Garmin GPS.

There are some bug fixes as well: When pasting data from Excel spreadsheets into the bulk add box, the cell delimiters were lost. This is fixed. The print function used to show half a page of unnecessary white space at the bottom, thus it sometimes would print blank pages at the end. This is fixed so you won’t be wasting paper needlessly any more.

As a bonus, you may now access the service from a shorter address: www.optimap.net (the old address will continue to work, and the page will remain identical)

I hope you enjoy the update! Please post questions, feedback, bugs and suggestions here. I’m sure I broke something during the update…

Introducing SkyLib

November 4th, 2011

SkyLib

For a long time now, my mantra has been optimization. To make the most out of limited resources makes sense both economically and environmentally. OptiMap was an example of this. Driving too far is just stupid. Using OptiMap saves you time and money and it saves the environment too.

There are many other wasteful behaviors we need to address to optimize the usefulness (utility) of our planet’s finite resources. When I started to learn about embodied energy, I was shocked by how much energy is spent in the process of manufacturing the products we buy. An average $20 book has an indirect footprint of 20 kg CO2, mainly due to extraction of the raw materials needed and manufacture of the book itself. This is the equivalent of driving an average car more than 130 kilometers. Given the sheer number of things that most people own, these indirect emissions certainly add up.

How can we optimize this? First, we need to realize that in many cases, ownership of these items is not why we buy them. We want access to the features that the item can provide. You don’t buy the boardgame Axis & Allies because you want to be the proud owner of it. You buy it to play it. And it probably collects dust 364 days a year.

If someone has the item I need, and it collects dust most of the time, they wouldn’t mind lending it to me, right. And I would certainly return the favor some other day. But we need to survey the resources available. Then make that information searchable. So that when you need a power drill, you can find the one closest to you. SkyLib.org is my attempt at doing this. Yes, it’s beta and yes it lacks many features. Certainly rough around the edges. But you can start organizing your stuff and building your personal library today.

Some features that are not done yet but under development:

  • Friends support, invites and import from other social networks
  • Buying and selling things
  • User ratings
  • Wanted-functionality (I need x)
  • Renting and deposits
  • Custom location search (Find item closest to me)
  • Facebook login
  • Embedding products on third-party websites
  • Intro-video

Feedback is hugely appreciated! Please head over to www.skylib.org and give it a try. I’m already sharing 120+ items with you as of this post.

The Dynamic Programming Algorithm for the Travelling Salesman Problem

June 24th, 2011

A reader asked me for some information on how the dynamic programming algorithm for the TSP works. I was surprised to find that a Google search found no good resources. Wikipedia merely acknowledges its existence: “One of the earliest applications of dynamic programming is the Held–Karp algorithm that solves the problem in time O(n22n).”

Consider the TSP problem with N+1 points labeled 0, 1, …, N. We start at point 0. The distance from point i to point j is dist[i][j].

In dynamic programming, we seek to solve a problem by first solving smaller instances of the same problem. We start by looking at the really trivial size problem: What is the best order to visit just one of the destinations?

Assume we have N destinations. There are N size-1 problems, one for each of the N destinations. The best way to visit each is the shortest path from node 0 to node N. We store the best solution to each of these problems in a table:

best[subset][end] = dist[0][end]

Here, subset represents which destinations have been visited. More specifically, subset is a bitmask: an integer where bit i is 1 if destination i has been visited and 0 otherwise. Also note that the stored solution is the solution to the A-Z TSP problem, so it does not include the cost to return to the origin. The variable end is the destination that this A-Z problem ends at.

Now, lets expand to all the A-Z TSP problems of size one larger:

best[subset][end] = min(best[subset \ { end }][i] + dist[i][end])

Here, i is an intermediary node that is 1 in subset and not equal to the end variable. Before we move on to the next size problem, we have to fill in all the possible subsets of the current size. Finding all of those subsets of size s is what the function nextSetOf(s) in BpTspSolver.js does. How do we justify this expansion? It does not matter to the distance of the larger problem in what order the intermediary destinations of the 1-size smaller problem ending at i was visited in, so we are safe to only store and look at the optimal such sub-solution.

Finally, when we reach the desired size where all the destinations are visited, we only need to look up the best solution to the A-Z TSP problem in the table:

best[2^(N+1)-1][N]

(2^(N+1)-1 is simply the integer with all the first N+1 bits set to 1). If we want to return to the origin, we instead take the min over all i of

best[2^(N+1)-1][i] + dist[i][0]

This then becomes the best solution to the roundtrip problem. It is important to note that while this solution may look fast, there are 2^(N+1) different subsets involved (really 2^N, because 0 is always visited). Also, each subset solution needs to be stored, causing high memory usage. However, O(2^N) is still much better than the brute force O(N!) solution. 10! is 3 628 800 while 2^10 is only 1024. With the brute force solution, OptiMap could solve optimally up to 9 destinations. The dynamic programming solution now allows OptiMap to solve optimally up to 15 locations.