#include "parser.h"
#include "printer.h"
#include "polynomial.h"
#include "division.h"
#include "buchberger.h"
#include "wallideal.h"
#include "lp.h"
#include "reversesearch.h"
#include "termorder.h"
#include "ep_standard.h"
#include "ep_xfig.h"
#include "polyhedralcone.h"
#include "gfanapplication.h"


class GroebnerConeApplication : public GFanApplication
{
  SimpleOption optionRestrict;
  FieldOption theFieldOption;
public:
  const char *helpText()
  {
    return "This program extracts the defining inequalities for a full-dimensional Groebner cone given a marked minimal Groebner basis. If the Groebner basis is not reduced the computed cone is not a true Groebner cone but a subset of it. In other words the computed cone is the closure of all points picking out the leading terms.\n";
  }
  GroebnerConeApplication():
    optionRestrict("--restrict","Add an inequality for each coordinate, so that the the cone is restricted to the positive orthant.") 
  {
    registerOptions();
  }

  char *name()
  {
    return "_groebnercone";
  }

  int main()
  {
    LpSolver::printList(Stderr);
    lpSetSolver("cddgmp");
        
    PolynomialSet g;

    g=FileParser(Stdin).parsePolynomialSet();
    g.scaleMarkedCoefficientsToOne();

    PolynomialSet wall;	
    IntegerVectorList normals=wallInequalities(g);
    //    IntegerVectorList flipableNormals=wallFlipableNormals(g);

    if(!normals.empty())
      if(optionRestrict.getValue())
	{
	  int n=normals.begin()->size();
	  for(int i=0;i<n;i++)
	    normals.push_back(IntegerVector::standardVector(n,i));
	}

    AsciiPrinter(Stdout).printVectorList(normals);
	
    return 0;
  }
};

static GroebnerConeApplication theApplication;

