#  Copyright (c) 1997-2004
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-----------------------------------------------------------------------------
#  $Project: polymake $$Id: rand_polytopes,v 1.2 2004/06/22 18:46:47 gawrilow Exp $

application 'polytope';

# This is a call example:
# my @p=generate_random_spheres(10, 4, 20); print_n_facets(@p); save_max_facets(@p);

# n_polytopes, dimension, n_vertices (in each) => list of RationalPolytope
sub generate_random_spheres($$$) {
   my ($n, $d, $n_vert)=@_;

   my @polytopes;

   for (my $i=0; $i<$n; ++$i) {
      $polytopes[$i]=new Apps::polytope::RationalPolytope("rand_$i");
      Apps::polytope::client("rand_sphere", $polytopes[$i], $d, $n_vert, "-seed", $i*100);
      $polytopes[$i]->commit;
   }

   return @polytopes;
}

# list of polytopes =>
sub print_n_facets {
   my @n_facets=map { $_->N_FACETS } @_;
   print "@n_facets\n";
}

# list of polytopes => saves the polytope with the most facets in a file
sub save_max_facets {
   my $p=shift;
   # construct the file name from the dimension and the number of vertices
   my $filename= "max_facets_" . $p->DIM . "_" . $p->N_VERTICES;
   my $n_facets=$p->N_FACETS;
   foreach (@_) {
      $p=$_ if $_->N_FACETS > $n_facets;
   }
   save($p, $filename, 1);
}

1

# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
