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

安装

Clone repo:

$ git clone https://github.com/nemanja-m/gaps.git
$ cd gaps

Install requirements:

$ pip install -r requirements.txt
$ sudo apt-get install python-tk

Install project in editable mode:

$ pip install -e .

Creating puzzles from images

To create puzzle from image use create_puzzle script.

i.e.

$ create_puzzle images/pillars.jpg --size=48 --destination=puzzle.jpg

[SUCCESS] Puzzle created with 420 pieces

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.

$ gaps --image=puzzle.jpg --generations=20 --population=600

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