1

I am modeling a vehicle routing and scheduling problem using CP. I have 2 kinds of decision variables, that is, sequencing and start time of each node.

The sequencing variable contains the node number, and start time of each node depends on the order it is traveled. Thus, I require to use sequencing variable as an index of start time variables.

But I got this error:

 <docplex.cp.expression.CpoIntVar object at 0x0000022A9E070C70>

It is how I write my code:

x={d:sub.integer_var_list(n[d],0, len(I)-1,"X") for d in D}
start={d:{i:sub.interval_var(start=[t[0][i],T-p[i,d]-t[i][len(I)-1]],size=p[i,d]) for i in C[d]} for d in D}

sub.add(sub.sum(sub.end_of(start[d][x[d][n[d]-2]]),t[x[d][n[d]-2]][x[d][n[d]-1]])<=T)

I appreciate you to help me in this regard

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41

1 Answers1

0

An indexing operation using a decision variable in constraint programming can be implemented using an element global constraint. The documentation for the element constraint in CP Optimiser's Python interface can be found here: https://ibmdecisionoptimization.github.io/docplex-doc/cp/docplex.cp.modeler.py.html#docplex.cp.modeler.element

This means that instead of y = x[i] where i is a variable, you would instead write y = model.element(x, i).

Dekker1
  • 5,565
  • 25
  • 33
  • Thanks for your response. But, unfortunately, I couldn't understand how can I use it I read the document but I could't solve it. @Dekker1 could you please make an example for this constraint how can I use element : sub.add(sub.sum(sub.end_of(start[d][x[d][n[d]-2]]),t[x[d][n[d]-2]][x[d][n[d]-1]])<=T) – Saeede Hosseini Mar 18 '21 at 05:28