DSL based approach to input Graph data in graph theory based java programs

Most of us have coded some programs which deal with graph theory algorithms like finding the shortest path between two vertices, finding the minimum spanning tree for a given graph and so on. In each of these algorithms the programatic way to represent the graph is to used either adjacency matrix or adjacency list. Both of them are not very intuitive way of defining the graph input. The adjacency matrix for example can lead to errors if the entries are not made in the right columns and rows. Moreover at run time you are not very sure which row/column represents which edge and things get even more complicated when it comes to input for a graph with large number of vertices.

During my engineering studies I had implemented quite a few graph algorithms in Java and in all of them I had nested for-loops for taking the adjacency matrix input. Recently when I was reading Martin Fowlers DSL book, I hit upon the idea of create a DSL for providing graph input i.e a DSL which would allow the user to specify the vertices, edges and their weights. I picked the graph algorithms which I had implemented and just stripped of the adjacency matrix input and instead made use of the DSL which I created. The algorithm worked like a charm.


Source : http://www.javacodegeeks.com/2013/07/dsl-based-approach-to-input-graph-data-in-graph-theory-based-java-programs.html

Back to Top