Skip to content

Commit dc80054

Browse files
committed
Add KaryTree
1 parent be25529 commit dc80054

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

pymathics/graph/graph_generators.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def graph_helper(
3535
G.graph_layout = options["System`GraphLayout"].get_string_value() or graph_layout
3636
g = Graph(G)
3737
G.vertex_labels = g.vertex_labels = options["System`VertexLabels"].get_string_value()
38-
shape = options["System`VertexShape"]
38+
shape = options["System`VertexShape"].get_string_value()
3939
G.node_shape = g.node_shape = WL_MARKER_TO_MATPLOTLIB.get(shape, shape)
4040

4141
if root is not None:
@@ -447,6 +447,40 @@ def apply(self, n, m, expression, evaluation, options):
447447
return g
448448

449449

450+
class KaryTree(_NetworkXBuiltin):
451+
"""<dl>
452+
<dt>'KaryTree[$r$, $n$]'
453+
<dd>Creates binary tree of $n$ vertices.
454+
</dl>
455+
456+
<dl>
457+
<dt>'KaryTree[$n$, $k]'
458+
<dd>Creates $k$-ary tree with $n$ vertices.
459+
</dl>
460+
>> KaryTree[10]
461+
= -Graph-
462+
463+
>> KaryTree[3, 10]
464+
= -Graph-
465+
466+
"""
467+
468+
messages = {
469+
"ilsmp": "Expected a non-negative integer at position 1 in ``.",
470+
"ilsmp2": "Expected a non-negative integer at position 2 in ``.",
471+
"mem": "Out of memory",
472+
}
473+
474+
options = DEFAULT_TREE_OPTIONS
475+
def apply(self, n, expression, evaluation, options):
476+
"%(name)s[n_Integer, OptionsPattern[%(name)s]]"
477+
return f_r_t_apply(self, Integer(2), n, expression, evaluation, options)
478+
479+
def apply_2(self, n, k, expression, evaluation, options):
480+
"%(name)s[n_Integer, k_Integer, OptionsPattern[%(name)s]]"
481+
return f_r_t_apply(self, k, n, expression, evaluation, options)
482+
483+
450484
class RandomTree(_NetworkXBuiltin):
451485
"""
452486
<dl>

0 commit comments

Comments
 (0)