Monday, April 20, 2009

Sri Lanka on the way forward ?

I am overjoyed with excitement with the news that hopefully the whole country will be free of terrorism within a matter of few weeks. Terrorism is the single biggest reason that left our country stranded among the poorest of nations in the world.

All around the world, there are many professionals who were born and educated in this island nation, but now living in foreign countries after giving up hope for a better future for our mother land. But once this lunacy of terrorism is over, I guess we would have an environment where all the Sinhalese, Tamils, Muslims and the rest can live in harmony. Every where I look in our country, and every industry that I think about, I can only see the potential for investments and development. I always imagine a future where all of our engineers, researchers and scientists return to Sri Lanka and start building the future Sri Lanka as one country, one nation and one people.

In the mean time, I wish that our tamil brothers and sisters would understand the reality of what is actually going on. Please open your eyes, don't be shadowed by the propaganda of the terrorists. There is nothing called a 'good terrorist' and a 'bad terrorist'. Realize that there is a difference between a true 'freedom fighter' and a 'terrorist'. Listen to the true voices of the innocent people who are been taken hostage by the ruthless organization.

If anyone feel that the Sri Lankan government can't be trusted, why not listen to the international media and international representatives. Check out the following videos.




See what they are doing in other countries as well ..



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.

Wednesday, October 1, 2008

Dijkstra's algorithm for MatLab

යාන්ත‍ම් පො‍ඩි විවේකයක් ලැබුනා. මොනව හරි ලියන්න කියල හිත හිතා ඉන්නකොට මම ඊයෙ ලියපු Matlab code එකක් මතක් උනා.
පහත දැක්වෙන්නේ Dijkstra Algorithm එකයි. කාට හෝ මේක ප්‍රයෝජනවත් වේ යැයි මම හිතනවා. අවුරුදු ගානකට කලින් මෙම ඇල්ගොරිතම දැනන් හිටියට, මේක කොයි තරම් වෙනස් ආකාරයේ ගැටළු සදහා යොදාගත හැකිද යන්න මට වැටහුනේ මෑතකදී.

Following is an implementation of the Dijkstra's Algorithm for Matlab. This algorithm is a solution for the 'single source shortest path problem', which is useful in many applications.

This code can be pasted in a new .m file in Matlab. Then this can be used as a function.

Format of the Inputs:

src: and integer defining the source node.
ConMat: Connection Matrix, a square matrix. Each element (i,j) of the matrix defines the length of a direct link from node i to node j (if there exists a link). If there is no link from i to j, the element (i,j) must contain -1.

Output format:

The output is given in an array (and) of size N, where N is the number of nodes in the network. Each element of the output array corresponds to a Node with same index. Each element will contain the index of the node which is the closest to the corresponding node, in the shortest path to the source. The element corresponding to source node would contain -1.

Eg. If the source node is 2, and the shortest path from 2 to 7 is 2-->4-->7, then the output array would contain | x |-1| x | 2 | x | x | 4 |.
As seen, the 7th element directs us to 4 th node, which inturn directs us to node 2. Similary, the shortest path to each other node from the source node could be extracted from the output.


%An implementation of the Dijkstra's algorithm for MatLab
%(c)Buddhika Gunawardena

function ans = Dijkstra(src,ConMat)

N = size(ConMat,1);
Visited = -1*ones(N,1); % Here -1 means Not defined
PrevNode = -1*ones(N,1);
Distance = Inf*ones(N,1);

Distance(src) = 0;
CurrentNode = src;
nVisited = 0;
while (nVisited <N)
Visited(CurrentNode) = 1;
for i=1:N
if (ConMat(CurrentNode,i)>0)
temp = ConMat(CurrentNode,i) + Distance(CurrentNode);
if (temp< Distance(i))
Distance(i) = temp;
PrevNode(i) = CurrentNode;
end
end
end
minimum = 0;
for i= 1:N
if (Visited(i)<0)&&(Distance(i)>0)
if (minimum ==0)
minimum = i;
elseif (Distance(i)<Distance(minimum))
minimum = i;
end
end
end
CurrentNode = minimum;

nVisited = nVisited +1;
end

ans = PrevNode;



Thursday, September 25, 2008

මගේ පළමු සිංහල සටහන..

පුරා වසරක ඇවෑමෙන් මට මගේ වෙබ් ලොග් සටහන මතක් වුනේ සිංහල යුනිකොඩ් භාවිතය පුරුදු වීමට මිස වෙන හේතුවකට නොවේ. වැඩකටයුතු නම් ඉතා අධික වුවත් මෙයට උත්සාහයක් දැරිය යුතු බව මට සිතුනි. ඉංගිරීසියෙන් සියළු අධ්‍යාපන කටයුතු කරන අපට, සිංහල භාවිතයට ලැබෙන අවස්ථා බොහෝ විරලය. එම නිසි අක්ෂර වින්‍යාසයද බොහෝ විට වරදීම‍ට ඉඩ ඇත. එහෙත් ඉගෙනීමට නම් වැරදි කළ යුතු බව කවුරු හෝ පණ්ඩිතයෙක් කියා ඇති වග මට මතකය.
වෙනත් භාෂා වල වෙබ් පිටු සහ බ්ලොග දකින වාරයක් පාසා අපේ ‍මවුබසින් කොම්පියුටරය භාවිතා කිරීමට හැක්කේ කවදාදැයි සිතුනු අවස්තා අපමනයි. එනිසා මෙම යුනිකොඩ් ව්‍යායාමයට හවුල් වූ සියළු දෙනාටම තෙරුවන් සරණ පතමි.

Monday, July 16, 2007

Sri Lanka whitewash Bangaladesh..!!


I was lucky to witness the 3rd Test between Sri Lanka and Bangaladesh at Asgiriya grounds, on the fourth day, where bangaladeshi's were white washed clean by the Sri Lankan team.
When the match started on Wednesday, I was hoping atleast the rain would hold the match longer until the 4th day which is a Saturday, so that I could catch a glimpse of my favourite cricketers from my home town. The rain god came to my rescue, only abt half of the overs were played during the first day and even the third day I guess.
On saturday morning, I just watched a few overs from TV and thought the Bangaladeshis are gonna hold on to their innings for some time at least this time. Shahriar Nafees was goin well and he looked pretty ok in getting the bat to hit the ball, u know, unlike javed omar on the other end who seemed to be completedly bamboozeled by Lasith Malinga's Bowling. I went to town to attend to some other bunesses and in abt two hours looked at the score on my mobile and it was 6 wickets down all of a sudden. Oh man.. here they go again.. being slumped once again for the third time in 3 matches. I ran to the asgiriya ground in a few minutes, just in time to catch the fall of the last four wickets. Wow, it was so nice to see some live action after a long while. It was great since the whole thing was shown on Big Screen as well. That was a new experience for me.
I took some pics of the match using my k800i. On top is a panoramic view of the ground, while lasith malinga was on fire on the right side of the screen.
Murali passed his milestone of 700 test wickets in the match too. That is a real achievement and he is just 8 wickets behind shane warne.

Monday, July 2, 2007

Blogging..At last..

I guez it took a long time for me to decide whether I need to blog or not. Well, here we go..

Reading some of the blogs online, sometimes I feel whether it is really worth being called blogging.. I thought that 'Blog' means 'Web' + 'Log'. But who would keep a log of a whole lot of crap. So I guez, the more appropriate word would be somethin like 'Web'+'Crap', which obviously doesn't sound right. So, I guez I would simply call my blog, 'Buddhika's crap'

Hope somebody reads it once in a while.. hih hih hee..