#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.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 9502 2010-02-24 00:26:29Z gawrilow $

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

CONFIGURE {
   find_via_path($azove, "azove2") || find_via_path($azove, "azove");
}

# @topic credits/azove
# azove is a tool designed for counting (without explicit enumeration) and enumeration of 0/1 vertices.
# Copyright by Markus Behle
# http://www.mpi-inf.mpg.de/~behle/azove.html

object Polytope<Rational> {

# @Category 0/1-polytopes
# Use the [[wiki:external_software#azove|azove]] program for counting 0/1-points in a polytope.
label azove

rule azove.points01: N_01POINTS : AMBIENT_DIM, FACETS | INEQUALITIES, AFFINE_HULL | EQUATIONS {
   my $dim = $this->AMBIENT_DIM;
   my $ineqs = eliminate_denominators($this->FACETS|INEQUALITIES);
   if (defined (my $AFFINE_HULL=$this->lookup("AFFINE_HULL | EQUATIONS"))) {
     my $eqs = eliminate_denominators($AFFINE_HULL);
     $ineqs /= $eqs / (-$eqs);
   }

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

# call azove
   open P, "$azove -c $tempname.ine 2>&1 |"
   or die "couldn't run $azove: $!";
   local $_;
   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:
