gaps: 一种基于遗传算法的拼图求解器

安装

Clone repo:

[code lang=bash]
$ git clone https://github.com/nemanja-m/gaps.git
$ cd gaps
[/code]

Install requirements:

[code lang=bash]
$ pip install -r requirements.txt
$ sudo apt-get install python-tk
[/code]

Install project in editable mode:

[code lang=bash]
$ pip install -e .
[/code]

Creating puzzles from images

To create puzzle from image use create_puzzle script.

i.e.

[code lang=bash]
$ create_puzzle images/pillars.jpg –size=48 –destination=puzzle.jpg

[SUCCESS] Puzzle created with 420 pieces

[/code]

will create puzzle with 420 pieces from images/pillars.jpg where each piece is 48×48 pixels.

Run create_puzzle --help for detailed help.

NOTE Created puzzle dimensions may be smaller then original image depending on
given puzzle piece size. Maximum possible rectangle is cropped from original image.

Solving puzzles

In order to solve puzzles, use gaps script.

i.e.

[code lang=bash]
$ gaps –image=puzzle.jpg –generations=20 –population=600
[/code]

This will start genetic algorithm with initial population of 600 and 20 generations.

Following options are provided:

Option Description
--image Path to puzzle
--size Puzzle piece size in pixels
--generations Number of generations for genetic algorithm
--population Number of individuals in population
--verbose Show best solution after each generation
--save Save puzzle solution as image

Run gaps --help for detailed help.

Related posts

Leave a Comment