Nik’s code:
Nik’s code:
In[]:=
topVertices[g_Graph]:=Extract[VertexList[g],Position[VertexInDegree[g],0]]expandAntichains[foliations_,elem_,descendants_]:=Catenate@Map[foliation|->With[{pos=FirstPosition[foliation,_?(ContainsAny[descendants]),{Length[foliation]+1},1]},MapAt[Append[elem],foliation,#]&/@Range[pos[[1]]-1]],foliations]GraphFoliations//ClearAllGraphFoliations[g_Graph]/;DirectedGraphQ[g]&&AcyclicGraphQ[g]:=Module[{vs,newGraph},vs=topVertices[g];newGraph=VertexDelete[g,vs];If[VertexCount[newGraph]==0,ResourceFunction["SetPartitions"][vs],DeleteCases[Catenate[(foliation|->Fold[expandAntichains[#1,#2,VertexOutComponent[g,#2,1]]&,{Prepend[foliation,{}]},vs])/@GraphFoliations[newGraph]],{},{2}]]]
Max/SW code:
Max/SW code:
In[]:=
ClearAll[FoliatedGraph];SyntaxInformation[FoliatedGraph]={"ArgumentsPattern"->{graph_,foliation_,opts___}};Options[FoliatedGraph]=Options[Graph];FoliatedGraph[graph_,foliation_List,options:OptionsPattern[]]:=Graph[graph,options,VertexSize->0.2,VertexStyle->Flatten[MapIndexed[#->Lighter[ColorData[24][First[#2]],0.2]&,foliation,{2}]],VertexLabels->Flatten[MapIndexed[#->Placed[First[#2],Center]&,foliation,{2}]]];
Foliations
Foliations
In[]:=
GraphFoliations
Out[]=
{{{5,1},{3},{2,6},{4}},{{5},{3,1},{2,6},{4}},{{5,1},{3},{2},{4,6}},{{5},{3,1},{2},{4,6}}}
In[]:=
FoliatedGraph
,#&/@GraphFoliations
Out[]=
,
,
,
Out[]=
In[]:=
CloudGet["https://wolfr.am/KXgcRNRJ"];
In[]:=
ShowQuietdrawFoliation
,#,Directive[AbsoluteThickness[1.5],Red],FindRoot::cvmit&/@GraphFoliations
Out[]=
,
,
,
In[]:=
ShowQuietdrawFoliationFoliatedGraph
,#,#,Directive[AbsoluteThickness[1.5],Red],FindRoot::cvmit&/@GraphFoliations
Out[]=
,
,
,
In[]:=
MultiwayMatrix[{m1_,m2_},t_Integer]:=With[{g=NestGraph[(f/@{m1.First[#],m2.First[#]})&,{f[{1,1}]},t]},g]
In[]:=
MultiwayMatrix[{m1_,m2_},t_Integer,VertexLabelsAutomatic]:=With[{g=NestGraph[(f/@{m1.First[#],m2.First[#]})&,{f[{1,1}]},t]},Graph[g,VertexLabels((#InputForm[First[#]])&/@VertexList[g])]]
In[]:=
SimpleGraph[MultiwayMatrix[{{{1,0},{1,1}},{{1,1},{0,0}}},5,VertexLabelsAutomatic]]
Out[]=