Google OR-Tools get vehicle last assigned node with callback

50 views
Skip to first unread message

Luca Maini

unread,
Jul 11, 2024, 8:42:29 AMJul 11
to or-tools-discuss

Hi i'm working on vehicle routing problem with Google or_tool library. i'm building a dynamical constraint that requires knowing the last node assigned to a vehicle. Is possible get the last node with a UnaryTransitCallback? How to do it? Are there other ways?

I tried with simple callback:

int StartIndexCallBack = routing.RegisterUnaryTransitCallback((long fromIndex) => { return fromIndex; });

but i don't know how to use it.

Thanks for your support.

Laurent Perron

unread,
Jul 11, 2024, 8:43:30 AMJul 11
to or-tools...@googlegroups.com
this is forbidden. Callbacks are stateless.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/537e609d-cdbd-4b8b-90fd-e59a55cd51den%40googlegroups.com.

blind.lin...@gmail.com

unread,
Jul 11, 2024, 11:22:05 AMJul 11
to or-tools...@googlegroups.com

If by last node you mean the one just prior to the current node, then just use the regular transit callback. Then you know both the prior and the current node.

James

-- You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.


To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/537e609d-cdbd-4b8b-90fd-e59a55cd51den%40googlegroups.com.

--
James E. Marca  
Activimetrics LLC  
signature.asc

Luca Maini

unread,
Jul 12, 2024, 2:27:12 AM (14 days ago) Jul 12
to or-tools-discuss
Thanks for your reply.
I try to explain my condition better. In my routing problem nodes belong to different zones (a zone can be contain different nodes), each zone is characterised by a maximum limit of vehicles that can pass through it at the same time (for example if the limit is set to 1 only one vehicle for time can execute a mission in that zone). I tried to solve this problem by introducing a MakeFixedDurationIntervalVar, for each node in the same zone, which blocks execution for a duration equal to the duration of the transit from the old node (belonging to the vehicle) until the arrival of the node in the zone. The duration must be calculated dynamically  because at the start I know neither the vehicle nor the last node assign to the vehicle.
I tried in this way but i don't know how to use the callback in this context:
int maxMissions = 1;
long duration = 0;
Solver solver = routing.solver();
for (int i = 0; i < data.Zones.Count; ++i)
{
    IntervalVar[] intervals = new IntervalVar[data.Zones[i].Length];
    for (int j = 0; j < data.Zones[i].Length; ++j)
    {
        // get index
        long missionIndex = manager.NodeToIndex(data.Zones[i][j]);
        long StartIndex = callback node....
        duration = data.TimeMatrix[StartIndex, missionIndex];
        // Add load duration at start of routes
        intervals[j] = solver.MakeFixedDurationIntervalVar(timeDimension.CumulVar(StartIndex), duration, "interval_engaged");
    }

    long[] resource_usage = Enumerable.Repeat<long>(1, intervals.Length).ToArray();
    solver.Add(solver.MakeCumulative(intervals, resource_usage, maxMissions, "SharedRessource"));
}

Thanks for your support.
Reply all
Reply to author
Forward
0 new messages