jgrapht/jgrapht — pull request #81 by tfeicht (2014-04-17 17:30:01+00:00)
Title: Jgrapht builder

What
-----
Builders for SimpleGraph and SimpleWeightedGraph.

Why
-----
Right now initializing graphs is very verbose:
* create an empty graph
* add vertices one by one
* add edges
* possibly set weights

With the builder object this can be done in a much more concise way.

Example:

```java
g = new SimpleWeightedGraphBuilder(DefaultWeightedEdge.class)
.edge(V1, V2, 1.0).edge(V1, V3, 2.0).edge(V3, V4, 3.0).edge(V2, V4, 4.0).build();
```
vs.

```java
g = new SimpleWeightedGraph(DefaultWeightedEdge.class);

regularWeightedGraph.addVertex(V1);
regularWeightedGraph.addVertex(V2);
regularWeightedGraph.addVertex(V3);
regularWeightedGraph.addVertex(V4);

regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V1, V2), 1.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V1, V3), 2.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V3, V4), 3.0);
regularWeightedGraph.setEdgeWeight(regularWeightedGraph.addEdge(V2, V4), 4.0);
```

If you think this is useful I will be open to implement builders for the other graph types.