[gecode-users] Understanding cumulatives constraint

Roberto Pinto librarama at gmail.com
Mon Jul 3 19:17:57 CEST 2006


Dear all,

I'm trying to compile a really basic example using the cumulatives
constraint, but I'm finding some problems that I hope you could help
me to solve.
My code is obtained starting from queens.cc, from which I inherited
the main structure changing the constraints.
I want to schedule 4 independent tasks on a single machine, which can
work one task at a time.

Hereby the complete and commented code:

/// START CODE---------------------------------------------------------------------
// Very basic scheduling problem.
#include "examples/support.hh"
#include "gecode/minimodel.hh"

class BasicScheduling : public Example {
protected:
  IntVarArray q; //starting date
  IntVarArray e; //ending date

public:
  /// The actual problem
  BasicScheduling(const Options& opt)
    : q(this,4,0,20), e(this,4,0,20) ///for this example, I assumed only 4 tasks
      {

      IntArgs height(4);
      IntArgs duration(4);
      IntArgs limit(1);
      IntArgs machine(4); ///let me understand: in this array, each
element represents the
///the machine assigned to a job, right?

      for (int i = 0; i < 4; i++)
            {
            height[i] = 1;    ///each task requires 1 unit of resource
per period
            duration[i] = 4;  /// each task lasts 4 periods
                                   ///that is, each task requires 4
resource units over 4 periods
            machine[i] = 1;  ///all tasks are worked on machine 1
            }

            limit = 1;            ///the machine has only one resource
unit per period

      for(int i = 0; i<4; i++)
            post(this, e[i] - duration[i] = q[i] );
///the ending date depends on the starting date and the duration

/// that's all?
            cumulatives(this, machine, q, duration, e, height,  limit, true);

///Ok, in this case I could use cumulative constraint for a single
machine, but I want to ///extend the problem to more than 1 machines

    branch(this, q, BVAR_SIZE_MIN, BVAL_MIN);
 }

  /// Constructor for cloning
///Indeed, I did not understand its purpose
  BasicScheduling(bool share, BasicScheduling& s) : Example(share,s) {
    q.update(this, share, s.q);
    e.update(this, share, s.e);
  }

  /// Perform copying during cloning
/// same comment as above, I just cut&paste from queens.cc
  virtual Space*
  copy(bool share) {
    return new BasicScheduling(share,*this);
  }

  /// Print solution
///doh, that's clear!!!
  virtual void
  print(void) {
    std::cout << "\t";
    for (int i = 0; i < q.size(); i++) {
      std::cout << q[i] << ":"<<e[i]<<", ";
      if ((i+1) % 10 == 0)
	std::cout << std::endl << "\t";
    }
    std::cout << std::endl;
    }
};

int
main(int argc, char** argv) {
  Options opt("BasicScheduling");
  opt.iterations = 2000;
  opt.size       = 4;
  opt.c_d        = 5;
  opt.parse(argc,argv);
  Example::run<BasicScheduling,DFS>(opt);
  return 0;
}

///END CODE--------------------------------------------------------

I was expecting a solution like:
0:4, 5:9, 10:14, 15:19

instead I obtained:
0:4, 0:4, 0:4, 0:4

that is, it seems that all jobs are worked in parallel, while my
intention was to work them serially. I concluded I misinterpreted the
cumulatives constraint.
Can you help me using this constraint? maybe, can you provide me with
a working example (amending my code, for example :-) )

Thank you for you help.

Best wishes
Libra




More information about the gecode-users mailing list