#include <gecode/driver.hh>
#include <gecode/int.hh>
#include <gecode/minimodel.hh>

using namespace Gecode;

class CumulativesTest : public Script {
public:
  IntVarArray x;
  CumulativesTest(const Options&) : x(*this,6,0,10) {
    IntArgs m(3, 0,0,0);
    IntArgs p(3, 5,5,10);
    IntArgs u(3, -2,-9,10);
    IntArgs c(1,0);
    IntVarArgs start(3);
    start[0]=x[0];
    start[1]=x[1];
    start[2]=x[2];
    IntVarArgs end(3);
    end[0]=x[3];
    end[1]=x[4];
    end[2]=x[5];

    rel(*this, start[0] <= 4);
    rel(*this, start[1] <= 5);
    rel(*this, start[2] == 0);

    for (int i=0; i<3; i++)
      rel(*this, start[i]+p[i]==end[i]);

    cumulatives(*this, m,start,p,end,u,c,false);

    branch(*this, end, INT_VAR_MAX_MAX, INT_VAL_MAX);
    branch(*this, start, INT_VAR_MIN_MIN, INT_VAL_MIN);
  }

  CumulativesTest(bool share, CumulativesTest& s) : Script(share,s) {
    x.update(*this, share, s.x);
  }

  virtual Space*
  copy(bool share) {
    return new CumulativesTest(share,*this);
  }

  /// Print solution
  virtual void
  print(std::ostream& os) const {
    os << x << std::endl;
  }
};

int
main(int argc, char* argv[]) {
  Options opt("CumulativesTest");
  opt.parse(argc,argv);
  Script::run<CumulativesTest,DFS,Options>(opt);
  return 0;
}
