Category: Exploration

  • Königsberg Bridge Problem

    Königsberg Bridge Problem

    Königsberg Bridge Problem

    , , ,

    The foundations of network science is graph theory, and at the beginning of graph theory stands one problem that started it all: The Königsberg Bridge Problem. The problem poses a simple challenge:

    “Can you go on a walk that crosses every one of the seven bridges of historical Königsberg exactly once?”

    No, you can’t. Some of the historical bridges in Königsberg don’t even exist anymore. But could you have done it, if you had lived in historical Königsberg? Could you do it in your city today? Thinking about this leads down a fascinating rabbit hole.

    Map of Königsberg by Matthäus Merian ca. 1652

    Eulerian Walks

    The map of Königsberg shown above was published in 1652 and is commonly attributed to “Merian-Erben”. But Merian-Erben isn’t a person. Erben means “heirs” in German and Merian-Erben are the heirs of Matthäus Merian, a famous Swiss engraver working in Frankfurt, Germany. When Merian died in 1650, the map of Königsberg was found among his estate, and two years later his heirs collectively published it with the attribution “Merian-Erben.”

    Historical Königsberg looks like a pretty town, doesn’t it. Wouldn’t it be nice to go for a little walk on a Sunday afternoon that crosses every bridge exactly once? But can you? It would take another eighty years till this puzzle was solved.

    Today we say that a walk that crosses every bridge in a city exactly once is an eulerian walk. The name honours Leonard Euler who solved the Königsberg bridge problem in 1736 and in doing so created a new branch of mathematics.

    Euler was well aware that the problem could be solved by carefully listing all possible walks and then checking each one in tern to see if it was a solution, he writes:

    Even in 1736 it would have been possible to solve the problem in this way in an afternoon: With only seven bridges, there are only 2520 paths that need to be tabulated and checked. But Euler’s idea is much better. It hints at tow powerful principle: Simple models and Economy of Information.

    An illustration of the topology of Königsberg from the publication of Euler's solution. Shown are two river islets. The right islet is connected to both banks of the river with one brige each. The left island is connected to each river bank by two bridges. Additionally there is one bridge connecting the two islets.

    Simple Models

    Euler’s first insight was that everything becomes easier when we eliminate the needless information. Merian’s map is nice, but all the details it shows are not relevant to the problem, and they obscure the view of the bridges.

    Problems become easier when we focus on the bare necessities needed to capture their essence. This is the reason why we make models, to simplify a world that is otherwise to complicated to understand.

    Euler’s map of Königsberg, shown above, shows only the elements that are necessary to capture the essence of the problem: the land masses and the bridges connecting them.

    Building on Euler’s work, there is an even easier way in which we can represent the structure of historical Königsberg. We represent the different land masses by the nodes of a network and we represent the the bridges connecting them as links between these nodes.

    Topology of Königsberg, now shown as a network.

    Economy of Information

    The other principle at which Euler hints is Economy of Information. In a nutshell: If we pose a question for which a typical answer would contain a lot of information, the answer will often be difficult to find. We need to pay a price for the information that we demand. A longer answer will take more work to find. Conversely if we ask a question that can be answered more quickly, then there is often an easy way to find the answer.

    If we ask how to walk across every bridge exactly once, the answer we are asking for is the walk itself, e.g. a set of instructions containing the sequence of bridges that we cross. By contrast if we ask is a walk possible at all, the answer is a simple yes or no.

    Euler focussed on the question why a walk that crosses every bridge exactly once might not exist. To discuss failure we need the concept of node degree. In our network representation of the city, each network node represents a landmass and each link represents a bridge. In network science the degree of a node is the number of links connecting , so in our case the degree of each landmass is the number of bridges connecting to it.

    Topology of Königsberg with the node degrees shown. They are 5,3,3, and 3.
    Examples of nodes of degree 1,2,3, and 4.

    Solving the puzzle

    Now consider what happens if our network contains a node of degree-one, a landmass with only one bridge connecting to it. If we don’t start the walk in this node of degree one, then we can only reach it by crossing the one bridge that connects to it. Once we have done that there is no way to leave the node again without using the bridge another time, which means the walk must end there. In summary that means: If a node of degree-one exists in the network, then it is either the start or the end point of an Eulerian walk or no such walk exists.

    By contrast a node of degree two does not have such a negative impact on our walk. With its two bridges we can use one to arrive and one to depart, and hence we cannot trap ourselves there. Only if we start our walk in a node of degree two, the walk will end when we return to it.

    So what about nodes of degree three? If a landmass has three bridges connecting to it we must visit it at least twice to use all bridges. On our first visit we arrive on one bridge and depart on another, without problem. But we have to visit another time to use the last bridge, and now this last bridge is the only one left—what started out as a node of degree three has now effectively become a node of degree one, so on our second visit we will get trapped in this node.

    By the same reasoning all nodes of odd degree behave like nodes of degree one. They are either the starting point of the eulerian walk or the end point or no eulerian walk exists. And since each walk can only have one starting point and one endpoint, no eulerian walk can exists in networks that contain more than two nodes of odd degree. If a network contains exactly two nodes of odd degree an eulerian walk exists. In that case we can start the walk in either of the two nodes of odd degree and then the other will be the end point. Finally, if a network contains no nodes of odd degree we can start the walk anywhere and the eulerian walk will be a circuit that eventually ends back at the starting point.

    So what about Königsberg?

    Illustration of the problem form a letter Euler wrote to Giovanni Marinoni.

    The Truth about Königsberg

    In the the Königsberg network one node has degree five and three nodes have degree three, so we have four nodes of odd degree. This proves that that no eulerian walk exists—we cannot go on a walk that crosses each bridge exactly once.

    Today the bridge problem is often portrayed as a serious problem that people wanted an answer for, but this is not what it was. In the eighteenth century their was no internet, no youtube, no social media. Instead people turned to books and wrote letters. Many, many letters. Even Kings and Queens of the time were keeping up with recent developments in science and mathematics, and members of the high society would challenge each other to solve puzzles. Occasionally they might send someone an insolvable puzzle as a joke. The most notorious one of these joke puzzles was the Königsberg bridge problem—a form of 18th century trolling.

    A good troll problem must not only be unsolvable, but it must also seem simple to ensnare its victims. Indeed, the Königsberg bridge network, is the smallest, simplest network for which there is no solution without this being immediately obvious. To be unsolvable a network must have at least four nodes, each of them with an odd degree. We don’t want any node to have degree one, because that put people immediately on the right track to the solution. So far the simplest network that meets these criteria, would have four nodes of degree three. But there is only one such network, and it forms a tetrahedron, a network that is so symmetric that we by exploiting the symmetry we can reduce the number of walks that need to be tried to just two—clearly not good for trolling. The next simplest unsolvable network has three nodes of degree three and one node of degree five and it is the Königsberg bridge graph.

    Euler would not be trolled by it. Instead he proved that the bridge problem was unsolvable in such an elegant way that everybody could understand the proof. Because the problem was already notorious the news of the proof spread like wildfire throughout Europe. Essentially by thinking about the city as a system of nodes and links Euler had invented a new way of describing the world with mathematics—a new way of modelling. Euler said he had wanted a proof that mirrored the elegance of geometry, and he called his new way of thinking Geometria Situs, the geometry of position. Later J. J. Sylvester coined another name for this kind of mathematics: Graph Theory, and today many would call it Network Science.

    Try It Yourself

    Why not try it yourself. You could design a bridge walk for your own town and perhaps it will become as popular as the one in Bristol.

  • Video-Art with Hydra

    Video-Art with Hydra

    Video-Art with Hydra

    , , , ,

    There are many software packages for video editing, which filter, cut and edit all you like, but they all work on videos that are already dead. The source material sits conserved in a file on your hard drive, frozen in time, while the events that are depicted have long since passed. Can you imagine, editing video live, working with a stream of data that has never been stored? Or even mixing, filtering, and combining several such streams?

    Enter: The Hydra

    Hydra is a project by software artist Olivia Jack. In a nutshell it builds on video filters that are already built in your web browser. Hydra gives you direct control over these so-called shaders, using a simple programming language. The result is a website which can pull in files from memory, livestreams and cameras and work with them in various surprising ways.

    For example I was able to make a small script that detects change in the video feed from my laptop camera in just five lines of code. You can see the result below this page….

    Try it yourself

    Want to try this yourself. It’s just one click away:

    How it works …

    Let’s take a look at the script that creates the motion detector. It starts with:

    s0.initCam()

    This tells video source 0 to be a stream that comes from the camera. Next we have

    solid(0.5,0.5,05).out(o0)

    This creates a neutral grey image (all three color channels are set to 0.5) and stores it as output o0. This output is just a convenient place where we can keep the image.

    src(s0).invert(1).out(o1)

    This takes source s0, which is the video camera and inverts all pixels, creating a negative image that is stored as output o1.

    src(s0).blend(o1,0.5).contrast(2).out(o2)

    Now we take the camera source s0 and blend it with the inverted image. The 0.5 means that both sources contribute 50% of the product. Now suppose the camera would be recording a static image, then blending the camera image with it’s own inverse would produce solid grey.

    But the inversion takes a little bit of time, so negative image is always a tiny bit older than the current image. So if the camera is recording a moving object the image and the negative do not cancel perfectly anymore and instead. We get a signal that is different from neutral grey wherever there was movement in the image. Now we only need some cosmetic adjustments:

    src(o0).diff(o2).add(src(o2).diff(o0)).thresh(0.4,0.4).add(o3,0.9).mult(solid(0,1,0)).out(o3)

    At this point the blended image is already stored in o2. We take it and subtract the neutral grey such that a pixel that hasn’t change is now black. Finally the intensity is scaled up, thresholded and we multiply with a pure green image to make everything nice bright green. We add 90 of the result from the previous iteration. This makes the detected differences easier to see by making them linger longer, creating a motion-blur like effect. We save the resulting stream as output o3. Now we only need to tell hydra that that output is what we want to see: