From 23a7baa2444adb9e96c7eedcb6cc775a4335a2ff Mon Sep 17 00:00:00 2001 From: Fightlapa Date: Thu, 16 Jul 2020 20:49:41 +0200 Subject: [PATCH 1/3] Adding fork graph, gem graph and bull graph to graph list --- src/sage/graphs/generators/basic.py | 61 +++++++++++++++++++++++++++++ src/sage/graphs/graph_generators.py | 6 +++ src/sage/graphs/graph_list.py | 3 ++ 3 files changed, 70 insertions(+) diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index 759481057fa..354aea85ee0 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -608,6 +608,67 @@ def DiamondGraph(): edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)] return graph.Graph(edges, pos=pos_dict, name="Diamond Graph") +def GemGraph(): + """ + Returns a gem graph with 5 nodes. + + A gem graph is a fan graph (4,1). + + PLOTTING: Upon construction, the position dictionary is filled to + override the spring-layout algorithm. By convention, the gem + graph is drawn as a gem, with the sharp part on the bottom. + + EXAMPLES: Construct and show a gem graph + + :: + + sage: g = graphs.GemGraph() + sage: g.show() + """ + pos_dict = {0:(0.5,0),1:(0,0.75),2:(0.25,1),3:(0.75,1),4:(1,0.75)} + edges = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (2, 3), (3, 4)] + return graph.Graph(edges, pos=pos_dict, name="Gem Graph") + +def ForkGraph(): + """ + Returns a fork graph with 5 nodes. + + A fork graph, sometimes also called chair graph, is 5 vertex tree. + + PLOTTING: Upon construction, the position dictionary is filled to + override the spring-layout algorithm. By convention, the fork + graph is drawn as a fork, with the sharp part on the bottom. + + EXAMPLES: Construct and show a fork graph + + :: + + sage: g = graphs.ForkGraph() + sage: g.show() + """ + pos_dict = {0:(0,0),1:(1,0),2:(0,1),3:(1,1),4:(0,2)} + edges = [(0, 2), (2, 3), (3, 1), (2, 4)] + return graph.Graph(edges, pos=pos_dict, name="Fork Graph") + +def DartGraph(): + """ + Returns a dart graph with 5 nodes. + + PLOTTING: Upon construction, the position dictionary is filled to + override the spring-layout algorithm. By convention, the dart + graph is drawn as a dart, with the sharp part on the bottom. + + EXAMPLES: Construct and show a dart graph + + :: + + sage: g = graphs.DartGraph() + sage: g.show() + """ + pos_dict = {0:(0,1),1:(-1,0),2:(1,0),3:(0,-1),4:(0,0)} + edges = [(0, 1), (0, 2), (1, 4), (2, 4), (0, 4), (3, 4)] + return graph.Graph(edges, pos=pos_dict, name="Dart Graph") + def EmptyGraph(): """ Returns an empty graph (0 nodes and 0 edges). diff --git a/src/sage/graphs/graph_generators.py b/src/sage/graphs/graph_generators.py index 283d9f5fc4a..792e904a79c 100644 --- a/src/sage/graphs/graph_generators.py +++ b/src/sage/graphs/graph_generators.py @@ -67,6 +67,9 @@ def __append_to_doc(methods): "CompleteGraph", "CompleteMultipartiteGraph", "DiamondGraph", + "GemGraph", + "DartGraph", + "ForkGraph", "DipoleGraph", "EmptyGraph", "Grid2dGraph", @@ -1887,6 +1890,9 @@ def quadrangulations(self, order, minimum_degree=None, minimum_connectivity=None CompleteBipartiteGraph = staticmethod(basic.CompleteBipartiteGraph) CompleteMultipartiteGraph= staticmethod(basic.CompleteMultipartiteGraph) DiamondGraph = staticmethod(basic.DiamondGraph) + GemGraph = staticmethod(basic.GemGraph) + DartGraph = staticmethod(basic.DartGraph) + ForkGraph = staticmethod(basic.ForkGraph) EmptyGraph = staticmethod(basic.EmptyGraph) Grid2dGraph = staticmethod(basic.Grid2dGraph) GridGraph = staticmethod(basic.GridGraph) diff --git a/src/sage/graphs/graph_list.py b/src/sage/graphs/graph_list.py index 21f50b1c6de..6263c56049f 100644 --- a/src/sage/graphs/graph_list.py +++ b/src/sage/graphs/graph_list.py @@ -303,6 +303,9 @@ def show_graphs(graph_list, **kwds): sage: glist.append(graphs.BarbellGraph(7, 4)) sage: glist.append(graphs.CycleGraph(15)) sage: glist.append(graphs.DiamondGraph()) + sage: glist.append(graphs.GemGraph()) + sage: glist.append(graphs.DartGraph()) + sage: glist.append(graphs.ForkGraph()) sage: glist.append(graphs.HouseGraph()) sage: glist.append(graphs.HouseXGraph()) sage: glist.append(graphs.KrackhardtKiteGraph()) From 1838d264101892e533b87185f774be75673a7f7e Mon Sep 17 00:00:00 2001 From: Fightlapa Date: Sat, 18 Jul 2020 12:27:41 +0200 Subject: [PATCH 2/3] Fixed docs of new graph structures --- src/sage/graphs/generators/basic.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index 354aea85ee0..7d689e8b229 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -610,7 +610,7 @@ def DiamondGraph(): def GemGraph(): """ - Returns a gem graph with 5 nodes. + Return a gem graph with 5 nodes. A gem graph is a fan graph (4,1). @@ -618,9 +618,9 @@ def GemGraph(): override the spring-layout algorithm. By convention, the gem graph is drawn as a gem, with the sharp part on the bottom. - EXAMPLES: Construct and show a gem graph + EXAMPLES: - :: + Construct and show a gem graph:: sage: g = graphs.GemGraph() sage: g.show() @@ -631,7 +631,7 @@ def GemGraph(): def ForkGraph(): """ - Returns a fork graph with 5 nodes. + Return a fork graph with 5 nodes. A fork graph, sometimes also called chair graph, is 5 vertex tree. @@ -639,9 +639,9 @@ def ForkGraph(): override the spring-layout algorithm. By convention, the fork graph is drawn as a fork, with the sharp part on the bottom. - EXAMPLES: Construct and show a fork graph + EXAMPLES: - :: + Construct and show a fork graph:: sage: g = graphs.ForkGraph() sage: g.show() @@ -652,15 +652,15 @@ def ForkGraph(): def DartGraph(): """ - Returns a dart graph with 5 nodes. + Return a dart graph with 5 nodes. PLOTTING: Upon construction, the position dictionary is filled to override the spring-layout algorithm. By convention, the dart graph is drawn as a dart, with the sharp part on the bottom. - EXAMPLES: Construct and show a dart graph + EXAMPLES: - :: + Construct and show a dart graph:: sage: g = graphs.DartGraph() sage: g.show() From 5ec61331124c57038a0d7fa63ad1f66e624901e2 Mon Sep 17 00:00:00 2001 From: Fightlapa Date: Sat, 8 Aug 2020 12:07:20 +0200 Subject: [PATCH 3/3] Added long time comment in graph show method, fixed test --- src/sage/graphs/generators/basic.py | 6 +++--- src/sage/graphs/graph_list.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index 7d689e8b229..35a4412577d 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -623,7 +623,7 @@ def GemGraph(): Construct and show a gem graph:: sage: g = graphs.GemGraph() - sage: g.show() + sage: g.show() # long time """ pos_dict = {0:(0.5,0),1:(0,0.75),2:(0.25,1),3:(0.75,1),4:(1,0.75)} edges = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (2, 3), (3, 4)] @@ -644,7 +644,7 @@ def ForkGraph(): Construct and show a fork graph:: sage: g = graphs.ForkGraph() - sage: g.show() + sage: g.show() # long time """ pos_dict = {0:(0,0),1:(1,0),2:(0,1),3:(1,1),4:(0,2)} edges = [(0, 2), (2, 3), (3, 1), (2, 4)] @@ -663,7 +663,7 @@ def DartGraph(): Construct and show a dart graph:: sage: g = graphs.DartGraph() - sage: g.show() + sage: g.show() # long time """ pos_dict = {0:(0,1),1:(-1,0),2:(1,0),3:(0,-1),4:(0,0)} edges = [(0, 1), (0, 2), (1, 4), (2, 4), (0, 4), (3, 4)] diff --git a/src/sage/graphs/graph_list.py b/src/sage/graphs/graph_list.py index 6263c56049f..376a5f7eabf 100644 --- a/src/sage/graphs/graph_list.py +++ b/src/sage/graphs/graph_list.py @@ -319,7 +319,7 @@ def show_graphs(graph_list, **kwds): Check that length is <= 20:: sage: len(glist) - 14 + 17 Show the graphs in a graphics array::