3. Algorithm:
01. function schedule((V, E), times)
02.
let n = |times|
03.
sort times by pickup time
04.
V' = {}
05.
E' = {}
06.
07.
for i=0,n do
08.
for j=0,n do
09.
if i != j then
10.
// Assuming lookup in the times set is constant as is
adding vertices into V'
11.
// this operation will take O(n^2) time
12.
let a,b,c = times[i][src], times[i][dest], times[j]
[src]
13.
add the vertex (a,b,c, times[i][time]) into V'
14.
end
15.
end
16.
end
17.
18.
foreach (a,b,c, t) in V' do
19.
foreach (a',b',c', t') in V' do
20.
if (a,b,c) != (a',b',c') and c == a' and t+D(a,b)+D(b,c) <=
t'
then
21.
// Assuming distance calculation is constant as is
adding edges into E'
22.
// this operation will take O(n^4) time
23.
let cost be the t + D(a,b) + D(b,c)
24.
add the edge ((a,b,c,t),(a',b',c',t'), cost) into E'
25.
end
26.
end
27.
end
28.
29.
// Since a vertex will only connect to another if its ending time is <=
to the starting time of
30.
// the other, this ensures that there can be no cycles since earlier
31.
// nodes can only connect to later nodes but those later nodes can never
connect to a node even
32.
// earlier so that it could create a cycle.
33.