I have been working on scenario for implementing single pickup and multiple delivery scenario. I am creating multiple shipments all having same pickup location. Using SoftRouteConstraint, I am able to assign all jobs belong to same customer/order to a single vehicle(if it has enough space).
Now, I need ability to add/ignore pickup service time conditionally. Example: for 1 pickup and 3 deliveries, let’s say we need 2 vehicles(Vehicle 1 - 2 pickups and Vehicle 2 - 1 pickup).
In this case, pickup service time for Vehicle 1 should be considered only for 1st pickup.
Is there a way to write a listener that can influence service time, arrival and end time of an activity?
You can add this pickup time in TravelTime,
i.e: modifiedTravelTime (A-B) = travelTime(A-B) + pickup/delivery Time @ A
I cannot add pickup time while creating Shipment using Shipment.Builder. This will add pickup time for every shipment. Rather, I need a hook/listener while the engine is solving a problem. Similar to hard/soft constraints which influences the outcome of the solution.
I have tried to set ArrivalTime/EndTime of pickup activity using SoftActivityConstraint. But this doesn’t seem to have any impact on solution output.
If I understand your problem correctly, you want a constant service time at each location. Which is independent of number of shipments picked up/dropped at that location?
I want constant service at location independent of number of shipments at particular location for a vehicle.
Example: Let’s say, 4 Tons of load need to moved from a pickup point to 3 delivery points. Let’s assume JSprit assigns 2 vehicles to do this job. (Vehicle1 - 3 shipments and Vehicle2 - 1 shipment). In this case, constant service time need to be assigned to each vehicle independent of number of shipments.
You can account for constant service time by modifying travel time between two locations and making service time for each shipment as 0.
modifiedTravelTime (A-B) = travelTime(A-B) + service Time @ A
In your example: let pickup location be P, and delivery location D1,D2 and D3.
for each pair(P,D*) or (D*,D’) or (D*,P) increase travel time by service time of source location.
i.e: Modified TravelTime(P,D*) = TraelTime(P,D*) + service time @ P.
Once you get the result you can do post processing to get actual times.
Does it make sense?
I don’t think this approach would work. I need ability to add service time for first pickup the vehicle does at particular location. Subsequent pickup service times needs to be ignored for a particular vehicle.
When applied to my example: (Vehicle1 - 3 shipments and Vehicle2 - 1 shipment). Vehicle 1 should be assigned pickup service time for first shipment and it needs to be ignored for other 2 shipments.
I need ability to setArrTime or setEndTime of an activity, either through soft/hard constraint or ActivityVisitor. Even after changing arriving or end time in soft constraint or ActivityVisitor, JSpirit solver is ignoring the revised timings.
This is currently hard to model. @braktar has done work related to this. What you can do is that you set service time to zero and consider this in your transport time from A to B, i.e. t*(A,B)=t(A,B)+st(B) for all A != B where t(A,B) is the original transport time from A to B and st(B) is the service time for B. If A=B, t*(A,B)=t(A,B).
Oh just saw that @Bhoumik_Shah proposed exactly what I just suggested :). Thanks @Bhoumik_Shah :).
Thanks @Bhoumik_Shah and @stefan,
Can you please help me in understanding on where should I write this logic ?
I tried changing arrival and end time of activity using setArrTime or setEndTime methods in soft/hard constraint as well as ActivityVisitor. Somehow, JSpirit solver is ignoring these revised timings.
You don’t have to write logic proposed by @stefan and me
All you need to do is make service time zero for all the shipments and modify travel time between each location as:
You shoud never manipulate setArrTime and setEndTime.
As mentionned @Bhoumik_Shah, you could model the service time contraction as a delay to reach a new location directly in the time matrix.
I’ve worked on such feature and called it “SetupTime” which is equivalent to a preparation time once we arrive to a new location and seems to meet your requirement.
I’ve just updated it !
So you can define the setup time instead of service time in the problem definition
Last time I faced the problem, what I did was similar to braktar’s setup time, but in a reverse manner:
I still used the same old transport time between locations with different coordinates, but used a negative transport time if two locations had the same coordinate.
There are two drawbacks in this approach:
number of locations is larger: locations with the same coordinates will no longer be the same location - they will bear different id and/or index so that I can identify them and impose negative transport time between them;
if there are time windows, they might be violated.
Thank you all. I was able to resolve the problem by making service time zero and modifying the travel time.
I will also tryout suggestion given by @braktar and @jie31best.