#!/usr/bin/env perl # # Requires that the directory $outdir exists under the current # directory. $outdir is defined in the top of the file. # # After execution, $outdir will contain intake, discharge, and parking # tables. $exited percent of the tickets will appear in the discharge # table, the rest will have their associated licenses in the parking # table. # use strict; use warnings; use DateTime; use DateTime::Format::Strptime; my $outdir = 'inputs'; my $ndigits = 8; # ndigits in number of tickets; 3 = 1000 tickets my $exited = 0.9; # fraction of cars which have exited the lot my @chars = ('a'..'z', '0'..'9'); my @states = ('ma', 'ma', 'ma', 'ma', 'ma', 'ma', 'ct', 'nh', 'vt'); my @stays = (30, 60, 180, 240, 300, 1400, 2881); my $format = DateTime::Format::Strptime->new(pattern => '%F %H:%M', time_zone => 'floating'); my $in = DateTime->new(year => 2008, month => 2, day => 1, hour => 9, minute => 0, second => 0, time_zone => 'floating', formatter => $format); sub rand_license { my $len = shift; my $s; $s .= $chars[rand @chars] foreach 1 .. $len; return $s; } open(INTAKE, ">$outdir/intake") or die("Cannot open intake"); open(DISCHARGE, ">$outdir/discharge") or die("Cannot open discharge"); open(PARKING, ">$outdir/parking") or die("Cannot open parking"); sub rand_state { return $states[rand @states]; } my $spot = 1; my $limit = 10 ** ($ndigits - 1); for(my $i = 1; $i <= $limit; ++$i) { my $license = rand_license(8); my $state = rand_state(); printf INTAKE "ticket%0*d\t$license $state $in\n", $ndigits, $i; if($i <= $exited * $limit) { my $out = $in->clone; $out->add(minutes => $stays[rand @stays]); printf DISCHARGE "ticket%0*d\t$out\n", $ndigits, $i; } else { printf PARKING "spot%0*d\t$license\n", $ndigits, $spot++; } $in->add(minutes => 5); if($i % ($limit / 100) == 0) { printf STDERR "%d%% done\n", $i / ($limit / 100); } }