/* 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: knapsack.cc 9588 2010-03-19 10:22:46Z joswig $
*/

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

namespace polymake { namespace polytope {

perl::Object knapsack(const Vector<Rational> b)
{
  const int d = b.dim()-1;
  if (d < 1)
    throw std::runtime_error("knapsack: dimension d >= 1 required");

  perl::Object p("Polytope<Rational>");
  p.set_description() << "knapsack " << b << endl;

  Matrix<Rational> F = b / (zero_vector<Rational>(d) | unit_matrix<Rational>(d));
    
  p.take("AMBIENT_DIM") << d;
  p.take("INEQUALITIES") << F;
  p.take("BOUNDED") << true;

  return p;
}

UserFunction4perl("# @category Producing from scratch"
		  "# Produce a knapsack polytope defined by one linear inequality (and non-negativity constraints)."
		  "# "
		  "# @param Vector<Rational> b linear inequality"
		  "# @return Polytope",
		  &knapsack, "knapsack");
} }
