Saturday, March 7, 2009

What is this credit crisis ?

Being an engineer, one thing I understand about the 'credit crisis' is that it has become very difficult to find a decent job thesedays. I sincerely hope that the situation would be better in a few months, when I graduate with my Masters degree ..

One of my friends send me the following links in youtube. It is a very interesting but simple explanation of whats going on..



It is also a very well composed presentation :). It is a part of a thesis by a guy named Jonathan Jarvis. Well done buddy. Keep'em coming.


Monday, March 2, 2009

k - Shortest, Link - Disjoint paths for Matlab


Here is a useful piece of Matlab code for anyone who needs to find a set of link disjoint paths in a given undirected graph. I couldn't find a single function in Matlab to do it, so here is my solution. It is so simple and I have used the 'graphshortespath' function which is available in the Bioinformatics toolbox. Maybe not the optimal algorithm, but does the job and it was sufficient for my purpose :)

% (c)Buddhika Gunawardena , 2009
% Filename: KShortestLinkDisjointPaths.m
% Description: A simple function to calculate k shortest and link disjoint
% paths of a given undirected graph (G) from source (src) to destination
% (dst)
% Inputs:
% G: A connectivity matrix where if (i,j) = 1, there is a link from
% node i to node j, and 0 otherwise. Here it is always a symmetric matrix.
% k : The number of paths to be calculated
% src: source node
% dst: destination node
% Outputs:
% paths: a k x NNodes matrix that shows all k paths found. NNodes is
% the number of nodes in the Graph. row in the matrix contain a single
% path from source to destination. (node numbers from source until
% destination)


function paths = KShortestLinkDisjointPaths(G,k,src,dst)

NNodes = size(G,1);

paths = zeros(k,NNodes);
for p = 1:k
[dist, path]= graphshortestpath(sparse(G), src, dst);
if (dist~=inf)
n = size(path,2);
paths(p,1:n)= path;
for i = 1:n-1
G(path(i),path(i+1))=0;
G(path(i+1),path(i))=0;
end
end
end

And here is an example of it's usage,

G = [ 0 1 1 0 ;
1 0 1 1 ;
1 1 0 1 ;
0 1 1 0 ];
k = 2;

src = 1;
dst = 4;

paths = KShortestLinkDisjointPaths(G,k,src,dst)

The simple graph used in this example is shown in figure above. And the output would be,

paths =

1 2 4 0
1 3 4 0

Cheers !

PS. I must mention the nice simple tool that I use to convert coding such that I can insert it directly in my blog. Try it yourself. Its so simple.