#include "newtonpolytope.h"

#include "lp.h"


IntegerVectorList newtonPolytope(Polynomial const &p)
{
  IntegerVectorList polytope;

  for(TermMap::const_iterator i=p.terms.begin();i!=p.terms.end();i++)
    {
      polytope.push_back(i->first.exponent);      
    }

  // redundancy check:
  
  assert(!polytope.empty());

  int n=polytope.begin()->size();

  for(IntegerVectorList::iterator j=polytope.begin();j!=polytope.end();j++)
    {
      j->resize(n+1);
      (*j)[n]=1;
    }

  for(IntegerVectorList::iterator j=polytope.begin();j!=polytope.end();j++)
    if(!isFacet(polytope,j))
      {
	IntegerVectorList::iterator k=j;
	j++;
	polytope.erase(k);
	j--;
      }
  
  for(IntegerVectorList::iterator j=polytope.begin();j!=polytope.end();j++)
    j->resize(n);
  
  return polytope;
}
