From e98ea582a7a8153646fc4dbebd16e09b37cfe185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonia=20P=C3=A9rez-Cerezo?= Date: Mon, 22 Apr 2024 16:50:46 +0200 Subject: [PATCH] Added scripts to create this dataset --- scripts/README.md | 34 ++++++++++++++ scripts/triangulation_bookkeeping.pl | 28 ++++++++++++ scripts/triangulation_bookkeeping_minimal.pl | 45 +++++++++++++++++++ scripts/triangulation_bookkeeping_output.pl | 47 ++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 scripts/README.md create mode 100755 scripts/triangulation_bookkeeping.pl create mode 100755 scripts/triangulation_bookkeeping_minimal.pl create mode 100755 scripts/triangulation_bookkeeping_output.pl diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..8970b42 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,34 @@ +## Scripts to filter out unique minimal triangulaitons + +These scripts dig through directories to find triangulations, take the +minimal ones, remove duplicates, and then export them, sorted by PL-type. + + +### Prerequisites + +- Polymake +- PostgreSQL + +### How to use: + +Create the database tables + +``` +CREATE TABLE triangulations (signature varchar, f_vector varchar, vertices integer, path varchar); +CREATE TABLE minimal_triangulations (signature varchar, f_vector varchar, vertices integer, path varchar); +``` + +Populate the triangulations table + +``` +find ~ -name *.poly -not -path "*comb_iso_classes*" -not -path "*flat*" | parallel --progress ./triangulation_bookkeeping.pl {} +``` + +Populate the minimal triangulations (by vertices) table by finding the +minimum triangulation for each signature + +``` +INSERT INTO minimal_triangulations SELECT DISTINCT ON (signature) * FROM triangulations ORDER BY signature, vertices +``` + +Remove combinatorially isomorphic triangulations by running `triangulation_bookkeeping_minimal.pl`, and output sorted by type using `triangulation_bookkeeping_output.pl` diff --git a/scripts/triangulation_bookkeeping.pl b/scripts/triangulation_bookkeeping.pl new file mode 100755 index 0000000..9858b49 --- /dev/null +++ b/scripts/triangulation_bookkeeping.pl @@ -0,0 +1,28 @@ +#!/usr/local/bin/polymake --script + +# Initialize table with triangulations + +use application "topaz"; +use strict; +use warnings; +use DBI; + +my $dbh = DBI->connect("dbi:Pg:dbname=researchdata_test", '', '', {AutoCommit => 0}); +my $sth = $dbh->prepare("INSERT INTO triangulations VALUES (?, ?, ?, ?);"); + +my $path = shift; + +$path =~ m,([^/]+)\.poly$,; + +my $regdesc = $1; + +my $q=load_data("$path"); + +my $vert = @{$q->F_VECTOR}[0]; + + +$sth->execute($regdesc, "@{$q->F_VECTOR}", $vert, $path); +$dbh->commit; + + +# after this run INSERT INTO minimal_triangulations SELECT DISTINCT ON (signature) * FROM triangulations ORDER BY signature, vertices ; to get a table of minimal triangulations of each complex diff --git a/scripts/triangulation_bookkeeping_minimal.pl b/scripts/triangulation_bookkeeping_minimal.pl new file mode 100755 index 0000000..df93eef --- /dev/null +++ b/scripts/triangulation_bookkeeping_minimal.pl @@ -0,0 +1,45 @@ +#!/usr/local/bin/polymake --script + +### removes duplicate (combinatorially isomorphic) triangulations + +use application "topaz"; +use strict; +use warnings; +use DBI; + +my $dbh = DBI->connect("dbi:Pg:dbname=researchdata_test", '', '', {AutoCommit => 0}); +my $vst = $dbh->prepare("SELECT DISTINCT(vertices) FROM minimal_triangulations"); +my $pst = $dbh->prepare("SELECT path FROM minimal_triangulations WHERE vertices = (?)"); +my $pathdel = $dbh->prepare("DELETE FROM minimal_triangulations WHERE path = (?)"); + + + +$vst->execute(); + +while (my @data = $vst->fetchrow_array) { + my $vert = shift @data; + print("$vert\n"); + my %complexes = (); + $pst->execute($vert); + while (my @data = $pst->fetchrow_array ) { + my $path = shift @data; + $complexes{$path} = load_data("$path"); + } + my @ck = keys %complexes; + + foreach (keys %complexes) { + my $c = shift @ck; + foreach (@ck) { + if (defined $complexes{$_} and defined $complexes{$c} and isomorphic($complexes{$c}, $complexes{$_})) { + print "$c $_ \n"; + $pathdel->execute($_); + delete($complexes{$_}); + } + } + } +} + + +$dbh->commit; + + diff --git a/scripts/triangulation_bookkeeping_output.pl b/scripts/triangulation_bookkeeping_output.pl new file mode 100755 index 0000000..ca30844 --- /dev/null +++ b/scripts/triangulation_bookkeeping_output.pl @@ -0,0 +1,47 @@ +#!/usr/local/bin/polymake --script + +### Outputs minimal triangulations into sorted directories + +use application "topaz"; +use strict; +use warnings; +use DBI; +use File::Copy; + +my $dbh = DBI->connect("dbi:Pg:dbname=researchdata_test", '', '', {AutoCommit => 0}); +my $types = $dbh->prepare("SELECT DISTINCT(type) FROM complexes;"); ## select the types + + + +my $paths = $dbh->prepare("SELECT signature,vertices,path FROM minimal_triangulations WHERE signature IN (SELECT signature FROM complexes WHERE type = (?));"); + + +my $outdir = "minimal_triangulations"; +if (! -d $outdir ) { + mkdir $outdir +} + +$types->execute; +while (my @data = $types->fetchrow_array) { + my $type = shift @data; + if (not $type eq "") { + print "$type\n"; + $paths->execute($type); + if (! -d "$outdir/$type" ) { + mkdir "$outdir/$type"; + } + while (my @p = $paths->fetchrow_array) { + my $sig = shift @p; + my $vert = shift @p; + if (! -d "$outdir/$type/$vert" ) { + mkdir "$outdir/$type/$vert"; + } + my $path = shift @p; + copy($path,"$outdir/$type/$vert/$sig.poly"); + } + } +} + + +$dbh->commit; +