forked from RainerYuan/Teamex4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphProcessor.java
More file actions
123 lines (112 loc) · 4.78 KB
/
Copy pathGraphProcessor.java
File metadata and controls
123 lines (112 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;
/**
* This class adds additional functionality to the graph as a whole.
*
* Contains an instance variable, {@link #graph}, which stores information for all the vertices and edges.
* @see #populateGraph(String)
* - loads a dictionary of words as vertices in the graph.
* - finds possible edges between all pairs of vertices and adds these edges in the graph.
* - returns number of vertices added as Integer.
* - every call to this method will add to the existing graph.
* - this method needs to be invoked first for other methods on shortest path computation to work.
* @see #shortestPathPrecomputation()
* - applies a shortest path algorithm to precompute data structures (that store shortest path data)
* - the shortest path data structures are used later to
* to quickly find the shortest path and distance between two vertices.
* - this method is called after any call to populateGraph.
* - It is not called again unless new graph information is added via populateGraph().
* @see #getShortestPath(String, String)
* - returns a list of vertices that constitute the shortest path between two given vertices,
* computed using the precomputed data structures computed as part of {@link #shortestPathPrecomputation()}.
* - {@link #shortestPathPrecomputation()} must have been invoked once before invoking this method.
* @see #getShortestDistance(String, String)
* - returns distance (number of edges) as an Integer for the shortest path between two given vertices
* - this is computed using the precomputed data structures computed as part of {@link #shortestPathPrecomputation()}.
* - {@link #shortestPathPrecomputation()} must have been invoked once before invoking this method.
*
* @author sapan (sapan@cs.wisc.edu)
*
*/
public class GraphProcessor {
/**
* Graph which stores the dictionary words and their associated connections
*/
private GraphADT<String> graph;
/**
* Constructor for this class. Initializes instances variables to set the starting state of the object
*/
public GraphProcessor() {
this.graph = new Graph<>();
}
/**
* Builds a graph from the words in a file. Populate an internal graph, by adding words from the dictionary as vertices
* and finding and adding the corresponding connections (edges) between
* existing words.
*
* Reads a word from the file and adds it as a vertex to a graph.
* Repeat for all words.
*
* For all possible pairs of vertices, finds if the pair of vertices is adjacent {@link WordProcessor#isAdjacent(String, String)}
* If a pair is adjacent, adds an undirected and unweighted edge between the pair of vertices in the graph.
*
* @param filepath file path to the dictionary
* @return Integer the number of vertices (words) added
*/
public Integer populateGraph(String filepath) {
return 0;
}
/**
* Gets the list of words that create the shortest path between word1 and word2
*
* Example: Given a dictionary,
* cat
* rat
* hat
* neat
* wheat
* kit
* shortest path between cat and wheat is the following list of words:
* [cat, hat, heat, wheat]
*
* @param word1 first word
* @param word2 second word
* @return List<String> list of the words
*/
public List<String> getShortestPath(String word1, String word2) {
return null;
}
/**
* Gets the distance of the shortest path between word1 and word2
*
* Example: Given a dictionary,
* cat
* rat
* hat
* neat
* wheat
* kit
* distance of the shortest path between cat and wheat, [cat, hat, heat, wheat]
* = 3 (the number of edges in the shortest path)
*
* @param word1 first word
* @param word2 second word
* @return Integer distance
*/
public Integer getShortestDistance(String word1, String word2) {
return null;
}
/**
* Computes shortest paths and distances between all possible pairs of vertices.
* This method is called after every set of updates in the graph to recompute the path information.
* Any shortest path algorithm can be used (Djikstra's or Floyd-Warshall recommended).
*/
public void shortestPathPrecomputation() {
}
}