简体   繁体   English

彩色的正方形拼图与Numberjack

[英]Colored squares puzzle with Numberjack

I'm going crazy with this problem that I have to solve with Numberjack, that is a library in python for CSP. 我为必须使用Numberjack解决的这个问题而疯狂,这是python中用于CSP的库。 We have nxm squares with colored sides. 我们有带有彩色边的nxm正方形。 These squares must be arranged in anxm grid in such a way that the squares' adjacent sides are of the same color. 这些正方形必须以axm网格的方式排列,以使正方形的相邻边具有相同的颜色。 The square can be rotated and shifted. 正方形可以旋转和移动。 An example: 一个例子:

在此处输入图片说明

I thought about using 4 matrix (one for nord, one for sud, one for west and one for east side ) and a number for a color. 我考虑过使用4个矩阵(一个用于nord,一个用于sud,一个用于西,一个用于东)和一个数字。 Nord(i,j), West(i,j), East(i,j), Sud(i,j) describe the square i,j on the grid. Nord(i,j),West(i,j),East(i,j),Sud(i,j)描述网格上的正方形i,j。 Which constraints i have to consider? 我必须考虑哪些约束?

As this sounds like homework, let me just outline one model that works: 听起来像是功课,让我概述一个可行的模型:

Describe each given type of tile as a quintuple (Type,N,E,S,W) , where Type is an identifier for this type of tile, and N,E,S,W are the colours on the north, east, south and west side. 将每种给定类型的图块描述为五元组(Type,N,E,S,W) ,其中Type是该图块Type的标识符,而N,E,S,W是北,东,南的颜色和西侧。 For each type of tile, have four such tuples for the different rotations. 对于每种类型的图块,对于不同的旋转都有四个这样的元组。

Represent the grid with nxm similar tuples (Type,N,E,S,W) , where Type ranges over the tile type identifiers, and N,E,S,W over the colours. 用nxm个类似的元组(Type,N,E,S,W)表示网格,其中Type覆盖图块类型标识符,而N,E,S,W覆盖颜色。

You then need three types of constraints, all of which should be easily representable in Numberjack (and other finite-domain style solvers): 然后,您需要三种类型的约束,所有这些约束在Numberjack(和其他有限域样式求解器)中都应易于表示:

  • every grid tuple matches one of the tile descriptor tuples 每个网格元组都匹配图块描述符元组之一
  • adjacent colours match 相邻颜色匹配
  • the grid contains the right number of tiles of each type 网格包含每种类型的正确数量的图块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM