|
1 |
| -# LockPatternComplexity |
| 1 | +# Solving the Most Complex Lock Patterns |
| 2 | +3×3 | 5×5 |
| 3 | +:-:|:-: |
| 4 | + |  |
| 5 | +distance: 22 | distance: 116 |
2 | 6 |
|
3 | 7 | [](https://jaantollander.github.io/LockPatternComplexity.jl/stable)
|
4 | 8 | [](https://jaantollander.github.io/LockPatternComplexity.jl/dev)
|
5 | 9 | [](https://github.com/jaantollander/LockPatternComplexity.jl/actions)
|
| 10 | + |
| 11 | +4×4 | 6×6 |
| 12 | +:-:|:-: |
| 13 | + |  |
| 14 | +distance: 57 | distance: 188 |
| 15 | + |
| 16 | +Solving the most complex lock patterns using Constraint Programming with [MiniZinc](https://www.minizinc.org/). |
| 17 | + |
| 18 | +Lock patterns plots are generated using [Julia Language](https://julialang.org/) with Plots.jl package. |
| 19 | + |
| 20 | +This problem was inspired by [What Is The Most Complicated Lock Pattern?](https://www.youtube.com/watch?v=PKjbBQ0PBCQ) by *Dr. Zye*. I highly recommend watching the video! |
| 21 | + |
| 22 | +You can try out lock patterns with [lock pattern demo](https://tympanix.github.io/pattern-lock-js/) by @tympanix. |
| 23 | + |
| 24 | + |
| 25 | +## About |
| 26 | +We use similar definition of lock pattern complexity as in the *Dr. Zye*'s video. However, we generalize the definition such that we can find solutions for all n×n grid sizes. |
| 27 | + |
| 28 | +**Satisfiability problem** cares about finding a max complexity patterns, that is, patterns where each line has a unique line type. |
| 29 | + |
| 30 | +**Optimization problem** consideres max complexity pattern with higher taxicab distance as more complex. |
| 31 | + |
| 32 | +For small instances, it is possible to find the maximum the taxicab distance. For larger instances, simply finding satisfying solutions can be quite difficult. |
| 33 | + |
| 34 | +I'm writing more in-depth theory to the [**documentation**](https://jaantollander.github.io/lock-pattern-complexity/dev/). |
| 35 | + |
| 36 | + |
| 37 | +## Open Questions |
| 38 | +Can we find a max complexity pattern for 4×4 grid that provably maximizes the taxicab distance? |
| 39 | + |
| 40 | +Can we find a max complexity pattern for 5×5 grid that provably maximizes the taxicab distance? |
| 41 | + |
| 42 | +Can we find a max complexity pattern for 7×7 grid? |
| 43 | + |
| 44 | +<!-- We can generalize the definition of pattern complexity as maximizing the number of line types used in the pattern as primary objective and maximizing the taxicab distance as secondary objective. In the generalized definition, every grid size would have solutions. Also, it would preserve the max complexity patterns. --> |
| 45 | + |
| 46 | +<!-- A question that arises from the generalized definition is whether all grids have a generalized complexity pattern such that each line has a unique type. --> |
| 47 | + |
| 48 | + |
| 49 | +## Structure |
| 50 | +The [`src/nxn.mzn`](./src/nxn.mzn) file contains the MiniZinc constraint programming formulation. |
| 51 | + |
| 52 | +The [`src/plots.jl`](./src/plots.jl) file contains the plotting code. |
| 53 | + |
| 54 | +Each `nxn.sh` shell script inside [`scripts`](./scripts/) contains the command for running the model for the grid of given size. |
| 55 | + |
| 56 | +The [`results`](./results/) directory contains the output from the shell scripts and the generated SVG plots for each grid size and taxicab distance in format `<grid>/<distance>/<id>.svg`. |
| 57 | + |
| 58 | + |
| 59 | +## Instructions |
| 60 | +We can begin by installing MiniZinc and adding it to our PATH environment variable. The, we can run the appropriate shell file from the `src` directory and write the output to `results/3x3.txt` file. For example: |
| 61 | + |
| 62 | +```bash |
| 63 | +./scripts/3x3.sh > results/3x3.txt |
| 64 | +``` |
| 65 | + |
| 66 | +Alternatively, we can run the MiniZinc model directly. |
| 67 | + |
| 68 | +```bash |
| 69 | +minizinc src/nxn.mzn -s -a --solver gecode -D "n=3;" |
| 70 | +``` |
0 commit comments