Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package getPathSequential;
- import java.util.ArrayList;
- import java.util.concurrent.ExecutorService;
- public class MyRunnable implements Runnable {
- ArrayList<Integer> partialPath;
- int destination;
- ExecutorService tpe;
- public static int cnt = 0;
- public MyRunnable(ExecutorService tpe, ArrayList<Integer> path, int dest) {
- this.partialPath = path;
- this.tpe = tpe;
- this.destination = dest;
- }
- @Override
- public void run() {
- if (partialPath.get(partialPath.size() - 1) == destination) {
- System.out.println(partialPath);
- cnt++;
- if (cnt >= 6)
- tpe.shutdown();
- }
- // Try to add all possible next nodes that do not create a cycle.
- int lastNodeInPath = partialPath.get(partialPath.size() - 1);
- for (int i = 0; i < Main.graph.length; i++) {
- if (Main.graph[i][0] == lastNodeInPath) {
- if (partialPath.contains(Main.graph[i][1]))
- continue;
- ArrayList<Integer> newPartialPath = (ArrayList<Integer>) partialPath.clone();
- newPartialPath.add(Main.graph[i][1]);
- tpe.submit(new MyRunnable(tpe, newPartialPath, destination));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement