APCS/12 Graphs/06-07 Dijkstra_s Algorithm/AdjListWeighted.java
Rushil Umaretiya 3fc3554899 initial commit
2020-12-04 22:00:49 -05:00

85 lines
2.1 KiB
Java

// Name:
// Date:
import java.util.*;
import java.io.*;
/* Resource classes and interfaces
* for use with Graphs6: Dijkstra
* Graphs7: Dijkstra with Cities
*/
class Edge
{
public final wVertex target; //if it's public, you don't need accessor methods
public final double weight; //if it's public, you don't need accessor methods
public Edge(wVertex argTarget, double argWeight)
{
target = argTarget;
weight = argWeight;
}
}
interface wVertexInterface
{
String getName();
double getMinDistance();
void setMinDistance(double m);
//wVertex getPrevious(); //for Dijkstra 7
//void setPrevious(wVertex v); //for Dijkstra 7
ArrayList<Edge> getAdjacencies();
void addEdge(wVertex v, double weight);
int compareTo(wVertex other);
}
class wVertex implements Comparable<wVertex>, wVertexInterface
{
private final String name;
private ArrayList<Edge> adjacencies;
private double minDistance = Double.POSITIVE_INFINITY;
//private wVertex previous; //for building the actual path in Dijkstra 7
/* enter your code for this class here */
}
interface AdjListWeightedInterface
{
List<wVertex> getVertices();
Map<String, Integer> getNameToIndex();
wVertex getVertex(int i);
wVertex getVertex(String vertexName);
void addVertex(String v);
void addEdge(String source, String target, double weight);
void minimumWeightPath(String vertexName); //Dijkstra's
}
/* Interface for Graphs 7: Dijkstra with Cities
*/
interface AdjListWeightedInterfaceWithCities
{
List<String> getShortestPathTo(wVertex v);
AdjListWeighted graphFromEdgeListData(File vertexNames, File edgeListData) throws FileNotFoundException ;
}
public class AdjListWeighted implements AdjListWeightedInterface //,AdjListWeightedInterfaceWithCities
{
private List<wVertex> vertices = new ArrayList<wVertex>();
private Map<String, Integer> nameToIndex = new HashMap<String, Integer>();
//the constructor is a no-arg constructor
/* enter your code for Graphs 6 */
/* enter your code for two new methods in Graphs 7 */
}