Skip to content
Permalink
Browse files

move project

  • Loading branch information...
bretonics committed Jan 11, 2019
1 parent 6d0e0b3 commit e15c5627fce1af771e2d5fc283443940d9ef7733

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,24 @@
A 380
B 374
C 366
D 329
E 244
F 241
G 242
H 160
I 193
J 253
K 176
L 100
M 77
N 80
O 161
P 151
Q 199
R 226
S 170
T 92
U 80
V 85
W 165
Z 0
@@ -0,0 +1,25 @@
A B C D E F G H I J K L M N O P Q R S T U V W Z
A 0 71 0 0 0 0 0 0 0 151 0 0 0 0 0 0 0 0 0 0 0 0 0 0
B 71 0 75 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
C 0 75 0 118 0 0 0 0 0 140 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D 0 0 118 0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
E 0 0 0 111 0 70 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
F 0 0 0 0 70 0 75 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
G 0 0 0 0 0 75 0 120 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
H 0 0 0 0 0 0 120 0 146 0 0 138 0 0 0 0 0 0 0 115 0 0 0 0
I 0 0 0 0 0 0 0 146 0 80 0 97 0 0 0 0 0 0 0 0 0 0 0 0
J 151 0 140 0 0 0 0 0 80 0 99 0 0 0 0 0 0 0 110 0 0 0 75 0
K 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 0 0 211
L 0 0 0 0 0 0 0 138 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 101
M 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90
N 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 98 142 0 0 0 0 0 0 85
O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 86 0 0 0 0 0 0 0 0
P 0 0 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0 0 0 0 98 142 0 0 0 85
O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 86 0 0 0 0 0
P 0 0 0 0 0 0 0 0 0 0 0 0 0 98 86 0 0 0 0 0 0
Q 0 0 0 0 0 0 0 0 0 0 0 0 0 142 0 0 0 92 0 0 0
R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 92 0 87 0 0
S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 87 0 0 0
T 0 0 0 0 0 0 0 115 0 0 0 0 0 0 0 0 0 0 0 0 0
Z 0 0 0 0 0 0 0 0 0 0 211 101 90 85 0 0 0 0 0 0 0
@@ -0,0 +1,21 @@
A 380
B 374
C 366
D 329
E 244
F 241
G 242
H 160
I 193
J 253
K 176
L 100
M 77
N 80
O 161
P 151
Q 199
R 226
S 234
T 92
Z 0
@@ -16,7 +16,6 @@

import java.io.*;
import java.util.*;
import java.util.Scanner;


public class project {
@@ -34,11 +33,12 @@ public static void main(String[] args) throws IOException {
// Input files
Scanner graphFile = new Scanner(new File("graph_input.txt")); // graph file object
Scanner distanceFile = new Scanner(new File("direct_distance.txt")); // distance file object
// Scanner graphFile = new Scanner(new File("original.txt")); // graph file object
// Scanner distanceFile = new Scanner(new File("original_dd.txt")); // distance file object

// Data structures for adjacency graph and direct distance information
String[][] graph = parseGraph(graphFile); // Parse graph file
Map<String, Integer> distances = parseDistance(distanceFile); // Parse direct distance file

ArrayList<String> vertexNames = getVertices(graph); // get vertex names
String startNode = promptUser(vertexNames); // prompt user for start node

@@ -53,20 +53,26 @@ public static void main(String[] args) throws IOException {
* @return String[][] adjacency matrix of graph in string format.
*/
public static String[][] parseGraph(Scanner file) {
String[][] matrix = new String[26][26];
String[][] matrix = new String[27][26];
// String[][] returnMatrix = matrix;
int i = 0; // start of edges in each row

// Process graph file
while (file.hasNext()) { // loop every line
String line = file.nextLine(); // Get line as string
String[] values = line.split("\\s+"); // Split line by space(s)
int nNodes = values.length;
// Get each vertex's edge weight -
// Skip first column (j = 1), vertex names, which have already
// been captured in 1st row
for (int j = 1; j < nNodes; j++) {
String edge = values[j];
matrix[i][j-1] = edge; // need -1 because we want to store starting at index = 0
ArrayList<String> values = new ArrayList<String>();
String[] elements = line.split("\\s+"); // Split line by space(s)
// Get elements from line and store in ArrayList
for (int k = 0; k < elements.length; k++) {
values.add(elements[k]);
}
values.remove(0); //remove first element (spaces or node in row)
int nValues = values.size();
// .removeAll(Collections.singleton(null));
// Get each vertex's edge weight
for (int j = 0; j < nValues; j++) {
String edge = values.get(j);
matrix[i][j] = edge;
}
i++;
}
@@ -131,7 +137,7 @@ public static void shortestPath(String[][] graph, Map<String, Integer> distances
// Value == edge distance int
for (int e = 0; e < numVertices; e++) {
String vertex = vertexNames.get(e); // current vertex name
int edge = Integer.parseInt(graph[n+1][e]); // n + 1 required since index start at 0 column == vertex names
int edge = Integer.parseInt(graph[n+1][e]); // get edge value
// Store only connecting edges
if (edge != 0) {
// Make sure node to add is not one previously stored as being a "dead end"
@@ -155,10 +161,29 @@ public static void shortestPath(String[][] graph, Map<String, Integer> distances
nextNode = previousNode; // reset node back to previous node (backtrack)
deadEnd = currentNode; // set node that was "dead end"
} else {
// DETERMINE NEXT NODE IN PATH -- Algorithm dependent
previousNode = path.get(path.size()-1); // store previous node's vertex name
nextNode = smallest(adjacentNodes, distances, algorithm); // get next node of shortest path
// Check if next node to traverse already in path, keep getting new until unique
while (path.contains(nextNode)) {
// Skip first node entered
if (adjacentNodes.size() == 1) {
break;
}
adjacentNodes.remove(nextNode); // remove nextNode from testing traversal
// shortestPath.remove(nextNode); // remove nextNode from testing traversal
// DETERMINE NEXT NODE IN PATH -- Algorithm dependent
nextNode = smallest(adjacentNodes, distances, algorithm); // get next node of shortest path
System.out.println("\t Next node chosen ---> " + nextNode);
}
System.out.println("Adding next node '" + nextNode + "' to paths");
if (path.size() > 1) {
previousNode = path.get(path.size()-2); // store previous node's vertex name
} else {
previousNode = path.get(path.size()-1); // store previous node's vertex name
}
System.out.println("Previous node " + previousNode);

shortestPath.put(nextNode, adjacentNodes.get(nextNode)); // add selected node to shortest path
previousNode = path.get(path.size()-1); // store previous node's vertex name
path.add(nextNode); // add selected node to overall path
}
if (nextNode.equals("Z")) { break; } // exit once at node Z
Binary file not shown.
@@ -10,4 +10,4 @@ Projects
- [7](https://github.com/bretonics/MSSD/tree/master/CS526/Homework/7)
- [8](https://github.com/bretonics/MSSD/tree/master/CS526/Homework/8)
- [9](https://github.com/bretonics/MSSD/tree/master/CS526/Homework/9)
- [Project](https://github.com/bretonics/MSSD/tree/master/CS526/Homework/tests)
- [Project](https://github.com/bretonics/MSSD/tree/master/CS526/Project)

0 comments on commit e15c562

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.