Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. protected static <V, E> void shortestPathLinhasL(Graph<V, E> g, V vOrig, V[] vertices,boolean[] visited, int[] pathKeys, double[] dist) {
  2.  
  3. int vkey = g.getKey(vOrig);
  4. dist[vkey] = 0;
  5.  
  6. while (vkey != -1) {
  7. vOrig = vertices[vkey];
  8. visited[vkey] = true;
  9. Set<String> linhaprev =new LinkedHashSet<String>();
  10. for (Edge<V, E> edge : g.outgoingEdges(vOrig)) {
  11. V vAdj = g.opposite(vOrig, edge);
  12. int vkeyAdj = g.getKey(vAdj);
  13. double tempo=0;
  14.  
  15. Conexao x =(Conexao) edge.getElement();
  16.  
  17.  
  18. if(!linhaprev.isEmpty())
  19. {
  20. if(!(linhaprev.contains(x.getLinha().getCodigo())))
  21. {
  22. tempo=1;
  23. }
  24. else
  25. {
  26. tempo=0;
  27. }
  28. }
  29. linhaprev.add(x.getLinha().getCodigo());
  30.  
  31. if (!visited[vkeyAdj] && dist[vkeyAdj] > dist[vkey] + tempo) {
  32. dist[vkeyAdj] = dist[vkey] + tempo;
  33. pathKeys[vkeyAdj] = vkey;
  34.  
  35. }
  36. }
  37.  
  38. double minDist = Double.MAX_VALUE;
  39. vkey = -1;
  40.  
  41. for (int i = 0; i < g.numVertices(); i++) {
  42.  
  43. if (!visited[i] && dist[i] < minDist) {
  44. minDist = dist[i];
  45. vkey = i;
  46. }
  47.  
  48. }
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement