Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dominoes matching algorithm

Given some inputs, which consist of a left and right symbol, output chains which link the inputs.

Imagine the inputs to be dominoes which you cannot flip horizontally and need to chain them together. Creating big circular chains (ignore if you cannot physically do it with real dominos) is preferred over small circular chains which are preferred over chains where the start and end does not match.

Outputs with more circular chains (regardless of how many or chain length) are what we are looking for. For example, an output of 3 circular chains is better than 1 big chain and a leftover single domino.

Can someone point me in the right direction? What group of problems does this belong and are there existing algorithms for solving this?

Examples (outputs may be incorrect!):

in[0]=(A,B)
in[1]=(B,C)
in[2]=(C,A)
out[0]=(0,1,2)

in[0]=(A,B)
in[1]=(B,A)
in[2]=(C,D)
in[3]=(D,C)
out[0]=(0,1)
out[1]=(2,3)

in[0]=(A,B)
in[1]=(B,A)
in[2]=(C,D)
in[3]=(E,F)
out[0]=(0,1)
out[1]=(2)
out[2]=(3)

in[0]=(A,B)
in[1]=(B,A)
in[2]=(C,D)
in[3]=(D,E)
out[0]=(0,1)
out[1]=(2,3)

in[0]=(A,B)
in[1]=(B,C)
in[2]=(C,D)
out[0]=(0,1,2)
like image 522
zaf Avatar asked Mar 28 '11 10:03

zaf


1 Answers

Dominoes which cannot be flipped horizontally == directed graphs.

Putting dominoes one after the other is called a "path", if it is a closed path, it's a circuit.

A circuit that includes all the vertices of a graph is a Hamiltonian circuit.

Your problem in graph theory terms is: how to split (decompose) your graph into a minimum number of subgraphs that have Hamiltonian circuits. (a.k.a. Hamiltonian graphs)

like image 131
biziclop Avatar answered Oct 04 '22 03:10

biziclop