#!/usr/local/bin/perl -w # permalistgen # # makes alist matrices based on permutations. # # bizarre version which makes a top row of "w" big I's # and a bottom row of P's. # # the max weight per row is e.g. 24 ("l") # the max weight per col is 2 # # Nl defines the size of one of the Ps # # write them to code/GHC, please # # the perms are constructed assuming that Nl+1 is a prime and Nl is even. # permarand.p uses random perms. # # here are some primes # # 101 # 211 # 223 # 227 # 307 # 401 # 503 # 1009 # 1277 # 2003 # 2131 # 2137 # 3001 # 4001 # 5003 # 10007 $seed = 0 ; $l = 24 ; $w = 3 ; # weight per row of the gallager part eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; print STDERR "setting t to 2\n" ; $t = 2 ; srand ( $seed ) ; $N = int ( $Nl * $l ) ; $NNN = $N / $w ; $M = $Nl + $NNN ; if ( $N * $M <= 0 ) { print "usage: \n permalist24.p w=3 l=24 Nl=100 seed=0 > alist.file (Nl+1 prime, l should be divisible by w)\n" ; exit(0); } $head = $N." ".$M."\n" ; $head .= $t." ".$l."\n" ; $head .= "$t "x$N ; $head .= "\n" ; $head .= "$w "x$NNN ; # top N/3 rows have weight 3 $head .= "$l "x$Nl ; # the rest are weight 24 $head .= "\n" ; print $head ; # make null lists for ( $n = 1 ; $n <= $N ; $n ++ ) { $nlist[$n] = "" ; $numnlist[$n] = 0 ; } for ( $m = 1 ; $m <= $M ; $m ++ ) { $mlist[$m] = "" ; $nummlist[$m] = 0 ; } sub nullperm { for ( $nl = 1 ; $nl <= $Nl ; $nl ++ ) { $fto[$nl] = 0 ; } } sub checkperm { for ( $nl = 1 ; $nl <= $Nl ; $nl ++ ) { if ( $fto[$nl] != 1 ) { print STDERR "perm $q not valid $nl\n" ; for ( $n = 1 ; $n <= $Nl ; $n ++ ) { print STDERR "$n to $p[$n]\n" ; } exit(0) ; } } } # the first N/3 rows for ( $nl = 1 ; $nl <= $NNN ; $nl ++ ) { $n = $nl ; $m = $nl ; for ( $ww = 1 ; $ww <= $w ; $ww ++ , $n += $NNN ) { # put m and n on each others lists $nlist[$n] .= $m."\t" ; $mlist[$m] .= $n."\t" ; $numnlist[$n] ++ ; $nummlist[$m] ++ ; } } for ( $q = 0 ; $q <= $Nl ; $q ++ ) { $usedq[$q] = 0 ; } $usedq[1] = 1 ; $usedq[0] = 1 ; $usedq[$Nl] = 1 ; for ( # define what the offset of our square is $moff = $NNN , $noff = 0 , $ll = 1 ; $ll <= $l ; $ll ++ , $noff += $Nl ) { do { $q = int ( rand (( $Nl -1 )/2.0) ) + 1 ; } while ( $usedq[$q] ) ; $usedq[$q] ++ ; print STDERR "--- $q ---\n" ; # invent a perm &nullperm(); for ( $nl = 1 ; $nl <= $Nl ; $nl ++ ) { $from = $nl ; $to = ( $nl * $q ) % ( $Nl + 1 ) ; $p[$from] = $to ; $fto[$to] ++ ; } &checkperm(); # put in this perm &permadd(); } # append zeros to short lines for ( $n = 1 ; $n <= $N ; $n ++ ) { while ( $numnlist[$n] < $t ) { $nlist[$n] .= "0\t" ; $numnlist[$n] ++ ; } } for ( $m = 1 ; $m <= $M ; $m ++ ) { while ( $nummlist[$m] < $l ) { $mlist[$m] .= "0\t" ; $nummlist[$m] ++ ; } } sub permadd { for ( $nl = 1 ; $nl <= $Nl ; $nl ++ ) { $n = $noff + $nl ; $m = $p[$nl] + $moff ; # put m and n on each others lists $nlist[$n] .= $m."\t" ; $mlist[$m] .= $n."\t" ; $numnlist[$n] ++ ; $nummlist[$m] ++ ; } } # finish lists for ( $n = 1 ; $n <= $N ; $n ++ ) { $nlist[$n] =~ s/\t$/\n/ ; print $nlist[$n] ; } for ( $m = 1 ; $m <= $M ; $m ++ ) { $mlist[$m] =~ s/\t$/\n/ ; print $mlist[$m] ; }