#  Copyright (c) 1997-2006
#  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: azove.rules 7394 2006-07-20 10:04:39Z joswig $

# path to the "azove" executable
custom $azove;

CONFIGURE {
   $azove=find_via_path("azove")
   or die "'azove' program not found\n";
}

object RationalPolytope;

# Category: 0/1-polytopes
# Use the @see external.azove program for counting 0/1-points in a polytope.
label azove

azove.01points: N_01POINTS : AMBIENT_DIM, FACETS | INEQUALITIES, AFFINE_HULL | EQUATIONS
   my $dim = $this->AMBIENT_DIM;
   my @ineqs = convert_to_integer($this->FACETS|INEQUALITIES);
   if (defined (my $AFFINE_HULL=$this->lookup("AFFINE_HULL | EQUATIONS"))) {
     my @eqs = convert_to_integer($AFFINE_HULL);
     my @neg_eqs= map { negative($_) } @eqs;
     push @ineqs, @eqs, @neg_eqs;
   }
   my $f = @ineqs;

# write the ine-file
   my $tempname=new Poly::Tempfile;
   open(P, ">$tempname.ine")
     or die "can't create temporary file $tempname.ine: $!";
   print P "* Automatically generated by polymake.\n";
   print P "H-representation\n";
   print P "begin\n", $f, " ", $dim+1, " integer\n";
   print P @ineqs; # polymake and azove have the same format
   print P "end\n";
   close P;

# call azove
   open P, "azove -c $tempname.ine 2>&1 |"
   or die "couldn't run azove: $!";
   while (<P>) {
      if (my ($n)=/^Number of 0\/1 vertices =\s+(\d+)/) {
	$this->N_01POINTS=$n;
	close P;
	return;
      }
   }
   die "can't parse output from azove";


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