5
$\begingroup$

I'm trying to solve an rcpsp model.

I can't find documentation for the AddCumulative function of OR-Tools. How should this function be used?

I want to write this constraint in C++: $$\forall k \in R,\quad\text{cumulative}(s, p_{j}, [r_{jk}\mid j\in J\mid R_{k}])$$ ($s$ is my decision variable, a vector that saves the period of when the job begins, $p_{j}$ is the duration of activity $j$, $r_{jk}$ is the amount of resource used by activity $j$ and $R_{k}$ is the capacity of the resource $k$ each day), but the OR-Tools module apparently takes only one argument, although I've seen some examples where it takes 3.

Actually, if I give the function the parameter RHS, which is the resource capacity (what it is asking for), I get this error:

no matching function for call to ‘operations_research::sat::CpModelBuilder::AddCumulative(int*&)’
     cp_model.AddCumulative(rhs);
                               ^

In addition, the command prompt says that RHS must be IntVar but is int. So, my question is, what is the capacity that the function must take? And what happens with the other values like IntervalVar and resource consumption by job?

$\endgroup$
1
  • $\begingroup$ What is the $p$? What is $R_k$? $\endgroup$
    – dhasson
    Jan 20 '20 at 18:30
7
$\begingroup$

If you look at OR-Tools: CumulativeConstraint, AddCumulative takes a variable as argument, so if it is constant, create a variable with a fixed domain.

It returns a CumulativeConstraint with a method to add (IntervalVar, DemandVar) pairs to the constraint. See OR-Tools 7.4: C++ Reference (CumulativeConstraint).

Note that the rcpcp solver is implemented in python here

Here is a C++ code snippet with the cumulative constraint:

  const IntervalVar x = cp_model.NewIntervalVar(cp_model.NewIntVar({0, 20}),
                                                cp_model.NewConstant(5),
                                                cp_model.NewIntVar({0, 20}));
  const IntervalVar y = cp_model.NewIntervalVar(cp_model.NewIntVar({0, 20}),
                                                cp_model.NewConstant(5),
                                                cp_model.NewIntVar({0, 20}));
  const IntVar a = cp_model.NewIntVar({5, 10});
  const IntVar b = cp_model.NewIntVar({5, 10});
  const IntVar c = cp_model.NewIntVar({5, 10});

  CumulativeConstraint cumul = cp_model.AddCumulative(a);
  cumul.AddDemand(x, b);
  cumul.AddDemand(y, c);
$\endgroup$
6
  • $\begingroup$ Thanks for the edit. $\endgroup$ Jan 20 '20 at 19:37
  • $\begingroup$ Thanks Laurent. The example is in python and the cumulative uses 3 arguments. is there another example in c++ using cumulative function? Im trying to create an object cumulative and using the method add for each job but i don't know how to declare it. $\endgroup$ Jan 21 '20 at 13:27
  • $\begingroup$ edited my answer to add a code snippet. $\endgroup$ Jan 21 '20 at 15:22
  • $\begingroup$ thanks, it works! $\endgroup$ Jan 21 '20 at 16:58
  • $\begingroup$ Hi Laurent, what should i do if i have multiple resources, its possible to create a vector of CumulativeConstraint objects (i tried). If i just declare them apparently the new object overwrites the previous one. Is there a way? $\endgroup$ Jan 27 '20 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.