4
$\begingroup$

I'm trying to solve an RCPSPDc problem in OR-Tools with CP-SAT solver.

In my RCPSPDc model (with discount rate) i want to set this objective: $$\max_{s}\sum_{j\in J}\text{profit}_{j}\cdot \frac{1}{(1+\alpha)^{s_{j}}}$$ $s$ is my vector of variables, each element saves the value where the job $j\in J$ begins, i'm modeling this as an interval variable. $\alpha$ is the discount rate. Actually, I can't use float values in the objective and can't power values to an IntVar (OR-Tools don't permit), so I'm following a similar approach to the model with binary variable, but using the same variable $s$, and rounding the values.

I want to create a vector $\rm obj$ of size $N_{jobs}\cdot t_\max$ (number of jobs and horizon) and save as IntVar the precomputed expression $\textbf{w}$ of the sum with a boolean expression: s[j]==t, so it can be activated only in that case.

I did this:

 std::vector<IntVar> obj_final(nbTasks*tmax);
    for (int j = 0; j < nbTasks; ++j)
    {
        for (int t = 0; i < tmax; ++t)
        {
            const IntVar expr = cp_model.NewIntVar(Domain(-1000000000000000000,10000000000000000));
            const BoolVar bl = cp_model.NewBoolVar();
            cp_model.AddEquality(bl, starts[j]==actual_t);
            cp_model.AddEquality(round(w[j][i],expr).OnlyEnforceIf(bl);
            obj_final.push_back(expr);
        }
    }

but obviously it doesn't work because of the constraint of starts[j]==t (start of the interval variable $j$).

I tried to enforce it in that way:

cp_model.AddEquality(round(w[j][i],expr).OnlyEnforceIf(s[j]==t);

but OnlyEnforceIf takes only BoolVars and not bool.

How can I assign a value to a BoolVar as we do with IntVar -> cp_model.NewConstant()?

How can I make it to finally set as an objective the sum of all the elements in the vector that I created?

Thanks for reading.

$\endgroup$
3
  • 2
    $\begingroup$ For a given j, why don't you precompute [profit_j * 1/(1 + alpha)^x for x in range(0, horizon)]. Then just use model.AddElement(profit_var[j], precomputed_profit_array, start_j). $\endgroup$ Jan 22, 2020 at 16:14
  • $\begingroup$ sounds good but what exactly does AddElement, what is an element constraint? $\endgroup$ Jan 22, 2020 at 16:51
  • 1
    $\begingroup$ books.google.es/… and google.github.io/or-tools/cpp_sat/… $\endgroup$
    – Stradivari
    Jan 22, 2020 at 17:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.