Skip to main content

graphs and networks - Styling a FlowGraph


I tried to re-style a flow graph found via FindMaximumFlow, but this seems not to work:


vertices = {"s", 1, 2, 3, 4, 5, 6, "t"};
flows = {40, 30, 10, 22, 30, 54, 50, 37, 17, 32};
edges = {"s" <-> 1, 1 <-> 2, 2 <-> 3, 3 <-> "t", "s" <-> 4,
4 <-> 5, 5 <-> 3, 2 <-> 6, 6 <-> 4, 6 <-> "t"};

then


flowGraph = Graph[vertices,

edges,
EdgeCapacity -> flows,
EdgeWeight -> flows,
VertexLabels -> Placed["Name", Center],
VertexSize -> Medium,
GraphLayout -> "LayeredEmbedding",
EdgeLabels -> Placed["EdgeWeight", Center],
EdgeLabelStyle -> Directive[Blue, Medium]];

Now determining the optimum:



ℱ = FindMaximumFlow[flowGraph, "s", "t", "OptimumFlowData"];

with


g = ℱ["FlowGraph"]

So far everything is fine. But styling with something like


ℱ["FlowGraph", GraphStyle -> "SmallNetwork"]

does not work. When doing a right-click in the output (of F["FlowGraph"]) the styling options are offered and this works fine, but not when applying directly. At the moment my workaround is extracting the adjacency matrix and process this matrix. But I would prefer to choose directly a style. Has anyone a hint how this could be done?



Answer




g = ℱ["FlowGraph"];
SetProperty[RemoveProperty[g, DeleteCases[PropertyList[g], GraphLayout]],
GraphStyle -> "SmallNetwork"]

Mathematica graphics


What is happening: GraphStyle >> Details says:



Direct settings of any of Graph options override base settings provided by GraphStyle.



And, as can be seen using



PropertyList[ℱ["FlowGraph"]]


{EdgeShapeFunction, EdgeStyle, EdgeWeight, GraphHighlight, GraphHighlightStyle, GraphLayout, GraphStyle, VertexCoordinates, VertexShape, VertexShapeFunction, VertexSize, VertexStyle, VertexWeight}



many of styling options are set in ℱ["FlowGraph"], and they need to be removed for GraphStyle to work.


Comments