Browse Source

fix: repair and verify legacy builder

master
Dnomd343 6 days ago
parent
commit
98411a8027
  1. 10
      misc/all-graph/compare.py
  2. 47
      misc/graph/build.py

10
misc/all-graph/compare.py

@ -19,10 +19,12 @@ def compare(file_1: str, file_2: str) -> None:
for edge in g2.es: for edge in g2.es:
assert edge.attributes() == {} assert edge.attributes() == {}
for i in range(g1.vcount()): gv1 = {x['code']: x.attributes() for x in g1.vs}
assert g1.vs[i].attributes() == g2.vs[i].attributes() gv2 = {x['code']: x.attributes() for x in g2.vs}
assert gv1 == gv2
if __name__ == '__main__': if __name__ == '__main__':
for name in sorted(os.listdir('output-ig-raw')): assert sorted(os.listdir('legacy-ig')) == sorted(os.listdir('modern-ig'))
compare(f'output-ig/{name}', f'output-ig-raw/{name}') for name in sorted(os.listdir('modern-ig')):
compare(f'legacy-ig/{name}', f'modern-ig/{name}')

47
misc/graph/build.py

@ -4,12 +4,23 @@ import pickle
import igraph as ig import igraph as ig
from klotski import FastCal from klotski import FastCal
from klotski import CommonCode from klotski import Block, Layout
from klotski import Group, GroupUnion from klotski import Group, GroupUnion
def build_step_map(code: str) -> dict[CommonCode, int]: def is_valid_solution(code: Layout) -> bool:
cal = FastCal(CommonCode(code)) if str(code)[0] != 'D':
return False
seq = code.dump_seq()
is_z_valid = seq[9] == Block.SPACE and seq[10] == Block.SPACE
is_x_valid = seq[12] == Block.SPACE and seq[16] == Block.SPACE
is_y_valid = seq[15] == Block.SPACE and seq[19] == Block.SPACE
return is_x_valid or is_y_valid or is_z_valid
def build_step_map(code: str) -> dict[Layout, int]:
cal = FastCal(Layout(code))
cal.build_all() cal.build_all()
data = cal.exports() data = cal.exports()
result = {} result = {}
@ -19,8 +30,8 @@ def build_step_map(code: str) -> dict[CommonCode, int]:
return result return result
def build_min_step_scope(group: Group, targets: list[str]) -> dict[CommonCode, dict[CommonCode, int]]: def build_min_step_scope(group: Group, targets: list[str]) -> dict[Layout, dict[Layout, int]]:
targets = [CommonCode(x) for x in targets] targets = [Layout(x) for x in targets]
all_solution = set([x for x in group.cases() if str(x).startswith('D')]) all_solution = set([x for x in group.cases() if str(x).startswith('D')])
not_solved = all_solution - set(targets) not_solved = all_solution - set(targets)
@ -44,7 +55,7 @@ def build_min_step_scope(group: Group, targets: list[str]) -> dict[CommonCode, d
return result return result
def build_graph(nodes: dict[CommonCode, int]) -> ig.Graph: def build_graph(nodes: dict[Layout, int]) -> ig.Graph:
edges = [] edges = []
for code, step in nodes.items(): for code, step in nodes.items():
for next_case in code.next_cases(): for next_case in code.next_cases():
@ -67,16 +78,24 @@ def save_graph(name: str, graph: ig.Graph) -> None:
pickle.dump(graph, fp) pickle.dump(graph, fp)
def main() -> None: def build_data(group: Group) -> None:
targets = [ print(f'Start building: {group}')
'DAAF4CC', 'DABFD20', 'DAEF720', 'DAEFD20', 'DAFED20', 'DBAB4CC', 'DBAFD20', 'DEAB4CC', 'DEAFD20', 'DEEB60C', 'DFAA4CC', 'DFAED20', targets = [str(x)[:7] for x in list(group.cases()) if is_valid_solution(x)]
'DAA7F30', 'DAB9F30', 'DABDF80', 'DAE9F30', 'DAEDF80', 'DAFA730', 'DAFB780', 'DBADF80', 'DBAF780', 'DBBE930', 'DEADF80', 'DFAB780', if not targets:
'DAF60EC', 'DBE60EC', 'DBE70AC', 'DBF682C', 'DFA70AC', 'DFE90AC', return
]
group = GroupUnion(169).groups()[1]
data = build_min_step_scope(group, targets) data = build_min_step_scope(group, targets)
for target in targets: for target in targets:
save_graph(target, build_graph(data[CommonCode(target)])) save_graph(target, build_graph(data[Layout(target)]))
def main() -> None:
group = GroupUnion(169).groups()[1]
build_data(group)
# type_ids = [149, 154, 159, 164, 169, 174]
# groups = [y for x in type_ids for y in GroupUnion(x).groups()]
# for group in groups:
# build_data(group)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save