# Overlapping EdgeLabels

I have to make a directed graph for a maximum flow algorithm assignment. Although I have managed to make the graph for the better part, it still needs some work.

The problem is that Mathematica automatically centers EdgeLabels. This causes overlapping text at where the edges cross.

I used the following code:

Graph[{R1 \[DirectedEdge] A, R1 \[DirectedEdge] B,
R2 \[DirectedEdge] A, R2 \[DirectedEdge] B, R2 \[DirectedEdge] C,
R3 \[DirectedEdge] B, R3 \[DirectedEdge] C, A \[DirectedEdge] D,
A \[DirectedEdge] E, B \[DirectedEdge] D, B \[DirectedEdge] E,
B \[DirectedEdge] F, C \[DirectedEdge] E, C \[DirectedEdge] F,
D \[DirectedEdge] T, E \[DirectedEdge] T, F \[DirectedEdge] T},
EdgeWeight -> {120, 115, 70, 90, 110, 140, 120, 110, 85, 130, 95, 85,
130, 160, 220, 330, 240}, EdgeLabels -> "EdgeWeight",
EdgeLabelStyle -> VertexLabels -> "Name"]


And this produces the following graph.

For completeness, R1,R2,R3 are the sources and T is the sink. No need to solve the maximum flow problem.

Update: An alternative approach is to change the EdgeShape of selected edges to make them curved. For example, using the EdgeShapeFunction CurvedArc

Graph[edges, EdgeWeight -> ew, EdgeLabels -> "EdgeWeight", VertexLabels -> "Name",
Join[Thread[{"R2" -> "C", "R3" -> "B", "B" -> "F", "C" -> "E"} ->
GraphElementData[{"CurvedArc", "Curvature" -> 3/4}]],
Thread[{"R2" -> "A", "A" -> "E", "R1" -> "B", "B" -> "D"} ->
GraphElementData[{"CurvedArc", "Curvature" -> -3/4}]]]]


We get alternative pictures assigning Curvature values 3/4 and -3/4 to various subsets of the edges:

edges = {"R1" -> "A", "R1" -> "B", "R2" -> "A", "R2" -> "B",
"R2" -> "C", "R3" -> "B", "R3" -> "C", "A" -> "D", "A" -> "E",
"B" -> "D", "B" -> "E", "B" -> "F", "C" -> "E", "C" -> "F",
"D" -> "T", "E" -> "T", "F" -> "T"};
ew = {120, 115, 70, 90, 110, 140, 120, 110, 85, 130, 95, 85, 130, 160,  220, 330, 240};

Graph[edges, EdgeWeight -> ew,
EdgeLabels ->  Thread[edges -> (Placed[#, {3/5, {1/2, 1/2}}] & /@ ew)],
VertexLabels -> "Name", ImagePadding -> 20]


• @Nigel, my pleasure. Welcome to mma.se.
– kglr
Dec 15, 2014 at 13:36