From 313f93dbc5a3431ef92628e37791d4c4f289da20 Mon Sep 17 00:00:00 2001 From: Jack Grahl Date: Tue, 6 Jul 2021 23:54:45 +0100 Subject: [PATCH] Add lots of things that we expect to do in doctst. --- examples/split_problems.md | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 examples/split_problems.md diff --git a/examples/split_problems.md b/examples/split_problems.md new file mode 100644 index 0000000..d4a4a46 --- /dev/null +++ b/examples/split_problems.md @@ -0,0 +1,86 @@ +To make computation more tractable, a tiling problem can be split into two or more sub-problems. Each solution to the original problem is also the solution to exactly one of the sub-problems. + +``` +>>> from polyomino.board import Chessboard +>>> from polyomino.constant import TETROMINOS, ALL_PENTOMINOS + +``` + +First a problem which involves no repeated tiles. It can be solved without splitting, but let us look at how splitting works: +``` +>>> problem = Chessboard().tile_with(ALL_PENTOMINOS + [TETROMINOS['Square']]) +>>> subproblems = problem.split(at_least=2) +>>> len(subproblems) +3 +>>> example = subproblems[0] +>>> example + +>>> print(example.display()) ++-+-+-+-+-+-+-+-+ +| | | | ++ +-+-+-+-+-+ + +| | | | ++-+ +-+ +-+-+-+-+ +| | | | | | ++ +-+-+-+ +-+-+ + +| | | | ++-+-+-+-+-+-+ + + +| | | | | ++-+ +-+-+ +-+-+-+ +| | | | | | | ++ +-+ + +-+ +-+ + +| | | | | | ++ +-+ +-+ +-+ + +| | | | | ++-+-+-+-+-+-+-+-+ +>>> sub_solution = example.solve() +>>> sub_solution + +>>> example.is_solution(sub_solution.array) +True +>>> sub_solution.tiling +[[(0, 0), (1, 1), (1, 0), (2, 0)], [(0, 3), (1, 2), (0, 2), (0, 1)], [(3, 3), (2, 2), (2, 3), (1, 3)], [(3, 0), (2, 1), (3, 1), (3, 2)]] +>>> sub_solution.display() ++-+-+-+-+-+-+-+-+ +| | | | ++ +-+-+-+-+-+ + +| | | | ++-+ +-+ +-+-+-+-+ +| | | | | | ++ +-+-+-+ +-+-+ + +| | | | ++-+-+-+-+-+-+ + + +| | | | | ++-+ +-+-+ +-+-+-+ +| | | | | | | ++ +-+ + +-+ +-+ + +| | | | | | ++ +-+ +-+ +-+ + +| | | | | ++-+-+-+-+-+-+-+-+ +>>> solution = example.original_solution(sub_solution) +>>> solution + +>>> problem.is_solution(solution.array) +True +>>> solution.tiling +[[(0, 0), (1, 1), (1, 0), (2, 0)], [(0, 3), (1, 2), (0, 2), (0, 1)], [(3, 3), (2, 2), (2, 3), (1, 3)], [(3, 0), (2, 1), (3, 1), (3, 2)]] +>>> solution.display() ++-+-+-+-+-+-+-+-+ +| | | | ++ +-+-+-+-+-+ + +| | | | ++-+ +-+ +-+-+-+-+ +| | | | | | ++ +-+-+-+ +-+-+ + +| | | | ++-+-+-+-+-+-+ + + +| | | | | ++-+ +-+-+ +-+-+-+ +| | | | | | | ++ +-+ + +-+ +-+ + +| | | | | | ++ +-+ +-+ +-+ + +| | | | | ++-+-+-+-+-+-+-+-+ +```