How we can use a decision variable as an index of another decision variable using ILOG CP optimizer in python?

342 Views Asked by At

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

1

There are 1 best solutions below

1
Dekker1 On

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).