-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathea18GF.m
300 lines (288 loc) · 15.1 KB
/
ea18GF.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
(* ::Package:: *)
BeginPackage["ea18GF`",{"ea18`"}];
vMin;
vMax;
dssByV;
getGraphsWanted;
displayM;
getGraphEdgesAndStyles;
showGraph;
getFormattedGraph;
cols;
graphFINDERGUIS;
graphFINDERGUIS2;
vn;
ds;
colours;
left;
right;
go2;
lbls;
graphsWanted;
vStyles;
edges;
isoDisplay;
Begin["`Private`"];
Needs["ea18`",FileNameJoin[{NotebookDirectory[],"ea18.m"}]]
Needs["eaDataStructure`",FileNameJoin[{NotebookDirectory[],"eaDataStructure.m"}]]
getGraphsWanted[v0_,a0_,nums0_]:=Module[{},
{timing,graphC,countT,graphsComplete,graphsWanted,edges,vStyles}=makeGraphs[v0,a0,nums0];
];
isoDisplay[v_,a_]:=Module[{fnsDATA,fnsGRAPH,fnsCOMPLETE,aP,graphC,timing,countT,vStyles,gra,allCOMPLETE,positionDS,positionGRAPHS,completeGRAPHS},
fnsDATA=FileNames[ToString[a]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsGRAPH=FileNames[ToString[a]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsCOMPLETE=FileNames[StringJoin[ToString[v],"V","*.txt"],{FileNameJoin[{NotebookDirectory[],"graphdata"}]}];
{aP,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
gra=ToExpression[Import[fnsGRAPH[[1]]]];
allCOMPLETE=ReadList[fnsCOMPLETE[[1]]];
positionDS=Position[allCOMPLETE,a];
positionGRAPHS=positionDS[[1]][[1]];
completeGRAPHS=allCOMPLETE[[positionGRAPHS]][[2]];
Return[
Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],getFormattedGraph[completeGRAPHS,gra,graphC,a],Row[{"Number of Unique Graphs: ", Length[completeGRAPHS],Column[Table[Prepend[completeGRAPHSi[[3]],completeGRAPHSi[[2]]],{completeGRAPHSi,completeGRAPHS}]]}]}]];
];
displayM[m0_]:=Module[{m=m0},
Return[Row[{MatrixForm[m[[2]][[1]]],MatrixForm[m[[2]][[2]]]}]];
]
go2=False;
getGraphEdgesAndStyles[graphData0_]:=Module[{graphData=graphData0,groups,matrixInfo,edges={},pos,i,j,vf,vt,g,index,styles={},vertexList={}},
matrixInfo=getMatrixInfo[graphData];
groups=graphData[[1]];
pos=Flatten[Position[groups[[1]],{_,0,_,_,_,_,_,_}]];
For[i=1,i<=Length[pos],i++,
vf=groups[[1]][[pos[[i]]]][[4]];
AppendTo[vertexList,vf];
For[j=1,j<=Length[groups[[1]][[pos[[i]]]][[5]]],j++,
vt=groups[[1]][[pos[[i]]]][[5]][[j]];
AppendTo[edges,vf<->vt];
AppendTo[vertexList,vt];
];
];
index=matrixInfo[[1]];
For[i=1,i<=Length[index],i++,
If[MemberQ[vertexList,i],
AppendTo[styles,i->If[index[[i]][[1]]==1,Red,Blue]];
];
];
Return[{edges,styles}];
];
showGraph[graphData0_]:=Module[{graphData=graphData0,groups,matrixInfo,edges={},pos,i,j,vf,vt,g,gRow,styles},
matrixInfo=getMatrixInfo[graphData];
groups=graphData[[1]];
{edges,styles}=getGraphEdgesAndStyles[graphData];
g=Graph[edges,ImageSize->400,VertexLabels->"Name",VertexStyle->styles,VertexSize->Medium];
gRow={g};
If[PlanarGraphQ[g],
AppendTo[gRow,Graph[edges,ImageSize->{200,200},VertexLabels->"Name",GraphLayout->"PlanarEmbedding",VertexStyle->styles,VertexSize->Medium]];
];
Return[Column[{Row[gRow," "],displayM[matrixInfo],getFormattedFaceCounts[graphData],Row[{Column[Table[groups1i,{groups1i,groups[[1]]}]],Column[Table[groups2i,{groups2i,groups[[2]]}]]}," "]},Center,Spacings->1]];
];
getFormattedFaceCounts[graphData_]:=Module[{faceCounts,ds,cycleBooleans,edgeRules,mDeg,mEdges,possibleDials},
cycleBooleans=getCycleBooleans[graphData];
faceCounts=getFaceCounts[graphData];
edgeRules=getEdgeRules[graphData];
ds=getDegreeSequence[graphData];
{mDeg,mEdges}=getMDegAndMEdges[graphData];
possibleDials=getPossibleDials[graphData];
Return[Row[{TableForm[faceCounts[[1]],TableHeadings->{{"Open Count","Closed Count","Total Count"},Range[1,Length[ds[[1]]]]}],TableForm[faceCounts[[2]],TableHeadings->{{"Open Count","Closed Count","Total Count"},Range[Length[ds[[1]]]+1,Length[ds[[1]]]+Length[ds[[2]]]]}],TableForm[cycleBooleans],TableForm[edgeRules],Column[{Row[{{mDeg,mEdges},getIndexPerms[graphData],getConnectionOrder[graphData]}],Row[Table[Column[possibleDialsi],{possibleDialsi,possibleDials}]," "]}]}," "]];
];
getFormattedGraph[cgs_,gra_,graphC_,a0_]:=Module[{sames,oldEdges,oldCoords,oldStyles,newEdges,newCoords,newStyles,newLabels,newEdgeStyles,a=a0},
sames=getSames[cgs];
oldEdges=EdgeList[gra];
oldCoords=AbsoluteOptions[gra,VertexCoordinates][[1]][[2]];
oldStyles=AbsoluteOptions[gra,VertexStyle][[1]][[2]];
{newEdges,newCoords,newStyles,newLabels,newEdgeStyles}=vCoordsStylesAndLabels[oldEdges,oldCoords,oldStyles,sames,a];
Return[Graph[newEdges,VertexCoordinates->newCoords,EdgeStyle->newEdgeStyles,VertexLabels->newLabels,VertexShapeFunction->"Square",VertexSize->0.8,VertexStyle->newStyles,ImageSize->graphC*20]];
Return[{sames,oldEdges,oldCoords,oldStyles}];
];
getSames[cgs_]:=Module[{i,j,sames={}},
For[i=1,i<=Length[cgs],i++,
AppendTo[sames,Prepend[cgs[[i]][[3]],cgs[[i]][[2]]]];
];
Return[sames];
];
(*arranges the complete graph groups into a minimal (+1) amount of levels, the first level is only for individual graphs*)
levels[sams_]:=Module[{levs={{}},i,j,first,last},
For[i=1,i<=Length[sams],i++,
If[Length[sams[[i]]]==1,
AppendTo[levs[[1]],sams[[i]]],
j=2;
first=sams[[i]][[1]];
last=Last[sams[[i]]];
While[j<=Length[levs]&&(first<Last[Last[levs[[j]]]]),
j=j+1;
];
If[j<=Length[levs],
AppendTo[levs[[j]],sams[[i]]],
AppendTo[levs,{sams[[i]]}];
];
];
];
Return[levs];
];
vCoordsStylesAndLabels[oldEdges_,oldCoords_,oldStyles_,sames_,a0_]:=Module[{a=a0,levs,newEdges,newCoords,newStyles,newLabels,newEdgeStyles={},vDist,vN,flatLevs,from,to,newVn,co,i,j,k},
levs=levels[sames];
flatLevs=Flatten[levs];
newEdges=oldEdges;
newCoords=oldCoords;
newStyles=oldStyles;
newLabels=Table[i->Placed[ToString[i],{0.5,0.5}],{i,1,Length[newCoords]}];
newVn=Length[newCoords]+1;
If[Length[flatLevs]>0,
vN=flatLevs[[1]];
vDist=(newCoords[[1]][[2]]-newCoords[[vN]][[2]])/(Length[a[[1]]]-1);
For[i=1,i<=Length[levs],i++,
For[j=1,j<=Length[levs[[i]]],j++,
For[k=1,k<=Length[levs[[i]][[j]]],k++,
from=levs[[i]][[j]][[k]];
to=newVn;
newVn=newVn+1;
co=newCoords[[from]];
AppendTo[newCoords,co-{0,i*vDist}];
AppendTo[newLabels,to->Placed[ToString[from],{0.5,0.5}]];
AppendTo[newStyles,to->cols[[Mod[Length[levs[[i]][[j]]]-1,10]+1]]];
(*edges showing the extension down*)
(*
AppendTo[newEdges,from\[UndirectedEdge]to];*)
(*Has to be included if not showing all extensions can delete if uncommenting line above*)
If[i==1,
AppendTo[newEdges,from<->to];
];
If[k>=2,
AppendTo[newEdges,to-1<->to];
AppendTo[newEdgeStyles,to-1<->to->Directive[Thick,Black]];
];
];
];
];
];
Return[{newEdges,newCoords,newStyles,newLabels,newEdgeStyles}];
];
cols={Blue,Cyan,Magenta,Yellow,Brown,Orange,Pink,Purple,LightRed,LightGreen};
graphFINDERGUIS[vMin0_,vMax0_]:=Module[{},
vMin=vMin0;
vMax=vMax0;
dssByV=Table[getPairs[vi],{vi,vMin,vMax}];
popList1=Table[i->ToString[i+vMin-1],{i,1,vMax-vMin+1}];
Return[{
DynamicModule[{popList2=Table[dssByVij,{dssByVij,dssByV[[1]]}],vn=1,ds=dssByV[[1]][[1]],popList21=dssByV[[1]][[1]],fnsPDF={},fnsDATA={},go=False,graphC,timing,countT,vStyles,lb,p,nums={}},
Manipulate[Module[{},
popList2=Table[dssByVij,{dssByVij,dssByV[[vn]]}];
popList21=popList2[[1]];
ds=popList21;
];Column[{Button["GetData",v=vn+vMin-1;a=ds;go=True;go2=True;fnsPDF=FileNames[ToString[ds]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[vn]][[2]]]}]];
fnsDATA=FileNames[ToString[ds]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[vn]][[2]]]}]];
{a,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
nums={};
lb=Table[i->
If[MemberQ[vStyles,i->_],
p=Flatten[Position[vStyles,i->_]][[1]];
Graphics[{vStyles[[p]][[2]],Rectangle[],Black,Text[Style[ToString[i],Bold,10],{0.5,0.5}]},ImageSize->30]
,
Graphics[{LightBlue,Rectangle[],Black,Text[Style[ToString[i],Bold,10],{0.5,0.5}]},ImageSize->30]
],{i,1,graphC}]],If[go,Column[{Row[{Column[{"V",vn+vMin-1}],Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],Row[{ToExpression[Import[fnsPDF[[1]]]]},""],TogglerBar[Dynamic[nums],lb],Dynamic[nums],Button["get All",getGraphsWanted[vn+vMin-1,a,{-1}]],Button["get graph Numbers",getGraphsWanted[vn+vMin-1,a,nums]],
Button["Print",
Print[Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],Row[{ToExpression[Import[fnsPDF[[1]]]]}]},Center]]]},Center]]}],
Row[{Control[{{vn,1},popList1,ControlType->PopupMenu}],Dynamic[Control[{{ds,popList21},Dynamic[popList2],ControlType->PopupMenu}]]}]]
],
DynamicModule[{lbls=Table[j->graphsWanted[[j]][[1]],{j,1,Length[graphsWanted]}],left,right},Manipulate[
lbls=Table[j->graphsWanted[[j]][[1]],{j,1,Length[graphsWanted]}];
If[Length[lbls]>0,
Row[{Column[{If[Length[graphsWanted]>=left,showGraph[graphsWanted[[left]][[2]]]],Button["Print",Print["GRAPH NUMBER: ",lbls[[left]][[2]]];Print[showGraph[graphsWanted[[left]][[2]]]]]}],Column[{If[Length[graphsWanted]>=right,showGraph[graphsWanted[[right]][[2]]]],Button["Print",Print["GRAPH NUMBER: ",lbls[[right]][[2]]];Print[showGraph[graphsWanted[[right]][[2]]]]]}]}]
],
Row[{Dynamic[Control[{{left,1},Dynamic[lbls],ControlType->RadioButtonBar}]],Dynamic[Control[{{right,1},Dynamic[lbls],ControlType->RadioButtonBar}]]}]
]
],
Manipulate[Column[{Row[{Column[{"V",v}],Column[{"Degree Sequences",a}]}," "],TreeGraph[edges,GraphLayout->{"LayeredEmbedding", "RootVertex"->1},VertexLabels->Placed["Name",{0.5,0.5}],VertexShapeFunction->"Square",VertexSize->0.8,VertexStyle->{vStyles,{}}[[colours]],ImageSize->graphC*20]}],Control[{{colours,1},{1->"Original",2->"test Colours"},ControlType->RadioButtonBar}]]
,
Thread[Range[10]->cols],
DynamicModule[{popList2=Table[dssByVij,{dssByVij,dssByV[[1]]}],go=False,a,graphC,timing,countT,vStyles,fnsDATA,fnsGRAPH,fnsCOMPLETE,gra,i,j,allCOMPLETE,positionDS,positionGRAPHS,completeGRAPHS},
Manipulate[Module[{},
popList2=Table[dssByVij,{dssByVij,dssByV[[i]]}];
popList21=popList2[[1]];
j=popList21;
];
Column[{Button["GetData",
go=True;
fnsDATA=FileNames[ToString[j]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[i]][[2]]]}]];
fnsGRAPH=FileNames[ToString[j]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[i]][[2]]]}]];
fnsCOMPLETE=FileNames[StringJoin[ToString[popList1[[i]][[2]]],"V","*.txt"],{FileNameJoin[{NotebookDirectory[],"graphdata"}]}];
{a,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
gra=ToExpression[Import[fnsGRAPH[[1]]]];
allCOMPLETE=ReadList[fnsCOMPLETE[[1]]];
positionDS=Position[allCOMPLETE,a];
positionGRAPHS=positionDS[[1]][[1]];
completeGRAPHS=allCOMPLETE[[positionGRAPHS]][[2]];
],
If[go,
Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],getFormattedGraph[completeGRAPHS,gra,graphC,a],Row[{"Number of Unique Graphs: ", Length[completeGRAPHS],Column[Table[Prepend[completeGRAPHSi[[3]],completeGRAPHSi[[2]]],{completeGRAPHSi,completeGRAPHS}]]}]}]
]
}],
Row[{Control[{{i,1},popList1,ControlType->PopupMenu}],Dynamic[Control[{{j,popList21},Dynamic[popList2],ControlType->PopupMenu}]]}]]
],
Thread[Range[10]->cols],
Dynamic[If[go2,
fnsDATA=FileNames[ToString[a]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsGRAPH=FileNames[ToString[a]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsCOMPLETE=FileNames[StringJoin[ToString[v],"V","*.txt"],{FileNameJoin[{NotebookDirectory[],"graphdata"}]}];
{aP,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
gra=ToExpression[Import[fnsGRAPH[[1]]]];
allCOMPLETE=ReadList[fnsCOMPLETE[[1]]];
positionDS=Position[allCOMPLETE,a];
positionGRAPHS=positionDS[[1]][[1]];
completeGRAPHS=allCOMPLETE[[positionGRAPHS]][[2]];
Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],getFormattedGraph[completeGRAPHS,gra,graphC,a],Row[{"Number of Unique Graphs: ", Length[completeGRAPHS],Column[Table[Prepend[completeGRAPHSi[[3]],completeGRAPHSi[[2]]],{completeGRAPHSi,completeGRAPHS}]]}]}]
]]
}];
];
graphFINDERGUIS2[vMin0_,vMax0_]:=Module[{},
vMin=vMin0;
vMax=vMax0;
dssByV=Table[getPairs[vi],{vi,vMin,vMax}];
popList1=Table[i->ToString[i+vMin-1],{i,1,vMax-vMin+1}];
Return[{
DynamicModule[{popList2=Table[dssByVij,{dssByVij,dssByV[[1]]}],vn=1,ds=dssByV[[1]][[1]],popList21=dssByV[[1]][[1]],fnsPDF={},fnsDATA={},go=False,graphC,timing,countT,vStyles,lb,p,nums={}},
Manipulate[Module[{},
popList2=Table[dssByVij,{dssByVij,dssByV[[vn]]}];
popList21=popList2[[1]];
ds=popList21;
];Column[{Button["GetData",v=vn+vMin-1;a=ds;go=True;go2=True;fnsPDF=FileNames[ToString[ds]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[vn]][[2]]]}]];
fnsDATA=FileNames[ToString[ds]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[popList1[[vn]][[2]]]}]];
{a,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
nums={};
lb=Table[i->
If[MemberQ[vStyles,i->_],
p=Flatten[Position[vStyles,i->_]][[1]];
Graphics[{vStyles[[p]][[2]],Rectangle[],Black,Text[Style[ToString[i],Bold,10],{0.5,0.5}]},ImageSize->30]
,
Graphics[{LightBlue,Rectangle[],Black,Text[Style[ToString[i],Bold,10],{0.5,0.5}]},ImageSize->30]
],{i,1,graphC}]],If[go,Column[{Row[{Column[{"V",vn+vMin-1}],Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],Row[{ToExpression[Import[fnsPDF[[1]]]]},""],TogglerBar[Dynamic[nums],lb,Appearance -> "Horizontal" -> {Automatic,20}],Dynamic[nums],Button["get All",getGraphsWanted[vn+vMin-1,a,{-1}]],Button["get graph Numbers",getGraphsWanted[vn+vMin-1,a,nums]],
Button["Print",
Print[Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],Row[{ToExpression[Import[fnsPDF[[1]]]]}]},Center]]]},Center]]}],
Row[{Control[{{vn,1},popList1,ControlType->PopupMenu}],Dynamic[Control[{{ds,popList21},Dynamic[popList2],ControlType->PopupMenu}]]}]]
],
DynamicModule[{left,right},Manipulate[
lbls=Table[j->graphsWanted[[j]][[1]],{j,1,Length[graphsWanted]}];
If[Length[lbls]>0,
Row[{Column[{If[Length[graphsWanted]>=left,showGraph[graphsWanted[[left]][[2]]]],Button["Print",Print["GRAPH NUMBER: ",lbls[[left]][[2]]];Print[showGraph[graphsWanted[[left]][[2]]]]]}],Column[{If[Length[graphsWanted]>=right,showGraph[graphsWanted[[right]][[2]]]],Button["Print",Print["GRAPH NUMBER: ",lbls[[right]][[2]]];Print[showGraph[graphsWanted[[right]][[2]]]]]}]}]
],
Row[{Dynamic[Control[{{left,1},Dynamic[lbls],ControlType->RadioButtonBar}]],Dynamic[Control[{{right,1},Dynamic[lbls],ControlType->RadioButtonBar}]]}]
]
],
Thread[Range[10]->cols],
Dynamic[If[go2,
fnsDATA=FileNames[ToString[a]<>"*DATA.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsGRAPH=FileNames[ToString[a]<>"*graphs.txt",FileNameJoin[{NotebookDirectory[],ToString[v]}]];
fnsCOMPLETE=FileNames[StringJoin[ToString[v],"V","*.txt"],{FileNameJoin[{NotebookDirectory[],"graphdata"}]}];
{aP,graphC,timing,countT,vStyles}=ReadList[fnsDATA[[1]]];
gra=ToExpression[Import[fnsGRAPH[[1]]]];
allCOMPLETE=ReadList[fnsCOMPLETE[[1]]];
positionDS=Position[allCOMPLETE,a];
positionGRAPHS=positionDS[[1]][[1]];
completeGRAPHS=allCOMPLETE[[positionGRAPHS]][[2]];
Column[{Row[{Column[{"Degree Sequences",a}],Column[{"graphC",graphC}],Column[{"timing",timing}],Column[{"countT",countT}]}," "],getFormattedGraph[completeGRAPHS,gra,graphC,a],Row[{"Number of Unique Graphs: ", Length[completeGRAPHS],Column[Table[Prepend[completeGRAPHSi[[3]],completeGRAPHSi[[2]]],{completeGRAPHSi,completeGRAPHS}]]}]}]
]]
}];
];
End[];
EndPackage[];