Created
March 26, 2016 00:58
-
-
Save daspecster/96e8115aa37e2e06ced2 to your computer and use it in GitHub Desktop.
Working on BFT adjacent matrix with bfranco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.io.*; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
public class BFT { | |
public static boolean[]avail = new boolean [48]; // tells me whether or not a state has been used yet | |
public static int[][] dataSet = new int[48][48]; // prefilled adjacency matrix | |
public static String[] statesList = new String[48]; // prefilled list of states | |
public static void bft(int state){ | |
int cur; | |
Queue<Integer> q = new LinkedList<Integer>(); | |
q.offer(state); | |
avail[state] = false; | |
while (q.size() > 0){ | |
cur = q.remove(); | |
System.out.println(statesList[cur]); | |
for (int k = 0; k < 48; k++){ | |
if(avail[k] && dataSet[cur][k] == 1){ | |
//this is where I had the code that would output the "Found a path" in the outputDebug.txt | |
q.offer(k); | |
avail[k]=false; | |
k = 48; | |
} | |
} | |
} | |
} | |
public static void readFile () throws FileNotFoundException{ | |
Scanner scanner = new Scanner(new File("adjGraph.txt")); | |
for (int x = 0; x < dataSet[0].length; x++){ | |
for (int y = 0; y < dataSet.length; y++ ){ | |
dataSet[x][y] = scanner.nextInt(); | |
} | |
} | |
scanner = new Scanner(new File("states.txt")); | |
for (int x = 0; x < statesList.length; x++){ | |
statesList[x] = scanner.nextLine(); | |
} | |
for (int x = 0; x < avail.length; x++){ | |
avail[x] = true; | |
} | |
} | |
public static void main(String[] args) throws FileNotFoundException{ | |
readFile(); | |
bft(16); // 16 represents the node / state we want to start in (maine) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment