Hi,

I've encountered some issues with edge weights which potentially could cause bugs. I was wondering whether some corrections in the code are required.

Take the following simple code snippet:

//Define graph4, consisting of a single edge (0,1) with edge weight 10
WeightedGraph<Integer, DefaultWeightedEdge> graph4=new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);
graph4.addVertex(0);
graph4.addVertex(1);
DefaultWeightedEdge e1= graph4.addEdge(0, 1);
graph4.setEdgeWeight(e1, 10);
//Define graph5 without edges or vertices
SimpleWeightedGraph<Integer, DefaultWeightedEdge> graph5=new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);
graph5.setEdgeWeight(e1, 5);

System.out.println("Edge weight graph 4: "+graph4.getEdgeWeight(e1));
//OUTPUT: Edge weight graph 4: 5.0

Notice that jgrapht allowed me to change the weight of edge e1 in graph4 through graph5 which does not even contain this edge. This seems pretty awkward?

1. the setEdgeWeight should only work if the graph contains the edge.
2. I think that it would be a good idea to update the documentation of the DefaultWeightedEdge, thereby emphasizing that edge weights are stored on the edges, and not in the graph. Lets say you have 2 graphs, g1 and g2 both containing the same edge e (same object). Invoking g1.setEdgeWeight(e, 10) will also change the weight of this edge in graph g2. 

I'm not sure how to accomplish the following:
Given a weighted graph g1, create a subgraph g2 containing a subset of the edges of g1 with *different* weights. Then for a given edge e which is contained in both g1 and g2, I would like to invoke:
"Weight of e in g1: "+ g1.getEdgeWeight(e);
"Weight of e in g2: "+ g2.getEdgeWeight(e);
I could do something ugly by creating a mapping from edges in graph g1 to different edges in graph g2. Then for a given edge e in g1 I could invoke:
Map<DefaultWeightedEdge, DefaultWeightedEdge> edgeMapping=...;
"Weight of e in g1: "+ g1.getEdgeWeight(e);
"Weight of e in g2: "+ g2.getEdgeWeight(edgeMapping.get(e));
I would be happy to learn about cleaner methods. 


br,

Joris