Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package getPathSequential;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.concurrent.ExecutorService;
  5.  
  6. public class MyRunnable implements Runnable {
  7. ArrayList<Integer> partialPath;
  8. int destination;
  9. ExecutorService tpe;
  10. public static int cnt = 0;
  11.  
  12. public MyRunnable(ExecutorService tpe, ArrayList<Integer> path, int dest) {
  13. this.partialPath = path;
  14. this.tpe = tpe;
  15. this.destination = dest;
  16. }
  17.  
  18. @Override
  19. public void run() {
  20. if (partialPath.get(partialPath.size() - 1) == destination) {
  21. System.out.println(partialPath);
  22. cnt++;
  23. if (cnt >= 6)
  24. tpe.shutdown();
  25.  
  26. }
  27.  
  28. // Try to add all possible next nodes that do not create a cycle.
  29. int lastNodeInPath = partialPath.get(partialPath.size() - 1);
  30. for (int i = 0; i < Main.graph.length; i++) {
  31. if (Main.graph[i][0] == lastNodeInPath) {
  32. if (partialPath.contains(Main.graph[i][1]))
  33. continue;
  34. ArrayList<Integer> newPartialPath = (ArrayList<Integer>) partialPath.clone();
  35. newPartialPath.add(Main.graph[i][1]);
  36. tpe.submit(new MyRunnable(tpe, newPartialPath, destination));
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement