import py_svg_combinatorics as psc
import numpy as np
def get_random_subsets(N, sizes):
res = []
for size_, repeat_ in sizes:
for _ in range(repeat_):
res.append(list(np.random.choice(np.arange(1, N), size_)))
return res
def testsubsets():
N = 20
sets = get_random_subsets(20, [(2, 20), (3, 20)])
svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])
with open('vis.svg', 'w', encoding='utf-8') as lf:
lf.write(svg)
def testsubsets_with_dict():
sets = {'x_{1}=0': ['x_{1}', 'C_{0}'],
'x_{1}=1': ['x_{1}'],
'x_{2}=0': ['x_{2}'],
'x_{2}=1': ['x_{2}', 'C_{0}'],
'x_{3}=0': ['x_{3}', 'C_{0}'],
'x_{3}=1': ['x_{3}']}
svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])
with open('vis.svg', 'w', encoding='utf-8') as lf:
lf.write(svg)
def test3d():
alist = [[0, 1, 2],
[1, 0, 2],
[1, 1, 1],
[1, 2, 0],
[2, 0, 1],
[3, 2, 1],
[2, 1, 0]]
svg = psc.matchings2svg(alist)
with open('vis.svg', 'w', encoding='utf-8') as lf:
lf.write(svg)
def test4d():
alist = [[0, 'x_1', r'\frac11', 1],
[0, 'x_2', 'y^2', 1],
[0, 'x_1', 'y^2', 3]]
svg = psc.matchings2svg(alist)
with open('vis.svg', 'w', encoding='utf-8') as lf:
lf.write(svg)
def testtable():
alist = [['x_1', r'\frac11', 1],
['x_2', 'y^2', 1],
['x_1', 'y^2', 3]]
svg = psc.rows2svgtable(alist, selected_rows=[2])
with open('vis.svg', 'w', encoding='utf-8') as lf:
lf.write(svg)
testsubsets_with_dict()