Skip to content

Commit

Permalink
Trac #30159: Adding new small graph structures
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/30159
Reported by: gh-Fightlapa
Ticket author(s): Jakub Jabłoński
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Aug 9, 2020
2 parents b78fa7b + 5ec6133 commit 2f73418
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/sage/graphs/generators/basic.py
Expand Up @@ -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():
"""
Return 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() # 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)]
return graph.Graph(edges, pos=pos_dict, name="Gem Graph")

def ForkGraph():
"""
Return 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() # 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)]
return graph.Graph(edges, pos=pos_dict, name="Fork Graph")

def DartGraph():
"""
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::
sage: g = graphs.DartGraph()
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)]
return graph.Graph(edges, pos=pos_dict, name="Dart Graph")

def EmptyGraph():
"""
Returns an empty graph (0 nodes and 0 edges).
Expand Down
6 changes: 6 additions & 0 deletions src/sage/graphs/graph_generators.py
Expand Up @@ -67,6 +67,9 @@ def __append_to_doc(methods):
"CompleteGraph",
"CompleteMultipartiteGraph",
"DiamondGraph",
"GemGraph",
"DartGraph",
"ForkGraph",
"DipoleGraph",
"EmptyGraph",
"Grid2dGraph",
Expand Down Expand Up @@ -1893,6 +1896,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)
Expand Down
5 changes: 4 additions & 1 deletion src/sage/graphs/graph_list.py
Expand Up @@ -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())
Expand All @@ -316,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::
Expand Down

0 comments on commit 2f73418

Please sign in to comment.