ps2n3 - 3. Algorithm: 01. function schedule(V, E), times)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/12/2012 for the course CS 4820 taught by Professor Kleinberg during the Spring '08 term at Cornell University (Engineering School).

Page1 / 2

ps2n3 - 3. Algorithm: 01. function schedule(V, E), times)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online