Streamlining the code
In convelist
,
Map[List@@#&,cycle]
is succinctly written asList@@@cycle
.- You can map on the second level (i.e. over the vertex indices instead of the UndirectedEdges): for instance,
Union@Reap[Map[Sow,cycle,{2}]][[2,1]]
. - Since each edge in a cycle is ordered consistently, you can just use Span to take the first vertex in each edge:
cycle[[;;,;;,1]]
Your noIntersectionQ
can be replaced with DisjointQ
.
In finddisjointcycles
,
If you forgo For loops, declaring
i
,j
andn
becomes unnecessary. Keeping in mind Is there a Break[] equivalent for short-circuiting in Table?, you could useTable
:Table[ If[DisjointQ@@listOfLists[[{i,j}]], Return[{i,j},Table]], {i,Length@listOfLists},{j,i-1}]
While your functions are very useful for learning the internals of Mathematica, I'd say they're simple enough to not warrant definition. So I'd write something like
finddisjointcycle[g_Graph]:=
Table[ If[DisjointQ@@#[[{i,j}]],Return[{i,j},Table]],
{i,Length@#},{j,i-1}]& @FindCycle[g,{10},All][[;;,;;,1]]
If you want to find all such cycles, you can exploit SequencePosition
:
finddisjointcycles[g_Graph] := SequencePosition[
FindCycle[g,{10},All][[;;,;;,1]],
{x_,___,y_}/;DisjointQ[x,y]:>{x,y},Overlaps->True]
with the added benefit that you can simply include an extra ,1
parameter to limit it to one instance.
Chordless
You could somehow filter the result of FindCycle
to only deal with chordless ones. Alternatively, I believe FindFundamentalCycles
would return all chordless cycles, so you can filter its result for 10 long single face cycles.