1
$\begingroup$

This question is related to that one:Styling a flow graph. For a demonstration of a flowgraph I "styled" such a graph (an intermediate result in the algorithm of Ford-Fulkerson) in the following way:

    display = {Property["s" \[DirectedEdge] 4, EdgeWeight -> "0,30"],
   Property["s" \[DirectedEdge] 1, EdgeWeight -> "10"], 
   Property[
    1 \[DirectedEdge] "s", {EdgeWeight -> "30", EdgeStyle -> Red}], 
   Property[
    2 \[DirectedEdge] 1, {EdgeWeight -> "30", EdgeStyle -> Red}],
   Property[
    3 \[DirectedEdge] 2, {EdgeWeight -> "10", EdgeStyle -> Red}],
   Property[4 \[DirectedEdge] 5, EdgeWeight -> "0,54"],
   Property[5 \[DirectedEdge] 3, EdgeWeight -> "0,50"],
   Property[6 \[DirectedEdge] 4, EdgeWeight -> "0,17"],
   Property[2 \[DirectedEdge] 6, EdgeWeight -> "17"],
   Property[
    6 \[DirectedEdge] 2, {EdgeWeight -> "20", EdgeStyle -> Red}],
   Property[6 \[DirectedEdge] "t", EdgeWeight -> "12"],
   Property[
    "t" \[DirectedEdge] 6, {EdgeWeight -> "20", EdgeStyle -> Red}],
   Property[3 \[DirectedEdge] "t", EdgeWeight -> "12"],
   Property[
    "t" \[DirectedEdge] 3, {EdgeWeight -> "10", EdgeStyle -> Red}]};

This yields the following graph:

Intermediate Result

Next steps to find a path from "s" to "t", via FindPath - no problem

paths = FindPath[display, "s", "t", \[Infinity], All]
(*{{"s", 4, 5, 3, "t"}, {"s", 4, 5, 3, 2, 6, "t"}}*)

But the attempt to highlight one of these paths in the graph of the intermediate result is not successful, only the vertices are highlighted and I (so far) could not manage to get the edges highlighted (eg. dashed, or different color). So this code was (and is) nut successful:

Graph[display, EdgeLabels -> Placed["EdgeWeight", Center],
  VertexLabels -> Placed["Name", Center], 
  GraphStyle -> "SmallNetwork", GraphHighlightStyle -> "Dashed"];

Has anyone an hint for me how to mange it? Removing the properties as in the cited question would remove "my" properties.

Side question: I used "EdgeWeight" for the capacities, if I use "EdgeCapacity" these numbers are not shown when using EdgeLabels -> Placed["EdgeCapacity", Center]. I have no idea why.

$\endgroup$
3
$\begingroup$

Perhaps,

Using,

g = Graph[display, EdgeLabels -> Placed["EdgeWeight", Center], 
  VertexLabels -> Placed["Name", Center], 
  GraphStyle -> "SmallNetwork"]

then,

HighlightGraph[g, {Style[#, Green] & /@ paths[[1]], 
  Style[#, Green] & /@ DirectedEdge @@@ Partition[paths[[1]], 2, 1]}]

enter image description here

or to get default highlight styles:

HighlightGraph[g, DirectedEdge @@@ Partition[paths[[1]], 2, 1], 
 GraphHighlightStyle -> "Dashed"]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you, this solves my problem. (I still do not understand completely why my approach did not work) I tried e.g. ´HighlightGraph[display, PathGraph[{"s", 4, 5, 3, "t"}], GraphHighlightStyle -> "Dashed"]´ but only got the vertices highlighted. $\endgroup$ – mgamer Oct 26 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.