/* Copyright (c) 1997-2009
   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: dwarfed_cube.cc 9512 2010-02-28 22:24:19Z herr $
*/

#include <Rational.h>
#include <polymake.h>
#include <Matrix.h>

namespace polymake { namespace polytope {

perl::Object dwarfed_cube(int d)
{
   if (d < 2) {
      throw std::runtime_error("dwarfed_cube: d >= 2 required");
   }
   perl::Object p("Polytope<Rational>");
   p.set_description() << "dwarfed cube of dimension " << d << endl;

   Matrix<Rational> F(2*d+1,d+1);
   Rows<Matrix <Rational> >::iterator f=rows(F).begin();
   for (int i=1; i<=d; ++i) {
      //	 (*f)[0]=0;
      (*f)[i]=1;
      ++f;
      (*f)[0]=1;
      (*f)[i]=-1;
      ++f;
   }
      
   (*f).fill(-1);
   (*f)[0]=Rational(3,2);

   p.take("AMBIENT_DIM") << d;
   p.take("DIM") << d;
   p.take("FACETS") << F;
   p.take("BOUNDED") << true;
   p.take("POSITIVE") << true;
   return p;
}

UserFunction4perl("# @category Producing from scratch"
		  "# Produce a //d//-dimensional dwarfed cube."
		  "# @param Int d the dimension"
		  "# @return Polytope"
		  "# @author Thilo Rörig",
		  &dwarfed_cube, "dwarfed_cube($)");
} }
