// system includes
#include <math.h>
#include <iostream.h>
#include <stdlib.h>

// openGL includes
#include <GL/gl.h>
#include <GL/glu.h>

// gprims utility library: need definition of max_flt, etc.
#include "gprims/vector.H"

// local includes
#include "drawutils.H"
#include "lpsol.H"
#include "constraint.H"
#include "object.H"
#include "optfxn.H"
#include "/home/lebo/6.838/linprog/lp.h"

/* creates a linear programming problem with 4 constraints and an
   optimization function */
Lpsol::Lpsol ( Constraint *constraints, int n_constraints, Float3 *optfxn ) {
  // initialize constraints
  _H = new Constraint[n_constraints];
  for (int i=0;i<n_constraints;i++) {
    _H[i] = constraints[i];
  }
  _nconstraints = n_constraints;
  // initialize optimization function
  _c = new Optfxn(optfxn);
  // initialize bounding box to go from -1->1 on all axes
  _bb = new BB(-1,1,-1,1,-1,1);
  // initialize solution
  _soln = new Soln(_bb);
}

/* draws indexed constraint within bounding box */
int
Lpsol::drawConstraint(int index, float r, float g, float b) {
  return _H[index].draw(r,g,b,_bb);
}

/* draws all constraints within bounding box */
int
Lpsol::drawConstraints(float r, float g, float b) {
  int ret = 1;
  for (int i=0; i<_nconstraints; i++) {
    if (!drawConstraint(i,r,g,b)) ret = 0;
  }
  return ret;
}

/* draws sphere at solution point */
int
Lpsol::drawSolution(float r, float g, float b) {
  return _soln->draw();
}

/* draws optimization function vector
   (seg from origin with sphere at arrow tip */
int
Lpsol::drawOptfxn(float r, float g, float b) {
  return _c->draw(_bb);
}

/* draws bounding box */
int
Lpsol::drawBB(float r, float g, float b) {
  return _bb->draw(r,g,b);
}



