/* Copyright (c) 1997-20034
   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.
*/

#ident "$Project: polymake $$Id: dwarfed_cube.cc,v 1.4 2004/06/22 16:23:09 gawrilow Exp $"

#include <cstdlib>
#include <Rational.h>
#include <Poly.h>
#include <Matrix.h>

namespace polymake {
namespace polytope {

  void dwarfed_cube(Poly& p, int dim)
  {
    Matrix<Rational> F(2*dim+1,dim+1);
    Rows<Matrix <Rational> >::iterator f=rows(F).begin();
    for (int i=1; i<=dim; ++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") << dim;
    p.take("DIM") << dim;
    p.take("FACETS") << F;
    p.take("BOUNDED") << true;
    p.take("POSITIVE") << true;
  }
} }

using namespace polymake;

/** @file dwarfed_cube
 *
 *  Produce a $d$-dimensional dwarfed-cube.
 *
 *  @synopsis dwarfed_cube <file> <d>
 *
 *  @writing  AMBIENT_DIM, DIM, FACETS, BOUNDED, POSITIVE
 *
 *  @index clients Producing from scratch
 */

int main(int argc, const char *argv[]) {
   if (argc != 3) {
      cerr << "usage: " << argv[0] << " <file> <dimension>" << endl;
      return 1;
   }
   try {
      const int d=atoi(argv[2]);	// dimension
      if (d <= 1) {
	 cerr << argv[0] << ": d > 1" << endl;
	 return 1;
      }

      Poly p(argv[1], ios::out | ios::trunc);
      polytope::dwarfed_cube(p,d);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}
