Hi Milad,
I found a few more issues in the python model that I overlooked...
First: constraints need to be added explicitly to the model. This applies to the following statements (where
mdl.add(...)
was initially missing):
for v in Vehicles:
mdl.add(mdl.no_overlap(Q[v], distance_matrix))
# mdl.add(mdl.no_overlap(Q[v]))
and:
for v in Vehicles:
mdl.add(mdl.presence_of(x_i_k[(0,v)])==1)
mdl.add(mdl.presence_of(x_i_k[(11,v)])==1)
mdl.add(mdl.first(Q[v], x_i_k[(0,v)]))
mdl.add(mdl.last(Q[v], x_i_k[(11,v)]))
Then, I'm not sure to follow your formulation for the objective. I think the following formulation is expected:
# obj=sum((TravelDistance[t, t] * mdl.type_of_next(Q[v], x_i_k[(t, v)], t, t)) for v in Vehicles for t in CustomersDepot)
obj=sum((mdl.element([TravelDistance[t, t_dest] for t_dest in CustomersDepot], mdl.type_of_next(Q[v], x_i_k[(t, v)], t, t)) for v in Vehicles for t in CustomersDepot))
Unfortunately, after implementing these changes the model is unfeasible...
If the distance matrix in the
no_overlap
constraint is removed, the model becomes feasible.
I'm afraid there may be some data issues in the distance matrix or the start/end for intervals that makes the model unfeasible.
If you have a working OPL model, you should try to compare these data to understand where the difference is coming from...
Also, use text format when sharing models, if possible. That would make things much easier on my side to try to replicate your issues :-)
Best regards,
Hugues
------------------------------
Hugues Juille
------------------------------
Original Message:
Sent: Tue May 03, 2022 01:39 PM
From: milad faramarzzadeh
Subject: Python_Docplex.CP
Dear Hugues,
I really appreciate for the reply.
Yes you are right, after changing the mentioned ones, that part of model works but it shows another error in no overlap constraint and most probably typeOfNext is incorrect as well (attached the file)! I should derive the d(i)(j) parameter from my distance matrix and the second index value (j) should be entered as the typeofnext function to be able to derive the next customer, the vehicle visits after customer but sadly I can not code it properly! I would be really glad if you check these parts too. As already I mentioned my code in OPLE works correctly and I can share text version if you need. I think problems are just adopting nooverlap and typeofnext.
Best regards,
------------------------------
milad faramarzzadeh
Original Message:
Sent: Tue May 03, 2022 08:52 AM
From: Hugues Juille
Subject: Python_Docplex.CP
Hi Milad,
Thanks for sharing your OPL model (but I would have preferred a text version :-) ).
In your python model, the start
and end
bounds for interval variables x_i_k
and y_i
are not defined properly.
You should replace their definition as follows:
iv=mdl.interval_var(start=(ReadyTime[t], INTERVAL_MAX), end=(0, DueTime[t]), size=ser[t])
and
y_i[t]=mdl.interval_var(start=(ReadyTime[t], INTERVAL_MAX), end=(0, DueTime[t]), size=ser[t])
start
and end
are pairs of values that define the bounds for the interval (the documentation can be found here: https://rawgit.com/IBMDecisionOptimization/docplex-doc/master/docs/cp/docplex.cp.expression.py.html#docplex.cp.expression.interval_var).
After making that changes, the python model find an optimal solution.
Best regards,
Hugues
------------------------------
Hugues Juille
Original Message:
Sent: Mon May 02, 2022 04:17 PM
From: milad faramarzzadeh
Subject: Python_Docplex.CP
Dear Hugues,
Thanks a lot for the reply.
In fact my code works in OPL correctly. I attached it and you can take a short look on it.
Best regards,
------------------------------
milad faramarzzadeh
Original Message:
Sent: Mon May 02, 2022 09:12 AM
From: Hugues Juille
Subject: Python_Docplex.CP
Hi Milad,
Actually, running the conflict refiner on your model, the following conflict is returned:
alternative(intervalVar(start=95, end=125, size=10), [intervalVar(optional, start=95, end=125, size=10), intervalVar(optional, start=95, end=125, size=10), intervalVar(optional, start=95, end=125, size=10)])
In fact, there is a problme in the definition of your task intervals since there are all infeasible (if you do want to define: start
, end
and size
, then one should have: end = start + size
)
Best regards,
Hugues
------------------------------
Hugues Juille
Original Message:
Sent: Mon May 02, 2022 05:35 AM
From: milad faramarzzadeh
Subject: Python_Docplex.CP
Hi,
In my code typeOfNext works in OPL but I have problem about adapting 'typeOfNext' in python, I would be glad if you give me idea!
Cplex_using CP:
tuple triplet { int id1; int id2; int value; };
{triplet} M = { <i,j,d[i][j]> | i in nodes, j in nodes }
dvar sequence Q [v in w] in all (i in nodes)x[i][v]types all (i in nodes) i
dexpr int c = sum (k in w,i in 0..nnodes) (d[i][typeOfNext(Q[k],x[i][k],i,i)]);
Python_docplex.CP:
Please find it in attachment.
------------------------------
milad faramarzzadeh
------------------------------