Notebooks · lib/algo/legacy/tests/topo
lib/ algo/ legacy/ tests/ topo.viv
lib/algo/legacy/tests/topo.viv · 1 code cellOpen in the workbenchDownload .vivLook inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.
[1]lines 1–51
# Generated by tools/algo/check.py from lib/algo/algo.spec: do not edit. # Each case prints its input (= X), its results, and the verdict of each postcondition # (? ...) as lib/algo/props.viv computes it; check.py checks them again in Python. from algo.cases import algo_case, CASE_NAMES from algo.props import algo_is_topological from algo.legacy.topo import topological_sort #| ta_topological_sort: TheAlgorithms Kahn topological sort (graphs.viv) def algo_t_ta_topological_sort(kind, n, inside, skip: Arr) -> Bool { X = algo_case(kind, n, 1 + 97 * kind + n) print("@ ta_topological_sort", CASE_NAMES[kind], n) K = zeros(len(X)) SRC = [] DST = [] for i to len(X) { K[i] = len(X) - i } for i to len(X) { for j from i + 1 to len(X) { if X[i] + X[j] > 0.25 { SRC = append(SRC, K[i]) DST = append(DST, K[j]) } } } R = topological_sort(K, SRC, DST) print("= X", fmt(X)) print("= R", fmt(R)) print("= K", fmt(K)) print("= SRC", fmt(SRC)) print("= DST", fmt(DST)) p0 = algo_is_topological(R, K, SRC, DST) print("?", p0) return inside == 0 or ((p0 or skip[0] == 1)) } algo_t_ok_ta_topological_sort = true algo_t_kinds_ta_topological_sort = [0.0] algo_t_inside_ta_topological_sort = [1.0] algo_t_sizes_ta_topological_sort = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 8.0, 9.0, 15.0, 16.0, 17.0, 31.0, 32.0, 33.0] algo_t_skip_ta_topological_sort = [0.0] for algo_t_k to len(algo_t_kinds_ta_topological_sort) { for algo_t_s to len(algo_t_sizes_ta_topological_sort) { algo_t_r = algo_t_ta_topological_sort(algo_t_kinds_ta_topological_sort[algo_t_k], algo_t_sizes_ta_topological_sort[algo_t_s], algo_t_inside_ta_topological_sort[algo_t_k], algo_t_skip_ta_topological_sort[algo_t_k * 1:(algo_t_k + 1) * 1]) algo_t_ok_ta_topological_sort = algo_t_ok_ta_topological_sort and algo_t_r } } test "ta_topological_sort: topological R K SRC DST (kinds random)" { assert_true(algo_t_ok_ta_topological_sort) }