Skip to content

Commit bc1c917

Browse files
committed
Add LadderGraph
1 parent 45a8544 commit bc1c917

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

pymathics/graph/generators.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class CompleteGraph(_NetworkXBuiltin):
202202
"""
203203
<dl>
204204
<dt>'CompleteGraph[$n$]'
205-
<dd>gives the complete graph with $n$ vertices, $K_n$
205+
<dd>Returns the complete graph with $n$ vertices, $K_n$
206206
</dl>
207207
208208
>> CompleteGraph[8]
@@ -343,7 +343,7 @@ def apply(self, r, n, expression, evaluation, options):
343343
class GraphAtlas(_NetworkXBuiltin):
344344
"""<dl>
345345
<dt>'GraphAtlas[$n$]'
346-
<dd>gives graph number $i$ from the Networkx's Graph
346+
<dd>Returns graph number $i$ from the Networkx's Graph
347347
Atlas. There are about 1200 of them and get large as $i$
348348
increases.
349349
</dl>
@@ -503,6 +503,36 @@ def apply_2(self, n, k, expression, evaluation, options):
503503
return f_r_t_apply(self, k, n, expression, evaluation, options)
504504

505505

506+
class LadderGraph(_NetworkXBuiltin):
507+
"""
508+
<dl>
509+
<dt>'LadderGraph[$n$]'
510+
<dd>Returns the Ladder graph of length $n$.
511+
</dl>
512+
513+
>> StarGraph[8]
514+
= -Graph-
515+
"""
516+
517+
messages = {
518+
"ilsmp": "Expected a positive integer at position 1 in ``.",
519+
}
520+
521+
def apply(self, n, expression, evaluation, options):
522+
"%(name)s[n_Integer, OptionsPattern[%(name)s]]"
523+
py_n = n.get_int_value()
524+
525+
if py_n < 1:
526+
evaluation.message(self.get_name(), "ilsmp", expression)
527+
return
528+
529+
args = (py_n,)
530+
g = graph_helper(nx.ladder_graph, options, False, "spring", 0, *args)
531+
if not g:
532+
return None
533+
g.G.n = n
534+
return g
535+
506536
class PathGraph(_NetworkXBuiltin):
507537
"""
508538
<dl>
@@ -596,7 +626,7 @@ class StarGraph(_NetworkXBuiltin):
596626
"""
597627
<dl>
598628
<dt>'StarGraph[$n$]'
599-
<dd>gives a star graph with $n$ vertices
629+
<dd>Returns a star graph with $n$ vertices
600630
</dl>
601631
602632
>> StarGraph[8]

0 commit comments

Comments
 (0)