implementations of domino shuffling algorithm - MathOverflow most recent 30 from http://mathoverflow.net2013-05-26T09:02:52Zhttp://mathoverflow.net/feeds/question/40445http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://mathoverflow.net/questions/40445/implementations-of-domino-shuffling-algorithmimplementations of domino shuffling algorithmJohn Mangual2010-09-29T07:47:42Z2012-01-06T08:42:22Z
<p>Are there many implementations of the "domino shuffling" algorithm as found in <a href="http://front.math.ucdavis.edu/9801.5068" rel="nofollow">math.CO/9801068</a>? This topic may be out of fashion now but I wonder if any source code is circulating. I'm doing it myself, but I always have this fear of "reinventing the wheel".</p>
http://mathoverflow.net/questions/40445/implementations-of-domino-shuffling-algorithm/40448#40448Answer by Aaron Meyerowitz for implementations of domino shuffling algorithmAaron Meyerowitz2010-09-29T08:14:47Z2010-09-29T08:14:47Z<p>There is <a href="http://faculty.uml.edu/jpropp/tiling/www/applets/" rel="nofollow">http://faculty.uml.edu/jpropp/tiling/www/applets/</a> but you should ask Jim Propp.</p>
http://mathoverflow.net/questions/40445/implementations-of-domino-shuffling-algorithm/84860#84860Answer by James Propp for implementations of domino shuffling algorithmJames Propp2012-01-04T05:03:16Z2012-01-04T05:03:16Z<p>I use <a href="http://halcanary.org/mathapplets/toadshuffle/toadshuffle-v1.3/" rel="nofollow">http://halcanary.org/mathapplets/toadshuffle/toadshuffle-v1.3/</a> by Hal Canary. (The reference Aaron Meyerowitz gave is for generating random tilings via coupling-from-the-past, which is quite different from domino-shuffling.)</p>
http://mathoverflow.net/questions/40445/implementations-of-domino-shuffling-algorithm/84906#84906Answer by Benjamin Young for implementations of domino shuffling algorithmBenjamin Young2012-01-04T21:48:54Z2012-01-06T08:42:22Z<p>Here is one which produces ASCII art aztec diamond tilings. It's written in perl. As I recall, I wrote it as fast as possible, without making any attempt to do it efficiently, because I needed to make some pictures really quickly.</p>
<pre><code>#!/usr/bin/perl -w
use strict;
#=================================================================
sub delete_odd_blocks($) {
my $diamond = shift;
for my $r (0..scalar @$diamond - 2) {
my $c = index($$diamond[$r], "--" );
while($c != -1) {
if(substr($$diamond[$r+1], $c, 2) eq "==") {
substr($$diamond[$r], $c, 2) = "BB";
substr($$diamond[$r+1], $c, 2) = "BB";
}
$c = index($$diamond[$r], "--", $c + 2);
}
$c = index($$diamond[$r], "!|" );
while($c != -1) {
if(substr($$diamond[$r+1], $c, 2) eq "!|") {
substr($$diamond[$r], $c, 2) = "BB";
substr($$diamond[$r+1], $c, 2) = "BB";
}
$c = index($$diamond[$r], "!|", $c + 2);
}
}
}
#=================================================================
sub slide($) {
my $diamond = shift;
my $N = scalar @$diamond; # $N rows in the diamond
die "$N is an odd number" if($N % 2);
my (@output);
for my $r (0..$N/2) {
my $row = " "x$r . "A" x($N - 2*$r+2) . " "x$r;
push @output, $row;
unshift @output, $row;
}
push @$diamond, " "x $N;
for my $r (0..scalar @$diamond - 1) {
my $c = index($$diamond[$r], "|" );
while($c != -1) {
if(substr($$diamond[$r+1], $c, 1) eq "|") {
substr($output[$r+1], $c, 1) = "|";
substr($output[$r+2], $c, 1) = "|";
}
$c = index($$diamond[$r], "|", $c + 1);
}
$c = index($$diamond[$r], "!" );
while($c != -1) {
if(substr($$diamond[$r+1], $c, 1) eq "!") {
substr($output[$r+1], $c+2, 1) = "!";
substr($output[$r+2], $c+2, 1) = "!";
}
$c = index($$diamond[$r], "!", $c + 1);
}
$c = index($$diamond[$r], "--" );
while($c != -1) {
substr($output[$r+2], $c+1, 2) = "--";
$c = index($$diamond[$r], "--", $c + 2);
}
$c = index($$diamond[$r], "==" );
while($c != -1) {
substr($output[$r], $c+1, 2) = "==";
$c = index($$diamond[$r], "==", $c + 2);
}
}
pop @$diamond;
\@output;
}
#=================================================================
sub fill_even_blocks($) {
my $diamond = shift;
for my $r (0..scalar @$diamond - 2) {
my $c = index($$diamond[$r], "AA" );
while($c != -1) {
if(substr($$diamond[$r+1], $c, 2) eq "AA") {
if(rand() < 0.5) {
substr($$diamond[$r],$c,2) = "==";
substr($$diamond[$r+1],$c,2)= "--";
} else {
substr($$diamond[$r],$c,2) = "|!";
substr($$diamond[$r+1],$c,2)= "|!";
}
}
$c = index($$diamond[$r], "AA", $c + 2);
}
}
}
my $dimers;
if(rand() < 0.5) {
$dimers = ["|!", "|!"];
} else {
$dimers = ["==", "--"];
}
my $n = shift or die "Tell me the order of the diamond please\n";
for(1..$n-1) {
delete_odd_blocks($dimers);
$dimers = slide($dimers);
fill_even_blocks($dimers);
}
for (@$dimers) {
print "$_\n"
}
</code></pre>
<p>Here is a sample of the output (the outcome of running "perl shuffle 5" on the command line, if you called this script shuffle):</p>
<pre><code> ==
====
|!|!==
||!|!--!
|||!|!==!!
|||!|!!|!!
||--!!|!
||!!--
|!--
--
</code></pre>
<p>The domino shuffling algorithm has four types of dominoes: northbound, southbound, eastbound and westbound. I use "==", "--", for the northbound, southbound ones; two | symbols for the westbound ones and two ! for the eastbound ones. </p>
<p>This script, as I recall, was the first link in a tool chain which produced the following image of the height function of an Aztec Diamond (this link will eventually go stale, but it should be good for a year or two anyway):<img src="http://www.math.kth.se/~benyoung/order51.png" alt="Order 51 Aztec Diamond"></p>