Skip to main content
briefly describe chordless ideas
Source Link
Adam
  • 4k
  • 7
  • 24

Streamlining the code

In convelist,

  • Map[List@@#&,cycle] is succinctly written as List@@@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,

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.

Streamlining the code

In convelist,

  • Map[List@@#&,cycle] is succinctly written as List@@@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,

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.

Streamlining the code

In convelist,

  • Map[List@@#&,cycle] is succinctly written as List@@@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,

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.

Source Link
Adam
  • 4k
  • 7
  • 24

Streamlining the code

In convelist,

  • Map[List@@#&,cycle] is succinctly written as List@@@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,

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.