Project: Моделирование труднорешаемых задач
Views: 16Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu22041import py_svg_combinatorics as psc23import numpy as np45def get_random_subsets(N, sizes):6res = []7for size_, repeat_ in sizes:8for _ in range(repeat_):9res.append(list(np.random.choice(np.arange(1, N), size_)))10return res1112def testsubsets():13N = 2014sets = get_random_subsets(20, [(2, 20), (3, 20)])15# sets = [16# ['a', 0, 'b', 23, 2, 7],17# [1, 2, 77, 'b', 'f'],18# [2*i for i in range(20)],19# [3*i for i in range(10)],20# ]2122svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])23with open('vis.svg', 'w', encoding='utf-8') as lf:24lf.write(svg)252627def testsubsets_with_dict():28sets = {'x_{1}=0': ['x_{1}', 'C_{0}'],29'x_{1}=1': ['x_{1}'],30'x_{2}=0': ['x_{2}'],31'x_{2}=1': ['x_{2}', 'C_{0}'],32'x_{3}=0': ['x_{3}', 'C_{0}'],33'x_{3}=1': ['x_{3}']}34svg = psc.subsets2svg(sets, selected=[1,2], selected_items=['1', '8', '12'])35with open('vis.svg', 'w', encoding='utf-8') as lf:36lf.write(svg)373839def test3d():40alist = [[0, 1, 2],41[1, 0, 2],42[1, 1, 1],43[1, 2, 0],44[2, 0, 1],45[3, 2, 1],46[2, 1, 0]]4748svg = psc.matchings2svg(alist)49with open('vis.svg', 'w', encoding='utf-8') as lf:50lf.write(svg)515253def test4d():54alist = [[0, 'x_1', r'\frac11', 1],55[0, 'x_2', 'y^2', 1],56[0, 'x_1', 'y^2', 3]]5758svg = psc.matchings2svg(alist)59with open('vis.svg', 'w', encoding='utf-8') as lf:60lf.write(svg)616263def testtable():64alist = [['x_1', r'\frac11', 1],65['x_2', 'y^2', 1],66['x_1', 'y^2', 3]]6768svg = psc.rows2svgtable(alist, selected_rows=[2])69with open('vis.svg', 'w', encoding='utf-8') as lf:70lf.write(svg)717273# test3d()74# testtable()75# testsubsets()76testsubsets_with_dict()7778