/* 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: cyclic.cc 10061 2011-03-16 12:46:53Z herr $
*/

#include "polymake/client.h"
#include "polymake/Rational.h"
#include "polymake/Matrix.h"

namespace polymake { namespace polytope {

perl::Object cyclic(int d, int n, int x_start)
{
   if ((d < 2) || (d >= n)) {
      throw std::runtime_error("cyclic: d >= 2 and n > d required\n");
   }

   perl::Object p("Polytope<Rational>");
   p.set_description() << "Cyclic " << d << "-polytope on " << n << " vertices" << endl;

   Matrix<Rational> vertices(n,d+1);
   Rational* v=concat_rows(vertices).begin();

   // and now we compute n points (x_i^1,..,x_i^d) on the momentum curve in R^d
   for (int i=0, x=x_start;  i<n;  ++i, ++x) {
      *v++ = 1;
      Integer power_of_x(1);
      for (int j = 1; j <= d; ++j) {
         power_of_x *= x;
         *v++ = power_of_x;
      }
   }

   p.take("CONE_AMBIENT_DIM") << d+1;
   p.take("CONE_DIM") << d+1;
   p.take("N_VERTICES") << n;
   p.take("VERTICES") << vertices;
   p.take("BOUNDED") << true;
   return p;
}
   
UserFunction4perl("# @category Producing from scratch"
                  "# Produce a //d//-dimensional cyclic polytope with //n// points."
                  "# Prototypical example of a neighborly polytope.  Combinatorics completely known"
                  "# due to Gale's evenness criterion.  Coordinates are chosen on the moment curve"
                  "# at integer steps from //start//, or 0 if not specified."
                  "# @param Int d the dimension"
                  "# @param Int n the number of points"
                  "# @param Int start"
                  "# @return Polytope",
                  &cyclic, "cyclic($$;$=0)");
} }

// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
