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

1
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

1
420

pieces from

1
images/pillars.jpg

where each piece is 48×48 pixels.

Run

1
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

1
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
1
--image
Path to puzzle
1
--size
Puzzle piece size in pixels
1
--generations
Number of generations for genetic algorithm
1
--population
Number of individuals in population
1
--verbose
Show best solution after each generation
1
--save
Save puzzle solution as image

Run

1
gaps --help

for detailed help.

Be the first to comment

Leave a Reply

Your email address will not be published.