CoCalc Logo Icon
DocsShareSupport News Sign UpSign In
Views: 16
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu2204
Embed | Download | Raw |
1
2
import py_svg_combinatorics as psc
3
4
import numpy as np
5
6
def get_random_subsets(N, sizes):
7
res = []
8
for size_, repeat_ in sizes:
9
for _ in range(repeat_):
10
res.append(list(np.random.choice(np.arange(1, N), size_)))
11
return res
12
13
def testsubsets():
14
N = 20
15
sets = get_random_subsets(20, [(2, 20), (3, 20)])
16
# sets = [
17
# ['a', 0, 'b', 23, 2, 7],
18
# [1, 2, 77, 'b', 'f'],
19
# [2*i for i in range(20)],
20
# [3*i for i in range(10)],
21
# ]
22
23
svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])
24
with open('vis.svg', 'w', encoding='utf-8') as lf:
25
lf.write(svg)
26
27
28
def testsubsets_with_dict():
29
sets = {'x_{1}=0': ['x_{1}', 'C_{0}'],
30
'x_{1}=1': ['x_{1}'],
31
'x_{2}=0': ['x_{2}'],
32
'x_{2}=1': ['x_{2}', 'C_{0}'],
33
'x_{3}=0': ['x_{3}', 'C_{0}'],
34
'x_{3}=1': ['x_{3}']}
35
svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])
36
with open('vis.svg', 'w', encoding='utf-8') as lf:
37
lf.write(svg)
38
39
40
def test3d():
41
alist = [[0, 1, 2],
42
[1, 0, 2],
43
[1, 1, 1],
44
[1, 2, 0],
45
[2, 0, 1],
46
[3, 2, 1],
47
[2, 1, 0]]
48
49
svg = psc.matchings2svg(alist)
50
with open('vis.svg', 'w', encoding='utf-8') as lf:
51
lf.write(svg)
52
53
54
def test4d():
55
alist = [[0, 'x_1', r'\frac11', 1],
56
[0, 'x_2', 'y^2', 1],
57
[0, 'x_1', 'y^2', 3]]
58
59
svg = psc.matchings2svg(alist)
60
with open('vis.svg', 'w', encoding='utf-8') as lf:
61
lf.write(svg)
62
63
64
def testtable():
65
alist = [['x_1', r'\frac11', 1],
66
['x_2', 'y^2', 1],
67
['x_1', 'y^2', 3]]
68
69
svg = psc.rows2svgtable(alist, selected_rows=[2])
70
with open('vis.svg', 'w', encoding='utf-8') as lf:
71
lf.write(svg)
72
73
74
# test3d()
75
# testtable()
76
# testsubsets()
77
testsubsets_with_dict()
78